create-sordo 0.0.0-stage → 0.3.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 (62) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/README.md +52 -2
  3. package/bin/create-sordo.ts +11 -0
  4. package/package.json +36 -5
  5. package/src/index.ts +675 -0
  6. package/src/probes.ts +28 -0
  7. package/src/prompts.ts +141 -0
  8. package/src/readme.ts +74 -0
  9. package/src/ui.ts +207 -0
  10. package/src/versions.ts +3 -0
  11. package/templates/_backend/app/routes/api/todos.ts +27 -0
  12. package/templates/_claude/.claude/commands/sordo-init.md +64 -0
  13. package/templates/_claude/.claude/hooks/biome-check.sh +17 -0
  14. package/templates/_claude/.claude/rules/build-time-discovery.md +17 -0
  15. package/templates/_claude/.claude/rules/bun-native.md +28 -0
  16. package/templates/_claude/.claude/rules/filesystem-routing.md +31 -0
  17. package/templates/_claude/.claude/rules/islands.md +46 -0
  18. package/templates/_claude/.claude/rules/optional-ai.md +16 -0
  19. package/templates/_claude/.claude/rules/web-standards-boundary.md +25 -0
  20. package/templates/_claude/.claude/settings.json +22 -0
  21. package/templates/_claude/.claude/skills/sordo/SKILL.md +121 -0
  22. package/templates/_claude/.claude/skills/sordo-cli/SKILL.md +112 -0
  23. package/templates/_claude/CLAUDE.md +28 -0
  24. package/templates/_codex/.codex/README.md +10 -0
  25. package/templates/_codex/.codex/rules/build-time-discovery.md +17 -0
  26. package/templates/_codex/.codex/rules/bun-native.md +28 -0
  27. package/templates/_codex/.codex/rules/filesystem-routing.md +31 -0
  28. package/templates/_codex/.codex/rules/islands.md +46 -0
  29. package/templates/_codex/.codex/rules/optional-ai.md +15 -0
  30. package/templates/_codex/.codex/rules/sordo-cli.md +108 -0
  31. package/templates/_codex/.codex/rules/sordo-patterns.md +122 -0
  32. package/templates/_codex/.codex/rules/web-standards-boundary.md +25 -0
  33. package/templates/_codex/AGENTS.md +27 -0
  34. package/templates/_container/.dockerignore +7 -0
  35. package/templates/_container/Dockerfile +27 -0
  36. package/templates/_monorepo/packages/README.md +18 -0
  37. package/templates/_shared/sordo-patterns.md +122 -0
  38. package/templates/default/README-template.md +181 -0
  39. package/templates/default/app/islands/TodoApp.tsx +83 -0
  40. package/templates/default/app/routes/api/health.ts +8 -0
  41. package/templates/default/app/routes/index.tsx +29 -0
  42. package/templates/default/app/server.ts +28 -0
  43. package/templates/default/gitignore +9 -0
  44. package/templates/default/sordo.config.ts +5 -0
  45. package/templates/default/tsconfig.json +14 -0
  46. package/templates/ui-shadcn/components/button.tsx +63 -0
  47. package/templates/ui-shadcn/components/dialog.tsx +158 -0
  48. package/templates/ui-shadcn/demo/index.tsx +62 -0
  49. package/templates/ui-starter/_internal/cn.ts +6 -0
  50. package/templates/ui-starter/_internal/slot.ts +50 -0
  51. package/templates/ui-starter/_internal/variants.ts +1 -0
  52. package/templates/ui-starter/button.tsx +60 -0
  53. package/templates/ui-starter/card.tsx +92 -0
  54. package/templates/ui-starter/demo/TodoApp.tsx +86 -0
  55. package/templates/ui-starter/demo/index.tsx +45 -0
  56. package/templates/ui-starter/input.tsx +20 -0
  57. package/templates/ui-starter/label.tsx +18 -0
  58. package/templates/ui-starter/themes/neutral/tokens.css +46 -0
  59. package/templates/ui-starter/themes/slate/tokens.css +46 -0
  60. package/templates/ui-starter/themes/stone/tokens.css +46 -0
  61. package/templates/ui-starter/themes/zinc/tokens.css +46 -0
  62. package/templates/ui-starter/tokens.css +46 -0
