create-signet-app 0.4.7 → 0.5.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/README.md +160 -28
- package/{template-full → base/api}/api/app.ts +93 -15
- package/base/api/api/db/open.ts +121 -0
- package/{template-full → base/api}/api/db/schema.ts +22 -7
- package/{template-full → base/api}/api/env.ts +13 -0
- package/base/api/api/server.ts +157 -0
- package/{template-full → base/api}/api/services.ts +77 -8
- package/base/api/test/api.test.ts +51 -0
- package/base/api/test/helpers.ts +51 -0
- package/base/both/scripts/dev.ts +44 -0
- package/base/shared/README.md +298 -0
- package/{template-full → base/shared}/_github/workflows/ci.yml +1 -1
- package/{template-full → base/shared}/biome.json +1 -1
- package/{template-full → base/web}/src/lib/api.ts +28 -1
- package/{template-full → base/web}/src/main.tsx +4 -1
- package/{template-full → base/web}/src/routeTree.gen.ts +130 -90
- package/{template-full → base/web}/src/router.test.ts +12 -9
- package/base/web/src/routes/_app/index.tsx +55 -0
- package/{template-full → base/web}/src/routes/_app.tsx +39 -16
- package/{template-full → base/web}/vite.config.ts +3 -1
- package/package.json +9 -5
- package/parts/account/api/test/account.test.ts +30 -0
- package/parts/account/part.ts +6 -0
- package/parts/admin/api/test/admin.test.ts +35 -0
- package/parts/admin/part.ts +6 -0
- package/{template-full → parts/admin/web}/src/routes/_app/admin.tsx +2 -1
- package/{template-full → parts/auth/api}/api/routes/account.ts +32 -3
- package/{template-full → parts/auth/api}/api/routes/auth.ts +5 -3
- package/parts/auth/api/test/auth.test.ts +28 -0
- package/{template-full → parts/auth/both}/e2e/smoke.spec.ts +21 -7
- package/parts/auth/part.ts +22 -0
- package/parts/growth/part.ts +7 -0
- package/{template-full/_mcp → parts/mcp/api}/test/mcp.test.ts +25 -16
- package/parts/mcp/part.ts +8 -0
- package/parts/notifications/api/test/notifications.test.ts +18 -0
- package/parts/notifications/part.ts +6 -0
- package/{template-full → parts/notifications/web}/src/routes/_app/notifications.tsx +1 -1
- package/parts/orgs/api/test/orgs.test.ts +56 -0
- package/parts/orgs/part.ts +7 -0
- package/{template-full → parts/payments/api}/api/routes/billing.ts +3 -2
- package/parts/payments/api/test/payments.test.ts +31 -0
- package/parts/payments/part.ts +12 -0
- package/{template-full → parts/payments/web}/src/routes/_app/billing.tsx +6 -3
- package/parts/privacy/api/test/privacy.test.ts +20 -0
- package/parts/privacy/part.ts +7 -0
- package/src/compose.ts +369 -0
- package/src/describe.ts +200 -0
- package/src/desktop.ts +10 -10
- package/src/index.ts +433 -159
- package/template/biome.json +1 -1
- package/template-api/_targets/deno/Dockerfile +12 -0
- package/template-api/_targets/deno/_dockerignore +10 -0
- package/template-api/_targets/deno/src/server.ts +43 -0
- package/template-api/biome.json +1 -1
- package/template-cli/biome.json +1 -1
- package/template-extension/biome.json +1 -1
- package/template-full/README.md +0 -155
- package/template-full/api/db/open.ts +0 -33
- package/template-full/api/server.ts +0 -44
- package/template-full/scripts/dev.ts +0 -17
- package/template-full/src/routes/_app/index.tsx +0 -33
- package/template-full/test/api.test.ts +0 -189
- package/template-full/tsconfig.json +0 -9
- /package/{template-full → base/api}/api/db/index.ts +0 -0
- /package/{template-full → base/api}/api/db/kv.ts +0 -0
- /package/{template-full → base/api}/drizzle/0000_init.sql +0 -0
- /package/{template-full → base/api}/drizzle/0001_orgs.sql +0 -0
- /package/{template-full → base/api}/drizzle/meta/0000_snapshot.json +0 -0
- /package/{template-full → base/api}/drizzle/meta/0001_snapshot.json +0 -0
- /package/{template-full → base/api}/drizzle/meta/_journal.json +0 -0
- /package/{template-full → base/api}/drizzle.config.ts +0 -0
- /package/{template-full → base/api}/tsconfig.api.json +0 -0
- /package/{template-full → base/shared}/_gitignore +0 -0
- /package/{template-full → base/web}/index.html +0 -0
- /package/{template-full → base/web}/src/app.css +0 -0
- /package/{template-full → base/web}/src/components/toaster.tsx +0 -0
- /package/{template-full → base/web}/src/router.ts +0 -0
- /package/{template-full → base/web}/src/routes/__root.tsx +0 -0
- /package/{template-full → base/web}/tsconfig.app.json +0 -0
- /package/{template-full → base/web}/tsconfig.node.json +0 -0
- /package/{template-full → base/web}/tsconfig.test.json +0 -0
- /package/{template-full → parts/account/web}/src/routes/_app/account.tsx +0 -0
- /package/{template-full → parts/auth/both}/playwright.config.ts +0 -0
- /package/{template-full → parts/auth/web}/src/routes/login.tsx +0 -0
- /package/{template-full → parts/notifications/api}/api/routes/notifications.ts +0 -0
- /package/{template-full → parts/orgs/web}/src/routes/_app/org/index.tsx +0 -0
- /package/{template-full → parts/orgs/web}/src/routes/_app/org/members.tsx +0 -0
- /package/{template-full → parts/orgs/web}/src/routes/_app/org/new.tsx +0 -0
- /package/{template-full → parts/orgs/web}/src/routes/invite.$token.tsx +0 -0
- /package/{template-full → parts/payments/api}/api/plans.ts +0 -0
- /package/{template-full → parts/privacy/api}/api/routes/privacy.ts +0 -0
- /package/{template-full → parts/privacy/web}/src/routes/_app/privacy.tsx +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { app, post, signIn } from "./helpers.ts"
|
|
3
|
+
|
|
4
|
+
test("consent is given and withdrawn; an erasure request opens", async () => {
|
|
5
|
+
const cookie = await signIn("+919000000004")
|
|
6
|
+
expect((await post("/api/privacy/consents/analytics", {}, cookie)).status).toBe(200)
|
|
7
|
+
// A browser sends Origin on a DELETE; the CSRF guard refuses one without it.
|
|
8
|
+
const withdraw = await app.request("/api/privacy/consents/analytics", {
|
|
9
|
+
method: "DELETE",
|
|
10
|
+
headers: { cookie, origin: "http://localhost" },
|
|
11
|
+
})
|
|
12
|
+
expect(withdraw.status).toBe(200)
|
|
13
|
+
expect((await post("/api/privacy/requests", { kind: "erasure" }, cookie)).status).toBe(201)
|
|
14
|
+
const p = (await (await app.request("/api/privacy", { headers: { cookie } })).json()) as {
|
|
15
|
+
consents: { withdrawnAt: string | null }[]
|
|
16
|
+
requests: { kind: string }[]
|
|
17
|
+
}
|
|
18
|
+
expect(p.consents[0]?.withdrawnAt).not.toBeNull()
|
|
19
|
+
expect(p.requests[0]?.kind).toBe("erasure")
|
|
20
|
+
})
|
package/src/compose.ts
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The composer: an app is surfaces (web, api or both) plus parts. Files come
|
|
3
|
+
* from base/ and each selected part's folder, in halves:
|
|
4
|
+
*
|
|
5
|
+
* shared/ always web/ with the web surface
|
|
6
|
+
* api/ with the api both/ with both surfaces
|
|
7
|
+
*
|
|
8
|
+
* each laid over the app root. Code shared between parts (api/app.ts, the
|
|
9
|
+
* schema, services, the shell, the route tree) lives in base/ once, with each
|
|
10
|
+
* part's lines marked; `applyBlocks` keeps the lines of what was chosen and
|
|
11
|
+
* drops the markers, so the app carries no trace of the parts it left out.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { existsSync } from "node:fs"
|
|
15
|
+
import { cp, readdir, readFile, rm, writeFile } from "node:fs/promises"
|
|
16
|
+
import { join, resolve } from "node:path"
|
|
17
|
+
import account from "../parts/account/part.js"
|
|
18
|
+
import admin from "../parts/admin/part.js"
|
|
19
|
+
import auth from "../parts/auth/part.js"
|
|
20
|
+
import growth from "../parts/growth/part.js"
|
|
21
|
+
import mcp from "../parts/mcp/part.js"
|
|
22
|
+
import notifications from "../parts/notifications/part.js"
|
|
23
|
+
import orgs from "../parts/orgs/part.js"
|
|
24
|
+
import payments from "../parts/payments/part.js"
|
|
25
|
+
import privacy from "../parts/privacy/part.js"
|
|
26
|
+
|
|
27
|
+
type Deps = Record<string, string>
|
|
28
|
+
|
|
29
|
+
/** What one part adds, besides its files. Its code in shared files is marked `// <name>:begin`. */
|
|
30
|
+
export type Part = {
|
|
31
|
+
/** One line, for --help. */
|
|
32
|
+
description: string
|
|
33
|
+
/** Parts it cannot work without; added for you. */
|
|
34
|
+
needs?: PartName[]
|
|
35
|
+
/** Needs the API surface (it has no web half). */
|
|
36
|
+
apiOnly?: boolean
|
|
37
|
+
web?: { deps?: Deps }
|
|
38
|
+
api?: { deps?: Deps }
|
|
39
|
+
/** With both surfaces: dev deps and scripts (the browser test). */
|
|
40
|
+
both?: { devDeps?: Deps; scripts?: Record<string, string> }
|
|
41
|
+
/** Lines for the generated env file. A function, so secrets are fresh per app. */
|
|
42
|
+
env?: () => string[]
|
|
43
|
+
/** SQL tables its schema adds: the migrations keep only the chosen parts' tables. */
|
|
44
|
+
tables?: string[]
|
|
45
|
+
/** API files the web half also reads; a UI-only app gets a copy at the mapped path. */
|
|
46
|
+
uiCopies?: Record<string, string>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** In dependency order: a part comes after what it needs. */
|
|
50
|
+
export const PART_NAMES = [
|
|
51
|
+
"auth",
|
|
52
|
+
"account",
|
|
53
|
+
"orgs",
|
|
54
|
+
"admin",
|
|
55
|
+
"notifications",
|
|
56
|
+
"privacy",
|
|
57
|
+
"payments",
|
|
58
|
+
"growth",
|
|
59
|
+
"mcp",
|
|
60
|
+
] as const
|
|
61
|
+
export type PartName = (typeof PART_NAMES)[number]
|
|
62
|
+
export const PARTS: Record<PartName, Part> = {
|
|
63
|
+
auth,
|
|
64
|
+
account,
|
|
65
|
+
orgs,
|
|
66
|
+
admin,
|
|
67
|
+
notifications,
|
|
68
|
+
privacy,
|
|
69
|
+
payments,
|
|
70
|
+
growth,
|
|
71
|
+
mcp,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A named mix of parts. `full` is everything the full template had; `blank`
|
|
76
|
+
* is the base alone (the shell, the API, the database), for parts of your own.
|
|
77
|
+
* MCP is not listed: it is asked for (or --mcp / --no-mcp), as it always was.
|
|
78
|
+
*/
|
|
79
|
+
export const STARTERS = {
|
|
80
|
+
full: { parts: PART_NAMES.filter((p) => p !== "mcp") },
|
|
81
|
+
blank: { parts: [] },
|
|
82
|
+
} satisfies Record<string, { parts: PartName[] }>
|
|
83
|
+
export type StarterName = keyof typeof STARTERS
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The chosen parts plus everything they need, in PARTS order, and what was
|
|
87
|
+
* added for a need. Throws on an unknown part or a need that was excluded.
|
|
88
|
+
*/
|
|
89
|
+
export function resolveParts(
|
|
90
|
+
chosen: string[],
|
|
91
|
+
without: string[],
|
|
92
|
+
): { parts: PartName[]; added: { part: PartName; for: PartName }[] } {
|
|
93
|
+
for (const p of [...chosen, ...without])
|
|
94
|
+
if (!PART_NAMES.includes(p as PartName))
|
|
95
|
+
throw new Error(`Unknown part "${p}". Available: ${PART_NAMES.join(", ")}`)
|
|
96
|
+
const both = chosen.filter((p) => without.includes(p))
|
|
97
|
+
if (both.length) throw new Error(`"${both[0]}" is in both --with and --without.`)
|
|
98
|
+
const set = new Set(chosen as PartName[])
|
|
99
|
+
const added: { part: PartName; for: PartName }[] = []
|
|
100
|
+
// ponytail: needs are at most two deep, so a few passes settle; a cycle would be a bug in a manifest.
|
|
101
|
+
for (let pass = 0; pass < PART_NAMES.length; pass++)
|
|
102
|
+
for (const p of [...set])
|
|
103
|
+
for (const need of (PARTS[p] as Part).needs ?? []) {
|
|
104
|
+
if (without.includes(need))
|
|
105
|
+
throw new Error(`${p} needs ${need}: drop --without ${need}, or leave ${p} out.`)
|
|
106
|
+
if (!set.has(need)) {
|
|
107
|
+
set.add(need)
|
|
108
|
+
added.push({ part: need, for: p })
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { parts: PART_NAMES.filter((p) => set.has(p)), added }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** What runs the API: bun (bun:sqlite, Bun.serve), or deno or node (node:sqlite, node:http). */
|
|
115
|
+
export const RUNTIMES = ["bun", "deno", "node"] as const
|
|
116
|
+
export type Runtime = (typeof RUNTIMES)[number]
|
|
117
|
+
|
|
118
|
+
/** How each runtime runs a TypeScript file, with the app's env file loaded. */
|
|
119
|
+
const RUN: Record<Runtime, string> = {
|
|
120
|
+
bun: "bun",
|
|
121
|
+
deno: "deno run -A --env-file=.env",
|
|
122
|
+
node: "node --env-file-if-exists=.env",
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const MARKER_NAMES = new Set<string>([...PART_NAMES, "web", "api", ...RUNTIMES])
|
|
126
|
+
const BLOCK = /^\s*(?:\/\/|\{\/\*|<!--|#)\s*(!?[\w|-]+):(begin|end)\s*(?:\*\/\}|-->)?\s*$/
|
|
127
|
+
const TAG =
|
|
128
|
+
/\s+(?:\/\/\s*@(!?[\w|-]+)|#\s*@(!?[\w|-]+)|\{\/\*\s*@(!?[\w|-]+)\s*\*\/\}|<!--\s*@(!?[\w|-]+)\s*-->)\s*$/
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Keep what applies, drop the markers. A block is the lines between
|
|
132
|
+
* `// name:begin` and `// name:end` (also `{/* name:begin *\/}`, `<!-- … -->`,
|
|
133
|
+
* `# …`); blocks nest. A line ending in `// @name` is that one line. `!name`
|
|
134
|
+
* means "without name"; `a|b` means "with a or b", `!a|b` "with neither". Names are parts and the
|
|
135
|
+
* surfaces, `web` and `api`.
|
|
136
|
+
*/
|
|
137
|
+
export function applyBlocks(text: string, on: ReadonlySet<string>): string {
|
|
138
|
+
const name = (c: string) => c.replace(/^!/, "")
|
|
139
|
+
// Only our names are markers, so a stray `// @ts-expect-error` stays put.
|
|
140
|
+
const known = (c: string) =>
|
|
141
|
+
name(c)
|
|
142
|
+
.split("|")
|
|
143
|
+
.every((n) => MARKER_NAMES.has(n))
|
|
144
|
+
const holds = (c: string) =>
|
|
145
|
+
c.startsWith("!")
|
|
146
|
+
? !name(c)
|
|
147
|
+
.split("|")
|
|
148
|
+
.some((n) => on.has(n))
|
|
149
|
+
: c.split("|").some((n) => on.has(n))
|
|
150
|
+
const open: boolean[] = []
|
|
151
|
+
const out: string[] = []
|
|
152
|
+
for (const line of text.split("\n")) {
|
|
153
|
+
const block = BLOCK.exec(line)
|
|
154
|
+
if (block && known(block[1] as string)) {
|
|
155
|
+
if (block[2] === "begin") open.push(holds(block[1] as string))
|
|
156
|
+
else if (open.pop() === undefined) throw new Error(`Unmatched marker: ${line.trim()}`)
|
|
157
|
+
continue
|
|
158
|
+
}
|
|
159
|
+
if (!open.every(Boolean)) continue
|
|
160
|
+
const tag = TAG.exec(line)
|
|
161
|
+
const cond = tag && (tag[1] ?? tag[2] ?? tag[3] ?? tag[4])
|
|
162
|
+
if (!tag || !cond || !known(cond) || !line.slice(0, tag.index).trim()) out.push(line)
|
|
163
|
+
else if (holds(cond)) out.push(line.slice(0, tag.index))
|
|
164
|
+
}
|
|
165
|
+
if (open.length) throw new Error(`Unclosed marker (${open.length} open)`)
|
|
166
|
+
return out.join("\n")
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The blank lines a dropped block leaves, gone the way the formatter would
|
|
171
|
+
* have it: none at the top or bottom, never two in a row, none just inside brackets.
|
|
172
|
+
*/
|
|
173
|
+
export function tidy(text: string): string {
|
|
174
|
+
return text
|
|
175
|
+
.replace(/^\n+/, "")
|
|
176
|
+
.replace(/\n{2,}$/, "\n")
|
|
177
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
178
|
+
.replace(/([{([]|=>)\n\n/g, "$1\n")
|
|
179
|
+
.replace(/\n\n(\s*[})\]])/g, "\n$1")
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Every file under dir, relative to it. */
|
|
183
|
+
async function walk(dir: string, base = dir): Promise<string[]> {
|
|
184
|
+
const out: string[] = []
|
|
185
|
+
for (const e of await readdir(dir, { withFileTypes: true })) {
|
|
186
|
+
const full = join(dir, e.name)
|
|
187
|
+
if (e.isDirectory()) out.push(...(await walk(full, base)))
|
|
188
|
+
else out.push(full.slice(base.length + 1))
|
|
189
|
+
}
|
|
190
|
+
return out
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Keep the chosen parts' tables in drizzle/: drop each statement on a table
|
|
195
|
+
* of a part left out, and the table from the snapshot. A migration left with
|
|
196
|
+
* no statements goes, with its snapshot and journal entry.
|
|
197
|
+
* ponytail: drops only trailing migrations cleanly (prevId is not relinked);
|
|
198
|
+
* the base has two, and only the last can empty out.
|
|
199
|
+
*/
|
|
200
|
+
async function filterMigrations(dir: string, dropTables: Set<string>) {
|
|
201
|
+
if (!dropTables.size) return
|
|
202
|
+
const journalPath = join(dir, "meta/_journal.json")
|
|
203
|
+
const journal = JSON.parse(await readFile(journalPath, "utf8")) as {
|
|
204
|
+
entries: { idx: number; tag: string }[]
|
|
205
|
+
}
|
|
206
|
+
const keep: typeof journal.entries = []
|
|
207
|
+
for (const entry of journal.entries) {
|
|
208
|
+
const sqlPath = join(dir, `${entry.tag}.sql`)
|
|
209
|
+
const snapPath = join(dir, `meta/${entry.tag.slice(0, 4)}_snapshot.json`)
|
|
210
|
+
const statements = (await readFile(sqlPath, "utf8")).split("--> statement-breakpoint")
|
|
211
|
+
const kept = statements.filter((s) => {
|
|
212
|
+
const table = /CREATE TABLE `(\w+)`/.exec(s)?.[1] ?? / ON `(\w+)`/.exec(s)?.[1]
|
|
213
|
+
return !table || !dropTables.has(table)
|
|
214
|
+
})
|
|
215
|
+
if (!kept.some((s) => s.trim())) {
|
|
216
|
+
await rm(sqlPath)
|
|
217
|
+
await rm(snapPath)
|
|
218
|
+
continue
|
|
219
|
+
}
|
|
220
|
+
keep.push(entry)
|
|
221
|
+
if (kept.length !== statements.length)
|
|
222
|
+
await writeFile(sqlPath, kept.join("--> statement-breakpoint").trim())
|
|
223
|
+
// Snapshots are cumulative: a later one still lists an earlier one's tables.
|
|
224
|
+
const snap = JSON.parse(await readFile(snapPath, "utf8")) as { tables: Record<string, unknown> }
|
|
225
|
+
for (const t of dropTables) delete snap.tables[t]
|
|
226
|
+
await writeFile(snapPath, JSON.stringify(snap, null, 2))
|
|
227
|
+
}
|
|
228
|
+
if (keep.length !== journal.entries.length) {
|
|
229
|
+
journal.entries = keep
|
|
230
|
+
await writeFile(journalPath, JSON.stringify(journal, null, 2))
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export type ComposeOptions = {
|
|
235
|
+
parts: PartName[]
|
|
236
|
+
web: boolean
|
|
237
|
+
api: boolean
|
|
238
|
+
runtime?: Runtime
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** The base's own dependencies per surface, from index.ts (signet-mcp's index reads them there). */
|
|
242
|
+
export type BaseDeps = {
|
|
243
|
+
web: { deps: Deps; devDeps: Deps }
|
|
244
|
+
api: { deps: Deps; devDeps: Deps }
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const ROOT = resolve(import.meta.dirname, "..")
|
|
248
|
+
const sorted = (o: Deps) =>
|
|
249
|
+
Object.fromEntries(Object.entries(o).sort(([a], [b]) => a.localeCompare(b)))
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Lay the base and the chosen parts' files into dest and resolve their
|
|
253
|
+
* markers. Returns the package.json body and the env file lines.
|
|
254
|
+
*/
|
|
255
|
+
export async function compose(
|
|
256
|
+
dest: string,
|
|
257
|
+
{ parts, web, api, runtime = "bun" }: ComposeOptions,
|
|
258
|
+
base: BaseDeps,
|
|
259
|
+
) {
|
|
260
|
+
const halves = ["shared", ...(web ? ["web"] : []), ...(api ? ["api"] : [])]
|
|
261
|
+
if (web && api) halves.push("both")
|
|
262
|
+
for (const dir of ["base", ...parts.map((p) => `parts/${p}`)])
|
|
263
|
+
for (const half of halves) {
|
|
264
|
+
const src = join(ROOT, dir, half)
|
|
265
|
+
if (existsSync(src)) await cp(src, dest, { recursive: true })
|
|
266
|
+
}
|
|
267
|
+
const chosen = parts.map((p) => PARTS[p] as Part)
|
|
268
|
+
if (!api)
|
|
269
|
+
for (const p of parts)
|
|
270
|
+
for (const [from, to] of Object.entries((PARTS[p] as Part).uiCopies ?? {}))
|
|
271
|
+
await cp(join(ROOT, "parts", p, "api", from), join(dest, to))
|
|
272
|
+
|
|
273
|
+
const on = new Set<string>([...parts, ...(web ? ["web"] : []), ...(api ? ["api", runtime] : [])])
|
|
274
|
+
for (const f of await walk(dest)) {
|
|
275
|
+
const path = join(dest, f)
|
|
276
|
+
const text = await readFile(path, "utf8")
|
|
277
|
+
let out = applyBlocks(text, on)
|
|
278
|
+
if (out === text) continue
|
|
279
|
+
// Code only: in Markdown a blank line before `)` or after `(` can matter.
|
|
280
|
+
if (/\.(tsx?|json)$/.test(f)) out = tidy(out)
|
|
281
|
+
await writeFile(path, out.replace(/^\n+/, "").replace(/\n{3,}/g, "\n\n"))
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (api)
|
|
285
|
+
await filterMigrations(
|
|
286
|
+
join(dest, "drizzle"),
|
|
287
|
+
new Set(
|
|
288
|
+
PART_NAMES.filter((p) => !parts.includes(p)).flatMap(
|
|
289
|
+
(p) => (PARTS[p] as Part).tables ?? [],
|
|
290
|
+
),
|
|
291
|
+
),
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
const refs = [...(web ? ["app", "node", "test"] : []), ...(api ? ["api"] : [])]
|
|
295
|
+
const ref = (r: string) => `{ "path": "./tsconfig.${r}.json" }`
|
|
296
|
+
await writeFile(
|
|
297
|
+
join(dest, "tsconfig.json"),
|
|
298
|
+
`{\n "files": [],\n "references": ${
|
|
299
|
+
refs.length > 1
|
|
300
|
+
? `[\n${refs.map((r) => ` ${ref(r)}`).join(",\n")}\n ]`
|
|
301
|
+
: `[${ref(refs[0] as string)}]`
|
|
302
|
+
}\n}\n`,
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
const deps: Deps = {}
|
|
306
|
+
const devDeps: Deps = {}
|
|
307
|
+
for (const [on, b] of [
|
|
308
|
+
[web, base.web],
|
|
309
|
+
[api, base.api],
|
|
310
|
+
] as const) {
|
|
311
|
+
if (!on) continue
|
|
312
|
+
Object.assign(deps, b.deps)
|
|
313
|
+
Object.assign(devDeps, b.devDeps)
|
|
314
|
+
}
|
|
315
|
+
for (const p of chosen) {
|
|
316
|
+
if (web) Object.assign(deps, p.web?.deps)
|
|
317
|
+
if (api) Object.assign(deps, p.api?.deps)
|
|
318
|
+
if (web && api) Object.assign(devDeps, p.both?.devDeps)
|
|
319
|
+
}
|
|
320
|
+
const scripts: Record<string, string> =
|
|
321
|
+
web && api
|
|
322
|
+
? {
|
|
323
|
+
// Both halves: the API (restarting on change) and Vite, which proxies /api to it.
|
|
324
|
+
dev: `${RUN[runtime]} scripts/dev.ts`,
|
|
325
|
+
build: "tsc -b && vite build",
|
|
326
|
+
// One process serves the API and the built app from dist/.
|
|
327
|
+
start: `${RUN[runtime]} api/server.ts`,
|
|
328
|
+
preview: "vite preview",
|
|
329
|
+
lint: "biome check .",
|
|
330
|
+
format: "biome check --write .",
|
|
331
|
+
typecheck: "tsc -b --noEmit",
|
|
332
|
+
test: "bun test src test",
|
|
333
|
+
...Object.assign({}, ...chosen.map((p) => p.both?.scripts)),
|
|
334
|
+
}
|
|
335
|
+
: web
|
|
336
|
+
? {
|
|
337
|
+
dev: "vite",
|
|
338
|
+
build: "tsc -b && vite build",
|
|
339
|
+
preview: "vite preview",
|
|
340
|
+
lint: "biome check .",
|
|
341
|
+
format: "biome check --write .",
|
|
342
|
+
typecheck: "tsc -b --noEmit",
|
|
343
|
+
test: "bun test src",
|
|
344
|
+
}
|
|
345
|
+
: {
|
|
346
|
+
dev: `${RUN[runtime]} --watch api/server.ts`,
|
|
347
|
+
start: `${RUN[runtime]} api/server.ts`,
|
|
348
|
+
lint: "biome check .",
|
|
349
|
+
format: "biome check --write .",
|
|
350
|
+
typecheck: "tsc -b --noEmit",
|
|
351
|
+
test: "bun test test",
|
|
352
|
+
}
|
|
353
|
+
if (api)
|
|
354
|
+
Object.assign(scripts, {
|
|
355
|
+
"db:generate": "drizzle-kit generate",
|
|
356
|
+
"db:check": "signet-db-check drizzle",
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
pkg: {
|
|
361
|
+
scripts,
|
|
362
|
+
dependencies: sorted(deps),
|
|
363
|
+
devDependencies: sorted(devDeps),
|
|
364
|
+
// Runs api/server.ts as is: type stripping is on by default from 22.18.
|
|
365
|
+
...(api && runtime === "node" ? { engines: { node: ">=22.18" } } : {}),
|
|
366
|
+
},
|
|
367
|
+
env: api ? ["APP_ENV=development", ...chosen.flatMap((p) => p.env?.() ?? []), ""] : [],
|
|
368
|
+
}
|
|
369
|
+
}
|
package/src/describe.ts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `--describe "<sentence>"`: one sentence to a whole-app plan. Picks the
|
|
3
|
+
* template and theme, splits the sentence into pages, asks signet-mcp's
|
|
4
|
+
* `plan_page` about each, and renders PLAN.md and AGENTS.md. No LLM call: the
|
|
5
|
+
* same sentence always gives the same files.
|
|
6
|
+
*
|
|
7
|
+
* The keyword lists below only choose between Signet's own templates and
|
|
8
|
+
* themes. They are not about any product; an app's own vocabulary stays in the app.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { INDEX } from "@dapplelight/signet-mcp/generated"
|
|
12
|
+
import { type PagePlan, planPage } from "@dapplelight/signet-mcp/plan"
|
|
13
|
+
|
|
14
|
+
export type DescribeTemplate = "web" | "api" | "full"
|
|
15
|
+
export type DescribeTheme = "editorial" | "cinematic" | "finance"
|
|
16
|
+
export type Page = { name: string; plan: PagePlan }
|
|
17
|
+
export type Described = { template: DescribeTemplate; theme: DescribeTheme; pages: Page[] }
|
|
18
|
+
/** How the chosen package manager spells running a script and a bin. */
|
|
19
|
+
export type Runner = { run: string; x: string }
|
|
20
|
+
|
|
21
|
+
// ponytail: keyword lists, not a classifier. A sentence that names none gets web and editorial.
|
|
22
|
+
const BACKEND =
|
|
23
|
+
/\b(api|backend|server|endpoints?|webhooks?|database|login|sign[- ]?(in|up)|accounts?|billing|payments?|subscriptions?|admin|auth\w*)\b/i
|
|
24
|
+
const FINANCE =
|
|
25
|
+
/\b(invoices?|expenses?|budgets?|bank\w*|ledger|accounting|finance|financial|payroll|money|transactions?|payments?)\b/i
|
|
26
|
+
const CINEMATIC =
|
|
27
|
+
/\b(videos?|films?|movies?|cinema\w*|stream\w*|gallery|photos?|music|trailers?|showcase|portfolio)\b/i
|
|
28
|
+
|
|
29
|
+
export const NO_PAGE_WORDS = "dashboard, settings, pricing, inbox"
|
|
30
|
+
|
|
31
|
+
/** Pieces of the sentence that can each name a page: "an inbox with settings and pricing". */
|
|
32
|
+
const segments = (sentence: string) =>
|
|
33
|
+
sentence
|
|
34
|
+
.split(/[,;&\n]|\b(?:and|with|plus|then|also)\b/i)
|
|
35
|
+
.map((s) => s.trim())
|
|
36
|
+
.filter(Boolean)
|
|
37
|
+
|
|
38
|
+
/** Each distinct page the sentence names, in the order it names them. */
|
|
39
|
+
function pagesFor(sentence: string, target: DescribeTemplate): Page[] {
|
|
40
|
+
const pages: Page[] = []
|
|
41
|
+
for (const part of segments(sentence)) {
|
|
42
|
+
const plan = planPage(INDEX, part, target)
|
|
43
|
+
// web and full pages are blocks; an api page is named by the route plan_page files it under.
|
|
44
|
+
const name = plan.blocks[0]?.name ?? /^src\/api\/(.+)\.ts$/.exec(plan.files[0]?.path ?? "")?.[1]
|
|
45
|
+
if (name && !pages.some((p) => p.name === name)) pages.push({ name, plan })
|
|
46
|
+
}
|
|
47
|
+
return pages
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function describeApp(
|
|
51
|
+
sentence: string,
|
|
52
|
+
want: { template?: DescribeTemplate; theme?: DescribeTheme },
|
|
53
|
+
): Described {
|
|
54
|
+
let template = want.template
|
|
55
|
+
let pages: Page[] | undefined
|
|
56
|
+
if (!template) {
|
|
57
|
+
const web = pagesFor(sentence, "web")
|
|
58
|
+
template = !BACKEND.test(sentence) ? "web" : web.length ? "full" : "api"
|
|
59
|
+
if (template === "web") pages = web
|
|
60
|
+
}
|
|
61
|
+
pages ??= pagesFor(sentence, template)
|
|
62
|
+
const theme =
|
|
63
|
+
want.theme ??
|
|
64
|
+
(template === "api"
|
|
65
|
+
? "editorial"
|
|
66
|
+
: FINANCE.test(sentence)
|
|
67
|
+
? "finance"
|
|
68
|
+
: CINEMATIC.test(sentence)
|
|
69
|
+
? "cinematic"
|
|
70
|
+
: "editorial")
|
|
71
|
+
return { template, theme, pages }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The order to build in: sign-in first, the catch-all pages last, the rest as named. */
|
|
75
|
+
const WEIGHT: Record<string, number> = { "auth-page": -1, "empty-page": 1, "error-page": 1 }
|
|
76
|
+
const buildOrder = (pages: Page[]) =>
|
|
77
|
+
[...pages].sort((a, b) => (WEIGHT[a.name] ?? 0) - (WEIGHT[b.name] ?? 0))
|
|
78
|
+
|
|
79
|
+
/** The plan's `data` lines that describe records, as `name: fields`, not callbacks or flags. */
|
|
80
|
+
function models(pages: Page[]) {
|
|
81
|
+
const out = new Map<string, { shape: string; pages: string[] }>()
|
|
82
|
+
for (const p of pages)
|
|
83
|
+
for (const line of p.plan.data) {
|
|
84
|
+
const m = /^(\w+): (.+)$/.exec(line)
|
|
85
|
+
if (!m || /^on[A-Z]/.test(m[1] as string) || /\b(called|calls|callback)\b/.test(line))
|
|
86
|
+
continue
|
|
87
|
+
if (!/\b(each|and)\b/.test(m[2] as string)) continue
|
|
88
|
+
const key = `${m[1]}`
|
|
89
|
+
const have = out.get(key)
|
|
90
|
+
if (have) have.pages.push(p.name)
|
|
91
|
+
else out.set(key, { shape: m[2] as string, pages: [p.name] })
|
|
92
|
+
}
|
|
93
|
+
return out
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function renderPlan(
|
|
97
|
+
appName: string,
|
|
98
|
+
sentence: string,
|
|
99
|
+
d: Described,
|
|
100
|
+
{ run, x }: Runner,
|
|
101
|
+
): string {
|
|
102
|
+
const head = `# Plan: ${appName}\n\n`
|
|
103
|
+
if (!d.pages.length)
|
|
104
|
+
return `${head}Template: ${d.template} · Theme: ${d.theme}\n\n## Pages\n\nNo page matched "${sentence}". Try words like ${NO_PAGE_WORDS}.\n`
|
|
105
|
+
|
|
106
|
+
const check = `${x} @dapplelight/signet-cli check`
|
|
107
|
+
const cmd = (c: string) => c.replace(/^npx /, `${x} `)
|
|
108
|
+
const quote = sentence
|
|
109
|
+
.split("\n")
|
|
110
|
+
.map((l) => `> ${l}`)
|
|
111
|
+
.join("\n")
|
|
112
|
+
const lines: string[] = [
|
|
113
|
+
`${head}${quote}\n\nTemplate: ${d.template} · Theme: ${d.theme}\n`,
|
|
114
|
+
"## Pages\n",
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
d.pages.forEach((p, i) => {
|
|
118
|
+
const { plan } = p
|
|
119
|
+
lines.push(`### ${i + 1}. ${p.name}\n`)
|
|
120
|
+
lines.push("**Blocks**\n")
|
|
121
|
+
if (plan.blocks.length) {
|
|
122
|
+
for (const b of plan.blocks) lines.push(`- \`${b.name}\`: ${b.why}`)
|
|
123
|
+
lines.push("", "```bash", ...plan.blocks.map((b) => cmd(b.command)), "```\n")
|
|
124
|
+
} else lines.push("- None: this page is API only.\n")
|
|
125
|
+
lines.push("**Components**\n")
|
|
126
|
+
lines.push(
|
|
127
|
+
...(plan.components.length
|
|
128
|
+
? plan.components.map((c) => `- \`${c.name}\`: \`${c.importPath}\``)
|
|
129
|
+
: ["- None."]),
|
|
130
|
+
"",
|
|
131
|
+
)
|
|
132
|
+
lines.push("**Modules**\n")
|
|
133
|
+
lines.push(...(plan.modules.length ? plan.modules.map((m) => `- \`${m}\``) : ["- None."]), "")
|
|
134
|
+
lines.push("**Data**\n")
|
|
135
|
+
lines.push(...(plan.data.length ? plan.data.map((l) => `- ${l}`) : ["- None."]), "")
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
lines.push("## Data models\n")
|
|
139
|
+
const ms = models(d.pages)
|
|
140
|
+
lines.push(
|
|
141
|
+
...(ms.size
|
|
142
|
+
? [...ms].map(([k, v]) => `- \`${k}\`: ${v.shape} (${v.pages.join(", ")})`)
|
|
143
|
+
: ["- None: the pages take props only."]),
|
|
144
|
+
"",
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
lines.push("## Recipes\n")
|
|
148
|
+
const recipes = [...new Set(d.pages.map((p) => p.plan.recipe).filter((r): r is string => !!r))]
|
|
149
|
+
lines.push(
|
|
150
|
+
...(recipes.length
|
|
151
|
+
? recipes.map((id) => {
|
|
152
|
+
const title = INDEX.recipes.find((r) => r.id === id)?.title ?? id
|
|
153
|
+
return `- \`${id}\`: ${title}. Call \`recipe({ task: "${id}" })\`.`
|
|
154
|
+
})
|
|
155
|
+
: ["- None matched."]),
|
|
156
|
+
"",
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
lines.push("## Build order\n")
|
|
160
|
+
buildOrder(d.pages).forEach((p, i) => {
|
|
161
|
+
lines.push(
|
|
162
|
+
p.plan.blocks.length
|
|
163
|
+
? `${i + 1}. ${p.name}: run its block command, wire its data, then \`${check} --pages /${p.name}\`.`
|
|
164
|
+
: `${i + 1}. ${p.name}: add \`src/api/${p.name}.ts\`${p.plan.recipe ? `, following the \`${p.plan.recipe}\` recipe` : ""}, then \`${check}\`.`,
|
|
165
|
+
)
|
|
166
|
+
})
|
|
167
|
+
lines.push("")
|
|
168
|
+
|
|
169
|
+
lines.push(
|
|
170
|
+
"## After each page\n",
|
|
171
|
+
"Fix every finding before you start the next page.\n",
|
|
172
|
+
"```bash",
|
|
173
|
+
`${check} --pages /<page>`,
|
|
174
|
+
`${run} test`,
|
|
175
|
+
"```\n",
|
|
176
|
+
`\`check\` typechecks, runs Biome, checks Signet's conventions and, with \`--pages\`, screenshots the page at 390 and 1280 px with axe. Start the dev server first (\`${run} dev\`). Or call \`check_app({ path: "." })\` on the Signet MCP server.`,
|
|
177
|
+
)
|
|
178
|
+
return `${lines.join("\n")}\n`
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function renderAgents(appName: string, d: Described, { run }: Runner): string {
|
|
182
|
+
return `${[
|
|
183
|
+
`# ${appName}: notes for coding agents`,
|
|
184
|
+
"",
|
|
185
|
+
"This app is built from PLAN.md, one page at a time.",
|
|
186
|
+
"",
|
|
187
|
+
"1. Read PLAN.md. Build the pages in its Build order and never skip ahead.",
|
|
188
|
+
"2. For each page: run its block command, wire the data it lists, then run the check from After each page.",
|
|
189
|
+
"3. Fix every finding before you move on. Never edit a page before the previous one passes.",
|
|
190
|
+
"4. Use `@dapplelight/signet-ui` components and `@dapplelight/signet-tokens` themes only.",
|
|
191
|
+
d.template === "api"
|
|
192
|
+
? "5. No hand-rolled validation or error shapes: use `@dapplelight/signet-server`."
|
|
193
|
+
: "5. No hand-rolled buttons, inputs or fetch wrappers: use the typed client in `src/lib/api.ts`.",
|
|
194
|
+
"6. To look up a component, theme or convention, add the Signet MCP server:",
|
|
195
|
+
" `claude mcp add signet -- bunx @dapplelight/signet-mcp`",
|
|
196
|
+
`7. Run \`${run} lint\`, \`${run} typecheck\` and \`${run} test\` before you finish.`,
|
|
197
|
+
"",
|
|
198
|
+
"If PLAN.md lists no pages, ask for a description of the first page before you build anything.",
|
|
199
|
+
].join("\n")}\n`
|
|
200
|
+
}
|
package/src/desktop.ts
CHANGED
|
@@ -23,28 +23,28 @@ export const DESKTOP_PKG = {
|
|
|
23
23
|
dependencies: {
|
|
24
24
|
"@dapplelight/signet-lib": "^0.4.1",
|
|
25
25
|
"@dapplelight/signet-tokens": "^0.4.0",
|
|
26
|
-
"@dapplelight/signet-ui": "^0.
|
|
26
|
+
"@dapplelight/signet-ui": "^0.4.0",
|
|
27
27
|
"@tauri-apps/api": "^2.0.0",
|
|
28
28
|
"@tauri-apps/plugin-opener": "^2.0.0",
|
|
29
29
|
"@tauri-apps/plugin-store": "^2.0.0",
|
|
30
30
|
"class-variance-authority": "^0.7.1",
|
|
31
31
|
clsx: "^2.1.1",
|
|
32
|
-
"lucide-react": "^1.
|
|
33
|
-
react: "^19.3.
|
|
34
|
-
"react-dom": "^19.3.
|
|
32
|
+
"lucide-react": "^1.74.0",
|
|
33
|
+
react: "^19.3.1",
|
|
34
|
+
"react-dom": "^19.3.1",
|
|
35
35
|
"tailwind-merge": "^3.7.0",
|
|
36
36
|
},
|
|
37
37
|
devDependencies: {
|
|
38
38
|
"@biomejs/biome": "^2.5.14",
|
|
39
|
-
"@tailwindcss/vite": "^4.3.
|
|
39
|
+
"@tailwindcss/vite": "^4.3.5",
|
|
40
40
|
"@tauri-apps/cli": "^2.0.0",
|
|
41
|
-
"@types/bun": "^1.4.
|
|
42
|
-
"@types/node": "^26.6.
|
|
41
|
+
"@types/bun": "^1.4.4",
|
|
42
|
+
"@types/node": "^26.6.6",
|
|
43
43
|
"@types/react": "^19.3.0",
|
|
44
44
|
"@types/react-dom": "^19.3.0",
|
|
45
|
-
"@vitejs/plugin-react": "^6.
|
|
46
|
-
tailwindcss: "^4.3.
|
|
45
|
+
"@vitejs/plugin-react": "^6.3.0",
|
|
46
|
+
tailwindcss: "^4.3.5",
|
|
47
47
|
typescript: "^7.0.2",
|
|
48
|
-
vite: "^8.3.
|
|
48
|
+
vite: "^8.3.8",
|
|
49
49
|
},
|
|
50
50
|
}
|