@sdxc/kit 2026.10.20 → 2026.10.23

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 (138) hide show
  1. package/README.md +178 -93
  2. package/changelog.jsonl +97 -0
  3. package/config.schema.json +160 -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 +77 -2
  23. package/dist/commands/make.js +53 -1
  24. package/dist/commands/run.d.ts +15 -11
  25. package/dist/commands/run.js +21 -16
  26. package/dist/commands/scaffold.d.ts +2 -1
  27. package/dist/commands/scaffold.js +1 -0
  28. package/dist/commands/setup.d.ts +26 -0
  29. package/dist/commands/setup.js +33 -0
  30. package/dist/config.d.ts +54 -0
  31. package/dist/config.js +92 -1
  32. package/dist/contract.d.ts +56 -3
  33. package/dist/contract.js +140 -7
  34. package/dist/dependencies.d.ts +2 -1
  35. package/dist/dependencies.js +11 -2
  36. package/dist/deploy/plan.d.ts +5 -0
  37. package/dist/deploy/plan.js +10 -0
  38. package/dist/destroy.d.ts +4 -4
  39. package/dist/destroy.js +24 -11
  40. package/dist/diagram.d.ts +32 -0
  41. package/dist/diagram.js +47 -0
  42. package/dist/doctor/checks.d.ts +2 -1
  43. package/dist/doctor/checks.js +26 -1
  44. package/dist/doctor/complexity.d.ts +13 -0
  45. package/dist/doctor/complexity.js +52 -0
  46. package/dist/doctor/crap.d.ts +14 -0
  47. package/dist/doctor/crap.js +67 -0
  48. package/dist/doctor/dependencies.d.ts +13 -0
  49. package/dist/doctor/dependencies.js +42 -0
  50. package/dist/doctor/duplication.d.ts +19 -0
  51. package/dist/doctor/duplication.js +106 -0
  52. package/dist/doctor/fan-out.d.ts +12 -0
  53. package/dist/doctor/fan-out.js +42 -0
  54. package/dist/doctor/feature-scatter.d.ts +15 -0
  55. package/dist/doctor/feature-scatter.js +84 -0
  56. package/dist/doctor/jsdoc.d.ts +44 -0
  57. package/dist/doctor/jsdoc.js +201 -0
  58. package/dist/doctor/module-size.d.ts +13 -0
  59. package/dist/doctor/module-size.js +50 -0
  60. package/dist/doctor/mutation.d.ts +20 -0
  61. package/dist/doctor/mutation.js +97 -0
  62. package/dist/doctor/orphans.d.ts +13 -0
  63. package/dist/doctor/orphans.js +50 -0
  64. package/dist/doctor/project.js +8 -5
  65. package/dist/doctor/result-throws.d.ts +17 -0
  66. package/dist/doctor/result-throws.js +72 -0
  67. package/dist/doctor/test-ratio.d.ts +12 -0
  68. package/dist/doctor/test-ratio.js +31 -0
  69. package/dist/fix/commands.d.ts +37 -0
  70. package/dist/fix/commands.js +63 -0
  71. package/dist/fix/emails.d.ts +21 -0
  72. package/dist/fix/emails.js +159 -0
  73. package/dist/fix/env.d.ts +29 -0
  74. package/dist/fix/env.js +58 -0
  75. package/dist/fix/index.d.ts +11 -0
  76. package/dist/fix/index.js +11 -0
  77. package/dist/fix/models.d.ts +20 -0
  78. package/dist/fix/models.js +95 -0
  79. package/dist/lock.js +12 -2
  80. package/dist/make/binding.d.ts +42 -0
  81. package/dist/make/binding.js +237 -0
  82. package/dist/make/generate.d.ts +11 -2
  83. package/dist/make/generate.js +47 -16
  84. package/dist/make/imports.js +7 -5
  85. package/dist/make/index.d.ts +4 -2
  86. package/dist/make/index.js +4 -1
  87. package/dist/make/kinds.d.ts +5 -0
  88. package/dist/make/kinds.js +14 -2
  89. package/dist/make/schema-diff.js +8 -1
  90. package/dist/make/stubs.d.ts +7 -2
  91. package/dist/make/stubs.js +8 -3
  92. package/dist/make/test.js +1 -0
  93. package/dist/models.js +7 -7
  94. package/dist/routes/modules.js +8 -5
  95. package/dist/routes/parse.js +8 -7
  96. package/dist/routes/routers.js +9 -5
  97. package/dist/scaffold/index.d.ts +2 -0
  98. package/dist/scaffold/index.js +13 -4
  99. package/dist/scaffold/render.d.ts +11 -1
  100. package/dist/scaffold/render.js +86 -1
  101. package/dist/setup/auth.d.ts +12 -0
  102. package/dist/setup/auth.js +209 -0
  103. package/dist/setup/billing.d.ts +11 -0
  104. package/dist/setup/billing.js +116 -0
  105. package/dist/setup/catalog.d.ts +25 -0
  106. package/dist/setup/catalog.js +34 -0
  107. package/dist/setup/credit.d.ts +13 -0
  108. package/dist/setup/credit.js +21 -0
  109. package/dist/setup/flags.d.ts +11 -0
  110. package/dist/setup/flags.js +62 -0
  111. package/dist/setup/index.d.ts +25 -0
  112. package/dist/setup/index.js +53 -0
  113. package/dist/setup/plan.d.ts +38 -0
  114. package/dist/setup/plan.js +62 -0
  115. package/dist/testing.js +3 -3
  116. package/dist/ui/layout.js +1 -1
  117. package/dist/ui/registry.d.ts +2 -2
  118. package/dist/upgrade/project.d.ts +2 -2
  119. package/dist/upgrade/prompt.js +7 -5
  120. package/package.json +10 -7
  121. package/registry/ui/attachment.json +2 -2
  122. package/registry/ui/sidebar.json +3 -3
  123. package/registry/ui/typeset.json +3 -3
  124. package/stubs/command.spec.stub +15 -0
  125. package/stubs/controller.api.spec.stub +15 -0
  126. package/stubs/controller.spec.stub +15 -0
  127. package/stubs/mcp.spec.stub +16 -0
  128. package/stubs/scaffold.migration.stub +2 -1
  129. package/stubs/scaffold.spec.stub +7 -0
  130. package/templates/app/AGENTS.md +21 -4
  131. package/templates/app/README.md +6 -3
  132. package/templates/app/app/commands/typegen.test.ts +20 -1
  133. package/templates/app/app/commands/typegen.ts +16 -2
  134. package/templates/app/app/initializers/cli.ts +7 -0
  135. package/templates/app/app/initializers/mail-transport.test.ts +8 -2
  136. package/templates/app/app/test/cloudflare-workers.ts +2 -0
  137. package/templates/app/package.json +1 -0
  138. package/templates/app/spec/config.jsonc +16 -0
