create-stitchkit 0.6.22 → 0.7.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 +64 -0
- package/README.md +9 -1
- package/UPGRADING.md +84 -16
- package/dist/cli.js +83 -56
- package/examples/repository/packages/backend/src/surface.snapshot.json +175 -88
- package/examples/repository/scripts/runtime-smoke.ts +156 -126
- package/package.json +12 -9
- package/template/README.md +12 -2
- package/template/_gitignore +1 -0
- package/template/bun.lock +12 -12
- package/template/docs/ADDING_A_FEATURE.md +21 -7
- package/template/package.json +5 -5
- package/template/packages/backend/package.json +1 -1
- package/template/packages/backend/src/cli.ts +1 -0
- package/template/packages/backend/src/index.ts +3 -0
- package/template/packages/backend/src/lib/live.ts +3 -1
- package/template/packages/backend/src/surface.snapshot.json +90 -50
- package/template/packages/backend/src/tools.ts +1 -1
- package/template/packages/config/package.json +1 -1
- package/template/packages/frontend/package.json +2 -2
- package/template/packages/shared/package.json +1 -1
- package/template/scripts/acceptance-environment.test.ts +59 -0
- package/template/scripts/acceptance-environment.ts +52 -0
- package/template/scripts/acceptance-local.ts +8 -28
- package/template/scripts/runtime-smoke.test.ts +49 -0
- package/template/scripts/runtime-smoke.ts +2 -2
- package/template/scripts/surface-snapshot.ts +135 -14
- package/templates/agent/package.json +7 -7
- package/templates/agent/src/runtime.ts +1 -1
- package/templates/telegram-bot/package.json +3 -3
- package/template/.data/board.sqlite +0 -0
- package/template/packages/backend/src/surface-manifest.test.ts +0 -237
- package/template/packages/backend/src/surface-manifest.ts +0 -220
- package/template/scripts/surface-conformance.ts +0 -173
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,70 @@ step is overwritten by the next release.
|
|
|
12
12
|
|
|
13
13
|
## [Unreleased]
|
|
14
14
|
|
|
15
|
+
## [0.7.0] - 2026-11-25
|
|
16
|
+
|
|
17
|
+
### ⚠️ Breaking changes
|
|
18
|
+
|
|
19
|
+
**Who must act:** every project scaffolded from an earlier `create-stitchkit` release that still keeps local copies of `surface-manifest.ts` / `surface-conformance.ts` or mounts MCP, Agent or CLI tools without an explicit `access` policy ([migration](./UPGRADING.md#starter-uses-stitchkittesting-and-mandatory-tool-access)).
|
|
20
|
+
|
|
21
|
+
- Removed the local copies of the framework's surface manifest and conformance runner from
|
|
22
|
+
the application template (`packages/backend/src/surface-manifest.ts`,
|
|
23
|
+
`packages/backend/src/surface-manifest.test.ts`, and `scripts/surface-conformance.ts`).
|
|
24
|
+
`scripts/surface-snapshot.ts` and `scripts/runtime-smoke.ts` now import
|
|
25
|
+
`buildSurfaceManifest`, `assertSurfaceManifestSnapshot`, `assertSurfaceDiscovery`,
|
|
26
|
+
`SurfaceManifestSchema`, and `runSurfaceProbes` directly from `stitchkit/testing`, and
|
|
27
|
+
`packages/backend/src/surface.snapshot.json` uses the canonical `manifestVersion: 3`
|
|
28
|
+
format. Before: `import { runSurfaceConformance } from './surface-conformance'`. After:
|
|
29
|
+
`import { assertLiveSurface } from './surface-snapshot'` and
|
|
30
|
+
`import { runSurfaceProbes } from 'stitchkit/testing'`. Existing projects adopt it by
|
|
31
|
+
[`UPGRADING.md`](./UPGRADING.md#starter-uses-stitchkittesting-and-mandatory-tool-access).
|
|
32
|
+
- Updated tool mounts in the application and agent templates for mandatory `access` and
|
|
33
|
+
`ToolNameEntry.expose`: `packages/backend/src/index.ts` passes `access: { open: 'public' }`
|
|
34
|
+
to `createMcpHandler`, `packages/backend/src/cli.ts` passes
|
|
35
|
+
`access: { open: 'local-operator' }` to `createCli`, `packages/backend/src/tools.ts` reads
|
|
36
|
+
`tool.expose`, and `templates/agent/src/runtime.ts` passes
|
|
37
|
+
`access: { gate: context.toolFenceLifecycle }` to `mountAgent`. Before:
|
|
38
|
+
`createCli({ name, version, services })` and `mountAgent([], { runtimeTools, lifecycle: context.toolFenceLifecycle })`.
|
|
39
|
+
After: `createCli({ name, version, services, access: { open: 'local-operator' } })` and
|
|
40
|
+
`mountAgent([], { runtimeTools, access: { gate: context.toolFenceLifecycle } })`.
|
|
41
|
+
|
|
42
|
+
### Added
|
|
43
|
+
|
|
44
|
+
- Newly scaffolded projects record the `create-stitchkit` package version in `project.json`
|
|
45
|
+
under `starter: { version }` (validated by `ProjectDeclarationSchema` in
|
|
46
|
+
`stitchkit/declaration`).
|
|
47
|
+
|
|
48
|
+
### Fixed
|
|
49
|
+
|
|
50
|
+
- `acceptance:local` gives the realtime socket and the CORS admission this run's
|
|
51
|
+
ephemeral ports. It moved every role to ephemeral ports but kept
|
|
52
|
+
`PUBLIC_REALTIME_ORIGIN` and `CORS_ORIGIN` from `.env`, so on a machine where
|
|
53
|
+
another process listened on 3210 or 3211 the browser under test opened that
|
|
54
|
+
process's socket. The environment is built by `scripts/acceptance-environment.ts`,
|
|
55
|
+
and a test refuses any variable of `.env.example` that would still name a
|
|
56
|
+
deployment port. An existing project adopts it by
|
|
57
|
+
[`UPGRADING.md`](./UPGRADING.md#acceptance-owns-every-address).
|
|
58
|
+
- The package and the projects generated from it no longer carry
|
|
59
|
+
`.data/board.sqlite`, the reference board's local database, and a generated
|
|
60
|
+
project ignores `.data/`. The documents describe the default scaffold as it is:
|
|
61
|
+
one reference feature, a notes board, beside the `/ui` catalogue and an admin
|
|
62
|
+
panel on fixture data, and the template README names what depends on the board.
|
|
63
|
+
|
|
64
|
+
## [0.6.23] - 2026-11-21
|
|
65
|
+
|
|
66
|
+
### Changed
|
|
67
|
+
|
|
68
|
+
- Generated projects resolve stitchkit 0.126.0. The backend's watch hub reads with
|
|
69
|
+
`read({ operation })`: `createWatchHub` now passes one request carrying an `AbortSignal` that
|
|
70
|
+
aborts when the last watcher leaves. An existing project adopts it by
|
|
71
|
+
[`UPGRADING.md`](./UPGRADING.md#watch-hub-reads-one-request) and the stitchkit 0.126.0
|
|
72
|
+
migration `watch-read-request` in `docs/guide/upgrading.md`, and from 0.125.0 the migration
|
|
73
|
+
`cli-framework-option-command-names`: a CLI command named like a framework option (`--quiet`)
|
|
74
|
+
is refused, and a leading framework flag before a native command in a CLI with a managed
|
|
75
|
+
factory and no default command must move after it.
|
|
76
|
+
- The generator, the starter and both templates run on Bun 1.4.5; the agent template moves to
|
|
77
|
+
`ai` 7.0.179 and OpenTUI 0.9.7, the telegram-bot template to `@types/bun` 1.4.5.
|
|
78
|
+
|
|
15
79
|
## [0.6.22] - 2026-11-17
|
|
16
80
|
|
|
17
81
|
### Changed
|
package/README.md
CHANGED
|
@@ -55,7 +55,15 @@ It uses one conventional `packages/*` namespace: `backend`, `frontend`,
|
|
|
55
55
|
machine-readable statement it makes about itself — and drive package, process,
|
|
56
56
|
transport, UI and SEO identity.
|
|
57
57
|
|
|
58
|
-
The default scaffold
|
|
58
|
+
The default scaffold carries no product of its own, but it is not empty. Its home
|
|
59
|
+
page holds one reference vertical feature — a notes board: schema, contract,
|
|
60
|
+
service, live channel, panel and the end-to-end check that a note posted in one
|
|
61
|
+
tab reaches another through the socket — beside the `/ui` catalogue and an admin
|
|
62
|
+
panel on fixture data that runs in development only. Replace the board with your
|
|
63
|
+
first feature; `docs/ADDING_A_FEATURE.md` in the generated project walks the same
|
|
64
|
+
slice, and its README lists what depends on the board.
|
|
65
|
+
|
|
66
|
+
To add the runnable repository example:
|
|
59
67
|
|
|
60
68
|
```bash
|
|
61
69
|
bun create stitchkit my-app --example repository
|
package/UPGRADING.md
CHANGED
|
@@ -26,9 +26,10 @@ changelog because the next release overwrites the entry that carried them.
|
|
|
26
26
|
|
|
27
27
|
## Flow
|
|
28
28
|
|
|
29
|
-
1. **Find your project's origin.**
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
1. **Find your project's origin.** Check `starter.version` in your repository's
|
|
30
|
+
`project.json` (recorded by the scaffolder). Earlier projects that omit
|
|
31
|
+
`starter` can check the changelog of the version they scaffolded with, or
|
|
32
|
+
diff their tree against a fresh scaffold of the target version.
|
|
32
33
|
2. **Read every `### ⚠️ Breaking changes` in range** in
|
|
33
34
|
[`CHANGELOG.md`](./CHANGELOG.md), from the version above yours up to your
|
|
34
35
|
target.
|
|
@@ -60,11 +61,78 @@ the first scaffolder release with a migration channel of its own.
|
|
|
60
61
|
|
|
61
62
|
---
|
|
62
63
|
|
|
64
|
+
## Released migration: 0.7.0
|
|
65
|
+
|
|
66
|
+
### starter uses stitchkit/testing and mandatory tool access
|
|
67
|
+
|
|
68
|
+
**Required.** Adopt these edits together with upgrading `stitchkit` to `0.127.0`
|
|
69
|
+
(see [`docs/guide/upgrading.md`](../../docs/guide/upgrading.md) for the framework changes).
|
|
70
|
+
|
|
71
|
+
1. Remove the copied surface helpers from your repository:
|
|
72
|
+
- Delete `packages/backend/src/surface-manifest.ts`,
|
|
73
|
+
`packages/backend/src/surface-manifest.test.ts`, and
|
|
74
|
+
`scripts/surface-conformance.ts`.
|
|
75
|
+
- Replace `scripts/surface-snapshot.ts` with the template version that imports
|
|
76
|
+
`buildSurfaceManifest`, `assertSurfaceManifestSnapshot`, `assertSurfaceDiscovery`,
|
|
77
|
+
and `SurfaceManifestSchema` from `stitchkit/testing`.
|
|
78
|
+
- Update `scripts/runtime-smoke.ts` to call `assertLiveSurface` from `./surface-snapshot`
|
|
79
|
+
and `runSurfaceProbes` from `stitchkit/testing` instead of `runSurfaceConformance` /
|
|
80
|
+
`defineSurfaceProbe`.
|
|
81
|
+
- Regenerate and review `packages/backend/src/surface.snapshot.json` with
|
|
82
|
+
`bun run surface:snapshot` (the snapshot moves to `manifestVersion: 3`).
|
|
83
|
+
2. Pass explicit `access` on every tool mount:
|
|
84
|
+
- In `packages/backend/src/index.ts`, add `access: { open: 'public' }` (or
|
|
85
|
+
`access: { gate: { beforeHandle: authHook } }` when your app has authenticated
|
|
86
|
+
scopes) to `createMcpHandler(...)`.
|
|
87
|
+
- In `packages/backend/src/cli.ts`, add `access: { open: 'local-operator' }` (or your
|
|
88
|
+
app's gate) to `createCli(...)`.
|
|
89
|
+
- In an agent-template project (`src/runtime.ts`), replace
|
|
90
|
+
`lifecycle: context.toolFenceLifecycle` with
|
|
91
|
+
`access: { gate: context.toolFenceLifecycle }` in `mountAgent(...)`.
|
|
92
|
+
3. In `packages/backend/src/tools.ts`, read `tool.expose` instead of `tool.transports`.
|
|
93
|
+
4. Optional: record your starter origin in `project.json` under `"starter": { "version": "<version>" }`.
|
|
94
|
+
5. Run `bun run check`, `bun run test`, and `bun run surface:snapshot` to confirm the
|
|
95
|
+
regenerated snapshot and checks pass.
|
|
96
|
+
|
|
97
|
+
### acceptance owns every address
|
|
98
|
+
|
|
99
|
+
**Voluntary.** Worth taking on a machine that runs other projects. Without it,
|
|
100
|
+
`bun run acceptance:local` can test the socket of whatever else listens on the
|
|
101
|
+
ports in your `.env`.
|
|
102
|
+
|
|
103
|
+
1. In `scripts/acceptance-local.ts`, in the object the environment is assigned,
|
|
104
|
+
add next to `PLAYWRIGHT_BASE_URL`:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
PUBLIC_REALTIME_ORIGIN: apiOrigin,
|
|
108
|
+
CORS_ORIGIN: webOrigin,
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Or take the whole file `scripts/acceptance-environment.ts` and its test from a
|
|
112
|
+
project generated by this release, and build the environment with it.
|
|
113
|
+
2. Add `.data/` to `.gitignore`. If `.data/board.sqlite` is committed, remove it
|
|
114
|
+
from the repository; the board recreates it on start.
|
|
115
|
+
3. Run `bun run acceptance:local` with something listening on 127.0.0.1:3211 and
|
|
116
|
+
check the run still passes.
|
|
117
|
+
|
|
118
|
+
## Released migration: 0.6.23
|
|
119
|
+
|
|
120
|
+
### watch hub reads one request
|
|
121
|
+
|
|
122
|
+
**With stitchkit 0.126.0.** Take it together with stitchkit 0.126.0, whose `createWatchHub` passes `read` one
|
|
123
|
+
`{ operation, args, scope, signal }` request; on 0.125.0 and earlier the entry does not compile.
|
|
124
|
+
|
|
125
|
+
1. In `packages/backend/src/lib/live.ts`, change `read: async (operation) =>` to
|
|
126
|
+
`read: async ({ operation }) =>`. A read of your own that calls the network or a slow query
|
|
127
|
+
takes `signal` from the same request and passes it on.
|
|
128
|
+
2. Run `bun run check`, then open the board in two tabs, post a note in one and check it appears
|
|
129
|
+
in the other.
|
|
130
|
+
|
|
63
131
|
## Released migration: 0.6.22
|
|
64
132
|
|
|
65
133
|
### unknown operation keeps the not_found wire code
|
|
66
134
|
|
|
67
|
-
Take it together with
|
|
135
|
+
**With stitchkit 0.123.0.** Take it together with stitchkit 0.123.0, which answers an unmatched route
|
|
68
136
|
`UNKNOWN_OPERATION`; on an earlier stitchkit the entry is inert.
|
|
69
137
|
|
|
70
138
|
1. In `packages/backend/src/transport/errors.ts`, add `UNKNOWN_OPERATION: 'not_found'` to
|
|
@@ -75,7 +143,7 @@ Take it together with the stitchkit release that answers an unmatched route
|
|
|
75
143
|
|
|
76
144
|
### supervision passes declared environment
|
|
77
145
|
|
|
78
|
-
Additive, and worth taking: without it a changed `.env` stays stale in a running role until
|
|
146
|
+
**Voluntary.** Additive, and worth taking: without it a changed `.env` stays stale in a running role until
|
|
79
147
|
`pm2 delete`.
|
|
80
148
|
|
|
81
149
|
1. In `scripts/declaration.ts`, after the `config({ path: … })` call that `renderEcosystem`
|
|
@@ -91,8 +159,8 @@ Additive, and worth taking: without it a changed `.env` stays stale in a running
|
|
|
91
159
|
|
|
92
160
|
### Canonical query client factory
|
|
93
161
|
|
|
94
|
-
This migration is additive, but it has a dependency order: first upgrade to a
|
|
95
|
-
Stitchkit release that exports `createQueryClientFactory` from
|
|
162
|
+
**With stitchkit 0.81.0.** This migration is additive, but it has a dependency order: first upgrade to a
|
|
163
|
+
Stitchkit release (0.81.0+) that exports `createQueryClientFactory` from
|
|
96
164
|
`stitchkit/react`. Then replace the local QueryClient construction with:
|
|
97
165
|
|
|
98
166
|
```ts
|
|
@@ -119,7 +187,7 @@ start.
|
|
|
119
187
|
|
|
120
188
|
### 1. The store directory has to be writable
|
|
121
189
|
|
|
122
|
-
`BOARD_STORE_PATH` defaults to `.data/board.sqlite`, relative to the API role's
|
|
190
|
+
**Voluntary.** Required as an operator step when adopting the vertical feature: `BOARD_STORE_PATH` defaults to `.data/board.sqlite`, relative to the API role's
|
|
123
191
|
working directory. The application creates the directory itself; what it cannot
|
|
124
192
|
do is make a read-only volume writable.
|
|
125
193
|
|
|
@@ -133,7 +201,7 @@ volume instead.
|
|
|
133
201
|
|
|
134
202
|
### 2. Decide about the trust fence, on purpose
|
|
135
203
|
|
|
136
|
-
`TRUSTED_HOSTS` is unset by default, and unset means **no fence**. That is
|
|
204
|
+
**Voluntary.** Required as an operator step when deploying over a network: `TRUSTED_HOSTS` is unset by default, and unset means **no fence**. That is
|
|
137
205
|
correct on a laptop and wrong on anything a network reaches — but a fence cannot
|
|
138
206
|
guess which names your deployment answers to, so it refuses to invent them.
|
|
139
207
|
|
|
@@ -149,7 +217,7 @@ and the fence reads that one rather than asking you a second time.
|
|
|
149
217
|
|
|
150
218
|
### 3. Nothing else
|
|
151
219
|
|
|
152
|
-
The rest of the feature is code you either copy or do not. The framework range
|
|
220
|
+
**Voluntary.** The rest of the feature is code you either copy or do not. The framework range
|
|
153
221
|
moved to `^0.76.1`; if you upgrade the dependency without taking the feature,
|
|
154
222
|
[the framework's own guide](../../docs/guide/upgrading.md) is the one to follow.
|
|
155
223
|
|
|
@@ -157,7 +225,7 @@ moved to `^0.76.1`; if you upgrade the dependency without taking the feature,
|
|
|
157
225
|
|
|
158
226
|
### the approval policy names a tool that no longer exists
|
|
159
227
|
|
|
160
|
-
One code edit, and one thing to do to a machine that was left mid-question.
|
|
228
|
+
**With stitchkit 0.71.0.** One code edit, and one thing to do to a machine that was left mid-question.
|
|
161
229
|
|
|
162
230
|
1. **Rename the key.** In `src/runtime.ts`, inside `loop.toolApproval`, replace
|
|
163
231
|
`apply_patch: 'user-approval'` with `edit_file: 'user-approval'`. While you
|
|
@@ -191,7 +259,7 @@ One code edit, and one thing to do to a machine that was left mid-question.
|
|
|
191
259
|
|
|
192
260
|
### the timestamp your API accepts got narrower
|
|
193
261
|
|
|
194
|
-
Zod moved to 4.5, and `z.iso.datetime()` now requires seconds. This is not a
|
|
262
|
+
**Required.** Zod moved to 4.5, and `z.iso.datetime()` now requires seconds. This is not a
|
|
195
263
|
code change — it is a change in what your endpoints admit, and it arrives the
|
|
196
264
|
moment you install.
|
|
197
265
|
|
|
@@ -222,7 +290,7 @@ moment you install.
|
|
|
222
290
|
|
|
223
291
|
### a release refuses a stale artifact, and cleanup is bounded
|
|
224
292
|
|
|
225
|
-
Two changes an existing project should take, both about a shutdown or a start
|
|
293
|
+
**Voluntary.** Two changes an existing project should take, both about a shutdown or a start
|
|
226
294
|
that looked safe and was not.
|
|
227
295
|
|
|
228
296
|
1. **Stamp the build.** Copy `scripts/build-stamp.ts` from a fresh scaffold,
|
|
@@ -250,7 +318,7 @@ No operator step: nothing about a running machine changes.
|
|
|
250
318
|
|
|
251
319
|
### the gate list runs, and never deploys
|
|
252
320
|
|
|
253
|
-
The `Gates` list in the generated guides presented five commands in a row, two
|
|
321
|
+
**Voluntary.** The `Gates` list in the generated guides presented five commands in a row, two
|
|
254
322
|
of which check a **running** deployment — with nothing in the list that starts
|
|
255
323
|
one. The fix is not to add a deploy command: `bun run pm2:prod` applies your
|
|
256
324
|
declared migrations and reloads the deployment you are running, so a list that
|
|
@@ -298,7 +366,7 @@ No operator step: nothing about a running machine changes.
|
|
|
298
366
|
|
|
299
367
|
### the declaration schema is imported
|
|
300
368
|
|
|
301
|
-
For a project generated **before** the scaffolder version that drops the schema
|
|
369
|
+
**With stitchkit 0.60.0.** For a project generated **before** the scaffolder version that drops the schema
|
|
302
370
|
mirror. Nothing in your tree stops working if you skip this — the copy keeps
|
|
303
371
|
parsing. What you lose by skipping is the guarantee: your copy no longer moves
|
|
304
372
|
when the framework's schema does, and nothing tells you.
|
|
@@ -339,7 +407,7 @@ No operator step: nothing about a running machine changes.
|
|
|
339
407
|
|
|
340
408
|
### the project declares itself
|
|
341
409
|
|
|
342
|
-
Everything in this section is for a project generated **before** the scaffolder
|
|
410
|
+
**Required.** Everything in this section is for a project generated **before** the scaffolder
|
|
343
411
|
version that introduces `project.json`.
|
|
344
412
|
|
|
345
413
|
#### The declaration replaces `app.config.json`
|
package/dist/cli.js
CHANGED
|
@@ -10,8 +10,12 @@ var {spawn } = globalThis.Bun;
|
|
|
10
10
|
import { basename } from "path";
|
|
11
11
|
|
|
12
12
|
// ../core/src/declaration/declaration.ts
|
|
13
|
+
import { z as z2 } from "zod";
|
|
14
|
+
|
|
15
|
+
// ../core/src/declaration/command.ts
|
|
13
16
|
import { z } from "zod";
|
|
14
|
-
|
|
17
|
+
|
|
18
|
+
// ../core/src/declaration/machine-names.ts
|
|
15
19
|
var MACHINE_PATTERNS = [
|
|
16
20
|
[/:\/\//, "an absolute address"],
|
|
17
21
|
[/^\/\//, "a protocol-relative host"],
|
|
@@ -33,23 +37,8 @@ function refuseMachineNames(label) {
|
|
|
33
37
|
error: (issue) => `${label} names a machine \u2014 ${namesAMachine(String(issue.input)) ?? "a value of the deployment"} is supplied by the deployment, not written in the code`
|
|
34
38
|
});
|
|
35
39
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var ProjectIdentitySchema = z.object({
|
|
39
|
-
slug: ProjectSlugSchema,
|
|
40
|
-
name: refuseMachineNames("A project name")(z.string().trim().min(1).max(80)),
|
|
41
|
-
version: z.string().regex(/^\d+\.\d+\.\d+$/, "Use a semantic version such as 0.1.0"),
|
|
42
|
-
description: ProjectDescriptionSchema
|
|
43
|
-
}).strict();
|
|
44
|
-
var RepositoryPathSchema = z.string().min(1).refine((value) => !value.startsWith("/"), "Use a path relative to the repository root").refine((value) => namesAMachine(value) === undefined, {
|
|
45
|
-
error: (issue) => `A path may not contain ${namesAMachine(String(issue.input)) ?? "a machine name"}`
|
|
46
|
-
}).refine((value) => !value.split("/").includes(".."), "A path may not climb out of the repository");
|
|
47
|
-
var BindingVariableSchema = z.string().regex(/^[A-Z][A-Z0-9_]*$/, "Name an environment variable, for example API_PORT");
|
|
48
|
-
var ProjectListenerSchema = z.object({
|
|
49
|
-
portVariable: BindingVariableSchema,
|
|
50
|
-
bindVariable: BindingVariableSchema,
|
|
51
|
-
readinessPath: refuseMachineNames("A readiness path")(z.string().startsWith("/", "Readiness is a path, for example /health"))
|
|
52
|
-
}).strict();
|
|
40
|
+
|
|
41
|
+
// ../core/src/declaration/command.ts
|
|
53
42
|
var ProjectRunModeSchema = z.enum(["development", "production"]);
|
|
54
43
|
var PROJECT_SCRIPT_LAUNCHERS = [
|
|
55
44
|
[/^(?:bun|npm|pnpm|yarn)$/, /^run$/],
|
|
@@ -75,53 +64,78 @@ var ProjectCommandSchema = z.object({
|
|
|
75
64
|
args: CommandArgumentsSchema
|
|
76
65
|
}).strict();
|
|
77
66
|
var ProjectRoleCommandSchema = ProjectCommandSchema.refine((value) => !launchesAScript(value.executable, value.args[0]), "Start the role process itself, not a script runner: a launcher between the supervisor and the role duplicates the shutdown signal and forces the drain").refine((value) => !value.args.includes("--filter"), "A workspace filter puts a launcher between the supervisor and the role, and the shutdown signal never reaches it");
|
|
78
|
-
|
|
67
|
+
|
|
68
|
+
// ../core/src/declaration/declaration.ts
|
|
69
|
+
var PROJECT_DECLARATION_SCHEMA_VERSION = 1;
|
|
70
|
+
var ProjectSlugSchema = z2.string().min(1).max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Use lowercase letters, numbers and single hyphens (for example: talk-control)");
|
|
71
|
+
var ProjectDescriptionSchema = z2.record(refuseMachineNames("A locale tag")(z2.string().min(1)), refuseMachineNames("A description")(z2.string().trim().min(1))).refine((value) => Object.keys(value).length > 0, "Describe the project in at least one locale");
|
|
72
|
+
var SemanticVersionSchema = z2.string().regex(/^\d+\.\d+\.\d+$/, "Use a semantic version such as 0.1.0");
|
|
73
|
+
var ProjectIdentitySchema = z2.object({
|
|
74
|
+
slug: ProjectSlugSchema,
|
|
75
|
+
name: refuseMachineNames("A project name")(z2.string().trim().min(1).max(80)),
|
|
76
|
+
version: SemanticVersionSchema,
|
|
77
|
+
description: ProjectDescriptionSchema
|
|
78
|
+
}).strict();
|
|
79
|
+
var ProjectStarterSchema = z2.strictObject({
|
|
80
|
+
version: SemanticVersionSchema
|
|
81
|
+
});
|
|
82
|
+
var RepositoryPathSchema = z2.string().min(1).refine((value) => !value.startsWith("/"), "Use a path relative to the repository root").refine((value) => namesAMachine(value) === undefined, {
|
|
83
|
+
error: (issue) => `A path may not contain ${namesAMachine(String(issue.input)) ?? "a machine name"}`
|
|
84
|
+
}).refine((value) => !value.split("/").includes(".."), "A path may not climb out of the repository");
|
|
85
|
+
var BindingVariableSchema = z2.string().regex(/^[A-Z][A-Z0-9_]*$/, "Name an environment variable, for example API_PORT");
|
|
86
|
+
var ProjectListenerSchema = z2.object({
|
|
87
|
+
portVariable: BindingVariableSchema,
|
|
88
|
+
bindVariable: BindingVariableSchema,
|
|
89
|
+
readinessPath: refuseMachineNames("A readiness path")(z2.string().startsWith("/", "Readiness is a path, for example /health"))
|
|
90
|
+
}).strict();
|
|
91
|
+
var ProjectRoleSchema = z2.object({
|
|
79
92
|
name: ProjectSlugSchema,
|
|
80
93
|
workingDirectory: RepositoryPathSchema.optional(),
|
|
81
|
-
commands:
|
|
94
|
+
commands: z2.record(ProjectRunModeSchema, ProjectRoleCommandSchema),
|
|
82
95
|
listener: ProjectListenerSchema.optional(),
|
|
83
|
-
drainFloorMs:
|
|
96
|
+
drainFloorMs: z2.number().int().nonnegative()
|
|
84
97
|
}).strict();
|
|
85
|
-
var ProjectBuildInputSchema =
|
|
98
|
+
var ProjectBuildInputSchema = z2.object({
|
|
86
99
|
name: ProjectSlugSchema,
|
|
87
100
|
path: RepositoryPathSchema,
|
|
88
|
-
digest:
|
|
101
|
+
digest: z2.string().regex(/^sha256:[0-9a-f]{64}$/, 'Use a lowercase sha256 digest, as "sha256:<64 hex>"')
|
|
89
102
|
}).strict();
|
|
90
|
-
var ProjectBuildSchema =
|
|
103
|
+
var ProjectBuildSchema = z2.object({
|
|
91
104
|
command: ProjectCommandSchema,
|
|
92
|
-
artifacts:
|
|
93
|
-
inputs:
|
|
105
|
+
artifacts: z2.array(RepositoryPathSchema).min(1),
|
|
106
|
+
inputs: z2.array(ProjectBuildInputSchema).optional()
|
|
94
107
|
}).strict().refine((build) => {
|
|
95
108
|
const names = (build.inputs ?? []).map((input) => input.name);
|
|
96
109
|
return new Set(names).size === names.length;
|
|
97
110
|
}, "Two build inputs share a name \u2014 a failure could then name either of them");
|
|
98
|
-
var ProjectRequirementPhaseSchema =
|
|
99
|
-
var ProjectRequirementSchema =
|
|
111
|
+
var ProjectRequirementPhaseSchema = z2.enum(["release", "start"]);
|
|
112
|
+
var ProjectRequirementSchema = z2.object({
|
|
100
113
|
name: ProjectSlugSchema,
|
|
101
|
-
phases:
|
|
114
|
+
phases: z2.array(ProjectRequirementPhaseSchema).min(1)
|
|
102
115
|
}).strict();
|
|
103
|
-
var ProjectMigrationsSchema =
|
|
104
|
-
engine: refuseMachineNames("A migration engine name")(
|
|
116
|
+
var ProjectMigrationsSchema = z2.object({
|
|
117
|
+
engine: refuseMachineNames("A migration engine name")(z2.string().min(1).max(64)),
|
|
105
118
|
root: RepositoryPathSchema,
|
|
106
119
|
lockfile: RepositoryPathSchema
|
|
107
120
|
}).strict();
|
|
108
|
-
var ProjectReleaseSchema =
|
|
109
|
-
var ProjectEnvShapeSchema =
|
|
110
|
-
var ProjectEnvVariableSchema =
|
|
121
|
+
var ProjectReleaseSchema = z2.object({ migrations: ProjectMigrationsSchema.optional() }).strict();
|
|
122
|
+
var ProjectEnvShapeSchema = z2.enum(["string", "integer", "boolean", "url", "enum"]);
|
|
123
|
+
var ProjectEnvVariableSchema = z2.object({
|
|
111
124
|
name: BindingVariableSchema,
|
|
112
125
|
shape: ProjectEnvShapeSchema,
|
|
113
|
-
required:
|
|
114
|
-
members:
|
|
126
|
+
required: z2.boolean(),
|
|
127
|
+
members: z2.array(refuseMachineNames("An enum member")(z2.string().min(1))).min(1).optional()
|
|
115
128
|
}).strict().refine((value) => value.shape === "enum" === (value.members !== undefined), "An enum variable lists its members; every other shape has none");
|
|
116
|
-
var ProjectDeclarationSchema =
|
|
117
|
-
schemaVersion:
|
|
118
|
-
kind:
|
|
129
|
+
var ProjectDeclarationSchema = z2.object({
|
|
130
|
+
schemaVersion: z2.literal(PROJECT_DECLARATION_SCHEMA_VERSION),
|
|
131
|
+
kind: z2.enum(["library", "application"]),
|
|
119
132
|
identity: ProjectIdentitySchema,
|
|
120
|
-
|
|
133
|
+
starter: ProjectStarterSchema.optional(),
|
|
134
|
+
roles: z2.array(ProjectRoleSchema),
|
|
121
135
|
build: ProjectBuildSchema.optional(),
|
|
122
|
-
requires:
|
|
136
|
+
requires: z2.array(ProjectRequirementSchema),
|
|
123
137
|
release: ProjectReleaseSchema,
|
|
124
|
-
env:
|
|
138
|
+
env: z2.object({ variables: z2.array(ProjectEnvVariableSchema) }).strict()
|
|
125
139
|
}).strict().refine((value) => value.kind === "application" ? value.roles.length > 0 : value.roles.length === 0, "An application declares at least one role; a library declares none").refine((value) => new Set(value.roles.map((role) => role.name)).size === value.roles.length, "Role names must be unique").refine((value) => new Set(value.requires.map((entry) => entry.name)).size === value.requires.length, "Name each requirement once and list its phases").refine((value) => value.requires.every((entry) => new Set(entry.phases).size === entry.phases.length), "List each phase of a requirement once").refine((value) => new Set(value.env.variables.map((entry) => entry.name)).size === value.env.variables.length, "Declare each environment variable once").refine((value) => listenerBindingProblem(value) === undefined, {
|
|
126
140
|
error: (issue) => listenerBindingProblem(issue.input) ?? "Listener bindings are inconsistent"
|
|
127
141
|
});
|
|
@@ -155,7 +169,7 @@ function listenerBindingProblem(value) {
|
|
|
155
169
|
}
|
|
156
170
|
return;
|
|
157
171
|
}
|
|
158
|
-
var VersionProbeSchema =
|
|
172
|
+
var VersionProbeSchema = z2.object({ schemaVersion: z2.unknown() }).loose();
|
|
159
173
|
function parseProjectDeclaration(source) {
|
|
160
174
|
const probe = VersionProbeSchema.safeParse(source);
|
|
161
175
|
const declared = probe.success ? probe.data.schemaVersion : undefined;
|
|
@@ -198,9 +212,13 @@ function createApplicationIdentity(destination, displayName) {
|
|
|
198
212
|
}
|
|
199
213
|
});
|
|
200
214
|
}
|
|
201
|
-
function withIdentity(declaration, identity) {
|
|
215
|
+
function withIdentity(declaration, identity, starterVersion) {
|
|
202
216
|
const copied = parseProjectDeclaration(declaration);
|
|
203
|
-
return parseProjectDeclaration({
|
|
217
|
+
return parseProjectDeclaration({
|
|
218
|
+
...copied,
|
|
219
|
+
identity,
|
|
220
|
+
...starterVersion !== undefined && { starter: { version: starterVersion } }
|
|
221
|
+
});
|
|
204
222
|
}
|
|
205
223
|
|
|
206
224
|
// src/options.ts
|
|
@@ -273,16 +291,16 @@ function parseOptions(args) {
|
|
|
273
291
|
import { lstat, mkdir, readdir, readFile, rm, writeFile } from "fs/promises";
|
|
274
292
|
import { homedir } from "os";
|
|
275
293
|
import { basename as basename2, dirname, extname, join as join2, parse, relative, resolve, sep } from "path";
|
|
276
|
-
import { z as
|
|
294
|
+
import { z as z4 } from "zod";
|
|
277
295
|
|
|
278
296
|
// src/format.ts
|
|
279
297
|
import { execFileSync } from "child_process";
|
|
280
298
|
import { existsSync } from "fs";
|
|
281
299
|
import { createRequire } from "module";
|
|
282
300
|
import { join } from "path";
|
|
283
|
-
import { z as
|
|
284
|
-
var ProcessReportSchema =
|
|
285
|
-
header:
|
|
301
|
+
import { z as z3 } from "zod";
|
|
302
|
+
var ProcessReportSchema = z3.object({
|
|
303
|
+
header: z3.object({ glibcVersionRuntime: z3.string().optional() })
|
|
286
304
|
});
|
|
287
305
|
function nativeBiome() {
|
|
288
306
|
const requireBiome = createRequire(import.meta.resolve("@biomejs/biome/bin/biome"));
|
|
@@ -330,14 +348,22 @@ var TEMPLATE_RENAMES = new Map([
|
|
|
330
348
|
["_env.example.append", ".env.example"],
|
|
331
349
|
["_gitignore", ".gitignore"]
|
|
332
350
|
]);
|
|
333
|
-
var RootManifestSchema =
|
|
334
|
-
name:
|
|
335
|
-
catalog:
|
|
336
|
-
workspaces:
|
|
337
|
-
dependencies:
|
|
338
|
-
devDependencies:
|
|
351
|
+
var RootManifestSchema = z4.looseObject({
|
|
352
|
+
name: z4.string().min(1),
|
|
353
|
+
catalog: z4.record(z4.string(), z4.string()).optional(),
|
|
354
|
+
workspaces: z4.unknown().optional(),
|
|
355
|
+
dependencies: z4.record(z4.string(), z4.string()).optional(),
|
|
356
|
+
devDependencies: z4.record(z4.string(), z4.string()).optional()
|
|
357
|
+
});
|
|
358
|
+
var ScaffolderManifestSchema = z4.looseObject({
|
|
359
|
+
version: z4.string().min(1)
|
|
339
360
|
});
|
|
361
|
+
async function readScaffolderVersion() {
|
|
362
|
+
const manifestPath = resolve(import.meta.dir, "../package.json");
|
|
363
|
+
return ScaffolderManifestSchema.parse(JSON.parse(await readFile(manifestPath, "utf8"))).version;
|
|
364
|
+
}
|
|
340
365
|
var IGNORED_DIRECTORIES = new Set([
|
|
366
|
+
".data",
|
|
341
367
|
".next",
|
|
342
368
|
".stitchkit",
|
|
343
369
|
"coverage",
|
|
@@ -460,7 +486,8 @@ async function scaffoldProject(templateDirectory, destination, options = {}) {
|
|
|
460
486
|
await rm(join2(resolvedDestination, "bun.lock"), { force: true });
|
|
461
487
|
}
|
|
462
488
|
const declarationPath = join2(resolvedDestination, "project.json");
|
|
463
|
-
const
|
|
489
|
+
const starterVersion = options.starterVersion ?? await readScaffolderVersion();
|
|
490
|
+
const declaration = withIdentity(JSON.parse(await readFile(declarationPath, "utf8")), identity, starterVersion);
|
|
464
491
|
await writeFile(declarationPath, `${JSON.stringify(declaration, undefined, 2)}
|
|
465
492
|
`);
|
|
466
493
|
if (options.identityModule !== false) {
|