anhedral 0.23.0 → 0.24.1

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 (74) hide show
  1. package/README.md +3 -3
  2. package/assets/launch/AGENTS.md.txt +7 -0
  3. package/assets/launch/README.md.txt +40 -0
  4. package/assets/launch/application.server.ts.txt +19 -7
  5. package/assets/launch/application.test.mjs.txt +8 -0
  6. package/assets/launch/backend-vite.config.ts.txt +18 -0
  7. package/assets/launch/home.tsx.txt +25 -2
  8. package/assets/launch/minimal-application.server.ts.txt +2 -2
  9. package/assets/launch/root.tsx.txt +38 -5
  10. package/assets/launch/router.tsx.txt +3 -2
  11. package/assets/launch/sign-in.tsx.txt +68 -5
  12. package/assets/launch/storage-page.tsx.txt +57 -0
  13. package/assets/launch/styles.css.txt +55 -16
  14. package/assets/launch/styling-tokens.cjs +45 -0
  15. package/assets/launch/vite.config.ts.txt +13 -0
  16. package/assets/stack/api-eslint.config.mjs.txt +2 -0
  17. package/assets/stack/api-index.ts.txt +1 -0
  18. package/assets/stack/api-proxy.ts.txt +112 -0
  19. package/assets/stack/auth-routes.ts.txt +3 -1
  20. package/assets/stack/auth.ts.txt +5 -4
  21. package/assets/stack/backend.test.mjs.txt +10 -0
  22. package/assets/stack/base-eslint.js.txt +16 -0
  23. package/assets/stack/billing-mode.ts.txt +2 -0
  24. package/assets/stack/billing-providers.ts.txt +8 -0
  25. package/assets/stack/db-index.ts.txt +7 -0
  26. package/assets/stack/db-migrate.mjs.txt +23 -0
  27. package/assets/stack/drizzle.config.ts.txt +2 -0
  28. package/assets/stack/entitlement-guard.ts.txt +2 -0
  29. package/assets/stack/entitlements.ts.txt +3 -1
  30. package/assets/stack/payment.test.mjs.txt +61 -0
  31. package/assets/stack/security.ts.txt +2 -0
  32. package/assets/stack/shared-eslint.config.mjs.txt +6 -0
  33. package/assets/stack/storage.test.mjs.txt +47 -0
  34. package/assets/stack/storage.ts.txt +3 -1
  35. package/assets/stack/stripe.ts.txt +4 -2
  36. package/dist/bounded-file.d.ts +2 -1
  37. package/dist/bounded-file.js +3 -2
  38. package/dist/cli-output.js +1 -1
  39. package/dist/composition/command.js +5 -2
  40. package/dist/composition/composition.d.ts +1 -0
  41. package/dist/composition/composition.js +9 -0
  42. package/dist/composition/editor.d.ts +2 -1
  43. package/dist/composition/editor.js +15 -3
  44. package/dist/composition/recipes.d.ts +2 -2
  45. package/dist/composition/recipes.js +62 -52
  46. package/dist/composition/update.js +15 -15
  47. package/dist/dependencies.d.ts +5 -6
  48. package/dist/dependencies.js +9 -1
  49. package/dist/launch.d.ts +1 -1
  50. package/dist/launch.js +26 -91
  51. package/dist/platform/deploy.js +5 -13
  52. package/dist/platform/environment.js +10 -2
  53. package/dist/platform/source.d.ts +2 -0
  54. package/dist/platform/source.js +52 -11
  55. package/dist/platform/state.js +9 -2
  56. package/dist/pnpm-policy.d.ts +1 -0
  57. package/dist/pnpm-policy.js +27 -0
  58. package/dist/render.d.ts +0 -10
  59. package/dist/render.js +1 -38
  60. package/dist/scaffold/bootstrap.d.ts +1 -2
  61. package/dist/scaffold/bootstrap.js +4 -8
  62. package/dist/scaffold/files.d.ts +12 -24
  63. package/dist/scaffold/files.js +9 -103
  64. package/dist/scaffold/styling.d.ts +2 -4
  65. package/dist/scaffold/styling.js +46 -69
  66. package/dist/scaffold/tanstack.d.ts +2 -2
  67. package/dist/scaffold/tanstack.js +37 -39
  68. package/dist/version.d.ts +1 -1
  69. package/dist/version.js +1 -1
  70. package/docs/capabilities.md +8 -0
  71. package/docs/software-factory.md +16 -7
  72. package/package.json +4 -2
  73. package/dist/api-proxy.d.ts +0 -1
  74. package/dist/api-proxy.js +0 -48
@@ -1,11 +1,8 @@
1
- import { readFileSync } from 'node:fs';
2
- import { CapabilityEditor } from './editor.js';
3
- import { CAPABILITY_DEPENDENCIES as P } from '../dependencies.js';
4
- import { STACK_DEPENDENCIES as D } from '../dependencies.js';
1
+ import { CAPABILITY_DEPENDENCIES, STACK_DEPENDENCIES } from '../dependencies.js';
5
2
  import { resourceName } from '../render.js';
3
+ import { launchTemplate, stackTemplate, workerConfig } from '../scaffold/files.js';
6
4
  import { composeTanstack, addTanstackAuth } from '../scaffold/tanstack.js';
7
- import { WEB_API_PROXY } from '../api-proxy.js';
8
- const template = (name) => readFileSync(new URL(`../../assets/stack/${name}`, import.meta.url), 'utf8');
5
+ import { CapabilityEditor } from './editor.js';
9
6
  const json = (value) => JSON.stringify(value, null, 2) + '\n';