@@ -6,20 +6,33 @@
6
6
  * @author [Sergio Xalambrí](https://sergiodxa.com)
7
7
  * @copyright Sergio Xalambrí 2026
8
8
  */
9
+ import { complexityCheck } from "./complexity.js";
10
+ import { crapCheck } from "./crap.js";
11
+ import { dependenciesCheck } from "./dependencies.js";
12
+ import { duplicationCheck } from "./duplication.js";
9
13
  import { emailsCheck } from "./emails.js";
10
14
  import { envCheck } from "./env.js";
15
+ import { fanOutCheck } from "./fan-out.js";
16
+ import { featureScatterCheck } from "./feature-scatter.js";
11
17
  import { installedCheck } from "./installed.js";
18
+ import { jsdocCheck } from "./jsdoc.js";
12
19
  import { layoutCheck } from "./layout.js";
13
20
  import { migrationsCheck } from "./migrations.js";
14
21
  import { modelsCheck } from "./models.js";
22
+ import { moduleSizeCheck } from "./module-size.js";
23
+ import { mutationCheck } from "./mutation.js";
24
+ import { orphansCheck } from "./orphans.js";
15
25
  import { pinsCheck } from "./pins.js";
16
26
  import { remixCheck } from "./remix.js";
27
+ import { resultThrowsCheck } from "./result-throws.js";
17
28
  import { routesCheck } from "./routes.js";
29
+ import { testRatioCheck } from "./test-ratio.js";
18
30
  import { typegenCheck } from "./typegen.js";
19
31
  import { uiCheck } from "./ui.js";
20
32
  /**
21
33
  * Every built-in check: release drift, the install and the `remix` peer first, then the
22
- * Worker's secrets and types, then the app's own code, layout to copied components.
34
+ * Worker's secrets and types, then the app's own code, layout and quality metrics, then
35
+ * copied components.
23
36
  */
24
37
  export const CHECKS = [
25
38
  pinsCheck,
@@ -32,6 +45,18 @@ export const CHECKS = [
32
45
  routesCheck,
33
46
  modelsCheck,
34
47
  emailsCheck,
48
+ jsdocCheck,
49
+ complexityCheck,
50
+ moduleSizeCheck,
51
+ dependenciesCheck,
52
+ fanOutCheck,
53
+ orphansCheck,
54
+ featureScatterCheck,
55
+ duplicationCheck,
56
+ resultThrowsCheck,
57
+ testRatioCheck,
58
+ crapCheck,
59
+ mutationCheck,
35
60
  uiCheck,
36
61
  ];
37
62
  /** Whether any check failed, which makes `sdxc doctor` exit 1. */
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The `complexity` check: every function's cyclomatic complexity stays at or under the
3
+ * configured maximum (default 4), so agent-written branches stay small enough to test and
4
+ * review. Oxlint's `complexity` rule is left off; this check is project-aware and configurable.
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 function whose cyclomatic complexity exceeds `doctor.complexity.max`.
12
+ */
13
+ export declare const complexityCheck: Check;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The `complexity` check: every function's cyclomatic complexity stays at or under the
3
+ * configured maximum (default 4), so agent-written branches stay small enough to test and
4
+ * review. Oxlint's `complexity` rule is left off; this check is project-aware and configurable.
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 { PROJECT_FOLDERS } from "../stats.js";
14
+ import { passed, skipped } from "./check.js";
15
+ import { isAppSource, listFiles } from "./files.js";
16
+ /**
17
+ * Warns on each function whose cyclomatic complexity exceeds `doctor.complexity.max`.
18
+ */
19
+ export const complexityCheck = {
20
+ name: "complexity",
21
+ async run(context) {
22
+ let max = context.config.doctor.complexity.max;
23
+ let findings = [];
24
+ let files = 0;
25
+ for (let folder of PROJECT_FOLDERS) {
26
+ for (let file of (await listFiles(context.root, folder)).filter(isAppSource)) {
27
+ files += 1;
28
+ let source = await wrap(() => readFile(join(context.root, file), "utf8"));
29
+ if (isFailure(source))
30
+ continue;
31
+ for (let fn of measureComplexity(file, source.data)) {
32
+ if (fn.complexity <= max)
33
+ continue;
34
+ findings.push(`${file}:${fn.line}: ${fn.name} has complexity ${fn.complexity} (max ${max})`);
35
+ }
36
+ }
37
+ }
38
+ if (files === 0)
39
+ return skipped("No app source to measure complexity");
40
+ if (findings.length === 0) {
41
+ return passed(`Every function stays at cyclomatic complexity ${max} or below`);
42
+ }
43
+ return {
44
+ status: "warn",
45
+ message: findings.length === 1
46
+ ? "Found 1 function above the cyclomatic complexity limit"
47
+ : `Found ${findings.length} functions above the cyclomatic complexity limit`,
48
+ findings,
49
+ fix: `Split each function so its decision points stay at ${max} or fewer, or raise doctor.complexity.max in .config/sdxc.jsonc`,
50
+ };
51
+ },
52
+ };
@@ -0,0 +1,14 @@
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 type { Check } from "./check.js";
10
+ /**
11
+ * Warns on each function whose CRAP score exceeds `doctor.crap.max` when coverage data is
12
+ * present at `doctor.crap.coverage`.
13
+ */
14
+ export declare const crapCheck: Check;
@@ -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,44 @@
1
+ /**
2
+ * The `jsdoc` check: every comment in the app's source is a JSDoc block whose description stays
3
+ * within three prose lines, so an edit cannot leave a long narrative or a `//` aside beside the
4
+ * code it describes. Tags are left out of the line budget; `@param`, `@returns` and `@throws`
5
+ * stay on one line, and `@description` is refused.
6
+ *
7
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
8
+ * @copyright Sergio Xalambrí 2026
9
+ */
10
+ import type { Check } from "./check.js";
11
+ /** The most prose lines a JSDoc description may hold. */
12
+ export declare const MAX_DESCRIPTION_LINES = 3;
13
+ /** One finding the check reports for a comment. */
14
+ export interface JsdocFinding {
15
+ /** The file, relative to the project root. */
16
+ file: string;
17
+ /** The 1-based line the comment starts on. */
18
+ line: number;
19
+ /** What is wrong with the comment. */
20
+ message: string;
21
+ }
22
+ /**
23
+ * Warns on each non-JSDoc comment that is not a tooling directive, each description longer than
24
+ * three prose lines, each banned `@description`, and each `@param` / `@returns` / `@throws` that
25
+ * spills onto a second line.
26
+ */
27
+ export declare const jsdocCheck: Check;
28
+ /**
29
+ * Every rule breach in `source`, in source order. A file the scanner cannot tokenize is left
30
+ * alone so the type checker names the syntax error.
31
+ *
32
+ * @param file - Path reported in each finding.
33
+ * @param source - The module's text.
34
+ */
35
+ export declare function inspectComments(file: string, source: string): JsdocFinding[];
36
+ /**
37
+ * Whether `value` is a JSDoc block (`/** … *\/`), the only comment shape a symbol may carry.
38
+ */
39
+ export declare function isJsdoc(value: string): boolean;
40
+ /**
41
+ * Whether `value` is a shebang, a triple-slash reference, or a tooling directive the repository
42
+ * keeps as the only non-JSDoc comments.
43
+ */
44
+ export declare function isToolingDirective(value: string): boolean;