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,18 +1,39 @@
1
1
  import ignore from 'ignore';
2
+ import { readBoundedFile } from '../bounded-file.js';
2
3
  import { constants } from 'node:fs';
3
- import { lstat, open, readFile, readdir } from 'node:fs/promises';
4
- import { join } from 'node:path';
4
+ import { lstat, open, readdir, stat } from 'node:fs/promises';
5
+ import { join, resolve } from 'node:path';
5
6
  import { sourceContainsCredential as localCredentialMaterial } from '../../assets/security/credential-patterns.mjs';
6
7
  import { SOURCE_LIMITS, sourceContainsCredential, uploadExcluded, uploadSecret, } from '../contracts/cli-transport.js';
7
8
  import { packSource, setSourceExecutable, sourceInventory, validateSourcePath, } from '../contracts/source-bundle.js';
8
9
  import { excludedSource, generatedSource, secretSource } from '../contracts/source-profile.js';
9
10
  import { platformFailure } from './state.js';
11
+ // Keep the directory open throughout all child lookups. These OS namespaces
12
+ // address the open object even if a writer renames its original directory.
13
+ export async function anchoredDirectory(handle) {
14
+ const identity = await handle.stat({ bigint: true });
15
+ const path = process.platform === 'linux'
16
+ ? '/proc/self/fd/' + handle.fd
17
+ : '/.vol/' + identity.dev + '/' + identity.ino;
18
+ const resolved = await stat(path, { bigint: true }).catch(() => null);
19
+ if (!identity.isDirectory() || identity.dev !== resolved?.dev || identity.ino !== resolved.ino)
20
+ throw platformFailure('This filesystem cannot safely anchor source directories for upload.');
21
+ return path;
22
+ }
10
23
  export async function packageSource(root) {
24
+ if (!['linux', 'darwin'].includes(process.platform))
25
+ throw platformFailure('Source packaging requires Linux procfs or a macOS volume supporting directory IDs. On Windows, run the CLI inside WSL.');
26
+ const directoryFlags = constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW;
11
27
  const files = new Map();
12
28
  let bytes = 0;
13
- async function walk(relative, rules) {
14
- const directory = join(root, relative);
15
- const gitignore = await lstat(join(directory, '.gitignore')).catch(() => null);
29
+ async function walk(handle, relative, rules) {
30
+ const directory = await anchoredDirectory(handle);
31
+ const ignorePath = join(directory, '.gitignore');
32
+ const gitignore = await lstat(ignorePath).catch((error) => {
33
+ if (error.code === 'ENOENT')
34
+ return null;
35
+ throw error;
36
+ });
16
37
  if (gitignore && (!gitignore.isFile() || gitignore.isSymbolicLink()))
17
38
  throw platformFailure('Source ignore file is unsafe.');
18
39
  if (gitignore) {
@@ -22,13 +43,17 @@ export async function packageSource(root) {
22
43
  ...rules,
23
44
  {
24
45
  base: relative,
25
- matcher: ignore().add(await readFile(join(directory, '.gitignore'), 'utf8')),
46
+ matcher: ignore().add(readBoundedFile(ignorePath, 65536, (opened) => {
47
+ if (opened.dev !== gitignore.dev || opened.ino !== gitignore.ino)
48
+ throw platformFailure('Source ignore file changed during packaging.');
49
+ }).toString('utf8')),
26
50
  },
27
51
  ];
28
52
  }
29
53
  for (const entry of (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
30
54
  const path = relative ? `${relative}/${entry.name}` : entry.name;
31
- if (excludedSource.test(path) ||
55
+ if (/^(?:\.env|\.dev\.vars|\.anhedral$)/i.test(entry.name) ||
56
+ excludedSource.test(path) ||
32
57
  generatedSource.test(path) ||
33
58
  secretSource.test(path) ||
34
59
  uploadExcluded.test(path) ||
@@ -44,17 +69,27 @@ export async function packageSource(root) {
44
69
  }
45
70
  if (ignored)
46
71
  continue;
47
- const info = await lstat(join(root, path));
72
+ const childPath = join(directory, entry.name);
73
+ const info = await lstat(childPath);
48
74
  if (info.isSymbolicLink() || (!info.isFile() && !info.isDirectory()))
49
75
  throw platformFailure('Source contains a symbolic link or special file. Exclude it before uploading.');
50
76
  validateSourcePath(path);
51
77
  if (info.isDirectory()) {
52
- await walk(path, rules);
78
+ const child = await open(childPath, directoryFlags);
79
+ try {
80
+ const opened = await child.stat();
81
+ if (opened.dev !== info.dev || opened.ino !== info.ino)
82
+ throw platformFailure('Source directory changed during packaging.');
83
+ await walk(child, path, rules);
84
+ }
85
+ finally {
86
+ await child.close();
87
+ }
53
88
  continue;
54
89
  }
55
90
  if (files.size >= SOURCE_LIMITS.files || (bytes += info.size) > SOURCE_LIMITS.bytes)
56
91
  throw platformFailure('Source exceeds its file or byte limit.');
57
- const handle = await open(join(root, path), constants.O_RDONLY | constants.O_NOFOLLOW);
92
+ const handle = await open(childPath, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
58
93
  let content;
59
94
  try {
60
95
  const before = await handle.stat();
@@ -86,7 +121,13 @@ export async function packageSource(root) {
86
121
  setSourceExecutable(files, path, Boolean(info.mode & 0o111));
87
122
  }
88
123
  }
89
- await walk('', []);
124
+ const rootHandle = await open(resolve(root) === process.cwd() ? '.' : root, directoryFlags);
125
+ try {
126
+ await walk(rootHandle, '', []);
127
+ }
128
+ finally {
129
+ await rootHandle.close();
130
+ }
90
131
  const config = files.get('anhedral.json');
91
132
  if (!config || !files.has('pnpm-lock.yaml'))
92
133
  throw platformFailure('Upload requires anhedral.json and pnpm-lock.yaml.');
@@ -1,7 +1,8 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { createHash, randomUUID } from 'node:crypto';
3
- import { lstat, mkdir, open, readFile, rename, unlink, writeFile } from 'node:fs/promises';
3
+ import { lstat, mkdir, open, rename, unlink, writeFile } from 'node:fs/promises';
4
4
  import { dirname, join } from 'node:path';
5
+ import { readBoundedFile } from '../bounded-file.js';
5
6
  import { CliArgumentError } from '../cli-arguments.js';
6
7
  import { CliFailure } from '../cli-errors.js';
7
8
  import { trustedLinuxCredentialHelper } from './credential-helper.js';
@@ -65,7 +66,13 @@ export async function readPrivate(path) {
65
66
  info.size > 65536 ||
66
67
  (process.platform !== 'win32' && ((info.mode & 0o077) !== 0 || info.uid !== process.getuid?.())))
67
68
  throw platformFailure('State file must be owned by you with mode 0600.');
68
- const text = await readFile(path, 'utf8');
69
+ const text = readBoundedFile(path, 65536, (opened) => {
70
+ if (opened.dev !== info.dev ||
71
+ opened.ino !== info.ino ||
72
+ (process.platform !== 'win32' &&
73
+ ((opened.mode & 0o077) !== 0 || opened.uid !== process.getuid?.())))
74
+ throw platformFailure('State file changed or has unsafe permissions.');
75
+ }).toString('utf8');
69
76
  try {
70
77
  return JSON.parse(text);
71
78
  }
@@ -2,3 +2,4 @@
2
2
  export declare function setPnpmPolicy(root: string, policy: Record<string, unknown>): void;
3
3
  /** Extend a pnpm patch map without replacing unrelated patches or YAML comments. */
4
4
  export declare function pnpmPatchPolicy(source: string, coordinate: string, patch: string): string;
5
+ export declare function secureWorkspacePolicy(source: string): string;
@@ -1,3 +1,4 @@
1
+ import { SECURITY_OVERRIDES } from './dependencies.js';
1
2
  import { existsSync, readFileSync } from 'node:fs';
2
3
  import path from 'node:path';
3
4
  import { writeFile } from './util.js';
@@ -38,3 +39,29 @@ export function pnpmPatchPolicy(source, coordinate, patch) {
38
39
  mapping.set(coordinate, patch);
39
40
  return document.toString({ lineWidth: 0 });
40
41
  }
42
+ export function secureWorkspacePolicy(source) {
43
+ const document = parseDocument(source);
44
+ if (document.errors.length || !isMap(document.contents))
45
+ throw Error('Invalid pnpm workspace YAML; review dependency overrides.');
46
+ if (!document.has('overrides')) {
47
+ const newline = source.includes('\r\n') ? '\r\n' : '\n';
48
+ return (source +
49
+ (source.endsWith('\n') ? '' : newline) +
50
+ 'overrides: ' +
51
+ JSON.stringify(SECURITY_OVERRIDES) +
52
+ newline);
53
+ }
54
+ const overrides = document.get('overrides', true);
55
+ if (!isMap(overrides))
56
+ throw Error('Expected an explicit pnpm overrides mapping.');
57
+ let changed = false;
58
+ for (const [selector, version] of Object.entries(SECURITY_OVERRIDES)) {
59
+ if (overrides.get(selector) === version)
60
+ continue;
61
+ if (overrides.has(selector))
62
+ throw Error('Review conflicting pnpm override for ' + selector);
63
+ overrides.set(selector, version);
64
+ changed = true;
65
+ }
66
+ return changed ? document.toString({ lineWidth: 0 }) : source;
67
+ }
package/dist/render.d.ts CHANGED
@@ -1,14 +1,4 @@
1
- /** Serialize an arbitrary value as a JavaScript/TypeScript string literal. */
2
- export declare function jsString(value: string): string;
3
- /** Escape text placed directly in HTML rather than in a JS string. */
4
- export declare function htmlText(value: string): string;
5
- /** Keep generated Markdown headings on one line and prevent heading/code injection. */
6
- export declare function markdownHeading(value: string): string;
7
1
  /** Derive a valid, deterministic unscoped npm package name from arbitrary text. */
8
2
  export declare function packageNameFromText(value: string): string;
9
- export declare function childPackageName(projectName: string, suffix: string): string;
10
- export declare function identifierSegment(value: string): string;
11
- /** Provider identity is separate from the npm package/directory name. */
12
- export declare function providerProjectName(value: string): string;
13
3
  /** Keep provider resource names within the shared Workers/R2/Queues naming limits. */
14
4
  export declare function resourceName(projectName: string, suffix: string): string;
package/dist/render.js CHANGED
@@ -2,24 +2,6 @@ import { createHash } from 'node:crypto';
2
2
  const PACKAGE_NAME_PATTERN = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
3
3
  const MAX_PACKAGE_NAME_LENGTH = 214;
4
4
  const RESERVED_PACKAGE_NAMES = new Set(['node_modules', 'favicon.ico']);
5
- /** Serialize an arbitrary value as a JavaScript/TypeScript string literal. */
6
- export function jsString(value) {
7
- return JSON.stringify(value);
8
- }
9
- /** Escape text placed directly in HTML rather than in a JS string. */
10
- export function htmlText(value) {
11
- return value
12
- .replace(/&/g, '&amp;')
13
- .replace(/</g, '&lt;')
14
- .replace(/>/g, '&gt;')
15
- .replace(/"/g, '&quot;')
16
- .replace(/'/g, '&#39;');
17
- }
18
- /** Keep generated Markdown headings on one line and prevent heading/code injection. */
19
- export function markdownHeading(value) {
20
- const normalized = value.replace(/[\r\n]+/g, ' ').trim() || 'Anhedral App';
21
- return normalized.replace(/([\\`*_{}\[\]()<>#+.!|~-])/g, '\\$1');
22
- }
23
5
  function assertPackageName(value) {
24
6
  const leafName = value.slice(value.lastIndexOf('/') + 1);
25
7
  if (value.length > MAX_PACKAGE_NAME_LENGTH ||
@@ -32,8 +14,6 @@ function assertPackageName(value) {
32
14
  function compactPackageSegment(value, maximumLength) {
33
15
  if (value.length <= maximumLength)
34
16
  return value;
35
- if (maximumLength <= 9)
36
- return value.slice(0, maximumLength).replace(/[._-]+$/g, '') || 'a';
37
17
  const digest = createHash('sha256').update(value, 'utf8').digest('hex').slice(0, 8);
38
18
  const prefix = value.slice(0, maximumLength - digest.length - 1).replace(/[._-]+$/g, '') || 'app';
39
19
  return `${prefix}-${digest}`;
@@ -53,18 +33,7 @@ export function packageNameFromText(value) {
53
33
  normalized = `anhedral-${normalized}`;
54
34
  return assertPackageName(compactPackageSegment(normalized, MAX_PACKAGE_NAME_LENGTH));
55
35
  }
56
- export function childPackageName(projectName, suffix) {
57
- assertPackageName(projectName);
58
- const normalizedSuffix = packageNameFromText(suffix);
59
- const separator = projectName.lastIndexOf('/');
60
- if (separator >= 0) {
61
- const scope = projectName.slice(0, separator + 1);
62
- const leaf = compactPackageSegment(`${projectName.slice(separator + 1)}-${normalizedSuffix}`, MAX_PACKAGE_NAME_LENGTH - scope.length);
63
- return assertPackageName(`${scope}${leaf}`);
64
- }
65
- return assertPackageName(compactPackageSegment(`${projectName}-${normalizedSuffix}`, MAX_PACKAGE_NAME_LENGTH));
66
- }
67
- export function identifierSegment(value) {
36
+ function identifierSegment(value) {
68
37
  const segment = value
69
38
  .normalize('NFKD')
70
39
  .toLowerCase()
@@ -72,12 +41,6 @@ export function identifierSegment(value) {
72
41
  .replace(/^-+|-+$/g, '');
73
42
  return segment || 'app';
74
43
  }
75
- /** Provider identity is separate from the npm package/directory name. */
76
- export function providerProjectName(value) {
77
- const normalized = identifierSegment(value);
78
- const digest = createHash('sha256').update(value).digest('hex').slice(0, 8);
79
- return compactPackageSegment(normalized === value ? normalized : `${normalized}-${digest}`, 63);
80
- }
81
44
  /** Keep provider resource names within the shared Workers/R2/Queues naming limits. */
82
45
  export function resourceName(projectName, suffix) {
83
46
  const segment = identifierSegment(projectName);
@@ -1,4 +1,3 @@
1
1
  import type { CommandRunner } from '../command-types.js';
2
2
  export declare function assertWorkspaceRuntime(run: CommandRunner, version?: string): void;
3
- /** No downloaded template, disposable Next app or initialization-time cloud operation. */
4
- export declare function bootstrapWorkspace(root: string, name: string, run: CommandRunner): void;
3
+ export declare function bootstrapWorkspace(root: string): void;
@@ -1,16 +1,12 @@
1
+ import { STACK_DEPENDENCIES } from '../dependencies.js';
1
2
  import { supportsWorkspaceRuntime } from '../runtime-policy.js';
2
3
  import { execFile } from '../util.js';
3
- import { STACK_DEPENDENCIES } from '../dependencies.js';
4
- import { json, put } from './files.js';
4
+ import { json, put, stackTemplate } from './files.js';
5
5
  export function assertWorkspaceRuntime(run, version = process.versions.node) {
6
6
  if (run === execFile && !supportsWorkspaceRuntime(version))
7
7
  throw new Error('Generated workspaces require Node.js 22.13+ on the 22.x line or Node.js 24+.');
8
8
  }
9
- /** No downloaded template, disposable Next app or initialization-time cloud operation. */
10
- export function bootstrapWorkspace(root, name, run) {
11
- assertWorkspaceRuntime(run);
12
- json(root, 'package.json', { name, private: true });
13
- put(root, 'pnpm-workspace.yaml', 'packages:\n - apps/*\n - packages/*\n');
9
+ export function bootstrapWorkspace(root) {
14
10
  json(root, 'packages/typescript-config/package.json', {
15
11
  name: '@workspace/typescript-config',
16
12
  private: true,
@@ -37,6 +33,6 @@ export function bootstrapWorkspace(root, name, run) {
37
33
  '@typescript-eslint/eslint-plugin': STACK_DEPENDENCIES['@typescript-eslint/eslint-plugin'],
38
34
  },
39
35
  });
40
- put(root, 'packages/eslint-config/base.js', "import parser from '@typescript-eslint/parser';\nimport plugin from '@typescript-eslint/eslint-plugin';\nexport const config = [{ ignores: ['dist/**', '.output/**', '.wrangler/**', 'worker-configuration.d.ts'] }, { files: ['**/*.{ts,tsx,cts,mts}'], languageOptions: { parser, parserOptions: { ecmaFeatures: { jsx: true } } }, plugins: { '@typescript-eslint': plugin }, rules: { ...plugin.configs.recommended.rules, 'no-undef': 'off', 'no-unused-vars': 'off', '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }] } }];\n");
36
+ put(root, 'packages/eslint-config/base.js', stackTemplate('base-eslint.js.txt'));
41
37
  put(root, 'packages/eslint-config/react-internal.js', "export { config } from './base.js';\n");
42
38
  }
@@ -1,26 +1,14 @@
1
- export type Json = Record<string, unknown>;
2
- export interface PackageManifest extends Json {
3
- name?: string;
4
- packageManager?: string;
5
- scripts?: Record<string, string>;
6
- dependencies?: Record<string, string>;
7
- devDependencies?: Record<string, string>;
8
- pnpm?: {
9
- overrides?: Record<string, string>;
10
- };
11
- }
12
- export interface TurboConfig extends Json {
13
- globalEnv?: string[];
14
- tasks: Record<string, {
15
- dependsOn?: string[];
16
- outputs?: string[];
17
- [key: string]: unknown;
18
- }>;
19
- }
20
- export declare function readJson<T extends Json = Json>(root: string, file: string): T;
1
+ export declare function launchTemplate(name: string): string;
2
+ export declare function stackTemplate(name: string): string;
21
3
  export declare function json(root: string, file: string, value: unknown): void;
22
4
  export declare function put(root: string, file: string, value: string): void;
23
- export declare function patchPackage(root: string, file: string, patch: PackageManifest): void;
24
- export declare function workerConfig(name: string): Json;
25
- export declare function worker(root: string, app: string, config: Json, source: string, dependencies?: Record<string, string>): void;
26
- export declare function sharedPackage(root: string, name: string, source: string, dependencies: Record<string, string>): void;
5
+ export declare function workerConfig(name: string, main: string, compatibilityDate: string): {
6
+ $schema: string;
7
+ name: string;
8
+ main: string;
9
+ compatibility_date: string;
10
+ compatibility_flags: string[];
11
+ observability: {
12
+ enabled: boolean;
13
+ };
14
+ };
@@ -1,20 +1,11 @@
1
- import { STACK_DEPENDENCIES, WORKER_DEV_PORTS } from '../dependencies.js';
2
- import { readBoundedFile, MAX_PROJECT_JSON_BYTES } from '../bounded-file.js';
1
+ import { readFileSync } from 'node:fs';
3
2
  import path from 'node:path';
4
3
  import { writeFile } from '../util.js';
5
- export function readJson(root, file) {
6
- let value;
7
- try {
8
- value = JSON.parse(readBoundedFile(path.join(root, file), MAX_PROJECT_JSON_BYTES).toString('utf8'));
9
- }
10
- catch (error) {
11
- if (error instanceof SyntaxError)
12
- throw new Error(`Invalid JSON in ${file}.`);
13
- throw error;
14
- }
15
- if (!value || typeof value !== 'object' || Array.isArray(value))
16
- throw new Error(`Expected a JSON object: ${file}.`);
17
- return value;
4
+ export function launchTemplate(name) {
5
+ return readFileSync(new URL(`../../assets/launch/${name}`, import.meta.url), 'utf8');
6
+ }
7
+ export function stackTemplate(name) {
8
+ return readFileSync(new URL(`../../assets/stack/${name}`, import.meta.url), 'utf8');
18
9
  }
19
10
  export function json(root, file, value) {
20
11
  writeFile(path.join(root, file), JSON.stringify(value, null, 2) + '\n');
@@ -22,98 +13,13 @@ export function json(root, file, value) {
22
13
  export function put(root, file, value) {
23
14
  writeFile(path.join(root, file), value);
24
15
  }
25
- export function patchPackage(root, file, patch) {
26
- const current = readJson(root, file);
27
- const merged = { ...current, ...patch };
28
- for (const key of ['scripts', 'dependencies', 'devDependencies']) {
29
- if (patch[key])
30
- merged[key] = { ...current[key], ...patch[key] };
31
- }
32
- json(root, file, merged);
33
- }
34
- export function workerConfig(name) {
16
+ export function workerConfig(name, main, compatibilityDate) {
35
17
  return {
36
18
  $schema: 'node_modules/wrangler/config-schema.json',
37
19
  name,
38
- main: 'src/index.ts',
39
- compatibility_date: '2026-10-05',
20
+ main,
21
+ compatibility_date: compatibilityDate,
40
22
  compatibility_flags: ['nodejs_compat'],
41
23
  observability: { enabled: true },
42
24
  };
43
25
  }
44
- export function worker(root, app, config, source, dependencies = {}) {
45
- const ports = WORKER_DEV_PORTS[app];
46
- if (!ports)
47
- throw new Error(`Unknown Worker application: ${app}.`);
48
- json(root, `apps/${app}/package.json`, {
49
- name: `@workspace/${app}`,
50
- private: true,
51
- type: 'module',
52
- scripts: {
53
- dev: `wrangler dev --port ${ports.http} --inspector-port ${ports.inspector}`,
54
- build: 'wrangler deploy --dry-run --outdir dist',
55
- deploy: 'wrangler deploy',
56
- typecheck: 'wrangler types && tsc --noEmit',
57
- lint: 'eslint . --max-warnings 0',
58
- },
59
- dependencies,
60
- devDependencies: {
61
- wrangler: STACK_DEPENDENCIES['wrangler'],
62
- typescript: STACK_DEPENDENCIES['typescript'],
63
- '@types/node': STACK_DEPENDENCIES['@types/node'],
64
- eslint: STACK_DEPENDENCIES['eslint'],
65
- '@workspace/eslint-config': 'workspace:*',
66
- },
67
- });
68
- json(root, `apps/${app}/wrangler.jsonc`, config);
69
- json(root, `apps/${app}/tsconfig.json`, {
70
- compilerOptions: {
71
- target: 'ES2022',
72
- lib: ['ES2022'],
73
- module: 'ESNext',
74
- moduleResolution: 'Bundler',
75
- strict: true,
76
- noUnusedLocals: true,
77
- noUnusedParameters: true,
78
- skipLibCheck: true,
79
- noEmit: true,
80
- types: ['node'],
81
- },
82
- include: ['src/**/*.ts', 'worker-configuration.d.ts'],
83
- });
84
- put(root, `apps/${app}/eslint.config.mjs`, 'import { config } from "@workspace/eslint-config/base";\nexport default [...config, { ignores: ["dist/**", ".wrangler/**", "worker-configuration.d.ts"] }, { files: ["**/*.ts"], rules: { "no-undef": "off", "no-unused-vars": "off" } }];\n');
85
- put(root, `apps/${app}/src/index.ts`, source);
86
- }
87
- export function sharedPackage(root, name, source, dependencies) {
88
- json(root, `packages/${name}/package.json`, {
89
- name: `@workspace/${name}`,
90
- private: true,
91
- type: 'module',
92
- exports: { '.': './src/index.ts' },
93
- scripts: { typecheck: 'tsc --noEmit', lint: 'eslint . --max-warnings 0' },
94
- dependencies,
95
- devDependencies: {
96
- typescript: STACK_DEPENDENCIES['typescript'],
97
- '@types/node': STACK_DEPENDENCIES['@types/node'],
98
- eslint: STACK_DEPENDENCIES['eslint'],
99
- '@workspace/eslint-config': 'workspace:*',
100
- },
101
- });
102
- json(root, `packages/${name}/tsconfig.json`, {
103
- compilerOptions: {
104
- target: 'ES2022',
105
- lib: ['ES2022', 'DOM'],
106
- module: 'ESNext',
107
- moduleResolution: 'Bundler',
108
- strict: true,
109
- noUnusedLocals: true,
110
- noUnusedParameters: true,
111
- skipLibCheck: true,
112
- noEmit: true,
113
- types: ['node'],
114
- },
115
- include: ['src/**/*.ts'],
116
- });
117
- put(root, `packages/${name}/eslint.config.mjs`, 'import { config } from "@workspace/eslint-config/base";\nexport default [...config, { ignores: ["dist/**", ".wrangler/**", "worker-configuration.d.ts"] }, { files: ["**/*.ts"], rules: { "no-undef": "off", "no-unused-vars": "off" } }];\n');
118
- put(root, `packages/${name}/src/index.ts`, source);
119
- }
@@ -1,4 +1,2 @@
1
- /** One shared token source for native components and DOM CSS. */
2
- export declare function scaffoldStyling({ root }: {
3
- root: string;
4
- }): void;
1
+ /** Generate CSS from the same tokens the styling package exports. */
2
+ export declare function scaffoldStyling(root: string): void;
@@ -1,76 +1,53 @@
1
1
  import { createRequire } from 'node:module';
2
- import path from 'node:path';
3
- import { json, patchPackage, put, readJson } from './files.js';
4
- /** One shared token source for native components and DOM CSS. */
5
- export function scaffoldStyling({ root }) {
6
- put(root, 'packages/styling/src/tokens.cjs', `exports.light = {
7
- '--background': '0 0% 100%',
8
- '--foreground': '0 0% 9%',
9
- '--card': '0 0% 100%',
10
- '--card-foreground': '0 0% 9%',
11
- '--popover': '0 0% 100%',
12
- '--popover-foreground': '0 0% 9%',
13
- '--primary': '0 0% 9%',
14
- '--primary-foreground': '0 0% 98%',
15
- '--secondary': '0 0% 96.1%',
16
- '--secondary-foreground': '0 0% 9%',
17
- '--muted': '0 0% 96.1%',
18
- '--muted-foreground': '0 0% 45.1%',
19
- '--accent': '0 0% 96.1%',
20
- '--accent-foreground': '0 0% 9%',
21
- '--destructive': '0 84.2% 60.2%',
22
- '--destructive-foreground': '0 0% 98%',
23
- '--border': '0 0% 89.8%',
24
- '--input': '0 0% 89.8%',
25
- '--ring': '0 0% 63.9%',
26
- '--radius': '0.5rem',
27
- };
28
-
29
- exports.dark = {
30
- ...exports.light,
31
- '--background': '0 0% 9%',
32
- '--foreground': '0 0% 98%',
33
- '--card': '0 0% 9%',
34
- '--card-foreground': '0 0% 98%',
35
- '--popover': '0 0% 9%',
36
- '--popover-foreground': '0 0% 98%',
37
- '--primary': '0 0% 98%',
38
- '--primary-foreground': '0 0% 9%',
39
- '--secondary': '0 0% 14.9%',
40
- '--secondary-foreground': '0 0% 98%',
41
- '--muted': '0 0% 14.9%',
42
- '--muted-foreground': '0 0% 63.9%',
43
- '--accent': '0 0% 14.9%',
44
- '--accent-foreground': '0 0% 98%',
45
- '--destructive': '0 70.9% 59.4%',
46
- '--border': '0 0% 14.9%',
47
- '--input': '0 0% 14.9%',
48
- };
49
-
50
- exports.spacing = { small: 4, medium: 8, large: 16 };
51
- `);
52
- patchPackage(root, 'packages/styling/package.json', {
53
- exports: {
54
- '.': './src/index.ts',
55
- './globals.css': './globals.css',
2
+ import { STACK_DEPENDENCIES } from '../dependencies.js';
3
+ import { json, launchTemplate, put, stackTemplate } from './files.js';
4
+ /** Generate CSS from the same tokens the styling package exports. */
5
+ export function scaffoldStyling(root) {
6
+ json(root, 'packages/styling/package.json', {
7
+ name: '@workspace/styling',
8
+ private: true,
9
+ type: 'module',
10
+ exports: { '.': './src/index.ts', './globals.css': './globals.css' },
11
+ scripts: { typecheck: 'tsc --noEmit', lint: 'eslint . --max-warnings 0' },
12
+ dependencies: {},
13
+ devDependencies: {
14
+ typescript: STACK_DEPENDENCIES.typescript,
15
+ '@types/node': STACK_DEPENDENCIES['@types/node'],
16
+ eslint: STACK_DEPENDENCIES.eslint,
17
+ '@workspace/eslint-config': 'workspace:*',
56
18
  },
57
19
  });
58
- const tokens = createRequire(import.meta.url)(path.join(root, 'packages/styling/src/tokens.cjs'));
59
- const rule = (selector, values) => selector +
60
- ' {\n' +
61
- Object.entries(values)
62
- .map(([key, value]) => ' ' + key + ': ' + value + ';')
63
- .join('\n') +
64
- '\n}\n';
65
- put(root, 'packages/styling/globals.css', rule(':root', tokens.light) +
66
- '@media (prefers-color-scheme: dark) {\n' +
67
- rule(':root', tokens.dark) +
68
- '}\n');
69
- put(root, 'packages/styling/src/tokens.d.cts', 'export const light: Record<string, string>;\nexport const dark: Record<string, string>;\nexport const spacing: { small: number; medium: number; large: number };\n');
70
- const config = readJson(root, 'packages/styling/tsconfig.json');
71
20
  json(root, 'packages/styling/tsconfig.json', {
72
- ...config,
73
- compilerOptions: { ...config.compilerOptions, allowJs: true },
21
+ compilerOptions: {
22
+ target: 'ES2022',
23
+ lib: ['ES2022', 'DOM'],
24
+ module: 'ESNext',
25
+ moduleResolution: 'Bundler',
26
+ strict: true,
27
+ noUnusedLocals: true,
28
+ noUnusedParameters: true,
29
+ skipLibCheck: true,
30
+ noEmit: true,
31
+ types: ['node'],
32
+ allowJs: true,
33
+ },
74
34
  include: ['src/**/*.ts', 'src/**/*.cjs'],
75
35
  });
36
+ put(root, 'packages/styling/eslint.config.mjs', stackTemplate('shared-eslint.config.mjs.txt'));
37
+ put(root, 'packages/styling/src/index.ts', "export { light, dark, spacing } from './tokens.cjs';\n");
38
+ put(root, 'packages/styling/src/tokens.cjs', launchTemplate('styling-tokens.cjs'));
39
+ const tokens = createRequire(import.meta.url)('../../assets/launch/styling-tokens.cjs');
40
+ const theme = (values, indent = '') => [
41
+ indent + ':root {',
42
+ ...Object.entries(values).map(([key, value]) => `${indent} ${key}: ${value};`),
43
+ indent + '}',
44
+ ].join('\n');
45
+ put(root, 'packages/styling/globals.css', [
46
+ theme(tokens.light),
47
+ '@media (prefers-color-scheme: dark) {',
48
+ theme(tokens.dark, ' '),
49
+ '}',
50
+ '',
51
+ ].join('\n'));
52
+ put(root, 'packages/styling/src/tokens.d.cts', 'export const light: Record<string, string>;\nexport const dark: Record<string, string>;\nexport const spacing: { small: number; medium: number; large: number };\n');
76
53
  }
@@ -1,10 +1,10 @@
1
- import { CapabilityEditor } from '../composition/editor.js';
2
1
  import type { Capability } from '../composition/catalog.js';
2
+ import { CapabilityEditor } from '../composition/editor.js';
3
3
  /** The launch foundation is a web service; Hono owns application services and data. */
4
4
  export declare function scaffoldTanstack(root: string, name: string): void;
5
5
  /** One-time source upgrade, planned in the same bounded overlay as each addition. */
6
6
  export declare function normalizeOjFoundation(e: CapabilityEditor, installed: readonly Capability[], refreshConfiguration?: boolean): boolean;
7
7
  /** Fingerprinted composition adapters; application routes stay source-owned. */
8
- export declare function composeTanstack(e: CapabilityEditor, installed: readonly Capability[]): void;
8
+ export declare function composeTanstack(e: CapabilityEditor, installed: readonly Capability[], refreshConfiguration?: boolean): void;
9
9
  /** Install account source only when the backend authentication capability is added. */
10
10
  export declare function addTanstackAuth(e: CapabilityEditor): void;