sordo 0.0.0-stage → 0.2.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 (137) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/CLAUDE.md +124 -0
  3. package/README.md +102 -2
  4. package/bin/sordo.ts +5 -0
  5. package/package.json +64 -5
  6. package/src/adapters/bun.ts +59 -0
  7. package/src/adapters/edge.ts +38 -0
  8. package/src/adapters/types.ts +39 -0
  9. package/src/agents-md/collect.ts +113 -0
  10. package/src/agents-md/generate.ts +44 -0
  11. package/src/agents-md/index.ts +9 -0
  12. package/src/agents-md/render.ts +150 -0
  13. package/src/agents-md/subprocess-entry.ts +92 -0
  14. package/src/agents-md/subprocess-runner.ts +111 -0
  15. package/src/agents-md/write.ts +38 -0
  16. package/src/agents-md/zod-to-json-schema.ts +18 -0
  17. package/src/ai/context.ts +72 -0
  18. package/src/ai/define.ts +15 -0
  19. package/src/ai/errors.ts +51 -0
  20. package/src/ai/index.ts +36 -0
  21. package/src/ai/middleware.ts +21 -0
  22. package/src/ai/registry.ts +96 -0
  23. package/src/ai/run.ts +185 -0
  24. package/src/ai/scan.ts +42 -0
  25. package/src/ai/stream.ts +71 -0
  26. package/src/ai/triggers.ts +124 -0
  27. package/src/ai/types.ts +67 -0
  28. package/src/ai/validate.ts +82 -0
  29. package/src/build/assets.ts +48 -0
  30. package/src/build/client-entry.ts +43 -0
  31. package/src/build/embedded.ts +66 -0
  32. package/src/build/hash.ts +21 -0
  33. package/src/build/index.ts +437 -0
  34. package/src/build/macros/agents-hash.macro.ts +9 -0
  35. package/src/build/macros/agents.macro.ts +21 -0
  36. package/src/build/macros/env.macro.ts +25 -0
  37. package/src/build/macros/manifest.macro.ts +8 -0
  38. package/src/build/macros/routes.macro.ts +10 -0
  39. package/src/build/page-entry.ts +136 -0
  40. package/src/build/scan-islands.ts +39 -0
  41. package/src/build/server-entry.ts +237 -0
  42. package/src/cli/ansi.ts +41 -0
  43. package/src/cli/build.ts +183 -0
  44. package/src/cli/commands/add/apply.ts +31 -0
  45. package/src/cli/commands/add/component-diff.ts +116 -0
  46. package/src/cli/commands/add/diff.ts +153 -0
  47. package/src/cli/commands/add/internal.ts +41 -0
  48. package/src/cli/commands/add/load-catalog.ts +22 -0
  49. package/src/cli/commands/add/peer-deps.ts +115 -0
  50. package/src/cli/commands/add/registry-fetch.ts +122 -0
  51. package/src/cli/commands/add/shadcn.ts +285 -0
  52. package/src/cli/commands/add/source.ts +273 -0
  53. package/src/cli/commands/add/stamper.ts +73 -0
  54. package/src/cli/commands/add/tokens.ts +81 -0
  55. package/src/cli/commands/add/ui-paths.ts +113 -0
  56. package/src/cli/commands/add.ts +427 -0
  57. package/src/cli/commands/deploy.ts +143 -0
  58. package/src/cli/commands/migrate.ts +149 -0
  59. package/src/cli/commands/secret.ts +316 -0
  60. package/src/cli/commands/ui/build.ts +111 -0
  61. package/src/cli/commands/ui/init.ts +132 -0
  62. package/src/cli/commands/ui/migrate/git-guard.ts +19 -0
  63. package/src/cli/commands/ui/migrate/radix.ts +67 -0
  64. package/src/cli/commands/ui/migrate/rtl.ts +148 -0
  65. package/src/cli/commands/ui/shadcn.ts +82 -0
  66. package/src/cli/commands/ui/view.ts +63 -0
  67. package/src/cli/commands/ui.ts +86 -0
  68. package/src/cli/commands/update.ts +134 -0
  69. package/src/cli/commands/upgrade.ts +53 -0
  70. package/src/cli/commands/view.ts +34 -0
  71. package/src/cli/dev.ts +393 -0
  72. package/src/cli/doctor/config-checks.ts +63 -0
  73. package/src/cli/doctor/deps.ts +295 -0
  74. package/src/cli/doctor/hydrate.ts +65 -0
  75. package/src/cli/doctor/monorepo.ts +158 -0
  76. package/src/cli/doctor/probes.ts +16 -0
  77. package/src/cli/doctor/report.ts +72 -0
  78. package/src/cli/doctor/toolchain.ts +95 -0
  79. package/src/cli/doctor/types.ts +36 -0
  80. package/src/cli/doctor.ts +127 -0
  81. package/src/cli/index.ts +163 -0
  82. package/src/cli/log.ts +135 -0
  83. package/src/cli/run/affected.ts +79 -0
  84. package/src/cli/run/cache-key.ts +177 -0
  85. package/src/cli/run/cache-store.ts +0 -0
  86. package/src/cli/run/files.ts +96 -0
  87. package/src/cli/run/git.ts +13 -0
  88. package/src/cli/run/runner.ts +189 -0
  89. package/src/cli/run/workspace.ts +216 -0
  90. package/src/cli/run.ts +184 -0
  91. package/src/cli/update-check.ts +157 -0
  92. package/src/client/index.ts +65 -0
  93. package/src/client/link.tsx +61 -0
  94. package/src/client/page.ts +250 -0
  95. package/src/config/define.ts +5 -0
  96. package/src/config/env.ts +36 -0
  97. package/src/config/load.ts +147 -0
  98. package/src/config/schema.ts +110 -0
  99. package/src/config/secrets.ts +108 -0
  100. package/src/dev/client.ts +97 -0
  101. package/src/dev/hot.ts +24 -0
  102. package/src/dev/index.ts +4 -0
  103. package/src/dev/tree.ts +95 -0
  104. package/src/dev/watcher.ts +95 -0
  105. package/src/index.ts +54 -0
  106. package/src/internal/hmr-client.ts +52 -0
  107. package/src/internal/open-in-editor.ts +23 -0
  108. package/src/internal/runtime.ts +30 -0
  109. package/src/middleware/cookie-jar.ts +135 -0
  110. package/src/middleware/cookies.ts +60 -0
  111. package/src/middleware/index.ts +99 -0
  112. package/src/middleware/request-id.ts +22 -0
  113. package/src/middleware/response-helpers.ts +25 -0
  114. package/src/plugin/index.ts +109 -0
  115. package/src/render/bootstrap.ts +44 -0
  116. package/src/render/dev-error.tsx +73 -0
  117. package/src/render/index.tsx +253 -0
  118. package/src/render/island.tsx +33 -0
  119. package/src/render/meta.tsx +48 -0
  120. package/src/render/shell.tsx +41 -0
  121. package/src/router/conflict.ts +20 -0
  122. package/src/router/filesystem.ts +37 -0
  123. package/src/router/index.ts +247 -0
  124. package/src/router/match.ts +91 -0
  125. package/src/router/pattern.ts +88 -0
  126. package/src/server/index.ts +250 -0
  127. package/src/types.ts +53 -0
  128. package/src/ui/schema.ts +68 -0
  129. package/src/ui/types.ts +10 -0
  130. package/templates/_internal/cn.ts +6 -0
  131. package/templates/_internal/slot.ts +50 -0
  132. package/templates/_internal/variants.ts +1 -0
  133. package/templates/themes/neutral/tokens.css +46 -0
  134. package/templates/themes/slate/tokens.css +46 -0
  135. package/templates/themes/stone/tokens.css +46 -0
  136. package/templates/themes/zinc/tokens.css +46 -0
  137. package/templates/tokens.css +46 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,101 @@
