create-stitchkit 0.6.18 → 0.6.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/cli.js +62 -27
  3. package/package.json +10 -9
  4. package/template/biome.json +4 -1
  5. package/template/bun.lock +303 -301
  6. package/template/e2e/starter.spec.ts +2 -2
  7. package/template/package.json +16 -16
  8. package/template/packages/backend/package.json +6 -6
  9. package/template/packages/backend/src/cleanup.ts +4 -7
  10. package/template/packages/backend/src/surface-manifest.test.ts +3 -3
  11. package/template/packages/config/package.json +3 -3
  12. package/template/packages/config/src/shutdown.ts +3 -4
  13. package/template/packages/config/src/variables.ts +5 -8
  14. package/template/packages/db/package.json +4 -4
  15. package/template/packages/frontend/package.json +29 -29
  16. package/template/packages/frontend/scripts/serve.ts +4 -4
  17. package/template/packages/frontend/src/components/ui/toaster.tsx +2 -2
  18. package/template/packages/frontend/src/env.ts +1 -2
  19. package/template/packages/frontend/src/lib/query-client.test.ts +1 -1
  20. package/template/packages/frontend/src/lib/query-client.ts +2 -3
  21. package/template/packages/frontend/src/lib/seo/cache-by-origin.ts +2 -2
  22. package/template/packages/frontend/src/lib/seo/request-origin.ts +5 -5
  23. package/template/packages/shared/package.json +2 -2
  24. package/template/packages/shared/src/contracts/board.ts +1 -3
  25. package/template/packages/shared/src/contracts/system.ts +1 -3
  26. package/template/scripts/acceptance-database.test.ts +4 -4
  27. package/template/scripts/acceptance-database.ts +4 -6
  28. package/template/scripts/acceptance-local.ts +6 -8
  29. package/template/scripts/build-stamp.test.ts +3 -5
  30. package/template/scripts/build-stamp.ts +8 -11
  31. package/template/scripts/check-authored.test.ts +16 -1
  32. package/template/scripts/check-authored.ts +7 -6
  33. package/template/scripts/client-boundary.test.ts +26 -8
  34. package/template/scripts/client-boundary.ts +30 -27
  35. package/template/scripts/declaration.test.ts +5 -7
  36. package/template/scripts/declaration.ts +14 -19
  37. package/template/scripts/deployment-preflight.ts +2 -3
  38. package/template/scripts/dev.ts +6 -8
  39. package/template/scripts/guide-paths.ts +2 -4
  40. package/template/scripts/readiness.ts +4 -5
  41. package/template/scripts/release-steps.test.ts +2 -4
  42. package/template/scripts/release-steps.ts +2 -2
  43. package/template/scripts/runtime-smoke.test.ts +6 -7
  44. package/template/scripts/serve-mode.test.ts +2 -2
  45. package/template/scripts/shutdown-budget.fixture.ts +3 -5
  46. package/template/scripts/shutdown-budget.test.ts +4 -8
  47. package/template/scripts/supervision-signal.test.ts +1 -1
  48. package/template/scripts/web-surface-smoke.ts +5 -8
  49. package/templates/agent/biome.json +4 -1
  50. package/templates/agent/package.json +11 -7
  51. package/templates/telegram-bot/biome.json +4 -1
  52. package/templates/telegram-bot/package.json +8 -4
@@ -1,15 +1,15 @@
1
1
  import { readdir, readFile } from 'node:fs/promises';
2
2
  import { extname, join } from 'node:path';
3
3
  import { parseSync, Visitor } from 'oxc-parser';
4
+ import databasePackage from '../packages/db/package.json';
4
5
 
5
6
  const roots = ['packages', 'scripts', 'e2e'];
6
7
  const rootFiles = ['playwright.config.ts', 'ecosystem.config.cjs', 'ecosystem.dev.config.cjs'];
7
8
  const processEnvMarker = ['process', 'env'].join('.');
8
9
  const replacedThemePackage = ['next', 'themes'].join('-');
9
10
  const generatedDirectories = new Set(['.git', '.next', 'dist', 'node_modules']);
