sordo 0.4.0 → 1.0.0

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 (152) hide show
  1. package/CHANGELOG.md +6 -116
  2. package/README.md +8 -175
  3. package/bin/sordo.ts +1 -4
  4. package/package.json +17 -41
  5. package/src/agents-md.ts +1 -0
  6. package/src/ai.ts +1 -0
  7. package/src/build.ts +1 -0
  8. package/src/client.ts +1 -0
  9. package/src/config.ts +1 -0
  10. package/src/dev.ts +1 -0
  11. package/src/index.ts +1 -55
  12. package/src/middleware.ts +1 -0
  13. package/src/plugin.ts +1 -0
  14. package/src/render.ts +1 -0
  15. package/src/router.ts +1 -0
  16. package/src/server.ts +1 -0
  17. package/CLAUDE.md +0 -124
  18. package/src/adapters/bun.ts +0 -59
  19. package/src/adapters/edge.ts +0 -75
  20. package/src/adapters/types.ts +0 -43
  21. package/src/agents-md/collect.ts +0 -113
  22. package/src/agents-md/generate.ts +0 -44
  23. package/src/agents-md/index.ts +0 -9
  24. package/src/agents-md/render.ts +0 -150
  25. package/src/agents-md/subprocess-entry.ts +0 -92
  26. package/src/agents-md/subprocess-runner.ts +0 -111
  27. package/src/agents-md/write.ts +0 -38
  28. package/src/agents-md/zod-to-json-schema.ts +0 -18
  29. package/src/ai/context.ts +0 -72
  30. package/src/ai/define.ts +0 -15
  31. package/src/ai/errors.ts +0 -51
  32. package/src/ai/index.ts +0 -36
  33. package/src/ai/middleware.ts +0 -21
  34. package/src/ai/registry.ts +0 -96
  35. package/src/ai/run.ts +0 -185
  36. package/src/ai/scan.ts +0 -42
  37. package/src/ai/stream.ts +0 -71
  38. package/src/ai/triggers.ts +0 -124
  39. package/src/ai/types.ts +0 -67
  40. package/src/ai/validate.ts +0 -82
  41. package/src/build/assets.ts +0 -48
  42. package/src/build/client-entry.ts +0 -43
  43. package/src/build/css.ts +0 -102
  44. package/src/build/embedded.ts +0 -66
  45. package/src/build/hash.ts +0 -21
  46. package/src/build/index.ts +0 -480
  47. package/src/build/macros/agents-hash.macro.ts +0 -9
  48. package/src/build/macros/agents.macro.ts +0 -21
  49. package/src/build/macros/env.macro.ts +0 -25
  50. package/src/build/macros/inline-assets.macro.ts +0 -28
  51. package/src/build/macros/manifest.macro.ts +0 -8
  52. package/src/build/macros/routes.macro.ts +0 -10
  53. package/src/build/page-entry.ts +0 -136
  54. package/src/build/scan-islands.ts +0 -39
  55. package/src/build/server-entry.ts +0 -256
  56. package/src/cli/ansi.ts +0 -41
  57. package/src/cli/build.ts +0 -195
  58. package/src/cli/commands/add/apply.ts +0 -31
  59. package/src/cli/commands/add/component-diff.ts +0 -116
  60. package/src/cli/commands/add/diff.ts +0 -153
  61. package/src/cli/commands/add/internal.ts +0 -41
  62. package/src/cli/commands/add/load-catalog.ts +0 -22
  63. package/src/cli/commands/add/peer-deps.ts +0 -115
  64. package/src/cli/commands/add/registry-fetch.ts +0 -122
  65. package/src/cli/commands/add/shadcn.ts +0 -285
  66. package/src/cli/commands/add/source.ts +0 -273
  67. package/src/cli/commands/add/stamper.ts +0 -73
  68. package/src/cli/commands/add/tokens.ts +0 -81
  69. package/src/cli/commands/add/ui-paths.ts +0 -113
  70. package/src/cli/commands/add.ts +0 -427
  71. package/src/cli/commands/deploy.ts +0 -143
  72. package/src/cli/commands/migrate.ts +0 -149
  73. package/src/cli/commands/secret.ts +0 -316
  74. package/src/cli/commands/ui/build.ts +0 -111
  75. package/src/cli/commands/ui/init.ts +0 -135
  76. package/src/cli/commands/ui/migrate/git-guard.ts +0 -19
  77. package/src/cli/commands/ui/migrate/radix.ts +0 -67
  78. package/src/cli/commands/ui/migrate/rtl.ts +0 -148
  79. package/src/cli/commands/ui/shadcn.ts +0 -82
  80. package/src/cli/commands/ui/view.ts +0 -63
  81. package/src/cli/commands/ui.ts +0 -86
  82. package/src/cli/commands/update.ts +0 -134
  83. package/src/cli/commands/upgrade.ts +0 -53
  84. package/src/cli/commands/view.ts +0 -34
  85. package/src/cli/dev.ts +0 -393
  86. package/src/cli/doctor/config-checks.ts +0 -63
  87. package/src/cli/doctor/deps.ts +0 -295
  88. package/src/cli/doctor/hydrate.ts +0 -65
  89. package/src/cli/doctor/monorepo.ts +0 -158
  90. package/src/cli/doctor/probes.ts +0 -16
  91. package/src/cli/doctor/report.ts +0 -72
  92. package/src/cli/doctor/toolchain.ts +0 -95
  93. package/src/cli/doctor/types.ts +0 -36
  94. package/src/cli/doctor.ts +0 -127
  95. package/src/cli/index.ts +0 -168
  96. package/src/cli/log.ts +0 -135
  97. package/src/cli/run/affected.ts +0 -79
  98. package/src/cli/run/cache-key.ts +0 -177
  99. package/src/cli/run/cache-store.ts +0 -0
  100. package/src/cli/run/files.ts +0 -96
  101. package/src/cli/run/git.ts +0 -13
  102. package/src/cli/run/runner.ts +0 -189
  103. package/src/cli/run/workspace.ts +0 -216
  104. package/src/cli/run.ts +0 -184
  105. package/src/cli/start.ts +0 -99
  106. package/src/cli/update-check.ts +0 -157
  107. package/src/client/index.ts +0 -65
  108. package/src/client/link.tsx +0 -61
  109. package/src/client/page.ts +0 -250
  110. package/src/config/define.ts +0 -5
  111. package/src/config/env.ts +0 -36
  112. package/src/config/load.ts +0 -152
  113. package/src/config/schema.ts +0 -135
  114. package/src/config/secrets.ts +0 -108
  115. package/src/dev/client.ts +0 -112
  116. package/src/dev/hot.ts +0 -24
  117. package/src/dev/index.ts +0 -4
  118. package/src/dev/tree.ts +0 -95
  119. package/src/dev/watcher.ts +0 -95
  120. package/src/internal/hmr-client.ts +0 -52
  121. package/src/internal/open-in-editor.ts +0 -23
  122. package/src/internal/runtime.ts +0 -30
  123. package/src/middleware/cookie-jar.ts +0 -135
  124. package/src/middleware/cookies.ts +0 -60
  125. package/src/middleware/index.ts +0 -127
  126. package/src/middleware/request-id.ts +0 -22
  127. package/src/middleware/response-helpers.ts +0 -25
  128. package/src/plugin/index.ts +0 -109
  129. package/src/render/bootstrap.ts +0 -44
  130. package/src/render/dev-error.tsx +0 -73
  131. package/src/render/index.tsx +0 -261
  132. package/src/render/island.tsx +0 -33
  133. package/src/render/meta.tsx +0 -48
  134. package/src/render/shell.tsx +0 -41
  135. package/src/router/conflict.ts +0 -20
  136. package/src/router/filesystem.ts +0 -37
  137. package/src/router/index.ts +0 -247
  138. package/src/router/match.ts +0 -91
  139. package/src/router/pattern.ts +0 -88
  140. package/src/server/index.ts +0 -250
  141. package/src/server/inline-assets.ts +0 -39
  142. package/src/types.ts +0 -53
  143. package/src/ui/schema.ts +0 -68
  144. package/src/ui/types.ts +0 -10
  145. package/templates/_internal/cn.ts +0 -6
  146. package/templates/_internal/slot.ts +0 -50
  147. package/templates/_internal/variants.ts +0 -1
  148. package/templates/themes/neutral/tokens.css +0 -46
  149. package/templates/themes/slate/tokens.css +0 -46
  150. package/templates/themes/stone/tokens.css +0 -46
  151. package/templates/themes/zinc/tokens.css +0 -46
  152. package/templates/tokens.css +0 -46