1
+ # sordo
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c5c1020: Remove the `patties-ui` package and its built-in 60-component catalog. `sordo add` now takes upstream shadcn/ui (`@shadcn/<name>`), local paths, URLs, and `ui.registries`; `sordo add <name>` for a non-catalog name points at `@shadcn/<name>`. The registry schema, `_internal` helpers, tokens, and theme presets now ship inside `sordo`, so `bun add -D patties-ui` is no longer needed. Scaffolded apps no longer depend on `patties-ui`.
8
+ - a50617f: `sordo add @shadcn/<name>` stamps upstream shadcn/ui verbatim: registry items are mapped onto the existing add pipeline (import alias rewrite, transitive registry deps, pinned peer deps, `cssVars` token merge, schema validation, HTTPS-only, never installs). `sordo ui init --shadcn` wires the `@/*` alias and `app/lib/utils.ts`. The registry `ComponentFileSchema` gains an optional `root` (`components` | `app`) for files stamped into `app/{components,hooks,lib}`; the stamper refuses any other app-dir destination.
9
+ - a50617f: Add opt-in whole-tree page hydration (`export const hydrate = true`, or `render: { hydrate: "pages" }`): the page's whole React tree hydrates as one root from a `__sordo_bootstrap` payload, so function props and shared context work. Pages can export `loader(req, ctx)` (plus optional `serialize`/`deserialize`); server-only exports are stripped from client bundles. Adds client-side navigation between hydrated pages (`Link`, `navigate`, `prefetch` from `sordo/client`), per-route client-bytes reporting in `sordo build`, and a `sordo doctor` check for pages mixing `<Island>` with `hydrate`. Client bundles now define `NODE_ENV`, so production builds ship React's production build. Routes without `hydrate` are unchanged.
10
+
11
+ ### Patch Changes
12
+
13
+ - 36541a8: `sordo dev` no longer misses a newly added or deleted route when the file watcher drops its event; the app tree is also rescanned every second, so the server restarts within about a second instead of serving a stale route table.
14
+ - 089cb1a: Fix the `edge` target crashing every request with `Bun is not defined` / `process is not defined` on workerd. Cookies fall back to a small built-in jar when `Bun.CookieMap` is absent, and env / cwd / semver lookups no longer assume `Bun` or `process` exist.
15
+
16
+ ## 0.1.0
17
+
18
+ ### Minor Changes
19
+
20
+ - 748b2d7: Add `sordo run <task>`: a Bun-native task runner with a content-addressed
21
+ output cache and affected detection for workspace monorepos.
22
+
23
+ `sordo run` wraps each `(package, task)` unit with a cache built entirely on
24
+ Bun builtins (`Bun.CryptoHasher`, `Bun.Glob`, `Bun.Archive`, `bun:sqlite`,
25
+ `Bun.$`, `Bun.spawn`) — no Turborepo/Nx. It walks the workspace in topological
26
+ order, computes a conservative nine-component sha256 cache key per task, and on a
27
+ hit restores the task's declared outputs and replays its log instead of
28
+ re-running. A leaf change rebuilds exactly it and its transitive dependents;
29
+ everything else restores from cache.
30
+
31
+ Declare per-task `inputs` / `outputs` / `env` / `cache` in a `tasks` block in
32
+ `sordo.config.ts`. Flags: `--filter`, `--affected --since <ref>`, `--no-cache`,
33
+ `--force`, and `--dry-run` (which explains every hit/miss and why a key changed).
34
+ `sordo dev` / `build` are unchanged. Remote caching (`--remote`) is reserved
35
+ for a later release.
36
+
37
+ - b893f36: Add `sordo doctor`: a read-only project hygiene report. Runs and contextualizes `bun audit` / `bun outdated`, adds sordo-specific checks (config validity, single-React invariant in monorepos), and prints one aligned report with a concrete remedy per finding. Composed from Bun builtins (`Bun.which`, `Bun.$`, `Bun.stringWidth`/`stripANSI`/`wrapAnsi`). Exit codes: 0 pass / 1 fail / 2 cannot-run.
38
+
39
+ ### Patch Changes
40
+
41
+ - ffa0b2b: Add an "update available" banner and a `sordo upgrade` command.
42
+
43
+ The CLI now prints a cached, channel-aware banner on startup when a newer
44
+ `sordo` is published, and `sordo upgrade` bumps the project's dependency to
45
+ the newest release on its channel (`bun add sordo@<latest|next|…>`). The
46
+ banner reads from a local cache and refreshes in the background, so it never
47
+ blocks the CLI; opt out with `--no-update-check` or `NO_UPDATE_NOTIFIER`.
48
+
49
+ - ffa0b2b: Make dev-server bin + React resolution workspace-aware so Bun-workspace monorepos (hoisted root `node_modules`) load a single copy of React and don't crash SSR with "Invalid hook call". Flat-app resolution is unchanged.
50
+ - a99d1bf: Make `patties-ui` truly optional at the CLI: the `add` / `ui` / `view` /
51
+ `update` catalog commands (the only modules that import `patties-ui`) are now
52
+ lazy-loaded in the command dispatcher, so `sordo dev` / `build` / `deploy` /
53
+ `secret` no longer fail with "Cannot find module 'patties-ui/schema'" in
54
+ projects that don't depend on the UI catalog (e.g. backend or `--no-ui`
55
+ projects scaffolded by create-sordo).
56
+
57
+ ## 0.0.12-next.0
58
+
59
+ ### Patch Changes
60
+
61
+ - ffa0b2b: Add an "update available" banner and a `sordo upgrade` command.
62
+
63
+ The CLI now prints a cached, channel-aware banner on startup when a newer
64
+ `sordo` is published, and `sordo upgrade` bumps the project's dependency to
65
+ the newest release on its channel (`bun add sordo@<latest|next|…>`). The
66
+ banner reads from a local cache and refreshes in the background, so it never
67
+ blocks the CLI; opt out with `--no-update-check` or `NO_UPDATE_NOTIFIER`.
68
+
69
+ - ffa0b2b: Make dev-server bin + React resolution workspace-aware so Bun-workspace monorepos (hoisted root `node_modules`) load a single copy of React and don't crash SSR with "Invalid hook call". Flat-app resolution is unchanged.
70
+ - a99d1bf: Make `patties-ui` truly optional at the CLI: the `add` / `ui` / `view` /
71
+ `update` catalog commands (the only modules that import `patties-ui`) are now
72
+ lazy-loaded in the command dispatcher, so `sordo dev` / `build` / `deploy` /
73
+ `secret` no longer fail with "Cannot find module 'patties-ui/schema'" in
74
+ projects that don't depend on the UI catalog (e.g. backend or `--no-ui`
75
+ projects scaffolded by create-sordo).
76
+
77
+ ## 0.0.8
78
+
79
+ ### Patch Changes
80
+
81
+ - 67ab8ce: Internal: move framework source from the repo root into
82
+ `packages/sordo/` so the framework participates in changesets-managed
83
+ releases. The repo root is now a private workspace shell; both
84
+ `sordo` and `create-sordo` live under `packages/*` and are
85
+ discovered uniformly by changesets and `bun --filter`.
86
+
87
+ No public API changes. The published tarball still ships `src/`,
88
+ `bin/`, `AGENTS.md`, `README.md`, and `CHANGELOG.md` at the same
89
+ relative paths inside the package.
90
+
91
+ ## 0.0.3
92
+
93
+ ### Patch Changes
94
+
95
+ - Ship phase 4: plugin system (`sordo/plugin` subpath). Adds `definePlugin`, `PluginServer.route`/`use`, `Bun.semver`-based compat checks, and hooks for build, dev, agents-md, and jobs.
96
+
97
+ ## 0.0.1
98
+
99
+ ### Patch Changes
100
+
101
+ - Initial release.
package/CLAUDE.md ADDED
@@ -0,0 +1,124 @@
1
+ # `sordo` package conventions
2
+
3
+ This is the framework itself — the runtime, CLI, build pipeline, dev server,
4
+ renderer, router, middleware, and adapters. Most things you'd add to a
5
+ Bun-native full-stack framework live somewhere under `src/`.
6
+
7
+ Project-wide rules live in `../../CLAUDE.md`. Read those first. The notes
8
+ below are specific to working inside this package.
9
+
10
+ ## Source layout
11
+
12
+ - `src/router/` — filesystem route scan + compile to Bun route patterns
13
+ - `src/render/` — React SSR (`renderToReadableStream`) + dev error overlay + island marker emission
14
+ - `src/client/` — browser hydration runtime: scans `[data-island]` markers; `page.ts` boots whole-tree hydrated pages (`export const hydrate = true`) and drives client-side navigation (`Link` / `navigate`) from the `__sordo_bootstrap` payload (framework specs 28/29)
15
+ - `src/build/` — route + island scan, client/server entry generation, `Bun.build` pipeline. Hydrated pages get a generated per-route entry (`page-entry.ts`) bundled in the same split build as islands; `loader`/`serialize` are stripped from client bundles via `Bun.Transpiler` export elimination. `adapter.bun.compile` (production) runs `bun build --compile` against the generated server-entry SOURCE and embeds app/public + client chunks via `with { type: "file" }` / `Bun.embeddedFiles`; `--compile` with `--target edge` is a config-time error
16
+ - `src/middleware/` — composition, `SordoContext`. `request-id.ts` mints `ctx.requestId` (echoed as `X-Request-Id`, inbound junk ignored); the router finalizer folds in the cookie flush and dev-only `Server-Timing`
17
+ - `src/dev/` — `bun --hot` / `bun --watch` integration, HMR WebSocket, `setupDevClient` (bundles islands in dev and serves `/_sordo/client/*`)
18
+ - `src/server/` — `startServer` / `createServer` around `Bun.serve`
19
+ - `src/config/` — `defineConfig`, env + secrets loading, Zod schemas. `config.agentsMd.path` (string or string[]) picks where the manifest lands; default is `CLAUDE.md`
20
+ - `src/ai/` — optional agents / tools / jobs primitives (Anthropic SDK is an optional peer dep)
21
+ - `src/agents-md/` — manifest generator + `writeManifestToFile` (splices into a fenced section so rules around it survive regeneration)
22
+ - `src/plugin/` — plugin system
23
+ - `src/adapters/` — `bun` and `edge` runtime adapters
24
+
25
+ ## Public entry points
26
+
27
+ Declared in `package.json#exports`:
28
+
29
+ `sordo`, `sordo/router`, `sordo/render`, `sordo/client`,
30
+ `sordo/build`, `sordo/dev`, `sordo/config`, `sordo/middleware`,
31
+ `sordo/server`, `sordo/ai`, `sordo/agents-md`, `sordo/plugin`.
32
+
33
+ CLI at `bin/sordo.ts` → `src/cli/index.ts` (`dev` / `build` / `run` / `deploy` / `secret` / `doctor` / `add` / `ui` / `view` / `update` / `upgrade` / `migrate`). `run` is the opt-in monorepo task orchestrator: `sordo run <task>` wraps each workspace `(package, task)` unit with a content-addressed output cache + affected detection (`src/cli/run.ts` + `src/cli/run/`, framework spec 27). Its cache is 100% Bun builtins (`Bun.CryptoHasher` sha256 key, `Bun.Glob`, `Bun.Archive` tarballs, `bun:sqlite` WAL index, `Bun.$` git, `Bun.spawn`); per-task `inputs`/`outputs`/`env`/`cache` come from a `tasks` block in `sordo.config.ts`. `sordo add <component>` stamps UI source (upstream shadcn/ui via `@shadcn/<name>`) into `app/components/ui/` (it also resolves local paths, https URLs, and `@ns/<name>` namespaced registries); `ui init` scaffolds tokens + helpers, `ui build` emits a fetchable registry, `view`/`update` preview-then-stamp, and `migrate` codemods radix imports / RTL logical props. See `src/cli/commands/` and `.claude/rules/ui-catalog.md`. `upgrade` bumps the project's `sordo` dependency to the newest release on its channel (stable→`latest`, prerelease→its pre tag); the CLI also prints a cached, channel-aware "update available" banner on startup (`src/cli/update-check.ts`, opt out with `--no-update-check` / `NO_UPDATE_NOTIFIER`). `doctor` aggregates read-only project-hygiene checks (toolchain probes, `bun audit` / `bun outdated`, lockfile sync, config + biome validity, and monorepo single-React / catalog invariants) into one aligned report with a remedy per finding and a CI exit code (`src/cli/doctor.ts` + `src/cli/doctor/`, cli spec 20); Phase 1 is report-only — no `--fix`. Width-aware output utilities live in `src/cli/ansi.ts` (`Bun.stringWidth` / `stripANSI` / `wrapAnsi`).
34
+
35
+ ## Dev mode wiring
36
+
37
+ `sordo dev` re-execs under `bun --hot --preserve-symlinks` and resolves the
38
+ re-exec entry through the user-project copy of the bin
39
+ (`<cwd>/node_modules/sordo/bin/sordo.ts` when present). This keeps module
40
+ resolution rooted in the app even when `sordo` is linked from a workspace —
41
+ without it, two copies of React load and SSR hooks blow up.
42
+
43
+ Templates wire dev mode via `setupDevClient({ appDir })` from `sordo/dev`:
44
+ it bundles islands in development, mutates a `ClientManifest` the renderer
45
+ holds by reference, and returns a `BunRoutes` map for `/_sordo/client/*`.
46
+ Pages emit hydration markers only when wrapped in `<Island name=…>` — direct
47
+ island imports SSR fine but never hydrate.
48
+
49
+ ## Tests
50
+
51
+ `bun test`. Snapshot-style assertions on the agent manifest live under
52
+ `tests/agents-md/`; the framework's checked-in `CLAUDE.md` manifest section
53
+ is regenerated by `scripts/generate-agents-md.ts` and CI fails on drift.
54
+
55
+ The manifest section below is auto-generated from
56
+ `tests/fixtures/ai-app/app`. Everything between the markers is regenerated
57
+ on every `sordo dev/build` (and by the script above); content outside the
58
+ markers is preserved.
59
+
60
+ <!-- sordo:manifest-start -->
61
+ > Generated by `sordo dev/build`. Edits inside the manifest markers are overwritten; content outside is preserved.
62
+
63
+ ## Route map
64
+
65
+ | File | URL | Methods |
66
+ |---|---|---|
67
+ | tests/fixtures/ai-app/app/routes/index.tsx | / | GET |
68
+
69
+ ## Islands
70
+
71
+ _No islands._
72
+
73
+ ## Agents
74
+
75
+ | Name | Model | Tools | Triggers |
76
+ |---|---|---|---|
77
+ | booking | claude-sonnet-4-6 | search | POST /api/booking/chat |
78
+ | concierge | claude-sonnet-4-6 | | |
79
+
80
+ ## Tools
81
+
82
+ ### `search`
83
+
84
+ Search hotel inventory.
85
+
86
+ Input schema:
87
+
88
+ ```json
89
+ {
90
+ "additionalProperties": false,
91
+ "properties": {
92
+ "city": {
93
+ "type": "string"
94
+ },
95
+ "from": {
96
+ "type": "string"
97
+ },
98
+ "to": {
99
+ "type": "string"
100
+ }
101
+ },
102
+ "required": [
103
+ "city",
104
+ "from",
105
+ "to"
106
+ ],
107
+ "type": "object"
108
+ }
109
+ ```
110
+
111
+ ## Jobs
112
+
113
+ | Name | Schedule | TZ |
114
+ |---|---|---|
115
+ | refresh-inventory | */15 * * * * | Asia/Makassar |
116
+
117
+ ## Middleware
118
+
119
+ Tracks request counts and attaches a marker for downstream handlers.
120
+
121
+ ## Environment variables
122
+
123
+ _No declared env vars._
124
+ <!-- sordo:manifest-end -->
package/README.md CHANGED
@@ -1,3 +1,103 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <img src="./sordo-banner.png" alt="Bun + Sordo" />
3
+ </p>
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ # Bun + Sordo
6
+
7
+ Sordo is a Bun-native full-stack meta-framework with React for UI and `Bun.serve` for HTTP. It is intentionally built around Bun primitives — `Bun.serve`, `Bun.Glob`, `Bun.build`, `bun --hot` — rather than as a Node-era framework with a Bun adapter. The goal is a smaller, more legible architecture that treats Bun as the foundation instead of a faster place to run old assumptions.
8
+
9
+ ## Quick start
10
+
11
+ ```sh
12
+ bunx create-sordo@latest my-app
13
+ cd my-app
14
+ bunx sordo dev
15
+ ```
16
+
17
+ By default the scaffold includes a `CLAUDE.md` for Claude Code (rules +
18
+ auto-generated manifest fenced into a marked section). Pick a different
19
+ agent platform with `--template`:
20
+
21
+ ```sh
22
+ bunx create-sordo@latest my-app --template codex # .codex/ + AGENTS.md
23
+ bunx create-sordo@latest my-app --template none # no agent file
24
+ ```
25
+
26
+ ## Manual setup
27
+
28
+ ```sh
29
+ bun add sordo react react-dom
30
+ ```
31
+
32
+ ```ts
33
+ import { setupDevClient } from "sordo/dev"
34
+ import { createRenderer } from "sordo/render"
35
+ import { createRouter } from "sordo/router"
36
+ import { startServer } from "sordo/server"
37
+
38
+ const appDir = import.meta.dir + "/app"
39
+ const devClient = await setupDevClient({ appDir })
40
+ const renderer = createRenderer({ manifest: devClient.manifest, dev: true })
41
+ const { routes, fallback } = await createRouter({ appDir, renderer })
42
+
43
+ startServer({
44
+ routes: { ...devClient.routes, ...routes },
45
+ fallback,
46
+ dev: true,
47
+ })
48
+ ```
49
+
50
+ Drop files into `app/routes/` for pages and API handlers, and into
51
+ `app/islands/` for components you want hydrated on the client. Wrap each
52
+ island use site in `<Island name="MyIsland">…</Island>` (from
53
+ `sordo/render`) so the SSR markers are emitted and the client runtime
54
+ hydrates them.
55
+
56
+ ## Agent manifest
57
+
58
+ `sordo dev` / `sordo build` regenerate a route + island + agent +
59
+ tool + job + middleware + env inventory. It's spliced between
60
+ `<!-- sordo:manifest-start -->` … `<!-- sordo:manifest-end -->` so
61
+ rules and notes above the section are preserved across regenerations.
62
+ Default target is `CLAUDE.md`; override with `config.agentsMd.path`
63
+ (string or `string[]`) in `sordo.config.ts`.
64
+
65
+ ## CLI
66
+
67
+ ```sh
68
+ sordo dev # bun --hot dev server (use --cold for bun --watch)
69
+ sordo build # production bundle
70
+ sordo build --target edge
71
+ sordo deploy # build then dispatch to an installed deploy plugin
72
+ sordo secret # manage dev-time secrets in the OS keychain
73
+ ```
74
+
75
+ UI components (upstream shadcn/ui, local paths, or registries):
76
+
77
+ ```sh
78
+ sordo ui init # scaffold tokens + _internal helpers (once)
79
+ sordo add @shadcn/button # stamp components into app/components/ui/
80
+ sordo view button # print a component's source before stamping
81
+ sordo update button # re-stamp from the catalog after showing the diff
82
+ sordo migrate # codemods: radix imports / RTL logical properties
83
+ sordo ui build # emit a fetchable registry.json (for registry authors)
84
+ ```
85
+
86
+ See `sordo --help` for all flags.
87
+
88
+ ## What's in the box
89
+
90
+ - Filesystem routing compiled to Bun route patterns
91
+ - React server rendering via `renderToReadableStream`
92
+ - Client islands with on-demand hydration
93
+ - HMR over a small WebSocket layer
94
+ - Build pipeline that inlines route + island manifests for portable Bun / edge output
95
+ - Single-file `--compile` binaries (`adapter.bun.compile`) with app/public + client chunks embedded via `Bun.embeddedFiles` — no `dist/` sidecar to ship
96
+ - Per-request correlation IDs on `ctx.requestId`, echoed as `X-Request-Id`; dev responses also carry `Server-Timing: total;dur=<ms>`
97
+ - Middleware composition, typed context, config + secrets loading
98
+ - Optional AI primitives (agents, tools, jobs) and agent-manifest generation (default `CLAUDE.md`, configurable)
99
+ - Plugin system
100
+
101
+ ## Background
102
+
103
+ Read the longer write-up: [_Bun, Patties, and Fries: A Complete Meal for the Bun-Native Web Stack_](https://medium.com/bihaviour/bun-patties-and-fries-a-complete-meal-for-the-bun-native-web-stack-01bcf977f564).
package/bin/sordo.ts ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bun
2
+ import { main } from "../src/cli/index.ts";
3
+
4
+ const code = await main(process.argv.slice(2));
5
+ if (code !== null) process.exit(code);
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
- "name": "sordo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "sordo",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "description": "Bun-native full-stack meta-framework with React rendering",
6
+ "license": "MIT",
7
+ "exports": {
8
+ ".": "./src/index.ts",
9
+ "./middleware": "./src/middleware/index.ts",
10
+ "./server": "./src/server/index.ts",
11
+ "./router": "./src/router/index.ts",
12
+ "./render": "./src/render/index.tsx",
13
+ "./client": "./src/client/index.ts",
14
+ "./build": "./src/build/index.ts",
15
+ "./dev": "./src/dev/index.ts",
16
+ "./config": "./src/config/define.ts",
17
+ "./ai": "./src/ai/index.ts",
18
+ "./agents-md": "./src/agents-md/index.ts",
19
+ "./plugin": "./src/plugin/index.ts"
20
+ },
21
+ "bin": {
22
+ "sordo": "bin/sordo.ts"
23
+ },
24
+ "files": [
25
+ "bin",
26
+ "src",
27
+ "templates",
28
+ "CLAUDE.md",
29
+ "README.md",
30
+ "CHANGELOG.md"
31
+ ],
32
+ "scripts": {
33
+ "test": "bun test",
34
+ "typecheck": "tsc --noEmit",
35
+ "lint": "biome check .",
36
+ "generate:agents-md": "bun run scripts/generate-agents-md.ts"
37
+ },
38
+ "peerDependencies": {
39
+ "react": "^19.0.0",
40
+ "react-dom": "^19.0.0",
41
+ "@anthropic-ai/sdk": "^0.30.0"
42
+ },
43
+ "peerDependenciesMeta": {
44
+ "@anthropic-ai/sdk": {
45
+ "optional": true
46
+ }
47
+ },
48
+ "dependencies": {
49
+ "zod": "^4.4.3"
50
+ },
51
+ "devDependencies": {
52
+ "@happy-dom/global-registrator": "^15.0.0",
53
+ "@types/react": "^19.0.0",
54
+ "@types/react-dom": "^19.0.0",
55
+ "class-variance-authority": "^0.7.0",
56
+ "cn": "^0.5.0",
57
+ "lucide-react": "^1.59.0",
58
+ "radix-ui": "^1.8.1",
59
+ "react": "^19.0.0",
60
+ "react-dom": "^19.0.0"
61
+ },
62
+ "engines": {
63
+ "bun": ">=1.3.0"
64
+ }
65
+ }
@@ -0,0 +1,59 @@
1
+ import type {
2
+ Adapter,
3
+ AdapterBuildInput,
4
+ AdapterContext,
5
+ EmittedArtifacts,
6
+ } from "./types.ts";
7
+
8
+ export const bunAdapter: Adapter = {
9
+ name: "bun",
10
+ buildTarget: "bun",
11
+ async emit(
12
+ input: AdapterBuildInput,
13
+ ctx: AdapterContext,
14
+ ): Promise<EmittedArtifacts> {
15
+ if (ctx.compile && ctx.mode === "production") {
16
+ const exePath = `${ctx.outDir}/server-bin`;
17
+ // Compile the SOURCE entry, not the stage-1 bundle: `with { type: "file" }`
18
+ // and `with { type: "macro" }` attributes only survive into --compile when
19
+ // the compiler sees the source. The source transitively imports the
20
+ // generated embedded-manifest.ts, so all assets land in the binary.
21
+ const proc = Bun.spawn({
22
+ cmd: [
23
+ "bun",
24
+ "build",
25
+ "--compile",
26
+ "--outfile",
27
+ exePath,
28
+ input.serverEntrySrc,
29
+ ],
30
+ stdout: "pipe",
31
+ stderr: "pipe",
32
+ });
33
+ // Drain both pipes concurrently with the exit wait. On a fresh runner
34
+ // `bun build --compile` downloads the runtime and streams progress; if we
35
+ // only read after `exited`, a full OS pipe buffer blocks the child on
36
+ // write while we block on exit — a deadlock that hangs CI until timeout.
37
+ const [, err, code] = await Promise.all([
38
+ new Response(proc.stdout).text(),
39
+ new Response(proc.stderr).text(),
40
+ proc.exited,
41
+ ]);
42
+ if (code !== 0) {
43
+ throw new Error(`sordo build: --compile failed (exit ${code})\n${err}`);
44
+ }
45
+ // Single-file deploy: assets + client chunks are embedded; drop the
46
+ // on-disk sidecars so the binary is the whole artifact.
47
+ await Bun.$`rm -rf ${`${ctx.outDir}/server`}`.quiet();
48
+ await Bun.$`rm -rf ${`${ctx.outDir}/client`}`.quiet();
49
+ await Bun.$`rm -rf ${`${ctx.outDir}/assets`}`.quiet();
50
+ return { serverEntry: exePath, assets: [] };
51
+ }
52
+ if (!input.serverEntryOut) {
53
+ throw new Error(
54
+ "sordo build: bun target requires a bundled server entry",
55
+ );
56
+ }
57
+ return { serverEntry: input.serverEntryOut, assets: input.assets };
58
+ },
59
+ };
@@ -0,0 +1,38 @@
1
+ import type {
2
+ Adapter,
3
+ AdapterBuildInput,
4
+ AdapterContext,
5
+ EmittedArtifacts,
6
+ } from "./types.ts";
7
+
8
+ // Emits a portable WinterCG / workerd-style Worker module. The framework stays
9
+ // vendor-neutral: no wrangler.toml, vercel.json, etc. — those belong to deploy
10
+ // plugins. The bundled server entry already wraps itself in
11
+ // `export default { fetch }` via build/server-entry.ts::bootForEdge.
12
+ export const edgeAdapter: Adapter = {
13
+ name: "edge",
14
+ buildTarget: "browser",
15
+ async emit(
16
+ input: AdapterBuildInput,
17
+ ctx: AdapterContext,
18
+ ): Promise<EmittedArtifacts> {
19
+ // Surface the worker module under the canonical name spec 12 promises
20
+ // (`dist/worker.js`). Bun.build wrote it as `<outDir>/server/server-entry.js`;
21
+ // we re-emit it at `<outDir>/worker.js` so deploy plugins and ad-hoc CLIs
22
+ // (`wrangler deploy <file>`) can find a predictable path.
23
+ const workerPath = `${ctx.outDir}/worker.js`;
24
+ if (!input.serverEntryOut) {
25
+ // Edge never compiles, so stage-1 Bun.build always runs and sets this.
26
+ throw new Error(
27
+ "sordo build: edge target requires a bundled server entry",
28
+ );
29
+ }
30
+ const bytes = await Bun.file(input.serverEntryOut).bytes();
31
+ await Bun.write(workerPath, bytes);
32
+ return {
33
+ serverEntry: workerPath,
34
+ assets: input.assets,
35
+ extraFiles: [workerPath],
36
+ };
37
+ },
38
+ };
@@ -0,0 +1,39 @@
1
+ import type { BuiltAsset } from "../build/assets.ts";
2
+ import type { SordoConfig } from "../config/schema.ts";
3
+
4
+ export interface AdapterContext {
5
+ appDir: string;
6
+ outDir: string;
7
+ mode: "development" | "production";
8
+ config?: SordoConfig;
9
+ compile?: boolean;
10
+ }
11
+
12
+ export interface AdapterBuildInput {
13
+ /** Absolute path to the bundled server entry produced by stage-1 Bun.build.
14
+ * Undefined in bun compile mode, where stage-1 is skipped and the adapter
15
+ * compiles `serverEntrySrc` directly so file/macro import attributes survive. */
16
+ serverEntryOut?: string;
17
+ /** Absolute path to the generated server-entry.ts SOURCE (for --compile). */
18
+ serverEntrySrc: string;
19
+ assets: BuiltAsset[];
20
+ }
21
+
22
+ export interface EmittedArtifacts {
23
+ /**
24
+ * Absolute path to the consumable server entry after the adapter's
25
+ * post-processing (e.g. compiled binary for bun, worker.js for edge).
26
+ */
27
+ serverEntry: string;
28
+ assets: BuiltAsset[];
29
+ extraFiles?: string[];
30
+ }
31
+
32
+ export interface Adapter {
33
+ name: "edge" | "bun";
34
+ buildTarget: "browser" | "bun";
35
+ emit(
36
+ input: AdapterBuildInput,
37
+ ctx: AdapterContext,
38
+ ): Promise<EmittedArtifacts>;
39
+ }
@@ -0,0 +1,113 @@
1
+ import { scanAgents, scanJobs, scanTools } from "../ai/scan.ts";
2
+ import { scanIslands } from "../build/scan-islands.ts";
3
+ import { scanRoutes } from "../router/filesystem.ts";
4
+ import type { RouteEntry } from "../types.ts";
5
+ import { type ModuleResult, runSubprocessBatch } from "./subprocess-runner.ts";
6
+
7
+ export interface CollectedData {
8
+ routes: RouteEntry[];
9
+ islands: Array<{ name: string; relPath: string }>;
10
+ agents: Array<{
11
+ name: string;
12
+ filePath: string;
13
+ ok: boolean;
14
+ data?: unknown;
15
+ error?: string;
16
+ }>;
17
+ tools: Array<{
18
+ name: string;
19
+ filePath: string;
20
+ ok: boolean;
21
+ data?: unknown;
22
+ error?: string;
23
+ }>;
24
+ jobs: Array<{
25
+ name: string;
26
+ filePath: string;
27
+ ok: boolean;
28
+ data?: unknown;
29
+ error?: string;
30
+ }>;
31
+ middlewareDocComment: string | null;
32
+ envVars: Array<{ name: string; required: boolean; description?: string }>;
33
+ }
34
+
35
+ export async function collect(
36
+ appDir: string,
37
+ env: Array<{ name: string; required: boolean; description?: string }>,
38
+ ): Promise<CollectedData> {
39
+ const [routes, islands, agentMods, toolMods, jobMods, middlewareDocComment] =
40
+ await Promise.all([
41
+ scanRoutes(appDir).catch(() => [] as RouteEntry[]),
42
+ scanIslands(appDir).catch(() => []),
43
+ scanAgents(appDir),
44
+ scanTools(appDir),
45
+ scanJobs(appDir),
46
+ extractMiddlewareDocComment(appDir),
47
+ ]);
48
+
49
+ const queries = [
50
+ ...agentMods.map((a) => ({ kind: "agent" as const, file: a.filePath })),
51
+ ...toolMods.map((t) => ({ kind: "tool" as const, file: t.filePath })),
52
+ ...jobMods.map((j) => ({ kind: "job" as const, file: j.filePath })),
53
+ ];
54
+
55
+ let subResults: ModuleResult[] = [];
56
+ if (queries.length > 0) {
57
+ const entryScript = resolveSubprocessEntry();
58
+ subResults = await runSubprocessBatch(entryScript, queries);
59
+ }
60
+
61
+ let cursor = 0;
62
+ const agents = agentMods.map((a) => mapResult(a, subResults[cursor++]));
63
+ const tools = toolMods.map((t) => mapResult(t, subResults[cursor++]));
64
+ const jobs = jobMods.map((j) => mapResult(j, subResults[cursor++]));
65
+
66
+ return {
67
+ routes,
68
+ islands: islands.map((i) => ({ name: i.name, relPath: i.relPath })),
69
+ agents,
70
+ tools,
71
+ jobs,
72
+ middlewareDocComment,
73
+ envVars: env,
74
+ };
75
+ }
76
+
77
+ function mapResult(
78
+ mod: { name: string; filePath: string },
79
+ r: ModuleResult | undefined,
80
+ ): {
81
+ name: string;
82
+ filePath: string;
83
+ ok: boolean;
84
+ data?: unknown;
85
+ error?: string;
86
+ } {
87
+ if (!r) return { ...mod, ok: false, error: "no subprocess result" };
88
+ return { ...mod, ok: r.ok, data: r.data, error: r.error };
89
+ }
90
+
91
+ async function extractMiddlewareDocComment(
92
+ appDir: string,
93
+ ): Promise<string | null> {
94
+ const path = `${appDir.replace(/\/+$/, "")}/middleware.ts`;
95
+ const f = Bun.file(path);
96
+ if (!(await f.exists())) return null;
97
+ const text = await f.text();
98
+ // Look for a leading /** ... */ block comment at the top of the file.
99
+ const m = text.match(/^\s*\/\*\*([\s\S]*?)\*\//);
100
+ if (!m) return null;
101
+ return (
102
+ m[1]
103
+ ?.split("\n")
104
+ .map((l) => l.replace(/^\s*\*\s?/, "").trim())
105
+ .filter((l) => l.length > 0)
106
+ .join(" ") ?? null
107
+ );
108
+ }
109
+
110
+ function resolveSubprocessEntry(): string {
111
+ // import.meta.dir points at src/agents-md/ when running from source.
112
+ return `${import.meta.dir}/subprocess-entry.ts`;
113
+ }