10
- // The supervision files used to read the environment directly to build an argv
11
- // for the web role. They no longer do — a role reads its own bindings — so they
12
- // are no longer environment boundaries, and this list is smaller by two.
11
+ // Roles read their own validated bindings; supervision passes no environment
12
+ // values in argv. Only runtime and tooling schemas are environment boundaries.
13
13
  const processEnvBoundaries = new Set([
14
14
  'packages/frontend/src/env.ts',
15
15
  'packages/config/src/server.ts',
@@ -25,8 +25,8 @@ function lineAt(source: string, offset: number): number {
25
25
  *
26
26
  * The gate refuses a cast because a cast can LAUNDER a type — claim something the value has not
27
27
  * been shown to be. A const-assertion cannot: it only narrows, it introduces no name, and it
28
- * cannot widen. Refusing it made five of the first fifteen findings on a real adoption false, in
29
- * a gate whose whole value is that its findings are worth acting on.
28
+ * cannot widen. Treating it as a type assertion would report a narrowing as an
29
+ * unproven type claim.
30
30
  *
31
31
  * `const` is a reserved word, so no type can be named `const` — the check has no false positive
32
32
  * of its own.
@@ -72,7 +72,8 @@ export function inspect(path: string, source: string): string[] {
72
72
  for (const specifier of source.matchAll(/from\s+['"]([^'"]+)['"]/g)) {
73
73
  const dependency = specifier[1];
74
74
  if (
75
- dependency === '@app/db' ||
75
+ dependency === databasePackage.name ||
76
+ dependency?.startsWith(`${databasePackage.name}/`) ||
76
77
  dependency?.startsWith('@prisma/') ||
77
78
  (path.startsWith('packages/shared/') && dependency?.startsWith('node:')) ||
78
79
  (path.startsWith('packages/shared/') && dependency === 'bun')
@@ -31,9 +31,8 @@ describe('the declaration stays out of the browser', () => {
31
31
  });
32
32
 
33
33
  describe('the scanner fails however the import is written', () => {
34
- // A check that only recognises the one spelling the leak had the first time
35
- // is a check that passes while the leak is back. These fixtures write it the
36
- // two other ways it can come back.
34
+ // Package, barrel and relative imports can reach the same declaration.
35
+ // Every spelling must be checked against the resolved file.
37
36
  const created: string[] = [];
38
37
  afterAll(() => {
39
38
  for (const path of created) rmSync(path, { recursive: true, force: true });
@@ -50,7 +49,7 @@ describe('the scanner fails however the import is written', () => {
50
49
  write(
51
50
  'packages/config/package.json',
52
51
  JSON.stringify({
53
- name: '@app/config',
52
+ name: '@demo-shop/config',
54
53
  exports: { './declaration': './src/declaration.ts' },
55
54
  }),
56
55
  );
@@ -67,14 +66,13 @@ describe('the scanner fails however the import is written', () => {
67
66
  const scan = fixture({
68
67
  'packages/frontend/src/page.tsx':
69
68
  "'use client';\nimport { appDeclaration } from './lib';\nexport const value = appDeclaration;\n",
70
- 'packages/frontend/src/lib/index.ts': "export * from '@app/config/declaration';\n",
69
+ 'packages/frontend/src/lib/index.ts': "export * from '@demo-shop/config/declaration';\n",
71
70
  });
72
71
  expect(findDeclarationLeaks(scan)).toHaveLength(1);
73
72
  });
74
73
 
75
74
  test('a relative path into the config package is a leak', () => {
76
- // No `@app/` prefix anywhere in the file, so a check on the specifier
77
- // string sees nothing at all.
75
+ // A relative import bypasses any check on the package's spelling.
78
76
  const scan = fixture({
79
77
  'packages/frontend/src/page.tsx':
80
78
  "'use client';\nimport { appDeclaration } from '../../config/src/declaration';\nexport const value = appDeclaration;\n",
@@ -85,7 +83,7 @@ describe('the scanner fails however the import is written', () => {
85
83
  test('a double-quoted import is a leak too', () => {
86
84
  const scan = fixture({
87
85
  'packages/frontend/src/page.tsx':
88
- '\'use client\';\nimport { appDeclaration } from "@app/config/declaration";\nexport const value = appDeclaration;\n',
86
+ '\'use client\';\nimport { appDeclaration } from "@demo-shop/config/declaration";\nexport const value = appDeclaration;\n',
89
87
  });
90
88
  expect(findDeclarationLeaks(scan)).toHaveLength(1);
91
89
  });
@@ -101,6 +99,26 @@ describe('the scanner fails however the import is written', () => {
101
99
  expect(findDeclarationLeaks(scan)).toEqual([]);
102
100
  });
103
101
 
102
+ test('a matching subpath under a foreign scope is not a workspace import', () => {
103
+ const scan = fixture({
104
+ 'packages/frontend/src/page.tsx':
105
+ "'use client';\nimport { appDeclaration } from '@foreign/config/declaration';\nexport const value = appDeclaration;\n",
106
+ });
107
+ expect(findDeclarationLeaks(scan)).toEqual([]);
108
+ });
109
+
110
+ test('the manifest name resolves a package whose directory has a different name', () => {
111
+ const scan = fixture({
112
+ 'packages/config/package.json': JSON.stringify({
113
+ name: 'shop-configuration',
114
+ exports: { './declaration': './src/declaration.ts' },
115
+ }),
116
+ 'packages/frontend/src/page.tsx':
117
+ "'use client';\nimport { appDeclaration } from 'shop-configuration/declaration';\nexport const value = appDeclaration;\n",
118
+ });
119
+ expect(findDeclarationLeaks(scan)).toHaveLength(1);
120
+ });
121
+
104
122
  test('both quote styles and side-effect imports are read', () => {
105
123
  expect(
106
124
  specifiers(
@@ -9,15 +9,12 @@ import { dirname, join, resolve } from 'node:path';
9
9
  * artifact and migration paths, and the name of every environment variable a
10
10
  * deployment supplies. One `import` from a module a client component happens to
11
11
  * use puts all of it, plus the Zod schema that parses it, into the browser
12
- * bundle. That is the exact mistake `app-identity.generated.ts` exists to
13
- * prevent, made from the other side — and it shipped, because nothing checked
14
- * the graph, only the file that imports directly.
12
+ * bundle. `app-identity.generated.ts` exposes only the public identity; the
13
+ * scanner follows the whole graph to keep the full declaration server-only.
15
14
  *
16
- * The check is a resolved FILE, not a spelling. Matching the string
17
- * `@app/config/declaration` catches the one way the leak was written the first
18
- * time and misses the two ways it comes back: a barrel that re-exports it, and
19
- * a relative path into the config package. Both end at the same file, so that
20
- * is what this follows.
15
+ * The check follows resolved files: a direct package import, a barrel and a
16
+ * relative path can all reach the same declaration. Workspace names come from
17
+ * package manifests so the check also follows a renamed package.
21
18
  */
22
19
  export interface ClientBoundaryScan {
23
20
  /** Repository root — where `packages/<name>` lives. */
@@ -77,25 +74,32 @@ function firstExistingFile(base: string): string | undefined {
77
74
  return undefined;
78
75
  }
79
76
 
80
- /** `@app/config/declaration` → the file its package's `exports` map names. */
81
77
  function resolveWorkspace(scan: ClientBoundaryScan, specifier: string): string | undefined {
82
- const parts = specifier.split('/');
83
- if (parts[0] !== '@app' || !parts[1]) return undefined;
84
- const packageRoot = join(scan.root, 'packages', parts[1]);
85
- const manifestPath = join(packageRoot, 'package.json');
86
- if (!existsSync(manifestPath)) return undefined;
87
- const subpath = parts.length > 2 ? `./${parts.slice(2).join('/')}` : '.';
88
- const manifest: unknown = JSON.parse(readFileSync(manifestPath, 'utf8'));
89
- const exportsField =
90
- typeof manifest === 'object' && manifest !== null
91
- ? Reflect.get(manifest, 'exports')
78
+ const packagesRoot = join(scan.root, 'packages');
79
+ if (!existsSync(packagesRoot)) return undefined;
80
+ for (const entry of readdirSync(packagesRoot, { withFileTypes: true })) {
81
+ if (!entry.isDirectory()) continue;
82
+ const packageRoot = join(packagesRoot, entry.name);
83
+ const manifestPath = join(packageRoot, 'package.json');
84
+ if (!existsSync(manifestPath)) continue;
85
+ const manifest: unknown = JSON.parse(readFileSync(manifestPath, 'utf8'));
86
+ if (typeof manifest !== 'object' || manifest === null) continue;
87
+ const name: unknown = Reflect.get(manifest, 'name');
88
+ if (typeof name !== 'string') continue;
89
+ if (specifier !== name && !specifier.startsWith(`${name}/`)) continue;
90
+ const subpath = specifier === name ? '.' : `.${specifier.slice(name.length)}`;
91
+ const exportsField: unknown = Reflect.get(manifest, 'exports');
92
+ const target: unknown =
93
+ typeof exportsField === 'string' && subpath === '.'
94
+ ? exportsField
95
+ : typeof exportsField === 'object' && exportsField !== null
96
+ ? Reflect.get(exportsField, subpath)
97
+ : undefined;
98
+ return typeof target === 'string'
99
+ ? firstExistingFile(resolve(packageRoot, target))
92
100
  : undefined;
93
- const target =
94
- typeof exportsField === 'object' && exportsField !== null
95
- ? Reflect.get(exportsField, subpath)
96
- : undefined;
97
- if (typeof target !== 'string') return undefined;
98
- return firstExistingFile(resolve(packageRoot, target));
101
+ }
102
+ return undefined;
99
103
  }
100
104
 
101
105
  export function resolveSpecifier(
@@ -103,13 +107,12 @@ export function resolveSpecifier(
103
107
  from: string,
104
108
  specifier: string,
105
109
  ): string | undefined {
106
- if (specifier.startsWith('@app/')) return resolveWorkspace(scan, specifier);
107
110
  const base = specifier.startsWith('@/')
108
111
  ? join(scan.frontendSrc, specifier.slice(2))
109
112
  : specifier.startsWith('.')
110
113
  ? resolve(dirname(from), specifier)
111
114
  : undefined;
112
- return base ? firstExistingFile(base) : undefined;
115
+ return base ? firstExistingFile(base) : resolveWorkspace(scan, specifier);
113
116
  }
114
117
 
115
118
  /** The import chain from a client entry to the declaration, if one exists. */
@@ -148,7 +148,7 @@ describe('the drain floor has one home', () => {
148
148
  test('the API role reads its grace period from the declaration', () => {
149
149
  const source = read('packages/backend/src/index.ts');
150
150
  // A literal here would be a second number able to disagree with the one a
151
- // supervisor reads, which is exactly how a 30s floor met a 15s kill timeout.
151
+ // supervisor reads, potentially allowing a 15s kill timeout for a 30s floor.
152
152
  expect(source).toContain('gracePeriodMs: apiRole.drainFloorMs');
153
153
  expect(source).not.toMatch(/gracePeriodMs:\s*\d/);
154
154
  });
@@ -157,8 +157,8 @@ describe('the drain floor has one home', () => {
157
157
  describe('an argument survives the generator intact', () => {
158
158
  test('a space and a quote reach the supervision file unmangled', () => {
159
159
  // The reason commands are argv and the generator serialises rather than
160
- // concatenates: `split(' ')` destroyed quoted arguments, and building
161
- // `'${part}'` by hand emitted invalid JavaScript for an argument
160
+ // concatenates: `split(' ')` destroys quoted arguments, and building
161
+ // `'${part}'` by hand emits invalid JavaScript for an argument
162
162
  // containing a quote.
163
163
  const awkward = {
164
164
  ...appDeclaration,
@@ -185,10 +185,8 @@ describe('an argument survives the generator intact', () => {
185
185
  });
186
186
 
187
187
  describe('the guidance a next agent reads names the keys that exist', () => {
188
- // `AGENTS.md` is not documentation about the past — it is the instruction the
189
- // next agent follows. It kept pointing at `env.required` for a whole release
190
- // after the key became `env.variables`, which is worse than a stale comment:
191
- // the agent goes looking for something that is not there.
188
+ // Guidance names current declaration keys so an agent can follow it without
189
+ // looking for fields that the declaration does not contain.
192
190
  const guidance = ['AGENTS.md', 'README.md'];
193
191
 
194
192
  for (const file of guidance) {
@@ -12,11 +12,10 @@ import { applicationVariables } from '../packages/config/src/variables';
12
12
  /**
13
13
  * Everything derived from the project declaration.
14
14
  *
15
- * Two things used to be written by hand and had already drifted: the list of
16
- * environment variables (three overlapping copies) and the two PM2 files (nine
17
- * diverging lines, one of which killed the backend mid-drain every time). Both
18
- * are now DERIVED — from `variables.ts` and from `project.json` — and the gate
19
- * refuses a checked-in file that does not match what this module renders.
15
+ * Environment variables are derived from `variables.ts`; both PM2 files are
16
+ * derived from `project.json`. Independent copies can disagree about required
17
+ * variables or kill a backend before its drain ends. The gate refuses a
18
+ * checked-in file that does not match what this module renders.
20
19
  *
21
20
  * Note what stays on which side. Roles, commands, readiness and the drain floor
22
21
  * come from the declaration, because they are true of the code. Restart policy
@@ -49,13 +48,11 @@ export const LOCAL_SUPERVISION: SupervisionPolicy = {
49
48
  *
50
49
  * The server forces for `forceTimeoutMs` (5s by default) once the grace period
51
50
  * ends, and `onComplete` then closes MCP and the database. A supervisor sized to
52
- * the drain floor alone kills the role in the middle of that tail — which is why
53
- * the earlier check, comparing against the floor only, reported that supervision
54
- * "allows the full shutdown" while 15s + 5s met a 20s kill timeout exactly.
51
+ * the drain floor alone can kill the role in the middle of that tail. A 15s
52
+ * drain plus 5s of forcing already spends a 20s timeout before cleanup begins.
55
53
  */
56
54
  // Imported, not restated: the role enforces these, and a number in two places
57
- // is two numbers that can disagree — which is exactly how a 15s drain met a
58
- // 20s kill timeout.
55
+ // is two numbers that can disagree about how long shutdown needs.
59
56
  const { FORCE_BUDGET_MS, CLEANUP_BUDGET_MS } = shutdownBudgets;
60
57
 
61
58
  /** The shortest time a supervisor may allow this role and still see it finish. */
@@ -66,10 +63,9 @@ export function terminationBudgetMs(role: ProjectRole): number {
66
63
  /**
67
64
  * JSON Schema types this projection can carry into the declaration.
68
65
  *
69
- * `number` used to be mapped to `integer`, which quietly told a deployment that
70
- * a fractional value was an integer — the declaration and the Zod contract it
71
- * is derived FROM would then disagree, which is the one failure the derivation
72
- * exists to prevent. A type with no faithful shape is refused instead: the
66
+ * Mapping `number` to `integer` would misrepresent fractional values and make
67
+ * the declaration disagree with its Zod source. A type with no faithful shape
68
+ * is rejected: the
73
69
  * declaration format gains the shape, or the project stops declaring that type.
74
70
  */
75
71
  const SHAPE_BY_JSON_TYPE: Record<string, ProjectEnvVariable['shape']> = {
@@ -115,8 +111,8 @@ function describeVariable(
115
111
  required: boolean,
116
112
  ): ProjectEnvVariable {
117
113
  if (property.enum) {
118
- // Members are refused rather than stringified. `String(member)` turned
119
- // numbers and booleans into text that no longer matched the value the Zod
114
+ // Members are rejected rather than stringified. `String(member)` would turn
115
+ // numbers and booleans into text that does not match the value the Zod
120
116
  // schema accepts, so a deployment reading the declaration would supply
121
117
  // something the application then rejects — the declaration would be derived
122
118
  // and still wrong.
@@ -156,9 +152,8 @@ export function renderProjectJson(): string {
156
152
  /**
157
153
  * The rule the drain floor exists for: a supervisor must allow at least as long
158
154
  * as the role needs to finish — the drain, the force that follows it, and the
159
- * cleanup after that. Shorter, and the process is killed mid-shutdown, which is
160
- * what a 15s kill timeout against a 30s floor did here, every time, for as long
161
- * as the two numbers lived in two hand-written files.
155
+ * cleanup after that. A 15s kill timeout against a 30s drain floor cannot allow
156
+ * orderly shutdown, even before forcing and cleanup take their own time.
162
157
  */
163
158
  export function assertSupervisionAllowsShutdown(
164
159
  declaration: ProjectDeclaration,
@@ -4,9 +4,8 @@
4
4
  * `runtime:smoke` checks a RUNNING deployment — that is what makes it a runtime
5
5
  * smoke rather than a build check. Without this the first `fetch` inside some
6
6
  * assertion fails with a bare `ECONNRESET`, which reads like a broken check
7
- * instead of an absent deployment and says nothing about what to do next. The
8
- * packed lane never saw it because the lane starts the roles itself; everyone
9
- * following the README's gate list saw it first.
7
+ * instead of an absent deployment and says nothing about what to do next. This
8
+ * preflight names the missing roles before any assertion tries to dial them.
10
9
  */
11
10
  export async function assertDeploymentIsAnswering(
12
11
  origins: Readonly<Record<string, string>>,
@@ -105,10 +105,9 @@ function assertToolAvailable(command: string, instruction: string): void {
105
105
  * The validated environment the development processes run with.
106
106
  *
107
107
  * Every variable the DECLARATION names, and no hand-written list beside it: a
108
- * list here went stale the moment a variable was added, and a role declaring a
109
- * port whose name was missing got `Number(undefined)` — reported as
110
- * `Port NaN (WORKER_PORT) is already in use`, which is a false diagnosis of a
111
- * real mistake.
108
+ * separate list can omit a role's port variable, turning a missing binding into
109
+ * `Number(undefined)` and a misleading `Port NaN (WORKER_PORT) is already in use`.
110
+ * Reading the declaration keeps missing bindings distinct from occupied ports.
112
111
  */
113
112
  export async function developmentEnvironment(
114
113
  overrides: Record<string, string> = {},
@@ -128,10 +127,9 @@ if (import.meta.main) {
128
127
 
129
128
  const environment = await developmentEnvironment();
130
129
  const roles = declaredRoleReadiness(appDeclaration, environment);
131
- // Reported only once it is TRUE. The supervisor returns at the spawn, and a
132
- // development build needs seconds after that before it listens — so the line
133
- // below used to be printed at a moment when nothing answered, and the next
134
- // command in the gate list got a connection reset.
130
+ // The supervisor returns at spawn; a development build needs time before it
131
+ // listens. Report readiness only after every role answers so the next gate
132
+ // can connect.
135
133
  await awaitRolesAnswering(roles);
136
134
  console.log(`${appDeclaration.identity.name} development processes are running`);
137
135
  for (const role of roles) console.log(`${role.name}: ${role.url}`);
@@ -5,10 +5,8 @@ import { join, resolve } from 'node:path';
5
5
  /**
6
6
  * Every repository path a guide names has to exist.
7
7
  *
8
- * `ADDING_A_FEATURE.md` is the one document a new consumer executes literally, and two of its
9
- * steps pointed at files the scaffold does not contain — `lib/api/client.ts` and a "shared
10
- * realtime source". The reader does not learn that by reading; they learn it by opening the path
11
- * and finding nothing, after having already trusted the sentence around it.
8
+ * A new consumer executes `ADDING_A_FEATURE.md` literally. Every referenced source file must
9
+ * exist so the reader can follow each step without discovering a missing path along the way.
12
10
  *
13
11
  * A path the guide tells you to CREATE is not a broken reference, so those are declared by the
14
12
  * guide itself: a line that introduces one carries `(created in this step)`. Everything else
@@ -43,9 +43,8 @@ export function declaredRoleReadiness(
43
43
  * An IPv6 literal is bracketed; everything else is written as it stands.
44
44
  *
45
45
  * `http://::1:3211/health` is not an address with a port — it is not a URL at
46
- * all, and `fetch` refuses it. A role bound to a specific IPv6 address is a
47
- * legitimate deployment, and it used to make the readiness wait fail on the
48
- * spelling rather than on the role.
46
+ * all, and `fetch` refuses it. Brackets let readiness probe a legitimate IPv6
47
+ * binding instead of failing on URL syntax.
49
48
  */
50
49
  function authority(host: string, port: string): string {
51
50
  const literal = host.includes(':') && !host.startsWith('[');
@@ -57,8 +56,8 @@ function authority(host: string, port: string): string {
57
56
  *
58
57
  * A supervisor returns as soon as it has SPAWNED a process, and a role needs
59
58
  * seconds after that before it listens. Printing "running" at the moment of the
60
- * spawn is a claim nobody checked: the next command in the gate list dialled
61
- * the declared port and got a connection reset, which reads as a broken check
59
+ * spawn is a claim nobody checked: the next command can dial the declared port
60
+ * before it listens and get a connection reset, which reads as a broken check
62
61
  * rather than an application still booting.
63
62
  */
64
63
  export async function awaitRolesAnswering(
@@ -43,10 +43,8 @@ describe('build artifacts are checked before roles start', () => {
43
43
  artifacts: ['packages/backend/nowhere'],
44
44
  },
45
45
  };
46
- // The test used to stop at the artifact name, which is why nobody noticed
47
- // that the second half of the sentence had become `[object Object]` when
48
- // commands turned into `{ executable, args }`. A diagnostic exists to be
49
- // retyped, so the assertion reads it the way an operator would.
46
+ // The full diagnostic must contain a command an operator can retype;
47
+ // serializing a command object as `[object Object]` is not actionable.
50
48
  expect(() => assertBuildArtifacts(unbuilt)).toThrow(
51
49
  /Missing build artifacts: packages\/backend\/nowhere — run `bun run build` first\./,
52
50
  );
@@ -33,8 +33,8 @@ const MIGRATION_COMMANDS: Record<string, string[]> = {
33
33
  * A declared command as an operator can retype it.
34
34
  *
35
35
  * `${command}` on a `{ executable, args }` object prints `[object Object]`, so
36
- * the one diagnostic that exists to tell an operator what to run told them
37
- * nothing. Quoting is deliberate: an argument with a space has to survive being
36
+ * a diagnostic using it cannot tell an operator what to run. Quoting is
37
+ * deliberate: an argument with a space has to survive being
38
38
  * read back.
39
39
  */
40
40
  export function formatCommand(command: { executable: string; args: string[] }): string {
@@ -21,9 +21,8 @@ describe('the portability check dials addresses the deployment claims', () => {
21
21
  });
22
22
 
23
23
  test('a deployment with nothing but its own address is told what to add', () => {
24
- // The reported failure, from the other side: the check used to carry two
25
- // fixture hosts of its own, so a deployment that had never been told about
26
- // them refused the request and the gate showed a bare 500.
24
+ // Portability probes require explicitly allowed hosts; inventing fixture
25
+ // hosts would make a deployment reject the request before the probe runs.
27
26
  const plan = planPortabilityCheck(dialled, { hosts: '127.0.0.1:3210' });
28
27
  expect(plan.kind).toBe('refuse');
29
28
  if (plan.kind !== 'refuse') return;
@@ -67,8 +66,8 @@ describe('the portability check dials addresses the deployment claims', () => {
67
66
 
68
67
  test('one host written twice is one address, not two', () => {
69
68
  // The count decides whether the property can be proved at all. Without
70
- // deduplication a duplicate entry passed as a second address and the check
71
- // compared the deployment with itself — a proof that cannot fail.
69
+ // deduplication a duplicate could count as a second address, making the
70
+ // check compare the deployment with itself — a proof that cannot fail.
72
71
  const plan = planPortabilityCheck(dialled, {
73
72
  hosts: '127.0.0.1:3210,alpha.example,alpha.example',
74
73
  });
@@ -90,7 +89,7 @@ describe('the portability check dials addresses the deployment claims', () => {
90
89
 
91
90
  describe('a gate list is not a deploy instruction', () => {
92
91
  // `runtime:smoke` and `e2e` check a running deployment, so the list has to
93
- // bring one up — and the wrong way to do that shipped once already:
92
+ // bring one up. It must not do that through `pm2:prod`:
94
93
  // `pm2:prod` applies the declared migrations and reloads the deployment the
95
94
  // developer is running. A gate creates and destroys its OWN deployment, and
96
95
  // that is `acceptance:local`.
@@ -158,7 +157,7 @@ describe('a role is ready when it answers, not when it is spawned', () => {
158
157
 
159
158
  test('an IPv6 bind address is bracketed, or it is not a URL at all', () => {
160
159
  // `http://::1:3211/health` cannot be parsed as an address with a port, so
161
- // the wait failed on the spelling instead of on the role.
160
+ // the wait would fail on URL syntax before it can reach the role.
162
161
  const addresses = declaredRoleReadiness(appDeclaration, {
163
162
  ...environment,
164
163
  BIND_HOST: '::1',
@@ -4,8 +4,8 @@ import { join } from 'node:path';
4
4
  /**
5
5
  * The web role refuses a mode it does not understand.
6
6
  *
7
- * `argv[2] === 'development' ? 'dev' : 'start'` meant a typo, an empty string
8
- * and a missing argument all became production in silence — the one decision
7
+ * `argv[2] === 'development' ? 'dev' : 'start'` would turn a typo, an empty string
8
+ * and a missing argument into production in silence — the one decision
9
9
  * that changes whether the role serves a build or compiles on demand. Run as a
10
10
  * real process, because the failure has to happen before Next is spawned.
11
11
  */
@@ -1,11 +1,9 @@
1
1
  /**
2
2
  * A role whose cleanup will not complete, as a real process.
3
3
  *
4
- * The regression this serves cannot be written against a promise. The defect
5
- * was never "the helper resolved late" — it was that the role set
6
- * `process.exitCode` and then waited for an event loop something was still
7
- * holding, so the process lived until the supervisor's SIGKILL: exactly the
8
- * ending the cleanup budget exists to prevent. Only a process can show that.
4
+ * A promise cannot prove process termination: setting `process.exitCode` still
5
+ * waits for an event loop with held handles. The role must exit before the
6
+ * supervisor's SIGKILL, and only a real process can demonstrate that bound.
9
7
  *
10
8
  * The interval below is the held handle. Nothing ever clears it, so this
11
9
  * process ends only if something ends it — which is the assertion.
@@ -30,10 +30,8 @@ describe('the termination budget is an upper bound, not an estimate', () => {
30
30
  });
31
31
 
32
32
  test('a close that hangs stops being waited for, and is named', async () => {
33
- // The defect this exists for: the drain had a deadline, the closes after it
34
- // had none, so a hung MCP session or database pool ran past the very kill
35
- // timeout the budget had told the supervisor to allow — turning an orderly
36
- // shutdown into the SIGKILL that runs no cleanup at all.
33
+ // MCP and database closes must fit the shutdown budget as well as the drain.
34
+ // An unbounded close would reach the supervisor's SIGKILL, which runs no cleanup.
37
35
  const result = await closeWithinBudget(
38
36
  [{ name: 'MCP', close: () => new Promise<void>(() => undefined) }],
39
37
  25,
@@ -63,10 +61,8 @@ describe('the termination budget is an upper bound, not an estimate', () => {
63
61
  });
64
62
 
65
63
  test('a close that fails is a failure, and keeps its cause', async () => {
66
- // It used to be swallowed into `undefined` with the note that the budget is
67
- // about time. The budget is — but a close that throws is a shutdown that
68
- // did not happen, and reporting it as a clean exit with the reason gone is
69
- // how a broken shutdown looks exactly like a working one.
64
+ // Timeouts and rejections are different shutdown failures. A rejected close
65
+ // must retain its cause rather than appear as a successful clean exit.
70
66
  const result = await closeWithinBudget([
71
67
  { name: 'database', close: () => Promise.reject(new Error('pool already gone')) },
72
68
  ]);
@@ -42,7 +42,7 @@ async function roleReceivesSignal(from: 'role directory' | 'workspace root'): Pr
42
42
  // negative-pid signal below reach the role behind the launcher. The
43
43
  // NEGATIVE case is the point: there the role never sees the signal, so
44
44
  // killing the launcher alone would leave it running for the life of the
45
- // machine — this test used to leak one role per run.
45
+ // machine. Cleanup must reach the role even when the launcher cannot.
46
46
  const child =
47
47
  from === 'role directory'
48
48
  ? Bun.spawn(['bun', 'run', 'start'], {
@@ -9,9 +9,8 @@ function publicUrl(origin: string, path: string): URL {
9
9
  /**
10
10
  * Every dial is bounded.
11
11
  *
12
- * A gate that hangs is worse than one that fails: it reports nothing, ever. An
13
- * endpoint that accepts the connection and never answers used to stop the whole
14
- * run with no output and no deadline.
12
+ * Every request has a deadline: an endpoint can accept the connection without
13
+ * answering, and the gate must report that failure within a bounded time.
15
14
  */
16
15
  function dial(url: URL, init?: RequestInit): Promise<Response> {
17
16
  return fetch(url, { ...init, signal: AbortSignal.timeout(DIAL_TIMEOUT_MS) });
@@ -113,10 +112,8 @@ function claimedHosts(hosts: string | undefined): string[] {
113
112
  *
114
113
  * The check can only dial an address the deployment claims: a forwarded host
115
114
  * outside `PUBLIC_WEB_HOSTS` is refused on purpose, and rightly so. Naming two
116
- * fixture hosts here therefore meant the deployment had to have been told about
117
- * those exact two names by somebody else — which only the packed lane ever was.
118
- * Everyone running the same command against their own deployment got a bare
119
- * 500 from a policy working exactly as designed.
115
+ * fixture hosts here would require every deployment to allow those exact names,
116
+ * or make the probe fail on host policy before checking portability.
120
117
  *
121
118
  * So the deployment declares and the check reads, instead of two copies of the
122
119
  * same fixture that must agree across two repositories.
@@ -224,7 +221,7 @@ export async function assertArtifactIsPlacementFree(
224
221
 
225
222
  // Same rule, one layer down. A forwarded protocol outside `http | https` is a
226
223
  // misconfigured proxy or a forgery, and both have to be visible: mapping
227
- // every unknown value to `http` produced a plausible canonical origin from
224
+ // every unknown value to `http` would produce a plausible canonical origin from
228
225
  // `ftp`, `javascript` and a truncated header alike.
229
226
  const [claimedAddress] = plan.addresses;
230
227
  for (const proto of ['ftp', 'javascript', 'HTTPS://', '']) {
@@ -1,5 +1,8 @@
1
1
  {
2
- "$schema": "https://biomejs.dev/schemas/2.5.14/schema.json",
2
+ "$schema": "https://biomejs.dev/schemas/2.6.5/schema.json",
3
+ "markdown": {
4
+ "formatter": { "enabled": false }
5
+ },
3
6
  "files": {
4
7
  "includes": ["**", "!!node_modules", "!!dist", "!!project.json", "!!**/.stitchkit"]
5
8
  },
@@ -6,6 +6,9 @@
6
6
  "catalog": {
7
7
  "stitchkit-tui": "^0.1.1"
8
8
  },
9
+ "overrides": {
10
+ "zod": "4.6.7"
11
+ },
9
12
  "scripts": {
10
13
  "dev": "bun --watch src/index.ts",
11
14
  "start": "bun src/index.ts",
@@ -16,21 +19,22 @@
16
19
  "build": "bun build src/index.ts --outdir dist --target bun --packages external"
17
20
  },
18
21
  "dependencies": {
19
- "@modelcontextprotocol/server": "^2.0.0",
22
+ "@modelcontextprotocol/server": "^2.4.0",
20
23
  "@openrouter/ai-sdk-provider": "^3.1.0",
21
- "ai": "^7.0.111",
22
- "stitchkit": "file:../../../core",
23
- "stitchkit-tui": "file:../../../tui",
24
- "zod": "4.6.5"
24
+ "ai": "^7.0.162",
25
+ "stitchkit": "link:../../../core",
26
+ "stitchkit-tui": "link:../../../tui",
27
+ "zod": "4.6.7"
25
28
  },
26
29
  "devDependencies": {
30
+ "@biomejs/biome": "2.6.5",
27
31
  "@typescript/native-preview": "7.0.0-dev.20260707.2",
28
- "@types/bun": "^1.4.2",
32
+ "@types/bun": "^1.4.4",
29
33
  "@types/react": "^19.3.0",
30
34
  "typescript": "^7.0.2"
31
35
  },
32
36
  "engines": {
33
37
  "bun": ">=1.3.0"
34
38
  },
35
- "packageManager": "bun@1.4.2"
39
+ "packageManager": "bun@1.4.4"
36
40
  }