sordo 0.5.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.
- package/CHANGELOG.md +6 -126
- package/README.md +8 -178
- package/bin/sordo.ts +1 -4
- package/package.json +17 -41
- package/src/agents-md.ts +1 -0
- package/src/ai.ts +1 -0
- package/src/build.ts +1 -0
- package/src/client.ts +1 -0
- package/src/config.ts +1 -0
- package/src/dev.ts +1 -0
- package/src/index.ts +1 -55
- package/src/middleware.ts +1 -0
- package/src/plugin.ts +1 -0
- package/src/render.ts +1 -0
- package/src/router.ts +1 -0
- package/src/server.ts +1 -0
- package/CLAUDE.md +0 -124
- package/src/adapters/bun.ts +0 -59
- package/src/adapters/edge.ts +0 -75
- package/src/adapters/types.ts +0 -43
- package/src/agents-md/collect.ts +0 -113
- package/src/agents-md/generate.ts +0 -44
- package/src/agents-md/index.ts +0 -9
- package/src/agents-md/render.ts +0 -151
- package/src/agents-md/subprocess-entry.ts +0 -92
- package/src/agents-md/subprocess-runner.ts +0 -111
- package/src/agents-md/write.ts +0 -38
- package/src/agents-md/zod-to-json-schema.ts +0 -18
- package/src/ai/context.ts +0 -72
- package/src/ai/define.ts +0 -15
- package/src/ai/errors.ts +0 -51
- package/src/ai/index.ts +0 -36
- package/src/ai/middleware.ts +0 -21
- package/src/ai/registry.ts +0 -96
- package/src/ai/run.ts +0 -185
- package/src/ai/scan.ts +0 -42
- package/src/ai/stream.ts +0 -71
- package/src/ai/triggers.ts +0 -124
- package/src/ai/types.ts +0 -67
- package/src/ai/validate.ts +0 -82
- package/src/build/assets.ts +0 -48
- package/src/build/client-entry.ts +0 -43
- package/src/build/css.ts +0 -128
- package/src/build/embedded.ts +0 -66
- package/src/build/hash.ts +0 -21
- package/src/build/index.ts +0 -505
- package/src/build/macros/agents-hash.macro.ts +0 -9
- package/src/build/macros/agents.macro.ts +0 -21
- package/src/build/macros/env.macro.ts +0 -25
- package/src/build/macros/inline-assets.macro.ts +0 -34
- package/src/build/macros/manifest.macro.ts +0 -8
- package/src/build/macros/routes.macro.ts +0 -10
- package/src/build/page-entry.ts +0 -136
- package/src/build/scan-islands.ts +0 -39
- package/src/build/server-entry.ts +0 -256
- package/src/cli/ansi.ts +0 -41
- package/src/cli/build.ts +0 -195
- package/src/cli/commands/add/apply.ts +0 -31
- package/src/cli/commands/add/component-diff.ts +0 -116
- package/src/cli/commands/add/diff.ts +0 -153
- package/src/cli/commands/add/internal.ts +0 -41
- package/src/cli/commands/add/load-catalog.ts +0 -22
- package/src/cli/commands/add/peer-deps.ts +0 -115
- package/src/cli/commands/add/registry-fetch.ts +0 -122
- package/src/cli/commands/add/shadcn.ts +0 -285
- package/src/cli/commands/add/source.ts +0 -273
- package/src/cli/commands/add/stamper.ts +0 -73
- package/src/cli/commands/add/tokens.ts +0 -81
- package/src/cli/commands/add/ui-paths.ts +0 -113
- package/src/cli/commands/add.ts +0 -427
- package/src/cli/commands/deploy.ts +0 -143
- package/src/cli/commands/migrate.ts +0 -149
- package/src/cli/commands/secret.ts +0 -316
- package/src/cli/commands/ui/build.ts +0 -111
- package/src/cli/commands/ui/init.ts +0 -135
- package/src/cli/commands/ui/migrate/git-guard.ts +0 -19
- package/src/cli/commands/ui/migrate/radix.ts +0 -67
- package/src/cli/commands/ui/migrate/rtl.ts +0 -148
- package/src/cli/commands/ui/shadcn.ts +0 -82
- package/src/cli/commands/ui/view.ts +0 -63
- package/src/cli/commands/ui.ts +0 -86
- package/src/cli/commands/update.ts +0 -134
- package/src/cli/commands/upgrade.ts +0 -53
- package/src/cli/commands/view.ts +0 -34
- package/src/cli/dev.ts +0 -393
- package/src/cli/doctor/config-checks.ts +0 -63
- package/src/cli/doctor/deps.ts +0 -295
- package/src/cli/doctor/hydrate.ts +0 -65
- package/src/cli/doctor/monorepo.ts +0 -158
- package/src/cli/doctor/probes.ts +0 -16
- package/src/cli/doctor/report.ts +0 -72
- package/src/cli/doctor/toolchain.ts +0 -95
- package/src/cli/doctor/types.ts +0 -36
- package/src/cli/doctor.ts +0 -127
- package/src/cli/index.ts +0 -168
- package/src/cli/log.ts +0 -135
- package/src/cli/run/affected.ts +0 -79
- package/src/cli/run/cache-key.ts +0 -177
- package/src/cli/run/cache-store.ts +0 -0
- package/src/cli/run/files.ts +0 -96
- package/src/cli/run/git.ts +0 -13
- package/src/cli/run/runner.ts +0 -189
- package/src/cli/run/workspace.ts +0 -216
- package/src/cli/run.ts +0 -184
- package/src/cli/start.ts +0 -99
- package/src/cli/update-check.ts +0 -157
- package/src/client/index.ts +0 -65
- package/src/client/link.tsx +0 -61
- package/src/client/page.ts +0 -250
- package/src/config/define.ts +0 -5
- package/src/config/env.ts +0 -36
- package/src/config/load.ts +0 -152
- package/src/config/schema.ts +0 -135
- package/src/config/secrets.ts +0 -108
- package/src/dev/client.ts +0 -112
- package/src/dev/hot.ts +0 -24
- package/src/dev/index.ts +0 -4
- package/src/dev/tree.ts +0 -95
- package/src/dev/watcher.ts +0 -95
- package/src/internal/hmr-client.ts +0 -52
- package/src/internal/open-in-editor.ts +0 -23
- package/src/internal/runtime.ts +0 -30
- package/src/middleware/cookie-jar.ts +0 -135
- package/src/middleware/cookies.ts +0 -60
- package/src/middleware/index.ts +0 -135
- package/src/middleware/request-id.ts +0 -22
- package/src/middleware/response-helpers.ts +0 -25
- package/src/plugin/index.ts +0 -109
- package/src/render/bootstrap.ts +0 -44
- package/src/render/dev-error.tsx +0 -73
- package/src/render/index.tsx +0 -261
- package/src/render/island.tsx +0 -33
- package/src/render/meta.tsx +0 -48
- package/src/render/shell.tsx +0 -41
- package/src/router/conflict.ts +0 -20
- package/src/router/filesystem.ts +0 -37
- package/src/router/index.ts +0 -269
- package/src/router/match.ts +0 -91
- package/src/router/pattern.ts +0 -104
- package/src/server/index.ts +0 -250
- package/src/server/inline-assets.ts +0 -57
- package/src/types.ts +0 -53
- package/src/ui/schema.ts +0 -68
- package/src/ui/types.ts +0 -10
- package/templates/_internal/cn.ts +0 -6
- package/templates/_internal/slot.ts +0 -50
- package/templates/_internal/variants.ts +0 -1
- package/templates/themes/neutral/tokens.css +0 -46
- package/templates/themes/slate/tokens.css +0 -46
- package/templates/themes/stone/tokens.css +0 -46
- package/templates/themes/zinc/tokens.css +0 -46
- package/templates/tokens.css +0 -46
package/src/adapters/bun.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
};
|
package/src/adapters/edge.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { collectClientChunks } from "../build/embedded.ts";
|
|
2
|
-
import { xxh64 } from "../build/hash.ts";
|
|
3
|
-
import type {
|
|
4
|
-
Adapter,
|
|
5
|
-
AdapterBuildInput,
|
|
6
|
-
AdapterContext,
|
|
7
|
-
EmittedArtifacts,
|
|
8
|
-
} from "./types.ts";
|
|
9
|
-
|
|
10
|
-
// Emits a portable WinterCG / workerd-style Worker module. The framework stays
|
|
11
|
-
// vendor-neutral: no wrangler.toml, vercel.json, etc. — those belong to deploy
|
|
12
|
-
// plugins. The bundled server entry already wraps itself in
|
|
13
|
-
// `export default { fetch }` via build/server-entry.ts::bootForEdge.
|
|
14
|
-
export const edgeAdapter: Adapter = {
|
|
15
|
-
name: "edge",
|
|
16
|
-
buildTarget: "browser",
|
|
17
|
-
async emit(
|
|
18
|
-
input: AdapterBuildInput,
|
|
19
|
-
ctx: AdapterContext,
|
|
20
|
-
): Promise<EmittedArtifacts> {
|
|
21
|
-
// Surface the worker module under the canonical name spec 12 promises
|
|
22
|
-
// (`dist/worker.js`). Bun.build wrote it as `<outDir>/server/server-entry.js`;
|
|
23
|
-
// we re-emit it at `<outDir>/worker.js` so deploy plugins and ad-hoc CLIs
|
|
24
|
-
// (`wrangler deploy <file>`) can find a predictable path.
|
|
25
|
-
const workerPath = `${ctx.outDir}/worker.js`;
|
|
26
|
-
if (!input.serverEntryOut) {
|
|
27
|
-
// Edge never compiles, so stage-1 Bun.build always runs and sets this.
|
|
28
|
-
throw new Error(
|
|
29
|
-
"sordo build: edge target requires a bundled server entry",
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
const bytes = await Bun.file(input.serverEntryOut).bytes();
|
|
33
|
-
await Bun.write(workerPath, bytes);
|
|
34
|
-
const extraFiles = [workerPath];
|
|
35
|
-
if (ctx.edgeAssets === "external") {
|
|
36
|
-
extraFiles.push(
|
|
37
|
-
await writeExternalAssets(input, `${ctx.outDir}/worker-assets`),
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
serverEntry: workerPath,
|
|
42
|
-
assets: input.assets,
|
|
43
|
-
extraFiles,
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// Lays files out so the directory root maps 1:1 to URL paths — point Workers
|
|
49
|
-
// static assets (`assets.directory`) at it. Client chunks are content-hashed by
|
|
50
|
-
// the client build; public/ files keep their names, the manifest records hashes.
|
|
51
|
-
async function writeExternalAssets(
|
|
52
|
-
input: AdapterBuildInput,
|
|
53
|
-
dir: string,
|
|
54
|
-
): Promise<string> {
|
|
55
|
-
await Bun.$`rm -rf ${dir}`.quiet();
|
|
56
|
-
const manifest: Record<string, { hash: string; bytes: number }> = {};
|
|
57
|
-
const files: { url: string; src: string }[] = [
|
|
58
|
-
...(input.clientOutDir
|
|
59
|
-
? await collectClientChunks(input.clientOutDir)
|
|
60
|
-
: []),
|
|
61
|
-
...input.assets.map((a) => ({ url: a.publicPath, src: a.src })),
|
|
62
|
-
];
|
|
63
|
-
for (const { url, src } of files) {
|
|
64
|
-
const bytes = await Bun.file(src).bytes();
|
|
65
|
-
await Bun.write(`${dir}${url}`, bytes);
|
|
66
|
-
manifest[url] = { hash: xxh64(bytes), bytes: bytes.byteLength };
|
|
67
|
-
}
|
|
68
|
-
// Workers static assets reads `_headers`; client URLs carry a content hash.
|
|
69
|
-
await Bun.write(
|
|
70
|
-
`${dir}/_headers`,
|
|
71
|
-
"/_sordo/client/*\n Cache-Control: public, max-age=31536000, immutable\n",
|
|
72
|
-
);
|
|
73
|
-
await Bun.write(`${dir}/manifest.json`, JSON.stringify(manifest, null, 2));
|
|
74
|
-
return dir;
|
|
75
|
-
}
|
package/src/adapters/types.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
/** edge only: where client chunks + public assets are served from. */
|
|
11
|
-
edgeAssets?: "inline" | "external";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface AdapterBuildInput {
|
|
15
|
-
/** Absolute path to the bundled server entry produced by stage-1 Bun.build.
|
|
16
|
-
* Undefined in bun compile mode, where stage-1 is skipped and the adapter
|
|
17
|
-
* compiles `serverEntrySrc` directly so file/macro import attributes survive. */
|
|
18
|
-
serverEntryOut?: string;
|
|
19
|
-
/** Absolute path to the generated server-entry.ts SOURCE (for --compile). */
|
|
20
|
-
serverEntrySrc: string;
|
|
21
|
-
assets: BuiltAsset[];
|
|
22
|
-
/** Absolute path to the built client output dir (chunks, CSS). */
|
|
23
|
-
clientOutDir?: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface EmittedArtifacts {
|
|
27
|
-
/**
|
|
28
|
-
* Absolute path to the consumable server entry after the adapter's
|
|
29
|
-
* post-processing (e.g. compiled binary for bun, worker.js for edge).
|
|
30
|
-
*/
|
|
31
|
-
serverEntry: string;
|
|
32
|
-
assets: BuiltAsset[];
|
|
33
|
-
extraFiles?: string[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface Adapter {
|
|
37
|
-
name: "edge" | "bun";
|
|
38
|
-
buildTarget: "browser" | "bun";
|
|
39
|
-
emit(
|
|
40
|
-
input: AdapterBuildInput,
|
|
41
|
-
ctx: AdapterContext,
|
|
42
|
-
): Promise<EmittedArtifacts>;
|
|
43
|
-
}
|
package/src/agents-md/collect.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from "../plugin/index.ts";
|
|
2
|
-
import { collect } from "./collect.ts";
|
|
3
|
-
import { render } from "./render.ts";
|
|
4
|
-
|
|
5
|
-
export interface ResolvedConfigLike {
|
|
6
|
-
appDir?: string;
|
|
7
|
-
env?: { required?: string[]; optional?: string[] };
|
|
8
|
-
plugins?: Plugin[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Public entry point for spec 11. Caller writes the returned string to disk.
|
|
12
|
-
export async function generateAgentsMd(
|
|
13
|
-
appDir: string,
|
|
14
|
-
config: ResolvedConfigLike = {},
|
|
15
|
-
): Promise<string> {
|
|
16
|
-
const envVars: Array<{
|
|
17
|
-
name: string;
|
|
18
|
-
required: boolean;
|
|
19
|
-
description?: string;
|
|
20
|
-
}> = [];
|
|
21
|
-
for (const r of config.env?.required ?? [])
|
|
22
|
-
envVars.push({ name: r, required: true });
|
|
23
|
-
for (const o of config.env?.optional ?? [])
|
|
24
|
-
envVars.push({ name: o, required: false });
|
|
25
|
-
|
|
26
|
-
const data = await collect(appDir, envVars);
|
|
27
|
-
let doc = { markdown: render(data) };
|
|
28
|
-
|
|
29
|
-
for (const p of config.plugins ?? []) {
|
|
30
|
-
const hook = p.hooks?.onAgentsMdGenerate;
|
|
31
|
-
if (typeof hook !== "function") continue;
|
|
32
|
-
try {
|
|
33
|
-
doc = await hook(doc);
|
|
34
|
-
} catch (err) {
|
|
35
|
-
const msg = (err as Error)?.message ?? String(err);
|
|
36
|
-
const wrapped = new Error(
|
|
37
|
-
`[plugin ${p.name}] onAgentsMdGenerate: ${msg}`,
|
|
38
|
-
);
|
|
39
|
-
(wrapped as Error & { cause?: unknown }).cause = err;
|
|
40
|
-
throw wrapped;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return doc.markdown;
|
|
44
|
-
}
|
package/src/agents-md/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { collect } from "./collect.ts";
|
|
2
|
-
export type { ResolvedConfigLike } from "./generate.ts";
|
|
3
|
-
export { generateAgentsMd } from "./generate.ts";
|
|
4
|
-
export { render } from "./render.ts";
|
|
5
|
-
export {
|
|
6
|
-
MANIFEST_END,
|
|
7
|
-
MANIFEST_START,
|
|
8
|
-
writeManifestToFile,
|
|
9
|
-
} from "./write.ts";
|
package/src/agents-md/render.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import type { CollectedData } from "./collect.ts";
|
|
2
|
-
|
|
3
|
-
// Deterministic Markdown rendering. Stable section order; alphabetical sort
|
|
4
|
-
// inside each section; canonical JSON in code blocks. Byte-identical for
|
|
5
|
-
// identical input — required by spec 11 acceptance.
|
|
6
|
-
export function render(data: CollectedData): string {
|
|
7
|
-
const out: string[] = [];
|
|
8
|
-
out.push(
|
|
9
|
-
"> Generated by `sordo dev/build`. Edits inside the manifest markers are overwritten; content outside is preserved.",
|
|
10
|
-
"",
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
out.push("## Route map", "");
|
|
14
|
-
if (data.routes.length === 0) {
|
|
15
|
-
out.push("_No routes._", "");
|
|
16
|
-
} else {
|
|
17
|
-
out.push("| File | URL | Methods |", "|---|---|---|");
|
|
18
|
-
const rows = data.routes
|
|
19
|
-
.filter((r) => r.kind !== "notFound")
|
|
20
|
-
.map((r) => ({
|
|
21
|
-
file: relPath(r.filePath),
|
|
22
|
-
pattern: r.bunPattern,
|
|
23
|
-
methods: r.kind === "page" ? "GET" : "(see source)",
|
|
24
|
-
}))
|
|
25
|
-
.sort((a, b) => a.file.localeCompare(b.file));
|
|
26
|
-
for (const r of rows)
|
|
27
|
-
out.push(`| ${r.file} | ${r.pattern} | ${r.methods} |`);
|
|
28
|
-
out.push("");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
out.push("## Islands", "");
|
|
32
|
-
if (data.islands.length === 0) {
|
|
33
|
-
out.push("_No islands._", "");
|
|
34
|
-
} else {
|
|
35
|
-
out.push("| Name | Source |", "|---|---|");
|
|
36
|
-
const rows = [...data.islands].sort((a, b) => a.name.localeCompare(b.name));
|
|
37
|
-
for (const i of rows) out.push(`| ${i.name} | ${i.relPath} |`);
|
|
38
|
-
out.push("");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
out.push("## Agents", "");
|
|
42
|
-
if (data.agents.length === 0) {
|
|
43
|
-
out.push("_No agents._", "");
|
|
44
|
-
} else {
|
|
45
|
-
out.push("| Name | Model | Tools | Triggers |", "|---|---|---|---|");
|
|
46
|
-
const rows = [...data.agents].sort((a, b) => a.name.localeCompare(b.name));
|
|
47
|
-
for (const a of rows) {
|
|
48
|
-
if (!a.ok) {
|
|
49
|
-
out.push(
|
|
50
|
-
`| ${a.name} | _error_ | _error_ | _error: ${escapeCell(a.error ?? "unknown")}_ |`,
|
|
51
|
-
);
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const d = a.data as {
|
|
55
|
-
model?: string;
|
|
56
|
-
tools?: string[];
|
|
57
|
-
triggers?: string[];
|
|
58
|
-
};
|
|
59
|
-
out.push(
|
|
60
|
-
`| ${a.name} | ${escapeCell(d.model ?? "")} | ${escapeCell((d.tools ?? []).join(", "))} | ${escapeCell((d.triggers ?? []).join(", "))} |`,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
out.push("");
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
out.push("## Tools", "");
|
|
67
|
-
if (data.tools.length === 0) {
|
|
68
|
-
out.push("_No tools._", "");
|
|
69
|
-
} else {
|
|
70
|
-
const rows = [...data.tools].sort((a, b) => a.name.localeCompare(b.name));
|
|
71
|
-
for (const t of rows) {
|
|
72
|
-
out.push(`### \`${t.name}\``, "");
|
|
73
|
-
if (!t.ok) {
|
|
74
|
-
out.push(`_error: ${t.error ?? "unknown"}_`, "");
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
const d = t.data as { description?: string; input?: unknown };
|
|
78
|
-
out.push(d.description ?? "_(no description)_", "", "Input schema:", "");
|
|
79
|
-
out.push("```json", canonicalJson(d.input ?? {}), "```", "");
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
out.push("## Jobs", "");
|
|
84
|
-
if (data.jobs.length === 0) {
|
|
85
|
-
out.push("_No jobs._", "");
|
|
86
|
-
} else {
|
|
87
|
-
out.push("| Name | Schedule | TZ |", "|---|---|---|");
|
|
88
|
-
const rows = [...data.jobs].sort((a, b) => a.name.localeCompare(b.name));
|
|
89
|
-
for (const j of rows) {
|
|
90
|
-
if (!j.ok) {
|
|
91
|
-
out.push(
|
|
92
|
-
`| ${j.name} | _error_ | _error: ${escapeCell(j.error ?? "unknown")}_ |`,
|
|
93
|
-
);
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
const d = j.data as { schedule?: string; tz?: string };
|
|
97
|
-
out.push(
|
|
98
|
-
`| ${j.name} | ${escapeCell(d.schedule ?? "")} | ${escapeCell(d.tz ?? "")} |`,
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
out.push("");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
out.push("## Middleware", "");
|
|
105
|
-
if (data.middlewareDocComment) {
|
|
106
|
-
out.push(data.middlewareDocComment, "");
|
|
107
|
-
} else {
|
|
108
|
-
out.push("_No global middleware._", "");
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
out.push("## Environment variables", "");
|
|
112
|
-
if (data.envVars.length === 0) {
|
|
113
|
-
out.push("_No declared env vars._", "");
|
|
114
|
-
} else {
|
|
115
|
-
out.push("| Name | Required | Description |", "|---|---|---|");
|
|
116
|
-
const rows = [...data.envVars].sort((a, b) => a.name.localeCompare(b.name));
|
|
117
|
-
for (const e of rows) {
|
|
118
|
-
out.push(
|
|
119
|
-
`| ${e.name} | ${e.required ? "yes" : "no"} | ${escapeCell(e.description ?? "")} |`,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
out.push("");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return out.join("\n");
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function relPath(absPath: string): string {
|
|
129
|
-
const cwd = process.cwd().replace(/\/+$/, "");
|
|
130
|
-
if (absPath.startsWith(`${cwd}/`)) return absPath.slice(cwd.length + 1);
|
|
131
|
-
return absPath;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function escapeCell(s: string): string {
|
|
135
|
-
return s.replace(/\|/g, "\\|").replace(/\n/g, " ");
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function canonicalJson(value: unknown): string {
|
|
139
|
-
return JSON.stringify(sortKeys(value), null, 2);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function sortKeys(value: unknown): unknown {
|
|
143
|
-
if (Array.isArray(value)) return value.map(sortKeys);
|
|
144
|
-
if (value && typeof value === "object") {
|
|
145
|
-
const obj = value as Record<string, unknown>;
|
|
146
|
-
const out: Record<string, unknown> = {};
|
|
147
|
-
for (const k of Object.keys(obj).sort()) out[k] = sortKeys(obj[k]);
|
|
148
|
-
return out;
|
|
149
|
-
}
|
|
150
|
-
return value;
|
|
151
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// Standalone script run via Bun.spawn from subprocess-runner.ts.
|
|
2
|
-
// Protocol (line-delimited JSON over stdio):
|
|
3
|
-
// stdin → { id: string, file: string, kind: "agent" | "tool" | "job" }
|
|
4
|
-
// stdout → { id: string, ok: true, data: ... } | { id: string, ok: false, error: string }
|
|
5
|
-
//
|
|
6
|
-
// `data` for tools includes a JSON-Schema rendering of the Zod input schema so
|
|
7
|
-
// the parent process doesn't need to import the user's Zod build.
|
|
8
|
-
|
|
9
|
-
import { zodToJsonSchema } from "./zod-to-json-schema.ts";
|
|
10
|
-
|
|
11
|
-
interface Request {
|
|
12
|
-
id: string;
|
|
13
|
-
file: string;
|
|
14
|
-
kind: "agent" | "tool" | "job";
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function main(): Promise<void> {
|
|
18
|
-
const decoder = new TextDecoder();
|
|
19
|
-
let buf = "";
|
|
20
|
-
for await (const chunk of Bun.stdin.stream() as unknown as AsyncIterable<Uint8Array>) {
|
|
21
|
-
buf += decoder.decode(chunk, { stream: true });
|
|
22
|
-
const lines = buf.split("\n");
|
|
23
|
-
buf = lines.pop() ?? "";
|
|
24
|
-
for (const line of lines) {
|
|
25
|
-
const trimmed = line.trim();
|
|
26
|
-
if (!trimmed) continue;
|
|
27
|
-
const req = JSON.parse(trimmed) as Request;
|
|
28
|
-
const res = await handle(req);
|
|
29
|
-
process.stdout.write(`${JSON.stringify(res)}\n`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function handle(
|
|
35
|
-
req: Request,
|
|
36
|
-
): Promise<{ id: string; ok: boolean; data?: unknown; error?: string }> {
|
|
37
|
-
try {
|
|
38
|
-
const mod = (await import(req.file)) as { default?: unknown };
|
|
39
|
-
const cfg = mod.default as Record<string, unknown> | undefined;
|
|
40
|
-
if (!cfg)
|
|
41
|
-
return { id: req.id, ok: false, error: "module has no default export" };
|
|
42
|
-
if (req.kind === "tool") {
|
|
43
|
-
const inputSchema = cfg.input;
|
|
44
|
-
const inputJson = zodToJsonSchema(inputSchema);
|
|
45
|
-
return {
|
|
46
|
-
id: req.id,
|
|
47
|
-
ok: true,
|
|
48
|
-
data: {
|
|
49
|
-
name: cfg.name,
|
|
50
|
-
description: cfg.description,
|
|
51
|
-
input: inputJson,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
if (req.kind === "agent") {
|
|
56
|
-
return {
|
|
57
|
-
id: req.id,
|
|
58
|
-
ok: true,
|
|
59
|
-
data: {
|
|
60
|
-
name: cfg.name,
|
|
61
|
-
model: cfg.model,
|
|
62
|
-
tools: cfg.tools ?? [],
|
|
63
|
-
triggers: cfg.triggers ?? [],
|
|
64
|
-
systemPrompt: cfg.systemPrompt,
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
// job
|
|
69
|
-
return {
|
|
70
|
-
id: req.id,
|
|
71
|
-
ok: true,
|
|
72
|
-
data: {
|
|
73
|
-
name: cfg.name,
|
|
74
|
-
schedule: cfg.schedule,
|
|
75
|
-
tz: cfg.tz,
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
} catch (err) {
|
|
79
|
-
return {
|
|
80
|
-
id: req.id,
|
|
81
|
-
ok: false,
|
|
82
|
-
error: (err as Error)?.message ?? String(err),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
main().catch((err) => {
|
|
88
|
-
process.stderr.write(
|
|
89
|
-
`subprocess-entry fatal: ${(err as Error)?.message ?? String(err)}\n`,
|
|
90
|
-
);
|
|
91
|
-
process.exit(1);
|
|
92
|
-
});
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
export interface ModuleQuery {
|
|
2
|
-
kind: "agent" | "tool" | "job";
|
|
3
|
-
file: string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface ModuleResult {
|
|
7
|
-
query: ModuleQuery;
|
|
8
|
-
ok: boolean;
|
|
9
|
-
data?: unknown;
|
|
10
|
-
error?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Runs a batch of module loads inside a single isolated subprocess. Each
|
|
14
|
-
// module's top-level side effects die with the subprocess. A module whose
|
|
15
|
-
// top-level throws produces a per-query error, not a build crash.
|
|
16
|
-
export async function runSubprocessBatch(
|
|
17
|
-
entryScript: string,
|
|
18
|
-
queries: ModuleQuery[],
|
|
19
|
-
opts: { timeoutMs?: number } = {},
|
|
20
|
-
): Promise<ModuleResult[]> {
|
|
21
|
-
if (queries.length === 0) return [];
|
|
22
|
-
|
|
23
|
-
const timeoutMs = opts.timeoutMs ?? 30_000;
|
|
24
|
-
|
|
25
|
-
const proc = Bun.spawn(["bun", entryScript], {
|
|
26
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
27
|
-
env: process.env,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const results = new Map<string, ModuleResult>();
|
|
31
|
-
const sink = proc.stdin as {
|
|
32
|
-
write: (chunk: string) => void;
|
|
33
|
-
end: () => void;
|
|
34
|
-
} | null;
|
|
35
|
-
for (let i = 0; i < queries.length; i++) {
|
|
36
|
-
const id = String(i);
|
|
37
|
-
const line =
|
|
38
|
-
JSON.stringify({ id, file: queries[i]?.file, kind: queries[i]?.kind }) +
|
|
39
|
-
"\n";
|
|
40
|
-
sink?.write(line);
|
|
41
|
-
}
|
|
42
|
-
sink?.end();
|
|
43
|
-
|
|
44
|
-
const reader = proc.stdout.getReader();
|
|
45
|
-
const decoder = new TextDecoder();
|
|
46
|
-
let buf = "";
|
|
47
|
-
|
|
48
|
-
const timeout = new Promise<never>((_, reject) =>
|
|
49
|
-
setTimeout(
|
|
50
|
-
() => reject(new Error(`subprocess timeout after ${timeoutMs}ms`)),
|
|
51
|
-
timeoutMs,
|
|
52
|
-
),
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const readAll = (async () => {
|
|
56
|
-
while (true) {
|
|
57
|
-
const { value, done } = await reader.read();
|
|
58
|
-
if (done) break;
|
|
59
|
-
buf += decoder.decode(value, { stream: true });
|
|
60
|
-
const lines = buf.split("\n");
|
|
61
|
-
buf = lines.pop() ?? "";
|
|
62
|
-
for (const line of lines) {
|
|
63
|
-
const t = line.trim();
|
|
64
|
-
if (!t) continue;
|
|
65
|
-
const parsed = JSON.parse(t) as {
|
|
66
|
-
id: string;
|
|
67
|
-
ok: boolean;
|
|
68
|
-
data?: unknown;
|
|
69
|
-
error?: string;
|
|
70
|
-
};
|
|
71
|
-
const q = queries[Number(parsed.id)];
|
|
72
|
-
if (!q) continue;
|
|
73
|
-
results.set(parsed.id, {
|
|
74
|
-
query: q,
|
|
75
|
-
ok: parsed.ok,
|
|
76
|
-
data: parsed.data,
|
|
77
|
-
error: parsed.error,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
})();
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
await Promise.race([readAll, timeout]);
|
|
85
|
-
} finally {
|
|
86
|
-
try {
|
|
87
|
-
proc.kill();
|
|
88
|
-
} catch {
|
|
89
|
-
// ignore
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
await proc.exited;
|
|
93
|
-
|
|
94
|
-
const out: ModuleResult[] = [];
|
|
95
|
-
for (let i = 0; i < queries.length; i++) {
|
|
96
|
-
const r = results.get(String(i));
|
|
97
|
-
const q = queries[i];
|
|
98
|
-
if (!q) continue;
|
|
99
|
-
if (!r) {
|
|
100
|
-
const stderrText = await new Response(proc.stderr).text().catch(() => "");
|
|
101
|
-
out.push({
|
|
102
|
-
query: q,
|
|
103
|
-
ok: false,
|
|
104
|
-
error: `no response from subprocess (stderr: ${stderrText.slice(0, 500) || "<empty>"})`,
|
|
105
|
-
});
|
|
106
|
-
} else {
|
|
107
|
-
out.push(r);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return out;
|
|
111
|
-
}
|