package/src/prompts.ts ADDED
@@ -0,0 +1,141 @@
1
+ // Interactive prompts for create-sordo. See cli specs 09 + 18.
2
+ // Uses Bun's built-in prompt() — no new dependency.
3
+ //
4
+ // Non-TTY callers must supply the equivalent flags; the run loop only invokes
5
+ // these helpers when stdin is a TTY and --yes was not passed. The prompt order
6
+ // (spec 18) is gated by project type: UI is asked only for frontend/fullstack,
7
+ // monorepo only for fullstack, and the deploy target option set depends on type.
8
+
9
+ export type AgentTemplate = "claude" | "codex" | "none";
10
+ export type ProjectType = "frontend" | "backend" | "fullstack";
11
+ export type Target = "bun" | "edge" | "container";
12
+ export type Theme = "neutral" | "slate" | "stone" | "zinc";
13
+ export type Deploy =
14
+ | "cloudflare"
15
+ | "vercel"
16
+ | "deno"
17
+ | "netlify"
18
+ | "bun"
19
+ | "none";
20
+
21
+ export interface PromptIO {
22
+ prompt?: (q: string) => string | null;
23
+ stdout?: (msg: string) => void;
24
+ isTTY?: boolean;
25
+ }
26
+
27
+ const DEFAULT_NAME = "my-sordo-app";
28
+
29
+ export function isInteractive(io: PromptIO = {}): boolean {
30
+ if (io.isTTY !== undefined) return io.isTTY;
31
+ return Boolean(process.stdin.isTTY);
32
+ }
33
+
34
+ export function promptName(
35
+ current: string | undefined,
36
+ isValid: (name: string) => boolean,
37
+ io: PromptIO = {},
38
+ ): string | undefined {
39
+ if (current) return current;
40
+ const ask = io.prompt ?? prompt;
41
+ const out = io.stdout ?? ((m: string) => process.stdout.write(m));
42
+
43
+ for (let attempt = 0; attempt < 5; attempt++) {
44
+ const answer = (ask(`Project name: (${DEFAULT_NAME}) `) ?? "").trim();
45
+ const candidate = answer === "" ? DEFAULT_NAME : answer;
46
+ if (isValid(candidate)) return candidate;
47
+ out(
48
+ `✗ invalid project name: "${candidate}" — use lowercase letters, digits, _ or -\n`,
49
+ );
50
+ }
51
+ return undefined;
52
+ }
53
+
54
+ // "old school" is the TTY label for the no-agent choice; the flag value stays
55
+ // `none` (spec 18). `--template` remains an alias for `--agent`.
56
+ export function promptAgent(io: PromptIO = {}): AgentTemplate {
57
+ const ask = io.prompt ?? prompt;
58
+ const answer = (
59
+ ask(
60
+ "Which coding agent are you using? [Claude/Codex/old school] (Claude) ",
61
+ ) ?? ""
62
+ )
63
+ .trim()
64
+ .toLowerCase();
65
+ if (answer === "codex") return "codex";
66
+ if (answer === "none" || answer === "old school" || answer === "old-school") {
67
+ return "none";
68
+ }
69
+ return "claude";
70
+ }
71
+
72
+ export function promptType(io: PromptIO = {}): ProjectType {
73
+ const ask = io.prompt ?? prompt;
74
+ const answer = (
75
+ ask(
76
+ "What kind of project are you building? [frontend/backend/fullstack] (fullstack) ",
77
+ ) ?? ""
78
+ )
79
+ .trim()
80
+ .toLowerCase();
81
+ if (answer === "frontend") return "frontend";
82
+ if (answer === "backend") return "backend";
83
+ return "fullstack";
84
+ }
85
+
86
+ // Asked only for frontend/fullstack — backend has no UI surface.
87
+ export function promptUi(io: PromptIO = {}): boolean {
88
+ const ask = io.prompt ?? prompt;
89
+ const answer = (ask("Do you want a styled UI template? [Y/n] (Y) ") ?? "")
90
+ .trim()
91
+ .toLowerCase();
92
+ return !(answer === "n" || answer === "no");
93
+ }
94
+
95
+ // Asked only for fullstack.
96
+ export function promptMonorepo(io: PromptIO = {}): boolean {
97
+ const ask = io.prompt ?? prompt;
98
+ const answer = (ask("Do you want a monorepo structure? [y/N] (N) ") ?? "")
99
+ .trim()
100
+ .toLowerCase();
101
+ return answer === "y" || answer === "yes";
102
+ }
103
+
104
+ // The option set depends on project type: container is fullstack-only.
105
+ export function promptTarget(type: ProjectType, io: PromptIO = {}): Target {
106
+ const ask = io.prompt ?? prompt;
107
+ const options = type === "fullstack" ? "bun/edge/container" : "bun/edge";
108
+ const answer = (ask(`Where will you deploy? [${options}] (bun) `) ?? "")
109
+ .trim()
110
+ .toLowerCase();
111
+ if (answer === "edge" || answer === "worker" || answer === "worker/edge") {
112
+ return "edge";
113
+ }
114
+ if (
115
+ type === "fullstack" &&
116
+ (answer === "container" ||
117
+ answer === "docker" ||
118
+ answer === "container/docker")
119
+ ) {
120
+ return "container";
121
+ }
122
+ return "bun";
123
+ }
124
+
125
+ export function promptDeploy(io: PromptIO = {}): Deploy {
126
+ const ask = io.prompt ?? prompt;
127
+ const answer = (
128
+ ask("Deploy plugin? [cloudflare/vercel/deno/netlify/none] (none) ") ?? ""
129
+ )
130
+ .trim()
131
+ .toLowerCase();
132
+ const valid: Deploy[] = [
133
+ "cloudflare",
134
+ "vercel",
135
+ "deno",
136
+ "netlify",
137
+ "bun",
138
+ "none",
139
+ ];
140
+ return (valid as string[]).includes(answer) ? (answer as Deploy) : "none";
141
+ }
package/src/readme.ts ADDED
@@ -0,0 +1,74 @@
1
+ // README + template-file rendering. See spec cli/09-create-sordo-dx item 2.
2
+ //
3
+ // `applyTemplate` does two passes:
4
+ // 1. Strip/keep conditional blocks delimited by:
5
+ // <!-- if:KEY=VALUE -->...<!-- /if -->
6
+ // The block is kept iff `vars[KEY] === VALUE`.
7
+ // 2. Replace `{{name}}`, `{{agent}}`, `{{type}}`, `{{ui}}`, `{{monorepo}}`,
8
+ // `{{app_name}}`, `{{target}}`, `{{deploy}}` placeholders with the
9
+ // corresponding `vars` entry.
10
+ //
11
+ // `renderTemplatesInTree` walks a scaffolded project and applies the template
12
+ // to every text file we care about (README.md, *.md, *.json, *.ts, *.tsx).
13
+ // Anything else is left untouched so we don't corrupt binary assets.
14
+
15
+ export interface TemplateVars {
16
+ name: string;
17
+ agent: "claude" | "codex" | "none";
18
+ type: "frontend" | "backend" | "fullstack";
19
+ ui: "yes" | "no";
20
+ monorepo: "yes" | "no";
21
+ target: "bun" | "edge" | "container";
22
+ deploy: "cloudflare" | "vercel" | "deno" | "netlify" | "bun" | "none";
23
+ app_name: string;
24
+ }
25
+
26
+ const CONDITIONAL_RE =
27
+ /<!--\s*if:([a-zA-Z_]+)=([a-zA-Z0-9_-]+)\s*-->([\s\S]*?)<!--\s*\/if\s*-->\n?/g;
28
+
29
+ const TEXT_EXT_RE =
30
+ /\.(md|mdx|json|jsonc|ts|tsx|js|jsx|sh|toml|yml|yaml|gitignore)$/;
31
+
32
+ export function applyTemplate(source: string, vars: TemplateVars): string {
33
+ const stripped = source.replace(
34
+ CONDITIONAL_RE,
35
+ (_match, key: string, value: string, body: string) => {
36
+ const v = (vars as unknown as Record<string, string>)[key];
37
+ return v === value ? body : "";
38
+ },
39
+ );
40
+ return (
41
+ stripped
42
+ .replaceAll("{{name}}", vars.name)
43
+ .replaceAll("{{agent}}", vars.agent)
44
+ .replaceAll("{{type}}", vars.type)
45
+ .replaceAll("{{ui}}", vars.ui)
46
+ .replaceAll("{{monorepo}}", vars.monorepo)
47
+ .replaceAll("{{app_name}}", vars.app_name)
48
+ .replaceAll("{{target}}", vars.target)
49
+ .replaceAll("{{deploy}}", vars.deploy)
50
+ // Legacy placeholders from earlier overlay revisions — kept so existing
51
+ // CLAUDE.md / AGENTS.md template text keeps interpolating.
52
+ .replaceAll("{{PROJECT_NAME}}", vars.name)
53
+ .replaceAll("{{DEPLOY_TARGET}}", vars.deploy)
54
+ );
55
+ }
56
+
57
+ export async function renderTemplatesInTree(
58
+ dir: string,
59
+ vars: TemplateVars,
60
+ ): Promise<void> {
61
+ const glob = new Bun.Glob("**/*");
62
+ for await (const rel of glob.scan({ cwd: dir, onlyFiles: true, dot: true })) {
63
+ if (!TEXT_EXT_RE.test(rel) && !rel.endsWith("README.md")) continue;
64
+ const path = `${dir}/${rel}`;
65
+ const file = Bun.file(path);
66
+ const text = await file.text();
67
+ if (!hasTemplateMarkers(text)) continue;
68
+ await Bun.write(path, applyTemplate(text, vars));
69
+ }
70
+ }
71
+
72
+ function hasTemplateMarkers(text: string): boolean {
73
+ return text.includes("{{") || text.includes("<!-- if:");
74
+ }
package/src/ui.ts ADDED
@@ -0,0 +1,207 @@
1
+ // UI starter integration (spec 18 §UI starter).
2
+ //
3
+ // create-sordo stays zero-dependency and offline, so instead of shelling out
4
+ // to `sordo ui init` + `sordo add` (which need the project's installed
5
+ // binary) we vendor the starter set under templates/ui-starter/ and copy it
6
+ // directly. The vendored copies are byte-for-byte identical to
7
+ // packages/sordo/templates/ (helpers, tokens, themes) — a drift test enforces
8
+ // that — so this is
9
+ // equivalent to what `sordo add button card input label` would stamp.
10
+
11
+ import { existsSync } from "node:fs";
12
+ import { resolve } from "node:path";
13
+ import type { Theme } from "./prompts.ts";
14
+
15
+ // Runtime peer deps the starter components + _internal helpers import.
16
+ // Peer deps of the starter set:
17
+ // button → cn + cva, card → cn, input → cn, label → cn + @radix-ui/react-label
18
+ export const UI_DEPS: Record<string, string> = {
19
+ "@radix-ui/react-label": "^2.1.0",
20
+ "class-variance-authority": "^0.7.0",
21
+ clsx: "^2.1.0",
22
+ "tailwind-merge": "^2.5.0",
23
+ };
24
+
25
+ // Dev-only: the Tailwind v4 CLI that compiles app.css → app.generated.css (the
26
+ // `css` script `dev`/`build` run for you — see pkgScripts in src/index.ts).
27
+ export const UI_DEV_DEPS: Record<string, string> = {
28
+ "@tailwindcss/cli": "^4.0.0",
29
+ };
30
+
31
+ const STARTER_COMPONENTS = ["button", "card", "input", "label"] as const;
32
+
33
+ // Stamp the vendored starter set into an app directory and rewrite the demo to
34
+ // import the stamped components. `uiStarterDir` is templates/ui-starter.
35
+ export async function applyUiStarter(
36
+ appRoot: string,
37
+ theme: Theme,
38
+ uiStarterDir: string,
39
+ ): Promise<void> {
40
+ const uiDir = `${appRoot}/app/components/ui`;
41
+ const internalDir = `${uiDir}/_internal`;
42
+ await Bun.$`mkdir -p ${internalDir}`.quiet();
43
+
44
+ for (const name of STARTER_COMPONENTS) {
45
+ await Bun.$`cp ${uiStarterDir}/${name}.tsx ${uiDir}/${name}.tsx`.quiet();
46
+ }
47
+ await Bun.$`cp -R ${uiStarterDir}/_internal/. ${internalDir}`.quiet();
48
+ await writeStyling(appRoot, theme, uiStarterDir);
49
+
50
+ // Demo page + island that import the stamped components. Only applies to
51
+ // frontend / fullstack, which always have app/routes + app/islands.
52
+ await Bun.$`cp ${uiStarterDir}/demo/index.tsx ${appRoot}/app/routes/index.tsx`.quiet();
53
+ await Bun.$`cp ${uiStarterDir}/demo/TodoApp.tsx ${appRoot}/app/islands/TodoApp.tsx`.quiet();
54
+ }
55
+
56
+ // Upstream shadcn/ui deps for the vendored button + dialog. `cn` is shadcn's
57
+ // own clsx + tailwind-merge package, imported directly by upstream source.
58
+ export const UI_SHADCN_DEPS: Record<string, string> = {
59
+ "class-variance-authority": "^0.7.1",
60
+ cn: "^0.5.0",
61
+ "lucide-react": "^1.59.0",
62
+ "radix-ui": "^1.8.1",
63
+ };
64
+
65
+ // `--ui shadcn`: upstream shadcn/ui on a whole-tree hydrated demo page. The
66
+ // vendored components under templates/ui-shadcn/components are byte-for-byte
67
+ // what `sordo add @shadcn/<name>` stamps (drift-tested), so later adds slot
68
+ // in beside them.
69
+ export async function applyShadcnStarter(
70
+ appRoot: string,
71
+ theme: Theme,
72
+ uiStarterDir: string,
73
+ uiShadcnDir: string,
74
+ ): Promise<void> {
75
+ const uiDir = `${appRoot}/app/components/ui`;
76
+ const libDir = `${appRoot}/app/lib`;
77
+ await Bun.$`mkdir -p ${uiDir} ${libDir}`.quiet();
78
+ await Bun.$`cp -R ${uiShadcnDir}/components/. ${uiDir}`.quiet();
79
+ // Upstream `registry:lib/utils` — keeps `@/lib/utils` imports working.
80
+ await Bun.write(`${libDir}/utils.ts`, 'export { cn } from "cn";\n');
81
+ await writeStyling(appRoot, theme, uiStarterDir);
82
+ await addAppAlias(appRoot);
83
+
84
+ await Bun.$`cp ${uiShadcnDir}/demo/index.tsx ${appRoot}/app/routes/index.tsx`.quiet();
85
+ // The hydrated page replaces the island demo.
86
+ await Bun.$`rm -rf ${appRoot}/app/islands`.quiet();
87
+ }
88
+
89
+ // `@/*` → `./app/*`, the alias upstream shadcn source imports through.
90
+ async function addAppAlias(appRoot: string): Promise<void> {
91
+ const path = `${appRoot}/tsconfig.json`;
92
+ const config = (await Bun.file(path).json()) as {
93
+ compilerOptions?: Record<string, unknown>;
94
+ };
95
+ config.compilerOptions = {
96
+ ...(config.compilerOptions ?? {}),
97
+ paths: { "@/*": ["./app/*"] },
98
+ };
99
+ await Bun.write(path, `${JSON.stringify(config, null, "\t")}\n`);
100
+ }
101
+
102
+ // Tokens, Tailwind entry, and the stylesheet route both starters share.
103
+ async function writeStyling(
104
+ appRoot: string,
105
+ theme: Theme,
106
+ uiStarterDir: string,
107
+ ): Promise<void> {
108
+ const componentsDir = `${appRoot}/app/components`;
109
+ const stylesDir = `${appRoot}/app/styles`;
110
+ await Bun.$`mkdir -p ${componentsDir} ${stylesDir}`.quiet();
111
+
112
+ const themeTokens = resolve(uiStarterDir, "themes", theme, "tokens.css");
113
+ const tokens = existsSync(themeTokens)
114
+ ? themeTokens
115
+ : resolve(uiStarterDir, "tokens.css");
116
+ await Bun.$`cp ${tokens} ${stylesDir}/tokens.css`.quiet();
117
+ // app.css is written (not vendored) because a committed `@theme` stylesheet
118
+ // would trip this repo's Biome CSS parser, which has Tailwind directives off.
119
+ await Bun.write(`${stylesDir}/app.css`, APP_CSS);
120
+ // Placeholder so the styles route's `type: "text"` import always resolves,
121
+ // even before the first `bun run css`. `dev`/`build` recompile it; it's
122
+ // gitignored so the real output never gets committed.
123
+ await Bun.write(`${stylesDir}/app.generated.css`, GENERATED_CSS_PLACEHOLDER);
124
+ // Type for the `type: "text"` CSS import so `tsc --noEmit` stays clean.
125
+ await Bun.write(`${stylesDir}/css.d.ts`, CSS_DTS);
126
+
127
+ // CSS wiring: Sordo ships no stylesheet link, so the starter serves the
128
+ // compiled Tailwind output from an API route and links it via a shared
129
+ // `head()`. Pages opt in by re-exporting `head` (the demo + every
130
+ // /sordo-init page does).
131
+ await Bun.write(`${componentsDir}/_head.tsx`, HEAD_TSX);
132
+ const apiDir = `${appRoot}/app/routes/api`;
133
+ await Bun.$`mkdir -p ${apiDir}`.quiet();
134
+ await Bun.write(`${apiDir}/styles.ts`, STYLES_ROUTE);
135
+ }
136
+
137
+ // Pre-wired Tailwind v4 + tokens stylesheet (the wiring `sordo ui init`
138
+ // prints). Sordo does not bundle Tailwind — compile this with the Tailwind
139
+ // CLI; see the generated README "Styling" section.
140
+ const APP_CSS = `@import "tailwindcss";
141
+ @import "./tokens.css";
142
+
143
+ @theme inline {
144
+ --color-background: var(--background);
145
+ --color-foreground: var(--foreground);
146
+ --color-card: var(--card);
147
+ --color-card-foreground: var(--card-foreground);
148
+ --color-popover: var(--popover);
149
+ --color-popover-foreground: var(--popover-foreground);
150
+ --color-primary: var(--primary);
151
+ --color-primary-foreground: var(--primary-foreground);
152
+ --color-secondary: var(--secondary);
153
+ --color-secondary-foreground: var(--secondary-foreground);
154
+ --color-muted: var(--muted);
155
+ --color-muted-foreground: var(--muted-foreground);
156
+ --color-accent: var(--accent);
157
+ --color-accent-foreground: var(--accent-foreground);
158
+ --color-destructive: var(--destructive);
159
+ --color-destructive-foreground: var(--destructive-foreground);
160
+ --color-border: var(--border);
161
+ --color-input: var(--input);
162
+ --color-ring: var(--ring);
163
+ --radius-lg: var(--radius);
164
+ --radius-md: calc(var(--radius) - 2px);
165
+ --radius-sm: calc(var(--radius) - 4px);
166
+ }
167
+ `;
168
+
169
+ // Written before the first compile so the styles route always imports cleanly.
170
+ const GENERATED_CSS_PLACEHOLDER = `/* Generated by \`bun run css\` from app/styles/app.css — do not edit.
171
+ Empty until the first compile; \`bun run dev\` / \`bun run build\` regenerate it. */
172
+ `;
173
+
174
+ // Lets \`import css from "./app.generated.css" with { type: "text" }\` typecheck.
175
+ const CSS_DTS = `declare module "*.css" {
176
+ const css: string;
177
+ export default css;
178
+ }
179
+ `;
180
+
181
+ // Shared <head> contributions. Pages re-export this as `head` so every route
182
+ // links the compiled stylesheet that app/routes/api/styles.ts serves.
183
+ const HEAD_TSX = `import type * as React from "react";
184
+
185
+ // Sordo links no stylesheet on its own, so the UI starter routes one in here:
186
+ // pages re-export this as \`head\` (\`export { head } from "../components/_head.tsx"\`)
187
+ // and the renderer emits whatever it returns into <head>. The "_" prefix keeps
188
+ // this file out of the route table.
189
+ export function head(): React.ReactNode {
190
+ return <link rel="stylesheet" href="/api/styles" />;
191
+ }
192
+ `;
193
+
194
+ // API route that hands out the compiled Tailwind sheet. The \`type: "text"\`
195
+ // import embeds the CSS into the bundle, so this works in dev and in the
196
+ // compiled production binary alike.
197
+ const STYLES_ROUTE = `import css from "../../styles/app.generated.css" with { type: "text" };
198
+
199
+ // GET /api/styles — the compiled Tailwind stylesheet. Sordo ships no CSS
200
+ // pipeline; the \`css\` script (run by \`dev\`/\`build\`) compiles app/styles/app.css
201
+ // into app.generated.css, and app/components/_head.tsx links this route.
202
+ export function GET(): Response {
203
+ return new Response(css, {
204
+ headers: { "content-type": "text/css; charset=utf-8" },
205
+ });
206
+ }
207
+ `;
@@ -0,0 +1,3 @@
1
+ // Generated by scripts/sync-versions.ts — do not edit. Versions of the
2
+ // workspace packages this create-sordo release ships alongside.
3
+ export const SORDO_VERSION = "0.3.0";
@@ -0,0 +1,27 @@
1
+ import type { SordoContext } from "sordo/middleware";
2
+
3
+ // A small in-memory sample resource so a backend project boots with a working
4
+ // endpoint. Swap the array for a real data source when you're ready.
5
+ interface Todo {
6
+ id: number;
7
+ text: string;
8
+ done: boolean;
9
+ }
10
+
11
+ const todos: Todo[] = [
12
+ { id: 1, text: "wire up a database", done: false },
13
+ { id: 2, text: "add authentication", done: false },
14
+ ];
15
+
16
+ export function GET(_req: Request, ctx: SordoContext): Response {
17
+ return ctx.json({ todos });
18
+ }
19
+
20
+ export async function POST(req: Request, ctx: SordoContext): Promise<Response> {
21
+ const body = (await req.json()) as { text?: unknown };
22
+ const text = typeof body.text === "string" ? body.text.trim() : "";
23
+ if (!text) return ctx.json({ error: "text is required" }, { status: 400 });
24
+ const todo: Todo = { id: todos.length + 1, text, done: false };
25
+ todos.push(todo);
26
+ return ctx.json({ todo }, { status: 201 });
27
+ }
@@ -0,0 +1,64 @@
1
+ ---
2
+ description: Guided, plan-mode first scaffold for a Sordo project — pick feature patterns, see a plan, then scaffold after approval.
3
+ ---
4
+
5
+ # /sordo-init
6
+
7
+ Guide the user through their first feature scaffold. This command is a thin
8
+ driver — all the recipe detail lives in the `sordo` skill. Do **not**
9
+ duplicate the pattern catalog here; defer to `/sordo`.
10
+
11
+ You are (or should be) in **plan mode**: explore and propose, but write nothing
12
+ until the user approves the plan.
13
+
14
+ Run these four steps:
15
+
16
+ 1. **Discover** — read the project to fit the plan to what was scaffolded:
17
+ - project type (frontend / backend / fullstack) and deploy target, from
18
+ `sordo.config.ts` and `package.json`,
19
+ - whether the UI starter is initialized (does `app/components/ui/_internal/`
20
+ exist?),
21
+ - flat vs. monorepo layout (is there an `apps/` workspace?).
22
+ 2. **Ask** — which feature pattern(s) from the `sordo` skill catalog the user
23
+ wants (auth-rbac, crm, task, pivot, dashboard), plus the domain specifics the
24
+ recipes adapt to: entity names, fields, and roles.
25
+ 3. **Plan** — present the file list, the `sordo add @shadcn/<name>` components to stamp, and
26
+ the mock-data shape, honoring the skill's **UI + mock data** depth contract
27
+ (no `bun:sqlite`, migrations, or real backend). Write nothing yet.
28
+ 4. **Scaffold** — once the user approves and exits plan mode:
29
+ - **Remove the starter demo first.** The scaffolder ships a placeholder
30
+ `app/routes/index.tsx` + `app/islands/TodoApp.tsx` to prove hydration. This
31
+ is pre-`/sordo-init` filler — delete both before generating the real
32
+ feature so the first page isn't a throwaway todo list. (Replace `index.tsx`
33
+ with the chosen pattern's landing page, or a minimal welcome if the pattern
34
+ has its own routes.)
35
+ - Generate the files per the `sordo` skill recipes. If UI setup isn't
36
+ initialized, run `sordo ui init --shadcn` first.
37
+
38
+ ## Framework constraints (don't re-derive these)
39
+
40
+ These are stable facts — bake them into the plan instead of tracing the source:
41
+
42
+ - **Page routes (`.tsx`) receive only `ctx.params`** as props. They cannot read
43
+ cookies, set headers, or redirect. Anything needing those goes in an API route
44
+ or middleware (below). Pages contribute to `<head>` via an exported
45
+ `head()` function.
46
+ - **`.ts` route files must live under `app/routes/api/`** (URL `/api/...`). A
47
+ `.ts` route anywhere else is a build error — e.g. logout is
48
+ `app/routes/api/logout.ts` → `/api/logout`, not `app/routes/logout.ts`.
49
+ - **`app/middleware.ts` is the only way to gate a page route.** It default-exports
50
+ one global `Middleware (req, ctx, next)` that runs on every request with full
51
+ `ctx` (cookies, `ctx.redirect`). Protect `/admin`-style pages here; never try
52
+ to gate inside the page component.
53
+ - **Form POSTs target API routes.** Since pages can't read the request body or
54
+ set cookies, login/mutation forms use a native `<form method="post"
55
+ action="/api/…">` posting to a `.ts` handler that sets the cookie and redirects.
56
+ - **`chart` and `form` are client islands** (they pull `recharts` /
57
+ `react-hook-form`). Wrap them in `<Island name="…">`; a server-rendered native
58
+ form avoids `form` entirely.
59
+ - **Styling is opt-in per page.** If `app/components/_head.tsx` exists (UI
60
+ projects have it), every new page route must re-export it —
61
+ `export { head } from "../components/_head.tsx";` — or it renders unstyled.
62
+
63
+ For ongoing work after this first scaffold (adding one component or one more
64
+ pattern later), the user invokes the `/sordo` skill directly.
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env bash
2
+ # PostToolUse hook: run Biome on the file Claude just touched.
3
+ # No-ops cleanly when Biome is not installed so it's safe to ship by default.
4
+ set -euo pipefail
5
+
6
+ file="${CLAUDE_FILE_PATH:-${1:-}}"
7
+ if [[ -z "${file}" ]]; then exit 0; fi
8
+ case "${file}" in
9
+ *.ts|*.tsx|*.js|*.jsx|*.json|*.jsonc) ;;
10
+ *) exit 0 ;;
11
+ esac
12
+
13
+ if command -v biome >/dev/null 2>&1; then
14
+ biome check --write --no-errors-on-unmatched "${file}" || exit 2
15
+ elif command -v bunx >/dev/null 2>&1; then
16
+ bunx --bun @biomejs/biome check --write --no-errors-on-unmatched "${file}" 2>/dev/null || exit 0
17
+ fi
@@ -0,0 +1,17 @@
1
+ # Build-time discovery rule
2
+
3
+ Routes, islands, agents, and tools are discovered from the filesystem
4
+ at **build time**, not at request time.
5
+
6
+ - `sordo build` scans `app/routes/`, `app/islands/`, `app/agents/`,
7
+ `app/tools/`, and `app/jobs/` and inlines the discovered tables into
8
+ the server bundle. The production server never calls `Bun.Glob` /
9
+ `scanRoutes` / `scanIslands`.
10
+ - This is what makes Sordo cold-start fast and adapter-portable
11
+ (edge runtimes that disallow filesystem access still work).
12
+ - **Dev mode is the exception.** The dev server re-scans on file
13
+ change to drive HMR.
14
+ - **Don't break the rule:** never write code that calls `Bun.Glob` or
15
+ reads `app/**` at request time. If you find yourself wanting to,
16
+ the answer is probably a build-time macro or a config option in
17
+ `sordo.config.ts`.
@@ -0,0 +1,28 @@
1
+ # Bun-native rule
2
+
3
+ This project runs on Bun. Reach for Bun primitives first; do not
4
+ reintroduce Node-era replacements just because a familiar library
5
+ provides them.
6
+
7
+ - **HTTP server:** `Bun.serve`. The framework already wires it — do
8
+ not add Express / Fastify / Hono / `node:http`.
9
+ - **Filesystem discovery:** `Bun.Glob`. Do not pull in `fast-glob`,
10
+ `globby`, or `chokidar`.
11
+ - **Bundling:** `Bun.build`. The framework runs it for you at
12
+ `sordo build`; you should not add Webpack / Rollup / esbuild /
13
+ Vite / tsup.
14
+ - **File I/O:** `Bun.file(path).text()` / `.json()` / `.bytes()` and
15
+ `Bun.write(path, data)` before reaching for `node:fs`.
16
+ - **Hashing / crypto:** `Bun.CryptoHasher`, `Bun.password`. Avoid
17
+ `crypto` / `bcrypt` unless you have a real reason.
18
+ - **Databases:** `bun:sqlite`, `Bun.sql` (Postgres), `Bun.RedisClient`,
19
+ `Bun.S3Client` before reaching for npm wrappers.
20
+ - **Environment:** `Bun.env`. The framework injects the public subset
21
+ declared in `sordo.config.ts#env.public`; secrets live in the OS
22
+ keychain (see `sordo-cli` skill).
23
+ - **Tests:** `bun test`. Do not add Jest or Vitest.
24
+ - **Package manager:** `bun` / `bunx`. Do not run `npm` / `npx` /
25
+ `yarn` / `pnpm` in this project.
26
+
27
+ If you genuinely need a Node-only library, that's fine — Bun's Node
28
+ compatibility is strong. But default to Bun primitives.
@@ -0,0 +1,31 @@
1
+ # Filesystem routing rule
2
+
3
+ Routes are discovered from the filesystem under `app/routes/`. Path
4
+ conventions:
5
+
6
+ | File | URL |
7
+ |---|---|
8
+ | `app/routes/index.tsx` | `/` |
9
+ | `app/routes/about.tsx` | `/about` |
10
+ | `app/routes/hotels/index.tsx` | `/hotels` |
11
+ | `app/routes/hotels/[city].tsx` | `/hotels/:city` |
12
+ | `app/routes/api/revenue.ts` | `/api/revenue` |
13
+ | `app/routes/_internal.tsx` | (private — never routed) |
14
+
15
+ - **Page routes** are `.tsx` files that default-export a React
16
+ component. The component receives no props by default; read params
17
+ / cookies / env from `SordoContext` via the page's optional
18
+ `loader` (export `loader` if you need server-side data).
19
+ - **API routes** are `.ts` files that export named HTTP-method handlers:
20
+ `GET`, `POST`, `PUT`, `DELETE`, `PATCH`. They return a standard
21
+ `Response`. Default exports in `.ts` files are reserved and will
22
+ error.
23
+ - **Dynamic segments** use `[param]` in the filename. The values land
24
+ in `ctx.params`.
25
+ - **Files starting with `_`** are private — co-located helpers,
26
+ components, or test files. They are never routed.
27
+ - **Reserved URL prefixes:** `/__sordo_*` and `/_sordo/*` are
28
+ framework-owned. Don't put your own routes under them.
29
+ - **Discovery happens at build time.** The production server bundle
30
+ has the route table inlined; it does not call `Bun.Glob` at runtime.
31
+ Dev mode re-scans on file change (that's where HMR comes from).
@@ -0,0 +1,46 @@
1
+ # Islands rule
2
+
3
+ The default rendering mode is server-side. Use **islands** for the
4
+ parts of a page that need browser-side interactivity (`useState`,
5
+ `useEffect`, event handlers).
6
+
7
+ - **Where they live:** `app/islands/*.tsx`. Files outside this
8
+ directory are server-only and never ship to the browser.
9
+ - **How to mark one:** start the file with `"use client";` and
10
+ default-export a React component. The framework auto-registers it,
11
+ bundles its client code, and serves the chunk under
12
+ `/_sordo/client/*` (in dev via `setupDevClient`; in production via
13
+ `sordo build`).
14
+ - **How to use one:** import the component from a route file and
15
+ wrap each use-site in `<Island name="…">…</Island>` from
16
+ `sordo/render`. The wrapper emits the `data-island` marker + props
17
+ sibling that the client runtime scans for — without it the markup
18
+ SSRs fine but never hydrates.
19
+
20
+ ```tsx
21
+ import { Island } from "sordo/render";
22
+ import TodoApp from "../islands/TodoApp.tsx";
23
+
24
+ export default function Index() {
25
+ return (
26
+ <main>
27
+ <Island name="TodoApp">
28
+ <TodoApp />
29
+ </Island>
30
+ </main>
31
+ );
32
+ }
33
+ ```
34
+ - **Naming:** the island's auto-registered name is the file path
35
+ relative to `app/islands/` with slashes replaced by dashes and the
36
+ extension stripped (e.g. `app/islands/forms/Signup.tsx` →
37
+ `forms-Signup`). Pass the same string as `<Island name="…">`. Default
38
+ exports are the only export consulted.
39
+ - **Dev mode hydrates.** `sordo dev` builds islands in
40
+ `--mode development` (no minify), serves them, and the client runtime
41
+ hydrates each `[data-island]` marker. HMR reloads the page on island
42
+ changes.
43
+ - **Don't put non-island helpers in `app/islands/`.** Every `.tsx`
44
+ in there is treated as a hydratable component. Put shared
45
+ presentational components in `app/components/` or co-locate them
46
+ under a `_` prefix.