@@ -1,295 +0,0 @@
1
- // Group B — dependency hygiene. Runs and contextualizes Bun's own commands
2
- // (`bun audit`, `bun outdated`) plus a local lockfile-sync check. The parsers
3
- // are pure so they can be unit-tested without a network round-trip.
4
- //
5
- // Note: `bun outdated --json` is NOT supported on Bun 1.3.x — the flag is
6
- // silently ignored and a markdown table is printed — so B.5 parses the table.
7
-
8
- import { join } from "node:path";
9
- import type { Finding, Status } from "./types.ts";
10
-
11
- export type Severity = "low" | "moderate" | "high" | "critical";
12
-
13
- export const SEVERITY_ORDER: readonly Severity[] = [
14
- "low",
15
- "moderate",
16
- "high",
17
- "critical",
18
- ];
19
-
20
- function severityRank(s: Severity): number {
21
- return SEVERITY_ORDER.indexOf(s);
22
- }
23
-
24
- export interface DepsOptions {
25
- offline: boolean;
26
- noAudit: boolean;
27
- noOutdated: boolean;
28
- auditLevel: Severity;
29
- }
30
-
31
- export interface OutdatedEntry {
32
- name: string;
33
- current: string;
34
- latest: string;
35
- major: boolean;
36
- }
37
-
38
- export interface Advisory {
39
- name: string;
40
- severity: Severity;
41
- }
42
-
43
- /** Leading-numeric major component of a version (e.g. "^1.2.3" → 1). */
44
- function majorOf(version: string): number {
45
- const m = version.match(/(\d+)/);
46
- return m ? Number.parseInt(m[1] as string, 10) : 0;
47
- }
48
-
49
- /**
50
- * Parse the markdown table `bun outdated` prints. Header + `|---` separators are
51
- * dropped; a ` (dev)` / ` (peer)` / ` (optional)` suffix on the package name is
52
- * stripped. Returns `[]` for an empty result.
53
- */
54
- export function parseOutdatedTable(text: string): OutdatedEntry[] {
55
- const out: OutdatedEntry[] = [];
56
- for (const raw of text.split("\n")) {
57
- const line = raw.trim();
58
- if (!line.startsWith("|")) continue;
59
- const cells = line
60
- .slice(1, line.endsWith("|") ? -1 : undefined)
61
- .split("|")
62
- .map((c) => c.trim());
63
- const first = cells[0] ?? "";
64
- if (first === "" || first === "Package") continue; // header
65
- if (first.startsWith("-")) continue; // separator row
66
- const name = first.replace(/\s+\((dev|peer|optional)\)$/, "");
67
- const current = cells[1] ?? "";
68
- const latest = cells[3] ?? cells[cells.length - 1] ?? "";
69
- if (!current || !latest) continue;
70
- out.push({
71
- name,
72
- current,
73
- latest,
74
- major: majorOf(current) !== majorOf(latest),
75
- });
76
- }
77
- return out;
78
- }
79
-
80
- function asSeverity(value: unknown): Severity | null {
81
- return value === "low" ||
82
- value === "moderate" ||
83
- value === "high" ||
84
- value === "critical"
85
- ? value
86
- : null;
87
- }
88
-
89
- /**
90
- * Extract advisories from `bun audit --json`. The exact shape varies (npm-style
91
- * `advisories` keyed by id, or `vulnerabilities` keyed by package); tolerate
92
- * both and ignore anything that doesn't carry a recognizable severity.
93
- */
94
- export function parseAuditJson(text: string): Advisory[] {
95
- let data: unknown;
96
- try {
97
- data = JSON.parse(text);
98
- } catch {
99
- return [];
100
- }
101
- if (!data || typeof data !== "object") return [];
102
- const out: Advisory[] = [];
103
-
104
- const collect = (entry: unknown, fallbackName: string): void => {
105
- if (!entry || typeof entry !== "object") return;
106
- const rec = entry as Record<string, unknown>;
107
- const severity = asSeverity(rec.severity);
108
- if (!severity) return;
109
- const name =
110
- (typeof rec.module_name === "string" && rec.module_name) ||
111
- (typeof rec.name === "string" && rec.name) ||
112
- fallbackName;
113
- out.push({ name, severity });
114
- };
115
-
116
- const root = data as Record<string, unknown>;
117
- const advisories = root.advisories;
118
- if (advisories && typeof advisories === "object") {
119
- for (const v of Object.values(advisories)) collect(v, "unknown");
120
- }
121
- const vulns = root.vulnerabilities;
122
- if (vulns && typeof vulns === "object" && !Array.isArray(vulns)) {
123
- for (const [name, v] of Object.entries(vulns)) collect(v, name);
124
- }
125
- return out;
126
- }
127
-
128
- /** Build the audit finding from parsed advisories, gated on `auditLevel`. */
129
- export function auditFinding(
130
- advisories: Advisory[],
131
- auditLevel: Severity,
132
- ): Finding {
133
- if (advisories.length === 0) {
134
- return {
135
- id: "audit",
136
- group: "Dependencies",
137
- status: "pass",
138
- detail: "no known security advisories",
139
- };
140
- }
141
- const threshold = severityRank(auditLevel);
142
- const failing = advisories.filter(
143
- (a) => severityRank(a.severity) >= threshold,
144
- );
145
- const list = failing.length > 0 ? failing : advisories;
146
- const top = [...list].sort(
147
- (a, b) => severityRank(b.severity) - severityRank(a.severity),
148
- )[0] as Advisory;
149
- const status: Status = failing.length > 0 ? "fail" : "warn";
150
- const count = list.length;
151
- const noun = count === 1 ? "advisory" : "advisories";
152
- return {
153
- id: "audit",
154
- group: "Dependencies",
155
- status,
156
- detail: `${count} ${top.severity} severity ${noun} (e.g. ${top.name})`,
157
- remedy: `bun update ${top.name}`,
158
- };
159
- }
160
-
161
- /** Build the outdated finding from parsed entries (never a failure). */
162
- export function outdatedFinding(entries: OutdatedEntry[]): Finding {
163
- if (entries.length === 0) {
164
- return {
165
- id: "outdated",
166
- group: "Dependencies",
167
- status: "pass",
168
- detail: "all dependencies up to date",
169
- };
170
- }
171
- const majors = entries.filter((e) => e.major);
172
- const majorNote =
173
- majors.length > 0
174
- ? ` (${majors.length} major: ${majors
175
- .slice(0, 1)
176
- .map((e) => `${e.name} ${majorOf(e.current)} → ${majorOf(e.latest)}`)
177
- .join(", ")})`
178
- : "";
179
- return {
180
- id: "outdated",
181
- group: "Dependencies",
182
- status: "warn",
183
- detail: `${entries.length} outdated${majorNote}`,
184
- remedy: "bun outdated to review",
185
- };
186
- }
187
-
188
- interface PackageJsonDeps {
189
- dependencies?: Record<string, string>;
190
- devDependencies?: Record<string, string>;
191
- }
192
-
193
- /** Escape a package name for use inside a RegExp. */
194
- function escapeRe(s: string): string {
195
- return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
196
- }
197
-
198
- /**
199
- * Name-level lockfile sync: every dependency / devDependency declared in the
200
- * root package.json must appear as a quoted token in `bun.lock`. A declared dep
201
- * absent from the lock means the lockfile is stale (a `bun install` is owed).
202
- */
203
- export async function checkLockfile(root: string): Promise<Finding> {
204
- const lockFile = Bun.file(join(root, "bun.lock"));
205
- if (!(await lockFile.exists())) {
206
- return {
207
- id: "lockfile",
208
- group: "Dependencies",
209
- status: "fail",
210
- detail: "bun.lock is missing",
211
- remedy: "bun install",
212
- };
213
- }
214
- const lockText = await lockFile.text();
215
-
216
- let pkg: PackageJsonDeps = {};
217
- try {
218
- pkg = (await Bun.file(
219
- join(root, "package.json"),
220
- ).json()) as PackageJsonDeps;
221
- } catch {
222
- // A missing/invalid root package.json surfaces in config checks; treat the
223
- // lock as in-sync here rather than double-reporting.
224
- return {
225
- id: "lockfile",
226
- group: "Dependencies",
227
- status: "pass",
228
- detail: "lockfile in sync",
229
- };
230
- }
231
-
232
- const declared = [
233
- ...Object.keys(pkg.dependencies ?? {}),
234
- ...Object.keys(pkg.devDependencies ?? {}),
235
- ];
236
- const missing = declared.filter(
237
- (name) => !new RegExp(`"${escapeRe(name)}"`).test(lockText),
238
- );
239
-
240
- if (missing.length > 0) {
241
- const shown = missing.slice(0, 3).join(", ");
242
- const more = missing.length > 3 ? `, +${missing.length - 3} more` : "";
243
- return {
244
- id: "lockfile",
245
- group: "Dependencies",
246
- status: "fail",
247
- detail: `lockfile out of sync — not in bun.lock: ${shown}${more}`,
248
- remedy: "bun install",
249
- };
250
- }
251
- return {
252
- id: "lockfile",
253
- group: "Dependencies",
254
- status: "pass",
255
- detail: "lockfile in sync",
256
- };
257
- }
258
-
259
- function skipped(id: string, detail: string): Finding {
260
- return { id, group: "Dependencies", status: "skip", detail };
261
- }
262
-
263
- /** Run group B: audit + outdated concurrently (subject to flags), then lockfile. */
264
- export async function checkDeps(
265
- root: string,
266
- opts: DepsOptions,
267
- ): Promise<Finding[]> {
268
- const auditTask = (async (): Promise<Finding | null> => {
269
- if (opts.noAudit) return null;
270
- if (opts.offline)
271
- return skipped("audit", "security audit skipped (offline)");
272
- const text = await Bun.$`bun audit --json --audit-level=${opts.auditLevel}`
273
- .cwd(root)
274
- .nothrow()
275
- .quiet()
276
- .text();
277
- return auditFinding(parseAuditJson(text), opts.auditLevel);
278
- })();
279
-
280
- const outdatedTask = (async (): Promise<Finding | null> => {
281
- if (opts.noOutdated) return null;
282
- if (opts.offline)
283
- return skipped("outdated", "outdated check skipped (offline)");
284
- const text = await Bun.$`bun outdated`.cwd(root).nothrow().quiet().text();
285
- return outdatedFinding(parseOutdatedTable(text));
286
- })();
287
-
288
- const [audit, outdated, lockfile] = await Promise.all([
289
- auditTask,
290
- outdatedTask,
291
- checkLockfile(root),
292
- ]);
293
-
294
- return [audit, outdated, lockfile].filter((f): f is Finding => f !== null);
295
- }
@@ -1,65 +0,0 @@
1
- // Config group — whole-tree hydration hygiene. A page that exports
2
- // `hydrate = true` hydrates its entire subtree, so `<Island>` wrappers on it
3
- // are dead weight (whole-tree wins; the island entry is never loaded).
4
-
5
- import { relative } from "node:path";
6
- import {
7
- type HydrateDefault,
8
- readHydrateFlag,
9
- } from "../../build/page-entry.ts";
10
- import { scanRoutes } from "../../router/filesystem.ts";
11
- import type { Finding } from "./types.ts";
12
-
13
- const ISLAND_USE_RE = /<Island[\s>]/;
14
-
15
- export async function checkHydration(
16
- cwd: string,
17
- appDir: string,
18
- defaultMode: HydrateDefault,
19
- ): Promise<Finding[]> {
20
- let entries: Awaited<ReturnType<typeof scanRoutes>>;
21
- try {
22
- entries = await scanRoutes(appDir);
23
- } catch {
24
- return [];
25
- }
26
- const out: Finding[] = [];
27
- let hydrated = 0;
28
- for (const entry of entries) {
29
- if (entry.kind !== "page") continue;
30
- const source = await Bun.file(entry.filePath).text();
31
- let flag: boolean;
32
- try {
33
- flag = readHydrateFlag(source, entry.filePath, defaultMode).hydrate;
34
- } catch (err) {
35
- out.push({
36
- id: "hydrate-export",
37
- group: "Config",
38
- status: "fail",
39
- detail: (err as Error).message.replace(/^sordo build: /, ""),
40
- remedy: "export `hydrate` as a literal: export const hydrate = true",
41
- });
42
- continue;
43
- }
44
- if (!flag) continue;
45
- hydrated++;
46
- if (ISLAND_USE_RE.test(source)) {
47
- out.push({
48
- id: "hydrate-islands",
49
- group: "Config",
50
- status: "warn",
51
- detail: `${relative(cwd, entry.filePath)} hydrates the whole page but also renders <Island>; the island markers are redundant`,
52
- remedy: "drop the <Island> wrappers, or export const hydrate = false",
53
- });
54
- }
55
- }
56
- if (hydrated > 0 && out.length === 0) {
57
- out.push({
58
- id: "hydrate",
59
- group: "Config",
60
- status: "pass",
61
- detail: `${hydrated} hydrated page(s), no island overlap`,
62
- });
63
- }
64
- return out;
65
- }
@@ -1,158 +0,0 @@
1
- // Group D — monorepo invariants. Runs only when the root package.json declares
2
- // `workspaces`; single-package projects skip the whole group. Reuses the
3
- // return-based `assertSingleReact` from dev.ts (framework/26) for the
4
- // single-React invariant.
5
-
6
- import { join } from "node:path";
7
- import { assertSingleReact } from "../dev.ts";
8
- import type { Finding } from "./types.ts";
9
-
10
- interface RootPkg {
11
- workspaces?: unknown;
12
- catalog?: Record<string, string>;
13
- catalogs?: Record<string, Record<string, string>>;
14
- }
15
-
16
- interface MemberPkg {
17
- name?: string;
18
- dependencies?: Record<string, string>;
19
- devDependencies?: Record<string, string>;
20
- peerDependencies?: Record<string, string>;
21
- optionalDependencies?: Record<string, string>;
22
- }
23
-
24
- /** `workspaces` globs from the root package.json (array or `{ packages }` form). */
25
- function workspaceGlobs(pkg: RootPkg): string[] {
26
- const ws = pkg.workspaces;
27
- if (Array.isArray(ws))
28
- return ws.filter((x): x is string => typeof x === "string");
29
- if (ws && typeof ws === "object") {
30
- const packages = (ws as { packages?: unknown }).packages;
31
- if (Array.isArray(packages))
32
- return packages.filter((x): x is string => typeof x === "string");
33
- }
34
- return [];
35
- }
36
-
37
- async function readJson<T>(path: string): Promise<T | null> {
38
- try {
39
- return (await Bun.file(path).json()) as T;
40
- } catch {
41
- return null;
42
- }
43
- }
44
-
45
- /** Scan one workspace glob to its member package.json paths (skipping node_modules). */
46
- async function globMembers(root: string, pattern: string): Promise<string[]> {
47
- const out: string[] = [];
48
- const glob = new Bun.Glob(`${pattern}/package.json`);
49
- for await (const rel of glob.scan({ cwd: root, onlyFiles: true })) {
50
- if (rel.includes("node_modules/")) continue;
51
- out.push(rel);
52
- }
53
- return out;
54
- }
55
-
56
- function allDeps(pkg: MemberPkg): Record<string, string> {
57
- return {
58
- ...pkg.dependencies,
59
- ...pkg.devDependencies,
60
- ...pkg.peerDependencies,
61
- ...pkg.optionalDependencies,
62
- };
63
- }
64
-
65
- export async function checkMonorepo(
66
- root: string,
67
- appDir: string,
68
- frameworkDir: string,
69
- ): Promise<Finding[]> {
70
- const rootPkg = await readJson<RootPkg>(join(root, "package.json"));
71
- const globs = rootPkg ? workspaceGlobs(rootPkg) : [];
72
- if (globs.length === 0) return []; // single-package project: group absent
73
-
74
- const out: Finding[] = [];
75
-
76
- // D.9 — every glob must resolve to at least one package.
77
- const memberRels: string[] = [];
78
- const emptyGlobs: string[] = [];
79
- for (const pattern of globs) {
80
- const members = await globMembers(root, pattern);
81
- if (members.length === 0) emptyGlobs.push(pattern);
82
- else memberRels.push(...members);
83
- }
84
- out.push(
85
- emptyGlobs.length > 0
86
- ? {
87
- id: "workspace-globs",
88
- group: "Monorepo",
89
- status: "fail",
90
- detail: `workspace glob matched no package: ${emptyGlobs.join(", ")}`,
91
- remedy:
92
- "fix the `workspaces` globs in package.json or add the package",
93
- }
94
- : {
95
- id: "workspace-globs",
96
- group: "Monorepo",
97
- status: "pass",
98
- detail: "workspace globs resolve",
99
- },
100
- );
101
-
102
- // D.10 — exactly one copy of react/react-dom across the hoisted tree.
103
- const react = assertSingleReact(root, appDir, frameworkDir);
104
- out.push(
105
- react.ok
106
- ? {
107
- id: "single-react",
108
- group: "Monorepo",
109
- status: "pass",
110
- detail: "single React copy",
111
- }
112
- : {
113
- id: "single-react",
114
- group: "Monorepo",
115
- status: "fail",
116
- detail:
117
- react.message.split("\n")[0]?.replace(/^✗\s*/, "") ??
118
- "duplicate React",
119
- remedy: "align the react version, then `bun install`",
120
- },
121
- );
122
-
123
- // D.11 — every `catalog:` reference resolves to a root catalog entry.
124
- const defaultCatalog = rootPkg?.catalog ?? {};
125
- const namedCatalogs = rootPkg?.catalogs ?? {};
126
- const dangling: string[] = [];
127
- for (const rel of memberRels) {
128
- const member = await readJson<MemberPkg>(join(root, rel));
129
- if (!member) continue;
130
- for (const [dep, range] of Object.entries(allDeps(member))) {
131
- if (!range.startsWith("catalog:")) continue;
132
- const name = range.slice("catalog:".length);
133
- const catalog = name === "" ? defaultCatalog : namedCatalogs[name];
134
- if (!catalog || !(dep in catalog)) {
135
- dangling.push(`${member.name ?? rel}:${dep} (${range})`);
136
- }
137
- }
138
- }
139
- out.push(
140
- dangling.length > 0
141
- ? {
142
- id: "catalog-refs",
143
- group: "Monorepo",
144
- status: "fail",
145
- detail: `dangling catalog reference: ${dangling.slice(0, 3).join(", ")}`,
146
- remedy:
147
- "add the entry to the root `catalog` / `catalogs` in package.json",
148
- }
149
- : {
150
- id: "catalog-refs",
151
- group: "Monorepo",
152
- status: "pass",
153
- detail: "catalog references resolve",
154
- },
155
- );
156
-
157
- return out;
158
- }
@@ -1,16 +0,0 @@
1
- // Toolchain probes for `sordo doctor`, built on `Bun.which` (rfc-bun-which).
2
- // Injectable so tests can simulate a missing `git` / `docker` / `claude` without
3
- // touching the real PATH. The scaffold has its own copy in create-sordo; this
4
- // is the framework-package equivalent the doctor spec calls for.
5
-
6
- export interface Probes {
7
- /** Absolute path of `tool` in PATH, or null when absent. */
8
- which(tool: string): string | null;
9
- /** The running Bun version (e.g. "1.3.14"). */
10
- bunVersion(): string;
11
- }
12
-
13
- export const realProbes: Probes = {
14
- which: (tool) => Bun.which(tool),
15
- bunVersion: () => Bun.version,
16
- };
@@ -1,72 +0,0 @@
1
- // Doctor report rendering. `renderText` produces the aligned, width-aware
2
- // human report (color gated on TTY/NO_COLOR via log.ts); `renderJson` produces
3
- // the CI-consumable shape with no ANSI. Detail strings are stored plain, so JSON
4
- // never carries escapes and text-mode applies color at render time.
5
-
6
- import { strip, terminalColumns, wrapWithPrefix } from "../ansi.ts";
7
- import { type Color, colorize } from "../log.ts";
8
- import {
9
- type DoctorReport,
10
- type Finding,
11
- GROUP_ORDER,
12
- type Status,
13
- type Summary,
14
- } from "./types.ts";
15
-
16
- export function summarize(checks: Finding[]): Summary {
17
- const summary: Summary = { failed: 0, warning: 0, passed: 0, skipped: 0 };
18
- for (const c of checks) {
19
- if (c.status === "fail") summary.failed++;
20
- else if (c.status === "warn") summary.warning++;
21
- else if (c.status === "pass") summary.passed++;
22
- else summary.skipped++;
23
- }
24
- return summary;
25
- }
26
-
27
- const SYMBOL: Record<Status, { glyph: string; color: Color }> = {
28
- pass: { glyph: "✓", color: "green" },
29
- warn: { glyph: "⚠", color: "yellow" },
30
- fail: { glyph: "✗", color: "red" },
31
- skip: { glyph: "–", color: "dim" },
32
- };
33
-
34
- export function renderText(report: DoctorReport): string {
35
- const cols = terminalColumns();
36
- const lines: string[] = ["sordo doctor", ""];
37
-
38
- for (const group of GROUP_ORDER) {
39
- const rows = report.checks.filter((c) => c.group === group);
40
- if (rows.length === 0) continue;
41
- lines.push(` ${group}`);
42
- for (const row of rows) {
43
- const { glyph, color } = SYMBOL[row.status];
44
- lines.push(` ${colorize(process.stdout, color, glyph)} ${row.detail}`);
45
- if (row.remedy) {
46
- lines.push(
47
- wrapWithPrefix(row.remedy, cols, " → ", " "),
48
- );
49
- }
50
- }
51
- }
52
-
53
- const { failed, warning, passed, skipped } = report.summary;
54
- const parts = [`${failed} failed`, `${warning} warning`, `${passed} passed`];
55
- if (skipped > 0) parts.push(`${skipped} skipped`);
56
- lines.push("", ` ${parts.join(", ")}`);
57
-
58
- return `${lines.join("\n")}\n`;
59
- }
60
-
61
- export function renderJson(report: DoctorReport): string {
62
- // Detail strings are built plain, but strip defensively so the machine shape
63
- // is guaranteed ANSI-free regardless of how a finding was constructed.
64
- const checks = report.checks.map((c) => ({
65
- id: c.id,
66
- group: c.group,
67
- status: c.status,
68
- detail: strip(c.detail),
69
- remedy: c.remedy ? strip(c.remedy) : null,
70
- }));
71
- return `${JSON.stringify({ checks, summary: report.summary }, null, 2)}\n`;
72
- }
@@ -1,95 +0,0 @@
1
- // Group A — toolchain probes. Extends the scaffold's two probes (bun fail, git
2
- // warn, cli/10-scaffold-probes) to a lifecycle set. The conditional docker /
3
- // claude probes only emit a row when the project actually uses them, gated on
4
- // file presence (a root Dockerfile / a `.claude/` dir) so projects that use
5
- // neither are never nagged.
6
-
7
- import { existsSync } from "node:fs";
8
- import { join } from "node:path";
9
- import { padEnd } from "../ansi.ts";
10
- import type { Probes } from "./probes.ts";
11
- import { realProbes } from "./probes.ts";
12
- import type { Finding } from "./types.ts";
13
-
14
- /** Minimum Bun the framework declares as supported (matches the spec example). */
15
- export const MIN_BUN = "1.3.0";
16
-
17
- /** Compare dotted numeric versions: <0, 0, >0 like a sort comparator. */
18
- function compareVersions(a: string, b: string): number {
19
- const pa = a.split(".").map((n) => Number.parseInt(n, 10) || 0);
20
- const pb = b.split(".").map((n) => Number.parseInt(n, 10) || 0);
21
- for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
22
- const d = (pa[i] ?? 0) - (pb[i] ?? 0);
23
- if (d !== 0) return d;
24
- }
25
- return 0;
26
- }
27
-
28
- export function checkToolchain(
29
- cwd: string,
30
- probes: Probes = realProbes,
31
- ): Finding[] {
32
- const out: Finding[] = [];
33
-
34
- const bunV = probes.bunVersion();
35
- if (compareVersions(bunV, MIN_BUN) >= 0) {
36
- out.push({
37
- id: "bun",
38
- group: "Toolchain",
39
- status: "pass",
40
- detail: `bun ${padEnd(bunV, 18)} (≥ ${MIN_BUN} required)`,
41
- });
42
- } else {
43
- out.push({
44
- id: "bun",
45
- group: "Toolchain",
46
- status: "fail",
47
- detail: `bun ${bunV} is older than the required ${MIN_BUN}`,
48
- remedy: "bun upgrade",
49
- });
50
- }
51
-
52
- if (probes.which("git")) {
53
- out.push({ id: "git", group: "Toolchain", status: "pass", detail: "git" });
54
- } else {
55
- out.push({
56
- id: "git",
57
- group: "Toolchain",
58
- status: "warn",
59
- detail: "git not found in PATH",
60
- remedy: "install git from https://git-scm.com",
61
- });
62
- }
63
-
64
- // docker — only relevant when the project ships a container build.
65
- if (existsSync(join(cwd, "Dockerfile"))) {
66
- out.push(
67
- probes.which("docker")
68
- ? { id: "docker", group: "Toolchain", status: "pass", detail: "docker" }
69
- : {
70
- id: "docker",
71
- group: "Toolchain",
72
- status: "warn",
73
- detail: "Dockerfile present but docker not found in PATH",
74
- remedy: "install Docker from https://docs.docker.com/get-docker",
75
- },
76
- );
77
- }
78
-
79
- // claude — only relevant for `--agent claude` projects (a `.claude/` overlay).
80
- if (existsSync(join(cwd, ".claude"))) {
81
- out.push(
82
- probes.which("claude")
83
- ? { id: "claude", group: "Toolchain", status: "pass", detail: "claude" }
84
- : {
85
- id: "claude",
86
- group: "Toolchain",
87
- status: "warn",
88
- detail: ".claude/ present but claude not found in PATH",
89
- remedy: "install Claude Code from https://claude.com/claude-code",
90
- },
91
- );
92
- }
93
-
94
- return out;
95
- }