create-stitchkit 0.6.23 → 0.8.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 +58 -0
- package/README.md +9 -1
- package/UPGRADING.md +93 -17
- package/dist/cli.js +82 -57
- package/examples/repository/packages/backend/src/surface.snapshot.json +175 -88
- package/examples/repository/project.json +0 -1
- package/examples/repository/scripts/runtime-smoke.ts +156 -126
- package/package.json +7 -4
- package/template/README.md +12 -2
- package/template/_gitignore +1 -0
- package/template/bun.lock +5 -10
- package/template/docs/ADDING_A_FEATURE.md +21 -7
- package/template/package.json +3 -3
- package/template/packages/backend/package.json +0 -1
- package/template/packages/backend/src/cli.ts +3 -2
- package/template/packages/backend/src/index.ts +6 -3
- 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 +0 -1
- package/template/packages/config/src/app-identity.generated.ts +0 -1
- package/template/packages/config/src/declaration.ts +10 -0
- package/template/packages/db/package.json +0 -1
- package/template/packages/frontend/package.json +1 -2
- package/template/packages/shared/package.json +0 -1
- package/template/project.json +0 -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/declaration.ts +4 -87
- package/template/scripts/env-variables.ts +83 -0
- 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 +2 -2
- package/templates/agent/project.json +0 -1
- package/templates/agent/src/runtime.ts +1 -1
- package/templates/telegram-bot/package.json +1 -1
- package/templates/telegram-bot/project.json +0 -1
- 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,64 @@ step is overwritten by the next release.
|
|
|
12
12
|
|
|
13
13
|
## [Unreleased]
|
|
14
14
|
|
|
15
|
+
## [0.8.0] - 2026-11-25
|
|
16
|
+
|
|
17
|
+
### ⚠️ Breaking changes
|
|
18
|
+
|
|
19
|
+
**Who must act:** every project scaffolded from an earlier `create-stitchkit` release that upgrades to `stitchkit@^0.128.0`, still carries `identity.version` in `project.json` or duplicate `"version"` fields in private workspace `packages/*/package.json`, or reads `appDeclaration.identity.version` in `packages/backend/src/{cli,index}.ts` ([migration](./UPGRADING.md#single-root-version)).
|
|
20
|
+
|
|
21
|
+
- Removed `identity.version` from all template `project.json` files (`template/`, `examples/repository/`, `templates/agent/`, `templates/telegram-bot/`), `packages/config/src/app-identity.generated.ts`, and `createApplicationIdentity()`, and removed duplicate `"version": "0.1.0"` fields from all private workspace subpackages (`template/packages/{backend,config,db,frontend,shared}/package.json`). The root `package.json` is now the single version source, exported as `appVersion` from `packages/config/src/declaration.ts` and passed to `createCli`, `createMcpHandler` (`serverInfo.version`), and `generateOpenApiDocument` (`info.version`). Before: `version: appDeclaration.identity.version`. After: `version: appVersion`. Existing projects adopt it by [`UPGRADING.md`](./UPGRADING.md#single-root-version).
|
|
22
|
+
- Updated the starter catalog to `stitchkit@^0.128.0` and the agent template catalog to `stitchkit-tui@^0.5.1`.
|
|
23
|
+
|
|
24
|
+
## [0.7.0] - 2026-11-25
|
|
25
|
+
|
|
26
|
+
### ⚠️ Breaking changes
|
|
27
|
+
|
|
28
|
+
**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)).
|
|
29
|
+
|
|
30
|
+
- Removed the local copies of the framework's surface manifest and conformance runner from
|
|
31
|
+
the application template (`packages/backend/src/surface-manifest.ts`,
|
|
32
|
+
`packages/backend/src/surface-manifest.test.ts`, and `scripts/surface-conformance.ts`).
|
|
33
|
+
`scripts/surface-snapshot.ts` and `scripts/runtime-smoke.ts` now import
|
|
34
|
+
`buildSurfaceManifest`, `assertSurfaceManifestSnapshot`, `assertSurfaceDiscovery`,
|
|
35
|
+
`SurfaceManifestSchema`, and `runSurfaceProbes` directly from `stitchkit/testing`, and
|
|
36
|
+
`packages/backend/src/surface.snapshot.json` uses the canonical `manifestVersion: 3`
|
|
37
|
+
format. Before: `import { runSurfaceConformance } from './surface-conformance'`. After:
|
|
38
|
+
`import { assertLiveSurface } from './surface-snapshot'` and
|
|
39
|
+
`import { runSurfaceProbes } from 'stitchkit/testing'`. Existing projects adopt it by
|
|
40
|
+
[`UPGRADING.md`](./UPGRADING.md#starter-uses-stitchkittesting-and-mandatory-tool-access).
|
|
41
|
+
- Updated tool mounts in the application and agent templates for mandatory `access` and
|
|
42
|
+
`ToolNameEntry.expose`: `packages/backend/src/index.ts` passes `access: { open: 'public' }`
|
|
43
|
+
to `createMcpHandler`, `packages/backend/src/cli.ts` passes
|
|
44
|
+
`access: { open: 'local-operator' }` to `createCli`, `packages/backend/src/tools.ts` reads
|
|
45
|
+
`tool.expose`, and `templates/agent/src/runtime.ts` passes
|
|
46
|
+
`access: { gate: context.toolFenceLifecycle }` to `mountAgent`. Before:
|
|
47
|
+
`createCli({ name, version, services })` and `mountAgent([], { runtimeTools, lifecycle: context.toolFenceLifecycle })`.
|
|
48
|
+
After: `createCli({ name, version, services, access: { open: 'local-operator' } })` and
|
|
49
|
+
`mountAgent([], { runtimeTools, access: { gate: context.toolFenceLifecycle } })`.
|
|
50
|
+
|
|
51
|
+
### Added
|
|
52
|
+
|
|
53
|
+
- Newly scaffolded projects record the `create-stitchkit` package version in `project.json`
|
|
54
|
+
under `starter: { version }` (validated by `ProjectDeclarationSchema` in
|
|
55
|
+
`stitchkit/declaration`).
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- `acceptance:local` gives the realtime socket and the CORS admission this run's
|
|
60
|
+
ephemeral ports. It moved every role to ephemeral ports but kept
|
|
61
|
+
`PUBLIC_REALTIME_ORIGIN` and `CORS_ORIGIN` from `.env`, so on a machine where
|
|
62
|
+
another process listened on 3210 or 3211 the browser under test opened that
|
|
63
|
+
process's socket. The environment is built by `scripts/acceptance-environment.ts`,
|
|
64
|
+
and a test refuses any variable of `.env.example` that would still name a
|
|
65
|
+
deployment port. An existing project adopts it by
|
|
66
|
+
[`UPGRADING.md`](./UPGRADING.md#acceptance-owns-every-address).
|
|
67
|
+
- The package and the projects generated from it no longer carry
|
|
68
|
+
`.data/board.sqlite`, the reference board's local database, and a generated
|
|
69
|
+
project ignores `.data/`. The documents describe the default scaffold as it is:
|
|
70
|
+
one reference feature, a notes board, beside the `/ui` catalogue and an admin
|
|
71
|
+
panel on fixture data, and the template README names what depends on the board.
|
|
72
|
+
|
|
15
73
|
## [0.6.23] - 2026-11-21
|
|
16
74
|
|
|
17
75
|
### 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,86 @@ the first scaffolder release with a migration channel of its own.
|
|
|
60
61
|
|
|
61
62
|
---
|
|
62
63
|
|
|
64
|
+
## Released migration: 0.8.0
|
|
65
|
+
|
|
66
|
+
### single-root-version
|
|
67
|
+
|
|
68
|
+
**Required.** Adopt these edits together with upgrading `stitchkit` to `0.128.0`
|
|
69
|
+
(see [`docs/guide/upgrading.md`](../../docs/guide/upgrading.md#declaration-single-version) for the
|
|
70
|
+
framework change).
|
|
71
|
+
|
|
72
|
+
1. Remove `"version"` from `project.json` under `identity` and regenerate
|
|
73
|
+
`packages/config/src/app-identity.generated.ts` (`bun run gen:declaration`).
|
|
74
|
+
2. Remove duplicate `"version"` fields from private internal workspace manifests
|
|
75
|
+
(`packages/*/package.json` where `"private": true`), keeping `"version"` only in the root
|
|
76
|
+
`package.json` (unless a subpackage is released independently).
|
|
77
|
+
3. Export `appVersion` from `packages/config/src/declaration.ts` by reading `../../../package.json`
|
|
78
|
+
and pass `appVersion` instead of `appDeclaration.identity.version` in
|
|
79
|
+
`packages/backend/src/cli.ts` (`createCli`) and `packages/backend/src/index.ts`
|
|
80
|
+
(`createMcpHandler` `serverInfo.version` and `generateOpenApiDocument` `info.version`).
|
|
81
|
+
4. Update the root `package.json` catalog to `"stitchkit": "^0.128.0"` (and in agent-template
|
|
82
|
+
projects, `"stitchkit-tui": "^0.5.1"`), run `bun install`, and verify with `bun run check` and
|
|
83
|
+
`bun run test`.
|
|
84
|
+
|
|
85
|
+
## Released migration: 0.7.0
|
|
86
|
+
|
|
87
|
+
### starter uses stitchkit/testing and mandatory tool access
|
|
88
|
+
|
|
89
|
+
**Required.** Adopt these edits together with upgrading `stitchkit` to `0.127.0`
|
|
90
|
+
(see [`docs/guide/upgrading.md`](../../docs/guide/upgrading.md) for the framework changes).
|
|
91
|
+
|
|
92
|
+
1. Remove the copied surface helpers from your repository:
|
|
93
|
+
- Delete `packages/backend/src/surface-manifest.ts`,
|
|
94
|
+
`packages/backend/src/surface-manifest.test.ts`, and
|
|
95
|
+
`scripts/surface-conformance.ts`.
|
|
96
|
+
- Replace `scripts/surface-snapshot.ts` with the template version that imports
|
|
97
|
+
`buildSurfaceManifest`, `assertSurfaceManifestSnapshot`, `assertSurfaceDiscovery`,
|
|
98
|
+
and `SurfaceManifestSchema` from `stitchkit/testing`.
|
|
99
|
+
- Update `scripts/runtime-smoke.ts` to call `assertLiveSurface` from `./surface-snapshot`
|
|
100
|
+
and `runSurfaceProbes` from `stitchkit/testing` instead of `runSurfaceConformance` /
|
|
101
|
+
`defineSurfaceProbe`.
|
|
102
|
+
- Regenerate and review `packages/backend/src/surface.snapshot.json` with
|
|
103
|
+
`bun run surface:snapshot` (the snapshot moves to `manifestVersion: 3`).
|
|
104
|
+
2. Pass explicit `access` on every tool mount:
|
|
105
|
+
- In `packages/backend/src/index.ts`, add `access: { open: 'public' }` (or
|
|
106
|
+
`access: { gate: { beforeHandle: authHook } }` when your app has authenticated
|
|
107
|
+
scopes) to `createMcpHandler(...)`.
|
|
108
|
+
- In `packages/backend/src/cli.ts`, add `access: { open: 'local-operator' }` (or your
|
|
109
|
+
app's gate) to `createCli(...)`.
|
|
110
|
+
- In an agent-template project (`src/runtime.ts`), replace
|
|
111
|
+
`lifecycle: context.toolFenceLifecycle` with
|
|
112
|
+
`access: { gate: context.toolFenceLifecycle }` in `mountAgent(...)`.
|
|
113
|
+
3. In `packages/backend/src/tools.ts`, read `tool.expose` instead of `tool.transports`.
|
|
114
|
+
4. Optional: record your starter origin in `project.json` under `"starter": { "version": "<version>" }`.
|
|
115
|
+
5. Run `bun run check`, `bun run test`, and `bun run surface:snapshot` to confirm the
|
|
116
|
+
regenerated snapshot and checks pass.
|
|
117
|
+
|
|
118
|
+
### acceptance owns every address
|
|
119
|
+
|
|
120
|
+
**Voluntary.** Worth taking on a machine that runs other projects. Without it,
|
|
121
|
+
`bun run acceptance:local` can test the socket of whatever else listens on the
|
|
122
|
+
ports in your `.env`.
|
|
123
|
+
|
|
124
|
+
1. In `scripts/acceptance-local.ts`, in the object the environment is assigned,
|
|
125
|
+
add next to `PLAYWRIGHT_BASE_URL`:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
PUBLIC_REALTIME_ORIGIN: apiOrigin,
|
|
129
|
+
CORS_ORIGIN: webOrigin,
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Or take the whole file `scripts/acceptance-environment.ts` and its test from a
|
|
133
|
+
project generated by this release, and build the environment with it.
|
|
134
|
+
2. Add `.data/` to `.gitignore`. If `.data/board.sqlite` is committed, remove it
|
|
135
|
+
from the repository; the board recreates it on start.
|
|
136
|
+
3. Run `bun run acceptance:local` with something listening on 127.0.0.1:3211 and
|
|
137
|
+
check the run still passes.
|
|
138
|
+
|
|
63
139
|
## Released migration: 0.6.23
|
|
64
140
|
|
|
65
141
|
### watch hub reads one request
|
|
66
142
|
|
|
67
|
-
Take it together with stitchkit 0.126.0, whose `createWatchHub` passes `read` one
|
|
143
|
+
**With stitchkit 0.126.0.** Take it together with stitchkit 0.126.0, whose `createWatchHub` passes `read` one
|
|
68
144
|
`{ operation, args, scope, signal }` request; on 0.125.0 and earlier the entry does not compile.
|
|
69
145
|
|
|
70
146
|
1. In `packages/backend/src/lib/live.ts`, change `read: async (operation) =>` to
|
|
@@ -77,7 +153,7 @@ Take it together with stitchkit 0.126.0, whose `createWatchHub` passes `read` on
|
|
|
77
153
|
|
|
78
154
|
### unknown operation keeps the not_found wire code
|
|
79
155
|
|
|
80
|
-
Take it together with
|
|
156
|
+
**With stitchkit 0.123.0.** Take it together with stitchkit 0.123.0, which answers an unmatched route
|
|
81
157
|
`UNKNOWN_OPERATION`; on an earlier stitchkit the entry is inert.
|
|
82
158
|
|
|
83
159
|
1. In `packages/backend/src/transport/errors.ts`, add `UNKNOWN_OPERATION: 'not_found'` to
|
|
@@ -88,7 +164,7 @@ Take it together with the stitchkit release that answers an unmatched route
|
|
|
88
164
|
|
|
89
165
|
### supervision passes declared environment
|
|
90
166
|
|
|
91
|
-
Additive, and worth taking: without it a changed `.env` stays stale in a running role until
|
|
167
|
+
**Voluntary.** Additive, and worth taking: without it a changed `.env` stays stale in a running role until
|
|
92
168
|
`pm2 delete`.
|
|
93
169
|
|
|
94
170
|
1. In `scripts/declaration.ts`, after the `config({ path: … })` call that `renderEcosystem`
|
|
@@ -104,8 +180,8 @@ Additive, and worth taking: without it a changed `.env` stays stale in a running
|
|
|
104
180
|
|
|
105
181
|
### Canonical query client factory
|
|
106
182
|
|
|
107
|
-
This migration is additive, but it has a dependency order: first upgrade to a
|
|
108
|
-
Stitchkit release that exports `createQueryClientFactory` from
|
|
183
|
+
**With stitchkit 0.81.0.** This migration is additive, but it has a dependency order: first upgrade to a
|
|
184
|
+
Stitchkit release (0.81.0+) that exports `createQueryClientFactory` from
|
|
109
185
|
`stitchkit/react`. Then replace the local QueryClient construction with:
|
|
110
186
|
|
|
111
187
|
```ts
|
|
@@ -132,7 +208,7 @@ start.
|
|
|
132
208
|
|
|
133
209
|
### 1. The store directory has to be writable
|
|
134
210
|
|
|
135
|
-
`BOARD_STORE_PATH` defaults to `.data/board.sqlite`, relative to the API role's
|
|
211
|
+
**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
|
|
136
212
|
working directory. The application creates the directory itself; what it cannot
|
|
137
213
|
do is make a read-only volume writable.
|
|
138
214
|
|
|
@@ -146,7 +222,7 @@ volume instead.
|
|
|
146
222
|
|
|
147
223
|
### 2. Decide about the trust fence, on purpose
|
|
148
224
|
|
|
149
|
-
`TRUSTED_HOSTS` is unset by default, and unset means **no fence**. That is
|
|
225
|
+
**Voluntary.** Required as an operator step when deploying over a network: `TRUSTED_HOSTS` is unset by default, and unset means **no fence**. That is
|
|
150
226
|
correct on a laptop and wrong on anything a network reaches — but a fence cannot
|
|
151
227
|
guess which names your deployment answers to, so it refuses to invent them.
|
|
152
228
|
|
|
@@ -162,7 +238,7 @@ and the fence reads that one rather than asking you a second time.
|
|
|
162
238
|
|
|
163
239
|
### 3. Nothing else
|
|
164
240
|
|
|
165
|
-
The rest of the feature is code you either copy or do not. The framework range
|
|
241
|
+
**Voluntary.** The rest of the feature is code you either copy or do not. The framework range
|
|
166
242
|
moved to `^0.76.1`; if you upgrade the dependency without taking the feature,
|
|
167
243
|
[the framework's own guide](../../docs/guide/upgrading.md) is the one to follow.
|
|
168
244
|
|
|
@@ -170,7 +246,7 @@ moved to `^0.76.1`; if you upgrade the dependency without taking the feature,
|
|
|
170
246
|
|
|
171
247
|
### the approval policy names a tool that no longer exists
|
|
172
248
|
|
|
173
|
-
One code edit, and one thing to do to a machine that was left mid-question.
|
|
249
|
+
**With stitchkit 0.71.0.** One code edit, and one thing to do to a machine that was left mid-question.
|
|
174
250
|
|
|
175
251
|
1. **Rename the key.** In `src/runtime.ts`, inside `loop.toolApproval`, replace
|
|
176
252
|
`apply_patch: 'user-approval'` with `edit_file: 'user-approval'`. While you
|
|
@@ -204,7 +280,7 @@ One code edit, and one thing to do to a machine that was left mid-question.
|
|
|
204
280
|
|
|
205
281
|
### the timestamp your API accepts got narrower
|
|
206
282
|
|
|
207
|
-
Zod moved to 4.5, and `z.iso.datetime()` now requires seconds. This is not a
|
|
283
|
+
**Required.** Zod moved to 4.5, and `z.iso.datetime()` now requires seconds. This is not a
|
|
208
284
|
code change — it is a change in what your endpoints admit, and it arrives the
|
|
209
285
|
moment you install.
|
|
210
286
|
|
|
@@ -235,7 +311,7 @@ moment you install.
|
|
|
235
311
|
|
|
236
312
|
### a release refuses a stale artifact, and cleanup is bounded
|
|
237
313
|
|
|
238
|
-
Two changes an existing project should take, both about a shutdown or a start
|
|
314
|
+
**Voluntary.** Two changes an existing project should take, both about a shutdown or a start
|
|
239
315
|
that looked safe and was not.
|
|
240
316
|
|
|
241
317
|
1. **Stamp the build.** Copy `scripts/build-stamp.ts` from a fresh scaffold,
|
|
@@ -263,7 +339,7 @@ No operator step: nothing about a running machine changes.
|
|
|
263
339
|
|
|
264
340
|
### the gate list runs, and never deploys
|
|
265
341
|
|
|
266
|
-
The `Gates` list in the generated guides presented five commands in a row, two
|
|
342
|
+
**Voluntary.** The `Gates` list in the generated guides presented five commands in a row, two
|
|
267
343
|
of which check a **running** deployment — with nothing in the list that starts
|
|
268
344
|
one. The fix is not to add a deploy command: `bun run pm2:prod` applies your
|
|
269
345
|
declared migrations and reloads the deployment you are running, so a list that
|
|
@@ -311,7 +387,7 @@ No operator step: nothing about a running machine changes.
|
|
|
311
387
|
|
|
312
388
|
### the declaration schema is imported
|
|
313
389
|
|
|
314
|
-
For a project generated **before** the scaffolder version that drops the schema
|
|
390
|
+
**With stitchkit 0.60.0.** For a project generated **before** the scaffolder version that drops the schema
|
|
315
391
|
mirror. Nothing in your tree stops working if you skip this — the copy keeps
|
|
316
392
|
parsing. What you lose by skipping is the guarantee: your copy no longer moves
|
|
317
393
|
when the framework's schema does, and nothing tells you.
|
|
@@ -352,7 +428,7 @@ No operator step: nothing about a running machine changes.
|
|
|
352
428
|
|
|
353
429
|
### the project declares itself
|
|
354
430
|
|
|
355
|
-
Everything in this section is for a project generated **before** the scaffolder
|
|
431
|
+
**Required.** Everything in this section is for a project generated **before** the scaffolder
|
|
356
432
|
version that introduces `project.json`.
|
|
357
433
|
|
|
358
434
|
#### 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,77 @@ 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
|
+
description: ProjectDescriptionSchema
|
|
77
|
+
}).strict();
|
|
78
|
+
var ProjectStarterSchema = z2.strictObject({
|
|
79
|
+
version: SemanticVersionSchema
|
|
80
|
+
});
|
|
81
|
+
var RepositoryPathSchema = z2.string().min(1).refine((value) => !value.startsWith("/"), "Use a path relative to the repository root").refine((value) => namesAMachine(value) === undefined, {
|
|
82
|
+
error: (issue) => `A path may not contain ${namesAMachine(String(issue.input)) ?? "a machine name"}`
|
|
83
|
+
}).refine((value) => !value.split("/").includes(".."), "A path may not climb out of the repository");
|
|
84
|
+
var BindingVariableSchema = z2.string().regex(/^[A-Z][A-Z0-9_]*$/, "Name an environment variable, for example API_PORT");
|
|
85
|
+
var ProjectListenerSchema = z2.object({
|
|
86
|
+
portVariable: BindingVariableSchema,
|
|
87
|
+
bindVariable: BindingVariableSchema,
|
|
88
|
+
readinessPath: refuseMachineNames("A readiness path")(z2.string().startsWith("/", "Readiness is a path, for example /health"))
|
|
89
|
+
}).strict();
|
|
90
|
+
var ProjectRoleSchema = z2.object({
|
|
79
91
|
name: ProjectSlugSchema,
|
|
80
92
|
workingDirectory: RepositoryPathSchema.optional(),
|
|
81
|
-
commands:
|
|
93
|
+
commands: z2.record(ProjectRunModeSchema, ProjectRoleCommandSchema),
|
|
82
94
|
listener: ProjectListenerSchema.optional(),
|
|
83
|
-
drainFloorMs:
|
|
95
|
+
drainFloorMs: z2.number().int().nonnegative()
|
|
84
96
|
}).strict();
|
|
85
|
-
var ProjectBuildInputSchema =
|
|
97
|
+
var ProjectBuildInputSchema = z2.object({
|
|
86
98
|
name: ProjectSlugSchema,
|
|
87
99
|
path: RepositoryPathSchema,
|
|
88
|
-
digest:
|
|
100
|
+
digest: z2.string().regex(/^sha256:[0-9a-f]{64}$/, 'Use a lowercase sha256 digest, as "sha256:<64 hex>"')
|
|
89
101
|
}).strict();
|
|
90
|
-
var ProjectBuildSchema =
|
|
102
|
+
var ProjectBuildSchema = z2.object({
|
|
91
103
|
command: ProjectCommandSchema,
|
|
92
|
-
artifacts:
|
|
93
|
-
inputs:
|
|
104
|
+
artifacts: z2.array(RepositoryPathSchema).min(1),
|
|
105
|
+
inputs: z2.array(ProjectBuildInputSchema).optional()
|
|
94
106
|
}).strict().refine((build) => {
|
|
95
107
|
const names = (build.inputs ?? []).map((input) => input.name);
|
|
96
108
|
return new Set(names).size === names.length;
|
|
97
109
|
}, "Two build inputs share a name \u2014 a failure could then name either of them");
|
|
98
|
-
var ProjectRequirementPhaseSchema =
|
|
99
|
-
var ProjectRequirementSchema =
|
|
110
|
+
var ProjectRequirementPhaseSchema = z2.enum(["release", "start"]);
|
|
111
|
+
var ProjectRequirementSchema = z2.object({
|
|
100
112
|
name: ProjectSlugSchema,
|
|
101
|
-
phases:
|
|
113
|
+
phases: z2.array(ProjectRequirementPhaseSchema).min(1)
|
|
102
114
|
}).strict();
|
|
103
|
-
var ProjectMigrationsSchema =
|
|
104
|
-
engine: refuseMachineNames("A migration engine name")(
|
|
115
|
+
var ProjectMigrationsSchema = z2.object({
|
|
116
|
+
engine: refuseMachineNames("A migration engine name")(z2.string().min(1).max(64)),
|
|
105
117
|
root: RepositoryPathSchema,
|
|
106
118
|
lockfile: RepositoryPathSchema
|
|
107
119
|
}).strict();
|
|
108
|
-
var ProjectReleaseSchema =
|
|
109
|
-
var ProjectEnvShapeSchema =
|
|
110
|
-
var ProjectEnvVariableSchema =
|
|
120
|
+
var ProjectReleaseSchema = z2.object({ migrations: ProjectMigrationsSchema.optional() }).strict();
|
|
121
|
+
var ProjectEnvShapeSchema = z2.enum(["string", "integer", "boolean", "url", "enum"]);
|
|
122
|
+
var ProjectEnvVariableSchema = z2.object({
|
|
111
123
|
name: BindingVariableSchema,
|
|
112
124
|
shape: ProjectEnvShapeSchema,
|
|
113
|
-
required:
|
|
114
|
-
members:
|
|
125
|
+
required: z2.boolean(),
|
|
126
|
+
members: z2.array(refuseMachineNames("An enum member")(z2.string().min(1))).min(1).optional()
|
|
115
127
|
}).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:
|
|
128
|
+
var ProjectDeclarationSchema = z2.object({
|
|
129
|
+
schemaVersion: z2.literal(PROJECT_DECLARATION_SCHEMA_VERSION),
|
|
130
|
+
kind: z2.enum(["library", "application"]),
|
|
119
131
|
identity: ProjectIdentitySchema,
|
|
120
|
-
|
|
132
|
+
starter: ProjectStarterSchema.optional(),
|
|
133
|
+
roles: z2.array(ProjectRoleSchema),
|
|
121
134
|
build: ProjectBuildSchema.optional(),
|
|
122
|
-
requires:
|
|
135
|
+
requires: z2.array(ProjectRequirementSchema),
|
|
123
136
|
release: ProjectReleaseSchema,
|
|
124
|
-
env:
|
|
137
|
+
env: z2.object({ variables: z2.array(ProjectEnvVariableSchema) }).strict()
|
|
125
138
|
}).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
139
|
error: (issue) => listenerBindingProblem(issue.input) ?? "Listener bindings are inconsistent"
|
|
127
140
|
});
|
|
@@ -155,7 +168,7 @@ function listenerBindingProblem(value) {
|
|
|
155
168
|
}
|
|
156
169
|
return;
|
|
157
170
|
}
|
|
158
|
-
var VersionProbeSchema =
|
|
171
|
+
var VersionProbeSchema = z2.object({ schemaVersion: z2.unknown() }).loose();
|
|
159
172
|
function parseProjectDeclaration(source) {
|
|
160
173
|
const probe = VersionProbeSchema.safeParse(source);
|
|
161
174
|
const declared = probe.success ? probe.data.schemaVersion : undefined;
|
|
@@ -191,16 +204,19 @@ function createApplicationIdentity(destination, displayName) {
|
|
|
191
204
|
return ProjectIdentitySchema.parse({
|
|
192
205
|
slug,
|
|
193
206
|
name,
|
|
194
|
-
version: "0.1.0",
|
|
195
207
|
description: {
|
|
196
208
|
en: `${name} is a production application built with Stitchkit.`,
|
|
197
209
|
ru: `${name} \u2014 production-\u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435 \u043D\u0430 Stitchkit.`
|
|
198
210
|
}
|
|
199
211
|
});
|
|
200
212
|
}
|
|
201
|
-
function withIdentity(declaration, identity) {
|
|
213
|
+
function withIdentity(declaration, identity, starterVersion) {
|
|
202
214
|
const copied = parseProjectDeclaration(declaration);
|
|
203
|
-
return parseProjectDeclaration({
|
|
215
|
+
return parseProjectDeclaration({
|
|
216
|
+
...copied,
|
|
217
|
+
identity,
|
|
218
|
+
...starterVersion !== undefined && { starter: { version: starterVersion } }
|
|
219
|
+
});
|
|
204
220
|
}
|
|
205
221
|
|
|
206
222
|
// src/options.ts
|
|
@@ -273,16 +289,16 @@ function parseOptions(args) {
|
|
|
273
289
|
import { lstat, mkdir, readdir, readFile, rm, writeFile } from "fs/promises";
|
|
274
290
|
import { homedir } from "os";
|
|
275
291
|
import { basename as basename2, dirname, extname, join as join2, parse, relative, resolve, sep } from "path";
|
|
276
|
-
import { z as
|
|
292
|
+
import { z as z4 } from "zod";
|
|
277
293
|
|
|
278
294
|
// src/format.ts
|
|
279
295
|
import { execFileSync } from "child_process";
|
|
280
296
|
import { existsSync } from "fs";
|
|
281
297
|
import { createRequire } from "module";
|
|
282
298
|
import { join } from "path";
|
|
283
|
-
import { z as
|
|
284
|
-
var ProcessReportSchema =
|
|
285
|
-
header:
|
|
299
|
+
import { z as z3 } from "zod";
|
|
300
|
+
var ProcessReportSchema = z3.object({
|
|
301
|
+
header: z3.object({ glibcVersionRuntime: z3.string().optional() })
|
|
286
302
|
});
|
|
287
303
|
function nativeBiome() {
|
|
288
304
|
const requireBiome = createRequire(import.meta.resolve("@biomejs/biome/bin/biome"));
|
|
@@ -330,14 +346,22 @@ var TEMPLATE_RENAMES = new Map([
|
|
|
330
346
|
["_env.example.append", ".env.example"],
|
|
331
347
|
["_gitignore", ".gitignore"]
|
|
332
348
|
]);
|
|
333
|
-
var RootManifestSchema =
|
|
334
|
-
name:
|
|
335
|
-
catalog:
|
|
336
|
-
workspaces:
|
|
337
|
-
dependencies:
|
|
338
|
-
devDependencies:
|
|
349
|
+
var RootManifestSchema = z4.looseObject({
|
|
350
|
+
name: z4.string().min(1),
|
|
351
|
+
catalog: z4.record(z4.string(), z4.string()).optional(),
|
|
352
|
+
workspaces: z4.unknown().optional(),
|
|
353
|
+
dependencies: z4.record(z4.string(), z4.string()).optional(),
|
|
354
|
+
devDependencies: z4.record(z4.string(), z4.string()).optional()
|
|
355
|
+
});
|
|
356
|
+
var ScaffolderManifestSchema = z4.looseObject({
|
|
357
|
+
version: z4.string().min(1)
|
|
339
358
|
});
|
|
359
|
+
async function readScaffolderVersion() {
|
|
360
|
+
const manifestPath = resolve(import.meta.dir, "../package.json");
|
|
361
|
+
return ScaffolderManifestSchema.parse(JSON.parse(await readFile(manifestPath, "utf8"))).version;
|
|
362
|
+
}
|
|
340
363
|
var IGNORED_DIRECTORIES = new Set([
|
|
364
|
+
".data",
|
|
341
365
|
".next",
|
|
342
366
|
".stitchkit",
|
|
343
367
|
"coverage",
|
|
@@ -460,7 +484,8 @@ async function scaffoldProject(templateDirectory, destination, options = {}) {
|
|
|
460
484
|
await rm(join2(resolvedDestination, "bun.lock"), { force: true });
|
|
461
485
|
}
|
|
462
486
|
const declarationPath = join2(resolvedDestination, "project.json");
|
|
463
|
-
const
|
|
487
|
+
const starterVersion = options.starterVersion ?? await readScaffolderVersion();
|
|
488
|
+
const declaration = withIdentity(JSON.parse(await readFile(declarationPath, "utf8")), identity, starterVersion);
|
|
464
489
|
await writeFile(declarationPath, `${JSON.stringify(declaration, undefined, 2)}
|
|
465
490
|
`);
|
|
466
491
|
if (options.identityModule !== false) {
|