10
7
  function dependency(e, app, dependencies) {
11
8
  e.merge(`${app}/package.json`, 'dependencies', dependencies);
@@ -18,7 +15,7 @@ function project(e, directory, name, scripts, dependencies, dev = {}) {
18
15
  type: 'module',
19
16
  scripts,
20
17
  dependencies,
21
- devDependencies: { typescript: D.typescript, ...dev },
18
+ devDependencies: { typescript: STACK_DEPENDENCIES.typescript, ...dev },
22
19
  }));
23
20
  }
24
21
  function apiConfig(e, key, value) {
@@ -47,28 +44,30 @@ function schemaExport(e, module) {
47
44
  e.writes.set(file, source + `\nexport * from './${module}';\n`);
48
45
  }
49
46
  export function addCapabilityRecipe(e, id, name) {
47
+ if (id === 'r2' || id === 'stripe') {
48
+ const manifest = e.json('apps/api/package.json');
49
+ if (!manifest.scripts?.test)
50
+ e.set('apps/api/package.json', ['scripts', 'test'], 'node --import tsx --test tests/*.test.mjs');
51
+ if (!manifest.devDependencies?.tsx && !manifest.dependencies?.tsx)
52
+ e.set('apps/api/package.json', ['devDependencies', 'tsx'], CAPABILITY_DEPENDENCIES.tsx);
53
+ }
50
54
  switch (id) {
51
55
  case 'hono': {
52
56
  project(e, 'apps/api', '@workspace/api', {
57
+ test: 'node --import tsx --test tests/*.test.mjs',
53
58
  dev: 'wrangler dev --port 8787 --inspector-port 9231',
54
59
  build: 'wrangler deploy --dry-run --outdir dist',
55
60
  deploy: 'wrangler deploy',
56
61
  typecheck: 'wrangler types && tsc --noEmit',
57
62
  lint: 'eslint . --max-warnings 0',
58
- }, { hono: D.hono }, {
59
- wrangler: D.wrangler,
60
- '@types/node': D['@types/node'],
61
- eslint: D.eslint,
63
+ }, { hono: STACK_DEPENDENCIES.hono }, {
64
+ tsx: CAPABILITY_DEPENDENCIES.tsx,
65
+ wrangler: STACK_DEPENDENCIES.wrangler,
66
+ '@types/node': STACK_DEPENDENCIES['@types/node'],
67
+ eslint: STACK_DEPENDENCIES.eslint,
62
68
  '@workspace/eslint-config': 'workspace:*',
63
69
  });
64
- e.create('apps/api/wrangler.jsonc', json({
65
- $schema: 'node_modules/wrangler/config-schema.json',
66
- name: resourceName(name, 'api'),
67
- main: 'src/index.ts',
68
- compatibility_date: '2026-10-05',
69
- compatibility_flags: ['nodejs_compat'],
70
- observability: { enabled: true },
71
- }));
70
+ e.create('apps/api/wrangler.jsonc', json(workerConfig(resourceName(name, 'api'), 'src/index.ts', '2026-10-05')));
72
71
  e.create('apps/api/tsconfig.json', json({
73
72
  compilerOptions: {
74
73
  target: 'ES2022',
@@ -82,8 +81,9 @@ export function addCapabilityRecipe(e, id, name) {
82
81
  },
83
82
  include: ['src/**/*.ts', 'worker-configuration.d.ts'],
84
83
  }));
85
- e.create('apps/api/eslint.config.mjs', "import { config } from '@workspace/eslint-config/base';\nexport default [...config, {ignores:['dist/**','.wrangler/**','worker-configuration.d.ts']}];\n");
86
- e.create('apps/api/src/index.ts', template('api-index.ts.txt'));
84
+ e.create('apps/api/eslint.config.mjs', stackTemplate('api-eslint.config.mjs.txt'));
85
+ e.create('apps/api/tests/backend.test.mjs', stackTemplate('backend.test.mjs.txt'));
86
+ e.create('apps/api/src/index.ts', stackTemplate('api-index.ts.txt'));
87
87
  e.create('apps/api/src/custom-environment.ts', 'export type CustomBindings = Record<never, never>;\nexport type CustomVariables = Record<never, never>;\n');
88
88
  const web = 'apps/web/wrangler.jsonc';
89
89
  const services = e.json(web).services ?? [];
@@ -97,7 +97,7 @@ export function addCapabilityRecipe(e, id, name) {
97
97
  else
98
98
  e.set(web, ['services'], [{ binding: 'ANHEDRAL_API', service: resourceName(name, 'api') }]);
99
99
  e.set('apps/api/package.json', ['devDependencies', 'wrangler'], e.json('apps/web/package.json').devDependencies.wrangler);
100
- e.create('apps/web/src/lib/api-proxy.ts', WEB_API_PROXY.replace("'idempotency-key'", "'idempotency-key', 'stripe-signature', 'last-event-id'").replace('AbortSignal.timeout(15000)', "AbortSignal.timeout(request.headers.get('accept')?.includes('text/event-stream') ? 35000 : 15000)"));
100
+ e.create('apps/web/src/lib/api-proxy.ts', stackTemplate('api-proxy.ts.txt'));
101
101
  break;
102
102
  }
103
103
  case 'database-auth': {
@@ -106,10 +106,10 @@ export function addCapabilityRecipe(e, id, name) {
106
106
  lint: 'eslint . --max-warnings 0',
107
107
  'db:generate': 'drizzle-kit generate',
108
108
  'db:migrate': 'node src/migrate.mjs',
109
- }, { 'drizzle-orm': D['drizzle-orm'] }, {
110
- 'drizzle-kit': D['drizzle-kit'],
111
- '@types/node': D['@types/node'],
112
- eslint: D.eslint,
109
+ }, { 'drizzle-orm': STACK_DEPENDENCIES['drizzle-orm'] }, {
110
+ 'drizzle-kit': STACK_DEPENDENCIES['drizzle-kit'],
111
+ '@types/node': STACK_DEPENDENCIES['@types/node'],
112
+ eslint: STACK_DEPENDENCIES.eslint,
113
113
  '@workspace/eslint-config': 'workspace:*',
114
114
  });
115
115
  e.set('packages/db/package.json', ['exports'], {
@@ -129,13 +129,13 @@ export function addCapabilityRecipe(e, id, name) {
129
129
  include: ['src/**/*.ts'],
130
130
  }));
131
131
  e.create('packages/db/eslint.config.mjs', "import { config } from '@workspace/eslint-config/base';\nexport default config;\n");
132
- e.create('packages/db/src/index.ts', "import { drizzle } from 'drizzle-orm/d1';\nimport * as schema from './schema';\nexport function createDatabase(binding: Parameters<typeof drizzle>[0]) { return drizzle(binding, { schema }); }\n");
133
- e.create('packages/db/src/schema.ts', template('auth-schema.ts.txt'));
134
- e.create('packages/db/drizzle/0000_better_auth.sql', template('auth-migration.sql.txt'));
135
- e.create('packages/db/drizzle/meta/0000_snapshot.json', template('auth-snapshot.json.txt'));
136
- e.create('packages/db/drizzle/meta/_journal.json', template('auth-journal.json.txt'));
137
- e.create('packages/db/drizzle.config.ts', "import { defineConfig } from 'drizzle-kit';\nexport default defineConfig({dialect:'sqlite', schema:'./src/schema.ts', out:'./drizzle'});\n");
138
- e.create('packages/db/src/migrate.mjs', "import { spawnSync } from 'node:child_process';\nimport { fileURLToPath } from 'node:url';\nconst args = process.argv.slice(2);\nif(args.length > 1 || args.some((v)=> !['--local','--remote'].includes(v))) throw Error('Use --local or explicitly --remote.');\nif(!process.env.npm_execpath) throw Error('Run through pnpm db:migrate.');\nconst cwd=fileURLToPath(new URL('../../../apps/api/',import.meta.url));\nconst result=spawnSync(process.execPath,[process.env.npm_execpath,'exec','wrangler','d1','migrations','apply','DB',args[0] ?? '--local'],{cwd,stdio:'inherit',shell:false});\nif(result.error)throw result.error;\nprocess.exitCode=result.status ?? 1;\n");
132
+ e.create('packages/db/src/index.ts', stackTemplate('db-index.ts.txt'));
133
+ e.create('packages/db/src/schema.ts', stackTemplate('auth-schema.ts.txt'));
134
+ e.create('packages/db/drizzle/0000_better_auth.sql', stackTemplate('auth-migration.sql.txt'));
135
+ e.create('packages/db/drizzle/meta/0000_snapshot.json', stackTemplate('auth-snapshot.json.txt'));
136
+ e.create('packages/db/drizzle/meta/_journal.json', stackTemplate('auth-journal.json.txt'));
137
+ e.create('packages/db/drizzle.config.ts', stackTemplate('drizzle.config.ts.txt'));
138
+ e.create('packages/db/src/migrate.mjs', stackTemplate('db-migrate.mjs.txt'));
139
139
  apiConfig(e, 'd1_databases', [
140
140
  {
141
141
  binding: 'DB',
@@ -146,15 +146,15 @@ export function addCapabilityRecipe(e, id, name) {
146
146
  ]);
147
147
  dependency(e, 'apps/api', {
148
148
  '@workspace/db': 'workspace:*',
149
- zod: D.zod,
150
- 'better-auth': P['better-auth'],
151
- '@better-auth/drizzle-adapter': P['@better-auth/drizzle-adapter'],
149
+ zod: STACK_DEPENDENCIES.zod,
150
+ 'better-auth': CAPABILITY_DEPENDENCIES['better-auth'],
151
+ '@better-auth/drizzle-adapter': CAPABILITY_DEPENDENCIES['@better-auth/drizzle-adapter'],
152
152
  });
153
- dependency(e, 'apps/web', { 'better-auth': P['better-auth'] });
154
- e.create('apps/api/src/auth.ts', template('auth.ts.txt'));
155
- e.create('apps/api/src/auth-features.ts', template('auth-features.ts.txt'));
156
- e.create('apps/api/src/security.ts', template('security.ts.txt'));
157
- e.create('apps/api/src/features/auth.ts', template('auth-routes.ts.txt'));
153
+ dependency(e, 'apps/web', { 'better-auth': CAPABILITY_DEPENDENCIES['better-auth'] });
154
+ e.create('apps/api/src/auth.ts', stackTemplate('auth.ts.txt'));
155
+ e.create('apps/api/src/auth-features.ts', stackTemplate('auth-features.ts.txt'));
156
+ e.create('apps/api/src/security.ts', stackTemplate('security.ts.txt'));
157
+ e.create('apps/api/src/features/auth.ts', stackTemplate('auth-routes.ts.txt'));
158
158
  addTanstackAuth(e);
159
159
  e.merge('package.json', 'scripts', {
160
160
  'db:generate': 'pnpm --dir packages/db db:generate',
@@ -167,22 +167,25 @@ export function addCapabilityRecipe(e, id, name) {
167
167
  break;
168
168
  }
169
169
  case 'r2':
170
+ e.create('apps/api/tests/storage.test.mjs', stackTemplate('storage.test.mjs.txt'));
171
+ e.create('apps/web/src/routes/storage.tsx', launchTemplate('storage-page.tsx.txt'));
170
172
  apiConfig(e, 'r2_buckets', [{ binding: 'FILES', bucket_name: resourceName(name, 'files') }]);
171
- e.create('apps/api/src/features/storage.ts', template('storage.ts.txt'));
173
+ e.create('apps/api/src/features/storage.ts', stackTemplate('storage.ts.txt'));
172
174
  break;
173
175
  case 'stripe':
174
- dependency(e, 'apps/api', { stripe: P.stripe });
175
- e.create('apps/api/src/features/stripe.ts', template('stripe.ts.txt'));
176
- e.create('apps/api/src/billing-mode.ts', template('billing-mode.ts.txt'));
177
- e.create('apps/api/src/features/entitlements.ts', template('entitlements.ts.txt'));
178
- e.create('apps/api/src/entitlement-guard.ts', template('entitlement-guard.ts.txt'));
179
- e.create('packages/db/src/billing-schema.ts', template('billing-schema.ts.txt'));
176
+ e.create('apps/api/tests/payment.test.mjs', stackTemplate('payment.test.mjs.txt'));
177
+ dependency(e, 'apps/api', { stripe: CAPABILITY_DEPENDENCIES.stripe });
178
+ e.create('apps/api/src/features/stripe.ts', stackTemplate('stripe.ts.txt'));
179
+ e.create('apps/api/src/billing-mode.ts', stackTemplate('billing-mode.ts.txt'));
180
+ e.create('apps/api/src/features/entitlements.ts', stackTemplate('entitlements.ts.txt'));
181
+ e.create('apps/api/src/entitlement-guard.ts', stackTemplate('entitlement-guard.ts.txt'));
182
+ e.create('packages/db/src/billing-schema.ts', stackTemplate('billing-schema.ts.txt'));
180
183
  schemaExport(e, 'billing-schema');
181
184
  break;
182
185
  }
183
186
  }
184
- export function composeCapabilities(e, installed) {
185
- composeTanstack(e, installed);
187
+ export function composeCapabilities(e, installed, operation = 'compose') {
188
+ composeTanstack(e, installed, operation === 'update');
186
189
  if (!installed.includes('hono'))
187
190
  return;
188
191
  const features = [
@@ -201,7 +204,7 @@ export function composeCapabilities(e, installed) {
201
204
  if (installed.includes('database-auth'))
202
205
  e.owned('apps/api/src/auth-platform.ts', 'export const platformAuthPlugins = () => [];\n');
203
206
  if (installed.includes('stripe'))
204
- e.owned('apps/api/src/billing-providers.ts', "import type {AppEnv} from './environment';\nimport {stripeEntitled} from './features/stripe';\nexport const billingProviders:Record<string,(env:AppEnv['Bindings'],userId:string)=>Promise<boolean>>={stripe:stripeEntitled};\n");
207
+ e.owned('apps/api/src/billing-providers.ts', stackTemplate('billing-providers.ts.txt'));
205
208
  const bindings = [
206
209
  'PUBLIC_APP_URL?: string',
207
210
  'BETTER_AUTH_SECRET?: string',
@@ -213,7 +216,14 @@ export function composeCapabilities(e, installed) {
213
216
  bindings.push('FILES: R2Bucket');
214
217
  if (installed.includes('stripe'))
215
218
  bindings.push('STRIPE_SECRET_KEY?: string', 'STRIPE_WEBHOOK_SECRET?: string', 'STRIPE_PRICE_ID?: string', 'BILLING_ENVIRONMENT?: string', 'BILLING_PROVIDER?: string');
216
- e.owned('apps/api/src/environment.ts', `import type { CustomBindings, CustomVariables } from './custom-environment';\nexport type AppEnv = { Bindings: CustomBindings & {${bindings.join(';\n')}}; Variables: CustomVariables & {userId:string;fileKey:string} };\n`);
219
+ e.owned('apps/api/src/environment.ts', `import type { CustomBindings, CustomVariables } from './custom-environment';\nexport type AppEnv = {
220
+ Bindings: CustomBindings & {
221
+ ${bindings.map((binding) => ` ${binding};`).join('\n')}
222
+ };
223
+ Variables: CustomVariables & { userId: string; fileKey: string };
224
+ };\n`);
225
+ if (operation === 'update')
226
+ return;
217
227
  appendExample(e, 'apps/api/.dev.vars.example', bindings
218
228
  .filter((binding) => binding.includes('string'))
219
229
  .map((binding) => binding.split('?')[0]));
@@ -9,8 +9,8 @@ import { CliFailure } from '../cli-errors.js';
9
9
  import { createReporter } from '../cli-output.js';
10
10
  import { assertPublicWorkspace, projectRoot, readState } from './command.js';
11
11
  import { CapabilityEditor, fingerprint } from './editor.js';
12
- import { normalizeOjFoundation } from '../scaffold/tanstack.js';
13
- import { composeSourceProvenance } from './composition.js';
12
+ import { composeCapabilities } from './recipes.js';
13
+ import { composeSourceProvenance, newerSourceMessage } from './composition.js';
14
14
  import { GENERATOR_VERSION } from '../version.js';
15
15
  import { runStagedTransaction } from '../transactions/transaction.js';
16
16
  import { put } from '../scaffold/files.js';
@@ -162,22 +162,15 @@ export function planStackUpdate(root, artifact) {
162
162
  (!isPublishedCliArtifact(artifact) || artifact.version !== GENERATOR_VERSION))
163
163
  throw Error('Only a verified published artifact matching this CLI can update deployment provenance.');
164
164
  assertPublicWorkspace(root, false, 'stack');
165
- const e = new CapabilityEditor(root, {});
165
+ const e = new CapabilityEditor(root, {}, 'update');
166
166
  const state = readState(e);
167
167
  Object.assign(e.managed, state.managedFiles);
168
168
  const configuration = e.json('anhedral.json');
169
169
  const previousVersion = configuration.composition.generatorVersion;
170
170
  const conflicts = [];
171
- if (typeof previousVersion === 'string') {
172
- const old = previousVersion.split(/[.-]/).slice(0, 3).map(Number);
173
- const current = GENERATOR_VERSION.split(/[.-]/).slice(0, 3).map(Number);
174
- const differing = old.findIndex((value, index) => value !== current[index]);
175
- if (differing >= 0 && old[differing] > current[differing])
176
- conflicts.push({
177
- code: 'NEWER_SOURCE',
178
- message: 'This source was generated by a newer CLI. Use that version or a newer published CLI; source downgrades are not supported.',
179
- });
180
- }
171
+ const newer = newerSourceMessage(previousVersion);
172
+ if (newer)
173
+ conflicts.push({ code: 'NEWER_SOURCE', message: newer });
181
174
  const attempt = (action) => {
182
175
  try {
183
176
  action();
@@ -196,7 +189,7 @@ export function planStackUpdate(root, artifact) {
196
189
  });
197
190
  attempt(() => {
198
191
  updateRootStylesheet(e);
199
- normalizeOjFoundation(e, state.installed, true);
192
+ composeCapabilities(e, state.installed, 'update');
200
193
  });
201
194
  attempt(() => updatePnpmPolicy(e));
202
195
  let artifactRequired = true;
@@ -342,5 +335,12 @@ export async function runStackUpdate(args, output, dependencies = {}) {
342
335
  if (plan.conflicts.length)
343
336
  process.exitCode = 1;
344
337
  const terminalSafe = (value) => stripVTControlCharacters(value.replace(/\r\n/g, '\n')).replace(/[\x00-\x08\x0b-\x1f\x7f]/g, '');
345
- createReporter(output, () => terminalSafe(`${applied ? 'Applied' : 'Preview'} source update ${plan.fromVersion ?? 'unknown'} → ${plan.toVersion}\nPlan: ${plan.planId}\n${plan.changes.map((change) => change.diff).join('\n')}${plan.conflicts.map((conflict) => conflict.message).join('\n')}\n${plan.nextAction}`)).result({ ...plan, dryRun: parsed.has('--dry-run'), applied });
338
+ const nextAction = plan.conflicts.length
339
+ ? 'Resolve the listed conflicts, then preview the update again.'
340
+ : !entries.length
341
+ ? 'Your generated stack files are up to date.'
342
+ : applied
343
+ ? 'Run pnpm install and pnpm check in the project directory.'
344
+ : `Apply this preview with pnpm dlx anhedral@${GENERATOR_VERSION} stack update${parsed.has('--offline') ? ' --offline' : ''} --expect-plan ${plan.planId}`;
345
+ createReporter(output, () => terminalSafe(`${applied ? 'Applied' : 'Preview'} source update ${plan.fromVersion ?? 'unknown'} → ${plan.toVersion}\nPlan: ${plan.planId}\n${plan.changes.map((change) => change.diff).join('\n')}${plan.conflicts.map((conflict) => conflict.message).join('\n')}\n${nextAction}`)).result({ ...plan, nextAction, dryRun: parsed.has('--dry-run'), applied });
346
346
  }
@@ -32,14 +32,13 @@ export declare const STACK_DEPENDENCIES: {
32
32
  readonly undici: "7.30.1";
33
33
  readonly stripe: "23.0.0";
34
34
  };
35
- export declare const WORKER_DEV_PORTS: {
36
- readonly api: {
37
- readonly http: 8787;
38
- readonly inspector: 9231;
39
- };
40
- };
41
35
  export declare const CAPABILITY_DEPENDENCIES: {
36
+ readonly tsx: "4.23.15";
42
37
  readonly 'better-auth': "1.7.7";
43
38
  readonly '@better-auth/drizzle-adapter': "1.7.7";
44
39
  readonly stripe: "23.0.0";
45
40
  };
41
+ export declare const SECURITY_OVERRIDES: {
42
+ readonly 'esbuild@0.18.20': "0.28.2";
43
+ readonly 'minimatch@10.2.6': "11.0.1";
44
+ };
@@ -85,12 +85,20 @@ export const STACK_DEPENDENCIES = {
85
85
  // renovate: datasource=npm depName=stripe
86
86
  stripe: '23.0.0',
87
87
  };
88
- export const WORKER_DEV_PORTS = { api: { http: 8787, inspector: 9231 } };
89
88
  // Backend, storage and payments extend the same Anhedral Stack foundation.
90
89
  export const CAPABILITY_DEPENDENCIES = {
90
+ tsx: '4.23.15',
91
91
  // renovate: datasource=npm depName=better-auth
92
92
  'better-auth': '1.7.7',
93
93
  // renovate: datasource=npm depName=@better-auth/drizzle-adapter
94
94
  '@better-auth/drizzle-adapter': '1.7.7',
95
95
  stripe: '23.0.0',
96
96
  };
97
+ // renovate: datasource=npm depName=esbuild
98
+ const DRIZZLE_ESBUILD_VERSION = '0.28.2';
99
+ // renovate: datasource=npm depName=minimatch
100
+ const ESLINT_MINIMATCH_VERSION = '11.0.1';
101
+ export const SECURITY_OVERRIDES = {
102
+ 'esbuild@0.18.20': DRIZZLE_ESBUILD_VERSION,
103
+ 'minimatch@10.2.6': ESLINT_MINIMATCH_VERSION,
104
+ };
package/dist/launch.d.ts CHANGED
@@ -17,7 +17,7 @@ export declare function launchPlan(options: LaunchOptions): {
17
17
  products: string[];
18
18
  stack: string;
19
19
  foundation: string;
20
- capabilities: ("hono" | "database-auth" | "r2" | "stripe")[];
20
+ capabilities: never[];
21
21
  targets: string[];
22
22
  dryRun: boolean;
23
23
  resourcesProvisioned: boolean;
package/dist/launch.js CHANGED
@@ -1,23 +1,23 @@
1
- import { existsSync, lstatSync, mkdirSync, readdirSync, realpathSync, rmdirSync } from 'node:fs';
2
- import { randomUUID } from 'node:crypto';
3
1
  import { spawnSync } from 'node:child_process';
2
+ import { randomUUID } from 'node:crypto';
3
+ import { existsSync, lstatSync, mkdirSync, readdirSync, realpathSync, rmdirSync } from 'node:fs';
4
4
  import path from 'node:path';
5
- import { scaffoldTanstack } from './scaffold/tanstack.js';
6
- import { bootstrapWorkspace, assertWorkspaceRuntime } from './scaffold/bootstrap.js';
7
- import { scaffoldStyling } from './scaffold/styling.js';
8
- import { json, put, sharedPackage } from './scaffold/files.js';
9
- import { CapabilityEditor } from './composition/editor.js';
10
- import { addCapabilityRecipe, composeCapabilities } from './composition/recipes.js';
5
+ import { CliArgumentError, commandArguments } from './cli-arguments.js';
6
+ import { printProgress, printResult } from './cli-output.js';
11
7
  import { launchCompositionSchema } from './composition/composition.js';
12
- import { runStagedTransaction } from './transactions/transaction.js';
8
+ import { CapabilityEditor } from './composition/editor.js';
9
+ import { composeCapabilities } from './composition/recipes.js';
10
+ import { PACKAGE_MANAGER, SECURITY_OVERRIDES, STACK_DEPENDENCIES, WORKSPACE_NODE_ENGINE, } from './dependencies.js';
13
11
  import { configureDependencyPatches, writeDependencyAudit } from './dependency-patches.js';
14
12
  import { setPnpmPolicy } from './pnpm-policy.js';
15
- import { GENERATOR_VERSION } from './version.js';
16
- import { PACKAGE_MANAGER, STACK_DEPENDENCIES, WORKSPACE_NODE_ENGINE } from './dependencies.js';
17
- import { execFile, appendGitignore } from './util.js';
18
- import { printProgress, printResult } from './cli-output.js';
19
- import { CliArgumentError, commandArguments } from './cli-arguments.js';
20
13
  import { packageNameFromText } from './render.js';
14
+ import { bootstrapWorkspace, assertWorkspaceRuntime } from './scaffold/bootstrap.js';
15
+ import { json, launchTemplate, put } from './scaffold/files.js';
16
+ import { scaffoldStyling } from './scaffold/styling.js';
17
+ import { scaffoldTanstack } from './scaffold/tanstack.js';
18
+ import { runStagedTransaction } from './transactions/transaction.js';
19
+ import { execFile, appendGitignore } from './util.js';
20
+ import { GENERATOR_VERSION } from './version.js';
21
21
  export function parseAnhedralStackOptions(args) {
22
22
  const parsed = commandArguments('init', args);
23
23
  const hasDirectory = parsed.positional.length > 0;
@@ -34,7 +34,6 @@ export function parseAnhedralStackOptions(args) {
34
34
  initializeGit: parsed.has('--git') || (!parsed.has('--no-git') && hasDirectory),
35
35
  };
36
36
  }
37
- const launchCapabilities = [];
38
37
  function rootFiles(root, name) {
39
38
  json(root, 'package.json', {
40
39
  name,
@@ -68,6 +67,7 @@ function rootFiles(root, name) {
68
67
  setPnpmPolicy(root, {
69
68
  packages: ['apps/*', 'packages/*'],
70
69
  sharedWorkspaceLockfile: true,
70
+ overrides: SECURITY_OVERRIDES,
71
71
  allowBuilds: { esbuild: true, workerd: true },
72
72
  });
73
73
  json(root, 'anhedral.json', {
@@ -90,7 +90,7 @@ function rootFiles(root, name) {
90
90
  foundation: 'tanstack-start',
91
91
  generatorVersion: GENERATOR_VERSION,
92
92
  identity: 'none',
93
- capabilities: Object.fromEntries(launchCapabilities.map((id) => [id, GENERATOR_VERSION])),
93
+ capabilities: {},
94
94
  }),
95
95
  });
96
96
  appendGitignore(root, 'node_modules/\ndist/\n.turbo/\n.wrangler/\n.tanstack/\n.oj-cache/\n*.tsbuildinfo\nworker-configuration.d.ts\n.dev.vars\n.dev.vars.*\n!.dev.vars.example\n.env\n.env.*\n!.env.example\n.anhedral/\n'
@@ -98,80 +98,16 @@ function rootFiles(root, name) {
98
98
  .split('\n'));
99
99
  writeDependencyAudit(root);
100
100
  }
101
- function documentation(root, name) {
102
- put(root, 'README.md', `# ${name}
103
-
104
- Anhedral Stack: web UI powered by OJ and TanStack Start server rendering/server functions
105
- and editable shadcn components.
106
- Only the web application is created initially. No backend or provider is provisioned.
107
-
108
- ## Develop
109
-
110
- Use the Node/pnpm versions in package.json. Run pnpm install if generation skipped
111
- installation, then pnpm dev and open http://localhost:3000. Run pnpm check and
112
- pnpm audit:deps before deployment. Editable routes live in apps/web/src/routes.
113
- Use cd apps/web && pnpm dlx shadcn@4.22.1 add card for more shadcn components.
114
- Shadcn is the default, not a restriction: use any UI library and preserve local edits.
115
- Keep LICENSE.shadcn with the copied starter components.
116
-
117
- ## Add services progressively
118
-
119
- Run anhedral add backend to add Hono, Drizzle/D1 and Better Auth together.
120
- Then run anhedral add storage for private storage, or anhedral add payment for payments.
121
- Missing prerequisites stop before writes; --with-dependencies opts into them.
122
- The public additions are backend, storage and payment; this application is web-only.
123
-
124
- After adding backend, copy apps/api/.dev.vars.example to apps/api/.dev.vars.
125
- Set PUBLIC_APP_URL=http://localhost:3000 and generate BETTER_AUTH_SECRET with
126
- \`node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"\`.
127
- Auth methods start disabled. Deliberately enable chosen methods in
128
- apps/api/src/auth-features.ts after configuring email/credentials and policies.
129
- Run pnpm db:migrate --local explicitly to initialize the isolated local D1 database,
130
- then pnpm dev. OJ runs the web and auxiliary API Workers with shared local
131
- persistence. Remote bindings are disabled for local development.
132
-
133
- R2 routes enforce authenticated owner access. Stripe adds schema and source only:
134
- run pnpm db:generate, review the SQL, then deliberately apply the local migration
135
- before exercising subscription/webhook flows. Configure Stripe test credentials,
136
- allowed prices and signed webhooks; activation and live payments are separate.
137
-
138
- ## Ownership and deployment
139
-
140
- Hono owns data, identity and private storage. Web server functions call its scoped
141
- service binding, never import another application's source or provider credentials.
142
- Custom API routes belong in apps/api/src/index.ts; schema/migrations in packages/db.
143
- Composition adapters are fingerprinted and customized files are never overwritten.
144
-
145
- Builds/startup never migrate databases. Provision D1/R2 only when selected and
146
- configure environment-specific resources/secrets separately. pnpm build emits web
147
- Worker artifacts under apps/web/dist and selected API artifacts under apps/api/dist. Anhedral Platform admission
148
- requires its separately reviewed Anhedral Stack runtime/artifact; generation is not activation.
149
- `);
150
- put(root, 'AGENTS.md', `# Anhedral Stack application
151
-
152
- Use the single Anhedral Stack, starting with TanStack Start and source-owned shadcn UI. Add backend for Hono,
153
- Drizzle/D1 and Better Auth together. Use the storage and payment additions only when required. Mobile,
154
- extensions and desktop are outside launch scope.
155
-
156
- Edit web product routes in apps/web/src/routes, API routes in apps/api/src/index.ts,
157
- and database schema in packages/db/src. Preserve customized composition adapters,
158
- semantic UI tokens and attribution. No cross-application source imports.
159
- Web server functions receive scoped API bindings through request context; keep
160
- identity, database/storage access and secrets inside Hono. Auth methods require
161
- explicit activation. Run pnpm check and pnpm audit:deps. Never migrate a configured
162
- database in builds/tests/startup; apply reviewed SQL deliberately to isolated fixtures.
163
- `);
164
- }
165
101
  export function launchPlan(options) {
166
102
  return {
167
103
  schemaVersion: 1,
168
104
  cliVersion: GENERATOR_VERSION,
169
105
  root: options.root,
170
106
  name: options.name,
171
- products: ['tanstack-start', ...launchCapabilities],
107
+ products: ['tanstack-start'],
172
108
  stack: 'anhedral-stack',
173
109
  foundation: 'tanstack-start',
174
- capabilities: [...launchCapabilities],
110
+ capabilities: [],
175
111
  targets: ['apps/web'],
176
112
  dryRun: options.dryRun,
177
113
  resourcesProvisioned: false,
@@ -215,25 +151,24 @@ export async function scaffoldLaunchProject(options, run = execFile, output = {}
215
151
  prepare: () => assertEmpty(true),
216
152
  build: async (stage) => {
217
153
  printProgress('Creating the Anhedral Stack…', display);
218
- bootstrapWorkspace(stage, options.name, run);
154
+ bootstrapWorkspace(stage);
219
155
  rootFiles(stage, options.name);
220
- sharedPackage(stage, 'styling', "export { light, dark, spacing } from './tokens.cjs';\n", {});
221
- scaffoldStyling({ root: stage });
156
+ scaffoldStyling(stage);
222
157
  scaffoldTanstack(stage, options.name);
223
158
  const editor = new CapabilityEditor(stage, {});
224
- const installed = [];
225
- for (const capability of installed)
226
- addCapabilityRecipe(editor, capability, options.name);
227
- composeCapabilities(editor, installed);
159
+ composeCapabilities(editor, []);
228
160
  editor.set('anhedral.json', ['capabilities'], {
229
161
  schemaVersion: 1,
230
- installed,
162
+ installed: [],
231
163
  managedFiles: editor.managed,
232
164
  resourcesProvisionedByCli: false,
233
165
  });
234
166
  for (const [file, source] of editor.writes)
235
167
  put(stage, file, source);
236
- documentation(stage, options.name);
168
+ put(stage, 'README.md', launchTemplate('README.md.txt')
169
+ .replace('__CLI_VERSION__', GENERATOR_VERSION)
170
+ .replace('__APP_NAME__', () => options.name.replace(/[\r\n]+/g, ' ')));
171
+ put(stage, 'AGENTS.md', launchTemplate('AGENTS.md.txt'));
237
172
  if (!options.skipInstall) {
238
173
  printProgress('Resolving Anhedral Stack dependencies…', display);
239
174
  run('pnpm', ['install', '--lockfile-only', '--no-frozen-lockfile'], stage);
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
- import { constants } from 'node:fs';
2
+ import { readBoundedFile } from '../bounded-file.js';
3
3
  import { join, resolve } from 'node:path';
4
4
  import { z } from 'zod';
5
5
  import { commandArgumentError } from '../cli-arguments.js';
@@ -58,21 +58,13 @@ export async function runDeploy({ options, origin, actor, token, stateDir, link,
58
58
  const file = options.value('--manifest');
59
59
  if (!file)
60
60
  throw commandArgumentError(command, 'Use deploy plan --manifest <file>.');
61
- const handle = await import('node:fs/promises').then((fs) => fs.open(resolve(file), constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK));
61
+ const source = readBoundedFile(resolve(file), 32768);
62
62
  let manifest;
63
63
  try {
64
- const info = await handle.stat();
65
- if (!info.isFile() || info.size > 32768)
66
- throw platformFailure('Deployment manifest exceeds its limit.');
67
- try {
68
- manifest = JSON.parse(await handle.readFile('utf8'));
69
- }
70
- catch {
71
- throw commandArgumentError(command, 'The deployment manifest is not valid JSON. Review it before retrying.');
72
- }
64
+ manifest = JSON.parse(source.toString('utf8'));
73
65
  }
74
- finally {
75
- await handle.close();
66
+ catch {
67
+ throw commandArgumentError(command, 'The deployment manifest is not valid JSON. Review it before retrying.');
76
68
  }
77
69
  const checkedManifest = deploymentManifestSchema.safeParse(manifest);
78
70
  if (!checkedManifest.success)
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { closeSync, constants, fstatSync, lstatSync, openSync, readSync } from 'node:fs';
3
- import { dirname, join, resolve } from 'node:path';
2
+ import { closeSync, constants, existsSync, fstatSync, lstatSync, openSync, readSync, } from 'node:fs';
3
+ import { basename, dirname, join, resolve } from 'node:path';
4
4
  import { z } from 'zod';
5
5
  import { commandArgumentError, commandArguments } from '../cli-arguments.js';
6
6
  import { createReporter } from '../cli-output.js';
@@ -30,10 +30,17 @@ const planSchema = z
30
30
  .strict();
31
31
  export function readEnvironmentSecret(file) {
32
32
  const path = resolve(file);
33
+ const cwd = lstatSync('.');
34
+ let excluded = /^(?:\.env|\.dev\.vars)/i.test(basename(path));
33
35
  for (let parent = dirname(path);; parent = dirname(parent)) {
34
36
  const info = lstatSync(parent);
35
37
  if (!info.isDirectory() || info.isSymbolicLink())
36
38
  throw platformFailure('Environment input has a symlinked or invalid directory.');
39
+ if (!excluded &&
40
+ ((info.dev === cwd.dev && info.ino === cwd.ino) || existsSync(join(parent, 'anhedral.json'))))
41
+ throw platformFailure('Environment input inside a project must use an excluded .env file or .anhedral directory. Use --stdin or a private file outside the project.');
42
+ if (basename(parent).toLowerCase() === '.anhedral')
43
+ excluded = true;
37
44
  if (dirname(parent) === parent)
38
45
  break;
39
46
  }
@@ -41,6 +48,7 @@ export function readEnvironmentSecret(file) {
41
48
  try {
42
49
  const info = fstatSync(descriptor);
43
50
  if (!info.isFile() ||
51
+ info.nlink !== 1 ||
44
52
  info.size > ENVIRONMENT_FILE_MAX_BYTES ||
45
53
  (process.platform !== 'win32' &&
46
54
  (info.uid !== process.getuid?.() || (info.mode & 0o077) !== 0)))
@@ -1,3 +1,5 @@
1
+ import { type FileHandle } from 'node:fs/promises';
2
+ export declare function anchoredDirectory(handle: FileHandle): Promise<string>;
1
3
  export declare function packageSource(root: string): Promise<{
2
4
  archive: Uint8Array<ArrayBuffer>;
3
5
  inventoryDigest: string;