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,250 +0,0 @@
1
- import type { ComponentType } from "react";
2
- import * as React from "react";
3
- import { hydrateRoot, type Root } from "react-dom/client";
4
- import {
5
- BOOTSTRAP_ID,
6
- type BootstrapPayload,
7
- bootstrapProps,
8
- NAV_HEADER,
9
- type NavPayload,
10
- } from "../render/bootstrap.ts";
11
-
12
- // biome-ignore lint/suspicious/noExplicitAny: page props are user-defined; the runtime only forwards them.
13
- type PageComponent = ComponentType<any>;
14
-
15
- // What a generated page entry hands the runtime: the page's default export plus
16
- // its optional client-side `deserialize` hook. Server-only exports (`loader`,
17
- // `serialize`) are stripped from the client bundle at build time.
18
- export interface PageExports {
19
- Page: PageComponent;
20
- deserialize?: (data: unknown) => unknown;
21
- }
22
-
23
- export interface HydratePageOptions {
24
- root?: string;
25
- bootstrap?: string;
26
- deserialize?: (data: unknown) => unknown;
27
- }
28
-
29
- // Module state is shared by every page entry because all page bundles come from
30
- // one `Bun.build` call with code splitting — this file lands in a shared chunk.
31
- const pages: Record<string, PageExports> = {};
32
- let reactRoot: Root | null = null;
33
- let currentRoute: string | null = null;
34
- let navSeq = 0;
35
- const navCache = new Map<string, Promise<NavPayload | null>>();
36
- // Page chunks are only ever served from here (build/index.ts PUBLIC_PREFIX).
37
- const CHUNK_PREFIX = "/_sordo/client/";
38
-
39
- function readBootstrap(selector: string): BootstrapPayload {
40
- const raw = document.querySelector(selector)?.textContent || "{}";
41
- try {
42
- const parsed = JSON.parse(raw) as Partial<BootstrapPayload>;
43
- return { ...parsed, params: parsed.params ?? {} };
44
- } catch (e) {
45
- console.error("[sordo] bootstrap payload parse failed:", e);
46
- return { params: {} };
47
- }
48
- }
49
-
50
- // Hydrate the page subtree under `#root` with the props the server rendered.
51
- // `<head>`, the bootstrap blob, and the module script sit outside the root.
52
- export function hydratePage(
53
- Page: PageComponent,
54
- options: HydratePageOptions = {},
55
- ): Root | null {
56
- const el = document.querySelector(options.root ?? "#root");
57
- if (!el) {
58
- console.error("[sordo] hydratePage: root element not found");
59
- return null;
60
- }
61
- const payload = readBootstrap(options.bootstrap ?? `#${BOOTSTRAP_ID}`);
62
- const props = bootstrapProps(payload, options.deserialize);
63
- return hydrateRoot(el, React.createElement(Page, props));
64
- }
65
-
66
- // Called by every generated page entry. The first call on a document hydrates;
67
- // later calls (a chunk loaded by `navigate`) only register the page.
68
- export function bootPage(route: string, exports: PageExports): void {
69
- pages[route] = exports;
70
- if (reactRoot) return;
71
- const start = () => {
72
- if (reactRoot) return;
73
- const el = document.getElementById("root");
74
- if (!el) {
75
- console.error("[sordo] bootPage: #root not found");
76
- return;
77
- }
78
- const payload = readBootstrap(`#${BOOTSTRAP_ID}`);
79
- const props = bootstrapProps(payload, exports.deserialize);
80
- reactRoot = hydrateRoot(
81
- el,
82
- React.createElement(exports.Page, { key: route, ...props }),
83
- );
84
- currentRoute = route;
85
- history.replaceState({ ...(history.state ?? {}), __sordo: 1 }, "");
86
- window.addEventListener("popstate", onPopState);
87
- };
88
- if (document.readyState === "loading") {
89
- document.addEventListener("DOMContentLoaded", start, { once: true });
90
- } else {
91
- start();
92
- }
93
- }
94
-
95
- function onPopState(event: PopStateEvent): void {
96
- if (!(event.state as { __sordo?: number } | null)?.__sordo) return;
97
- void navigate(location.href, { history: "none", scroll: false });
98
- }
99
-
100
- // True when a client-side transition is possible: this document booted a
101
- // hydrated page and the target is same-origin.
102
- export function canSoftNavigate(href: string): boolean {
103
- if (!reactRoot || typeof location === "undefined") return false;
104
- try {
105
- return new URL(href, location.href).origin === location.origin;
106
- } catch {
107
- return false;
108
- }
109
- }
110
-
111
- function navKey(url: URL): string {
112
- return url.pathname + url.search;
113
- }
114
-
115
- async function fetchNav(url: URL): Promise<NavPayload | null> {
116
- const res = await fetch(url, {
117
- headers: { [NAV_HEADER]: "1" },
118
- credentials: "same-origin",
119
- });
120
- if (!res.ok) return null;
121
- // A redirect that left the origin is not ours to render: full load instead.
122
- if (res.url && new URL(res.url).origin !== location.origin) return null;
123
- if (!(res.headers.get("content-type") ?? "").includes("application/json")) {
124
- return null;
125
- }
126
- const payload = (await res.json()) as NavPayload;
127
- if (payload.hydrated && !isTrustedChunk(payload.script)) return null;
128
- // Follow server-side redirects: the address bar should show the final URL.
129
- if (res.redirected && payload.hydrated) {
130
- (payload as NavPayload & { url?: string }).url = res.url;
131
- }
132
- return payload;
133
- }
134
-
135
- // The payload's `script` is import()ed, so it must be a same-origin framework
136
- // chunk — never a URL an echoing JSON endpoint or a redirect could inject.
137
- function isTrustedChunk(script: unknown): boolean {
138
- if (typeof script !== "string") return false;
139
- try {
140
- const u = new URL(script, location.href);
141
- return u.origin === location.origin && u.pathname.startsWith(CHUNK_PREFIX);
142
- } catch {
143
- return false;
144
- }
145
- }
146
-
147
- function loadNav(url: URL): Promise<NavPayload | null> {
148
- const key = navKey(url);
149
- let pending = navCache.get(key);
150
- if (!pending) {
151
- pending = fetchNav(url).catch(() => null);
152
- navCache.set(key, pending);
153
- }
154
- return pending;
155
- }
156
-
157
- async function loadPage(payload: NavPayload): Promise<PageExports | null> {
158
- if (!payload.hydrated) return null;
159
- const known = pages[payload.route];
160
- if (known) return known;
161
- await import(payload.script);
162
- return pages[payload.route] ?? null;
163
- }
164
-
165
- // Warm the nav payload and page chunk for `href` (e.g. on hover/focus).
166
- export function prefetch(href: string): void {
167
- if (!canSoftNavigate(href)) return;
168
- const url = new URL(href, location.href);
169
- void loadNav(url).then((p) => (p ? loadPage(p).catch(() => null) : null));
170
- }
171
-
172
- export interface NavigateOptions {
173
- replace?: boolean;
174
- // "none" is used for back/forward, where the browser already moved history.
175
- history?: "push" | "replace" | "none";
176
- scroll?: boolean;
177
- }
178
-
179
- // Client-side transition for hydrated pages: fetch the route's bootstrap
180
- // payload, load its page chunk, and re-render the shared root. Anything the
181
- // runtime can't handle (non-hydrated target, error, cross-origin) falls back to
182
- // a full document load so navigation always succeeds.
183
- export async function navigate(
184
- href: string,
185
- options: NavigateOptions = {},
186
- ): Promise<void> {
187
- const url = new URL(href, location.href);
188
- if (!canSoftNavigate(url.href)) {
189
- location.assign(url.href);
190
- return;
191
- }
192
- const seq = ++navSeq;
193
- const mode = options.history ?? (options.replace ? "replace" : "push");
194
- // Pop navigations always refetch: the cached payload may be stale.
195
- if (mode === "none") navCache.delete(navKey(url));
196
- const payload = await loadNav(url);
197
- navCache.delete(navKey(url));
198
- if (seq !== navSeq) return;
199
- if (!payload?.hydrated) {
200
- location.assign(url.href);
201
- return;
202
- }
203
- let exports: PageExports | null = null;
204
- try {
205
- exports = await loadPage(payload);
206
- } catch (e) {
207
- console.error("[sordo] failed to load page chunk:", e);
208
- }
209
- if (seq !== navSeq) return;
210
- if (!exports || !reactRoot) {
211
- location.assign(url.href);
212
- return;
213
- }
214
- const finalUrl = (payload as { url?: string }).url ?? url.href;
215
- if (mode === "push") history.pushState({ __sordo: 1 }, "", finalUrl);
216
- else if (mode === "replace")
217
- history.replaceState({ __sordo: 1 }, "", finalUrl);
218
- if (payload.title !== undefined) document.title = payload.title;
219
- const props = bootstrapProps(payload.bootstrap, exports.deserialize);
220
- // Keyed by route so moving between routes remounts, while a param change
221
- // within one route keeps component state — matching a full reload's identity.
222
- reactRoot.render(
223
- React.createElement(exports.Page, { key: payload.route, ...props }),
224
- );
225
- currentRoute = payload.route;
226
- if (options.scroll !== false) {
227
- const hash = new URL(finalUrl).hash;
228
- const target = hash ? document.getElementById(hash.slice(1)) : null;
229
- if (target) target.scrollIntoView();
230
- else window.scrollTo(0, 0);
231
- }
232
- }
233
-
234
- // Route pattern of the page currently mounted, or null before boot.
235
- export function getCurrentRoute(): string | null {
236
- return currentRoute;
237
- }
238
-
239
- // Unmount the page root and forget registered pages, returning the runtime to
240
- // its pre-boot state. For tests and hosts that swap documents in place.
241
- export function resetPageRuntime(): void {
242
- reactRoot?.unmount();
243
- reactRoot = null;
244
- currentRoute = null;
245
- navCache.clear();
246
- for (const k of Object.keys(pages)) delete pages[k];
247
- if (typeof window !== "undefined") {
248
- window.removeEventListener("popstate", onPopState);
249
- }
250
- }
@@ -1,5 +0,0 @@
1
- import type { SordoConfigInput } from "./schema.ts";
2
-
3
- export function defineConfig(config: SordoConfigInput): SordoConfigInput {
4
- return config;
5
- }
package/src/config/env.ts DELETED
@@ -1,36 +0,0 @@
1
- import { runtimeEnv } from "../internal/runtime.ts";
2
-
3
- export class MissingEnv extends Error {
4
- names: string[];
5
- constructor(names: string[]) {
6
- super(`MissingEnv: ${names.join(", ")}`);
7
- this.name = "MissingEnv";
8
- this.names = names;
9
- }
10
- }
11
-
12
- type EnvSource = Record<string, string | undefined>;
13
-
14
- function defaultSource(): EnvSource {
15
- return runtimeEnv();
16
- }
17
-
18
- export function getEnv(name: string, source?: EnvSource): string | undefined {
19
- const src = source ?? defaultSource();
20
- const v = src[name];
21
- if (v === undefined || v === "") return undefined;
22
- return v;
23
- }
24
-
25
- export function validateRequiredEnv(
26
- required: string[],
27
- source?: EnvSource,
28
- ): void {
29
- const src = source ?? defaultSource();
30
- const missing: string[] = [];
31
- for (const name of required) {
32
- const v = src[name];
33
- if (v === undefined || v === "") missing.push(name);
34
- }
35
- if (missing.length > 0) throw new MissingEnv(missing);
36
- }
@@ -1,152 +0,0 @@
1
- import { isAbsolute, resolve } from "node:path";
2
- import { z } from "zod";
3
- import {
4
- type SordoConfig,
5
- type SordoConfigInput,
6
- SordoConfigSchema,
7
- } from "./schema.ts";
8
-
9
- const CANDIDATES = ["sordo.config.ts", "sordo.config.js", "sordo.config.mjs"];
10
-
11
- export interface LoadedConfig {
12
- config: SordoConfig;
13
- path: string | null;
14
- }
15
-
16
- export interface LoadOptions {
17
- cwd: string;
18
- configPath?: string;
19
- overrides?: Partial<SordoConfigInput>;
20
- }
21
-
22
- export class ConfigNotFoundError extends Error {
23
- constructor(public readonly path: string) {
24
- super(`sordo config not found: ${path}`);
25
- this.name = "ConfigNotFoundError";
26
- }
27
- }
28
-
29
- interface CacheEntry {
30
- hash: bigint;
31
- raw: unknown;
32
- }
33
- const fileCache = new Map<string, CacheEntry>();
34
-
35
- export async function loadConfig(
36
- arg: string | LoadOptions = process.cwd(),
37
- ): Promise<LoadedConfig> {
38
- const opts: LoadOptions = typeof arg === "string" ? { cwd: arg } : { ...arg };
39
- const cwd = opts.cwd;
40
-
41
- let found: string | null;
42
- if (opts.configPath) {
43
- const abs = isAbsolute(opts.configPath)
44
- ? opts.configPath
45
- : resolve(cwd, opts.configPath);
46
- if (!(await Bun.file(abs).exists())) {
47
- throw new ConfigNotFoundError(abs);
48
- }
49
- found = abs;
50
- } else {
51
- found = await findConfigFile(cwd);
52
- }
53
-
54
- let raw: unknown = {};
55
- if (found) {
56
- raw = await readWithCache(found);
57
- }
58
-
59
- const merged = mergeOverrides(raw, opts.overrides);
60
- const parsed = parseOrThrow(merged, found);
61
-
62
- parsed.appDir = absolutize(parsed.appDir, cwd);
63
- parsed.outDir = absolutize(parsed.outDir, cwd);
64
- if (typeof parsed.css === "string") {
65
- parsed.css = absolutize(parsed.css, cwd);
66
- } else if (parsed.css) {
67
- parsed.css = { ...parsed.css, entry: absolutize(parsed.css.entry, cwd) };
68
- }
69
-
70
- return { config: parsed, path: found };
71
- }
72
-
73
- // CLI-friendly wrapper: never throws. On a missing/invalid config it returns a
74
- // one-line message the caller surfaces via log.error before exiting EXIT.USAGE,
75
- // instead of leaking an uncaught stack.
76
- export async function loadConfigOrUsage(
77
- opts: LoadOptions,
78
- ): Promise<{ config: SordoConfig } | { error: string }> {
79
- try {
80
- const { config } = await loadConfig(opts);
81
- return { config };
82
- } catch (err) {
83
- return { error: err instanceof Error ? err.message : String(err) };
84
- }
85
- }
86
-
87
- async function readWithCache(path: string): Promise<unknown> {
88
- const bytes = await Bun.file(path).bytes();
89
- const hash = Bun.hash(bytes) as bigint;
90
- const cached = fileCache.get(path);
91
- if (cached && cached.hash === hash) return cached.raw;
92
- const mod = (await import(`${path}?h=${hash}`)) as { default?: unknown };
93
- const raw = mod.default ?? {};
94
- fileCache.set(path, { hash, raw });
95
- return raw;
96
- }
97
-
98
- function parseOrThrow(raw: unknown, where: string | null): SordoConfig {
99
- try {
100
- return SordoConfigSchema.parse(raw);
101
- } catch (err) {
102
- if (err instanceof z.ZodError) {
103
- const lines = err.issues.map(
104
- (i) => ` - ${i.path.join(".") || "<root>"}: ${i.message}`,
105
- );
106
- throw new Error(
107
- `sordo config invalid (${where ?? "<defaults>"}):\n${lines.join("\n")}`,
108
- );
109
- }
110
- throw err;
111
- }
112
- }
113
-
114
- function mergeOverrides(
115
- raw: unknown,
116
- overrides?: Partial<SordoConfigInput>,
117
- ): unknown {
118
- if (!overrides) return raw;
119
- const base = (raw ?? {}) as Record<string, unknown>;
120
- const out: Record<string, unknown> = { ...base };
121
- for (const [key, value] of Object.entries(overrides) as [string, unknown][]) {
122
- if (value === undefined) continue;
123
- if (
124
- typeof value === "object" &&
125
- value !== null &&
126
- !Array.isArray(value) &&
127
- typeof base[key] === "object" &&
128
- base[key] !== null &&
129
- !Array.isArray(base[key])
130
- ) {
131
- out[key] = {
132
- ...(base[key] as Record<string, unknown>),
133
- ...(value as Record<string, unknown>),
134
- };
135
- } else {
136
- out[key] = value;
137
- }
138
- }
139
- return out;
140
- }
141
-
142
- async function findConfigFile(cwd: string): Promise<string | null> {
143
- for (const name of CANDIDATES) {
144
- const p = resolve(cwd, name);
145
- if (await Bun.file(p).exists()) return p;
146
- }
147
- return null;
148
- }
149
-
150
- function absolutize(p: string, cwd: string): string {
151
- return isAbsolute(p) ? p : resolve(cwd, p);
152
- }
@@ -1,135 +0,0 @@
1
- import { z } from "zod";
2
- import type { Plugin } from "../plugin/index.ts";
3
-
4
- const PluginSchema = z.custom<Plugin>(
5
- (v) =>
6
- typeof v === "object" &&
7
- v !== null &&
8
- typeof (v as { name?: unknown }).name === "string",
9
- { message: "plugin must be an object with a `name: string`" },
10
- );
11
-
12
- // Optional UI-scaffolding overrides. Everything not listed here stays a fixed
13
- // convention (style, baseColor, cssVariables, rsc, aliases, iconLibrary) — see
14
- // framework/25-ui-config-block. `.strict()` so an unknown key (e.g. `aliases`)
15
- // is a config error pointing the user at the convention it replaces. Paths are
16
- // kept relative here; the project-root-escape guard lives in `resolveUiPaths`.
17
- export const UiConfigSchema = z
18
- .object({
19
- componentsDir: z.string().default("app/components/ui"),
20
- internalDir: z.string().optional(),
21
- tokensFile: z.string().default("app/styles/tokens.css"),
22
- // Third-party registries for namespaced installs (`sordo add @acme/x`).
23
- // Keys are `@namespace`; values are an https base URL or a local path that
24
- // `sordo ui build` produced. `@shadcn` is built in. See cli/15.
25
- registries: z.record(z.string().regex(/^@/), z.string()).optional(),
26
- })
27
- .strict();
28
-
29
- export type UiConfig = z.infer<typeof UiConfigSchema>;
30
-
31
- // Per-task cache config for `sordo run` (framework/27-task-runner-cache).
32
- // `.strict()` so a typo (e.g. `output` for `outputs`, or a `dependsOn` field —
33
- // ordering is owned by the workspace graph, not a DSL) is a config error.
34
- // All fields optional: a bare `{}` means "cache with default inputs (the
35
- // package's tracked + untracked-non-ignored files minus `outputs`) and no
36
- // declared outputs to restore".
37
- export const TaskConfigSchema = z
38
- .object({
39
- inputs: z.array(z.string()).optional(),
40
- outputs: z.array(z.string()).optional(),
41
- env: z.array(z.string()).optional(),
42
- cache: z.boolean().optional(),
43
- })
44
- .strict();
45
-
46
- export type TaskConfig = z.infer<typeof TaskConfigSchema>;
47
-
48
- export const TasksConfigSchema = z.record(z.string(), TaskConfigSchema);
49
-
50
- export type TasksConfig = z.infer<typeof TasksConfigSchema>;
51
-
52
- // Optional stylesheet entry built by `sordo build` / the dev client into a
53
- // content-hashed asset the renderer links. A string is shorthand for
54
- // `{ entry }`. `tailwind` defaults to detecting `@import "tailwindcss"` in the
55
- // entry; Tailwind needs `bun-plugin-tailwind` installed in the app.
56
- export const CssConfigSchema = z.union([
57
- z.string().min(1),
58
- z
59
- .object({
60
- entry: z.string().min(1),
61
- tailwind: z.boolean().optional(),
62
- })
63
- .strict(),
64
- ]);
65
-
66
- export type CssConfig = z.infer<typeof CssConfigSchema>;
67
-
68
- export const SordoConfigSchema = z.object({
69
- target: z.enum(["bun", "edge"]).default("bun"),
70
- appDir: z.string().default("./app"),
71
- outDir: z.string().default("./.sordo"),
72
- plugins: z.array(PluginSchema).default([]),
73
- env: z
74
- .object({
75
- required: z.array(z.string()).default([]),
76
- public: z.array(z.string()).default([]),
77
- })
78
- .default({ required: [], public: [] }),
79
- secrets: z.array(z.string()).default([]),
80
- server: z
81
- .object({
82
- port: z.number().int().min(0).default(3000),
83
- hostname: z.string().default("0.0.0.0"),
84
- unix: z.string().optional(),
85
- reusePort: z.boolean().optional(),
86
- })
87
- .default({ port: 3000, hostname: "0.0.0.0" }),
88
- adapter: z
89
- .object({
90
- bun: z
91
- .object({
92
- compile: z.boolean().default(false),
93
- })
94
- .default({ compile: false }),
95
- edge: z
96
- .object({
97
- // "inline" bakes client chunks + CSS into worker.js; "external" writes
98
- // them to <outDir>/worker-assets for Workers static assets.
99
- assets: z.enum(["inline", "external"]).default("inline"),
100
- })
101
- .default({ assets: "inline" }),
102
- })
103
- .default({ bun: { compile: false }, edge: { assets: "inline" } }),
104
- // Generated agent-manifest target(s). Defaults to "CLAUDE.md" so the
105
- // manifest lands in the same file Claude already reads. The CLI splices
106
- // the manifest between fenced markers so any human-written content
107
- // (rules, notes) around the section is preserved across regenerations.
108
- // Use an array to write the same manifest to multiple files
109
- // (e.g. ["CLAUDE.md", "AGENTS.md"]).
110
- agentsMd: z
111
- .object({
112
- path: z
113
- .union([z.string(), z.array(z.string()).min(1)])
114
- .default("CLAUDE.md"),
115
- })
116
- .default({ path: "CLAUDE.md" }),
117
- // Whole-tree page hydration default. "off" keeps SSR-first / island-only
118
- // behavior; "pages" hydrates every route unless it exports `hydrate = false`.
119
- render: z
120
- .object({
121
- hydrate: z.enum(["off", "pages"]).default("off"),
122
- })
123
- .strict()
124
- .default({ hydrate: "off" }),
125
- // Optional, no default: absent must behave exactly as today (conventions only).
126
- ui: UiConfigSchema.optional(),
127
- // Relative paths resolve against the project root (where the config lives).
128
- css: CssConfigSchema.optional(),
129
- // Per-task input/output declarations consumed by `sordo run` (the cache
130
- // layer). Absent ⇒ `sordo run <task>` falls back to per-task defaults.
131
- tasks: TasksConfigSchema.optional(),
132
- });
133
-
134
- export type SordoConfig = z.infer<typeof SordoConfigSchema>;
135
- export type SordoConfigInput = z.input<typeof SordoConfigSchema>;
@@ -1,108 +0,0 @@
1
- import { resolve } from "node:path";
2
- import type { SordoConfig } from "./schema.ts";
3
-
4
- export interface LoadSecretsOptions {
5
- cwd?: string;
6
- serviceName?: string;
7
- }
8
-
9
- function isProduction(): boolean {
10
- const env = (typeof Bun !== "undefined" ? Bun.env : process.env) as Record<
11
- string,
12
- string | undefined
13
- >;
14
- return env.SORDO_ENV === "production" || env.NODE_ENV === "production";
15
- }
16
-
17
- async function resolveServiceName(
18
- cwd: string,
19
- override?: string,
20
- ): Promise<string> {
21
- if (override) return override;
22
- try {
23
- const pkgPath = resolve(cwd, "package.json");
24
- if (await Bun.file(pkgPath).exists()) {
25
- const pkg = (await Bun.file(pkgPath).json()) as { name?: string };
26
- if (pkg.name) return pkg.name;
27
- }
28
- } catch {
29
- // fall through to default
30
- }
31
- return "sordo";
32
- }
33
-
34
- export interface BunSecretsLike {
35
- get: (opts: {
36
- service: string;
37
- name: string;
38
- }) => Promise<string | null | undefined>;
39
- set?: (opts: {
40
- service: string;
41
- name: string;
42
- value: string;
43
- }) => Promise<void>;
44
- delete?: (opts: { service: string; name: string }) => Promise<void>;
45
- list?: (opts: { service: string }) => Promise<string[]>;
46
- }
47
-
48
- export function getSecretsApi(): BunSecretsLike | null {
49
- const b = (globalThis as { Bun?: { secrets?: unknown } }).Bun;
50
- if (!b?.secrets) return null;
51
- return b.secrets as BunSecretsLike;
52
- }
53
-
54
- export { resolveServiceName };
55
-
56
- export function isLibsecretError(err: unknown): boolean {
57
- const msg = (err as Error)?.message ?? String(err);
58
- return /libsecret|keyring|keychain|backend/i.test(msg);
59
- }
60
-
61
- export function isProductionEnv(): boolean {
62
- return isProduction();
63
- }
64
-
65
- export async function loadSecrets(
66
- config: SordoConfig,
67
- options: LoadSecretsOptions = {},
68
- ): Promise<void> {
69
- if (isProduction()) return;
70
- if (!config.secrets || config.secrets.length === 0) return;
71
-
72
- try {
73
- const api = getSecretsApi();
74
- if (!api) return;
75
-
76
- const cwd = options.cwd ?? process.cwd();
77
- const serviceName = await resolveServiceName(cwd, options.serviceName);
78
- const env = (typeof Bun !== "undefined" ? Bun.env : process.env) as Record<
79
- string,
80
- string | undefined
81
- >;
82
-
83
- let backendOk = true;
84
- for (const key of config.secrets) {
85
- if (!backendOk) break;
86
- try {
87
- const value = await api.get({ service: serviceName, name: key });
88
- if (value) {
89
- env[key] = value;
90
- if (typeof process !== "undefined") process.env[key] = value;
91
- }
92
- } catch (err) {
93
- const msg = (err as Error)?.message ?? String(err);
94
- if (/libsecret|keyring|keychain|backend/i.test(msg)) {
95
- console.warn(
96
- `[sordo] Bun.secrets backend unavailable; falling back to env (${msg})`,
97
- );
98
- backendOk = false;
99
- }
100
- // else: silently fall through to env for this key
101
- }
102
- }
103
- } catch (err) {
104
- console.warn(
105
- `[sordo] loadSecrets skipped: ${(err as Error)?.message ?? String(err)}`,
106
- );
107
- }
108
- }