anhedral 0.16.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/README.md +42 -20
  2. package/assets/contracts/LICENSE +201 -0
  3. package/assets/contracts/LICENSE.environment +201 -0
  4. package/assets/contracts/LICENSE.operations +201 -0
  5. package/assets/contracts/deployment-provenance.json +15 -0
  6. package/assets/contracts/environment-provenance.json +11 -0
  7. package/assets/contracts/operations-provenance.json +11 -0
  8. package/assets/launch/application.server.ts.txt +13 -0
  9. package/assets/launch/auth-client.ts.txt +4 -0
  10. package/assets/launch/home.tsx.txt +20 -0
  11. package/assets/launch/minimal-application.server.ts.txt +5 -0
  12. package/assets/launch/minimal-server.ts.txt +7 -0
  13. package/assets/launch/request-context.ts.txt +3 -0
  14. package/assets/launch/root.tsx.txt +27 -0
  15. package/assets/launch/router.tsx.txt +21 -0
  16. package/assets/launch/server.ts.txt +13 -0
  17. package/assets/launch/sign-in.tsx.txt +53 -0
  18. package/assets/launch/styles.css.txt +19 -0
  19. package/assets/security/credential-patterns.d.mts +3 -0
  20. package/assets/security/credential-patterns.mjs +59 -0
  21. package/assets/stack/api-index.ts.txt +6 -1
  22. package/assets/stack/event-retention.sql.txt +10 -0
  23. package/assets/stack/stripe.ts.txt +30 -13
  24. package/assets/ui/UPSTREAM.json +1 -18
  25. package/dist/bin.js +55 -36
  26. package/dist/capabilities.d.ts +1 -1
  27. package/dist/capability-catalog.d.ts +44 -11
  28. package/dist/capability-catalog.js +96 -11
  29. package/dist/capability-command.d.ts +2 -2
  30. package/dist/capability-command.js +178 -27
  31. package/dist/capability-editor.js +6 -5
  32. package/dist/capability-recipes.js +54 -6
  33. package/dist/cli-arguments.d.ts +2 -0
  34. package/dist/cli-arguments.js +101 -50
  35. package/dist/cli-commands.d.ts +1 -1
  36. package/dist/cli-commands.js +30 -6
  37. package/dist/cli-errors.d.ts +18 -0
  38. package/dist/cli-errors.js +63 -0
  39. package/dist/cli-output.d.ts +22 -0
  40. package/dist/cli-output.js +42 -7
  41. package/dist/command-runner.d.ts +1 -0
  42. package/dist/command-runner.js +88 -0
  43. package/dist/command-schema.d.ts +16 -0
  44. package/dist/command-schema.js +390 -21
  45. package/dist/completion.d.ts +2 -0
  46. package/dist/completion.js +201 -0
  47. package/dist/composition.d.ts +35 -0
  48. package/dist/composition.js +28 -0
  49. package/dist/contracts/cli-transport.d.ts +217 -0
  50. package/dist/contracts/cli-transport.js +167 -0
  51. package/dist/contracts/deployment.d.ts +282 -0
  52. package/dist/contracts/deployment.js +234 -0
  53. package/dist/contracts/environment-file.d.ts +7 -0
  54. package/dist/contracts/environment-file.js +112 -0
  55. package/dist/contracts/environment-transport.d.ts +79 -0
  56. package/dist/contracts/environment-transport.js +110 -0
  57. package/dist/contracts/runtime-logs-transport.d.ts +127 -0
  58. package/dist/contracts/runtime-logs-transport.js +50 -0
  59. package/dist/contracts/source-bundle.d.ts +11 -0
  60. package/dist/contracts/source-bundle.js +197 -0
  61. package/dist/contracts/source-profile.d.ts +4 -0
  62. package/dist/contracts/source-profile.js +5 -0
  63. package/dist/contracts/staging-transport.d.ts +79 -0
  64. package/dist/contracts/staging-transport.js +43 -0
  65. package/dist/dependencies.d.ts +10 -4
  66. package/dist/dependencies.js +17 -54
  67. package/dist/index.d.ts +6 -0
  68. package/dist/index.js +4 -0
  69. package/dist/launch.d.ts +21 -0
  70. package/dist/launch.js +250 -0
  71. package/dist/platform-command.d.ts +9 -0
  72. package/dist/platform-command.js +584 -0
  73. package/dist/platform-environment.d.ts +18 -0
  74. package/dist/platform-environment.js +257 -0
  75. package/dist/platform-operations.d.ts +26 -0
  76. package/dist/platform-operations.js +155 -0
  77. package/dist/platform-source.d.ts +8 -0
  78. package/dist/platform-source.js +111 -0
  79. package/dist/platform-state.d.ts +13 -0
  80. package/dist/platform-state.js +207 -0
  81. package/dist/platforms/tanstack.d.ts +8 -0
  82. package/dist/platforms/tanstack.js +155 -0
  83. package/dist/registry/options.js +34 -31
  84. package/dist/registry/resolve.js +2 -0
  85. package/dist/registry/usage.d.ts +4 -1
  86. package/dist/registry/usage.js +58 -4
  87. package/dist/scaffold/documentation.js +17 -48
  88. package/dist/scaffold/styling.d.ts +1 -1
  89. package/dist/scaffold/workspace.js +11 -7
  90. package/dist/stack-registry.d.ts +2 -4
  91. package/dist/stack-registry.js +1 -11
  92. package/dist/standard.js +21 -6
  93. package/dist/transaction.js +28 -3
  94. package/dist/ui-command.d.ts +4 -2
  95. package/dist/ui-command.js +79 -38
  96. package/dist/ui-project.d.ts +2 -0
  97. package/dist/ui-project.js +38 -8
  98. package/dist/util.js +40 -61
  99. package/dist/version.d.ts +1 -1
  100. package/dist/version.js +1 -1
  101. package/docs/capabilities.md +22 -88
  102. package/docs/software-factory.md +189 -16
  103. package/docs/stack-standard.md +6 -18
  104. package/docs/ui.md +9 -22
  105. package/docs/verification.md +6 -1067
  106. package/package.json +33 -22
  107. package/assets/ui/native/_controls.tsx +0 -521
  108. package/assets/ui/native/_core.tsx +0 -118
  109. package/assets/ui/native/_data.tsx +0 -200
  110. package/assets/ui/native/_display.tsx +0 -453
  111. package/assets/ui/native/_feedback.tsx +0 -242
  112. package/assets/ui/native/_legacy-dialog.tsx +0 -38
  113. package/assets/ui/native/_motion.tsx +0 -520
  114. package/assets/ui/native/_overlay.tsx +0 -402
  115. package/assets/ui/native/_selection.tsx +0 -366
  116. package/assets/ui/native/accordion.tsx +0 -1
  117. package/assets/ui/native/alert-dialog.tsx +0 -11
  118. package/assets/ui/native/alert.tsx +0 -1
  119. package/assets/ui/native/aspect-ratio.tsx +0 -1
  120. package/assets/ui/native/attachment.tsx +0 -8
  121. package/assets/ui/native/avatar.tsx +0 -8
  122. package/assets/ui/native/badge.tsx +0 -1
  123. package/assets/ui/native/breadcrumb.tsx +0 -9
  124. package/assets/ui/native/bubble.tsx +0 -1
  125. package/assets/ui/native/button-group.tsx +0 -1
  126. package/assets/ui/native/button.tsx +0 -86
  127. package/assets/ui/native/calendar.tsx +0 -170
  128. package/assets/ui/native/card.tsx +0 -44
  129. package/assets/ui/native/carousel.tsx +0 -1
  130. package/assets/ui/native/chart.tsx +0 -193
  131. package/assets/ui/native/checkbox.tsx +0 -1
  132. package/assets/ui/native/code-block.tsx +0 -137
  133. package/assets/ui/native/collapsible.tsx +0 -1
  134. package/assets/ui/native/combobox.tsx +0 -1
  135. package/assets/ui/native/command.tsx +0 -11
  136. package/assets/ui/native/context-menu.tsx +0 -16
  137. package/assets/ui/native/data-table.tsx +0 -1
  138. package/assets/ui/native/date-picker.tsx +0 -43
  139. package/assets/ui/native/dialog.tsx +0 -15
  140. package/assets/ui/native/direction.tsx +0 -1
  141. package/assets/ui/native/drawer.tsx +0 -10
  142. package/assets/ui/native/dropdown-menu.tsx +0 -16
  143. package/assets/ui/native/empty.tsx +0 -8
  144. package/assets/ui/native/field.tsx +0 -13
  145. package/assets/ui/native/hover-card.tsx +0 -1
  146. package/assets/ui/native/input-group.tsx +0 -8
  147. package/assets/ui/native/input-otp.tsx +0 -1
  148. package/assets/ui/native/input.tsx +0 -28
  149. package/assets/ui/native/item.tsx +0 -12
  150. package/assets/ui/native/kbd.tsx +0 -1
  151. package/assets/ui/native/label.tsx +0 -4
  152. package/assets/ui/native/layout.tsx +0 -26
  153. package/assets/ui/native/marker.tsx +0 -1
  154. package/assets/ui/native/menubar.tsx +0 -17
  155. package/assets/ui/native/message-scroller.tsx +0 -6
  156. package/assets/ui/native/message.tsx +0 -10
  157. package/assets/ui/native/native-select.tsx +0 -1
  158. package/assets/ui/native/navigation-menu.tsx +0 -10
  159. package/assets/ui/native/pagination.tsx +0 -9
  160. package/assets/ui/native/popover.tsx +0 -1
  161. package/assets/ui/native/progress.tsx +0 -1
  162. package/assets/ui/native/questionnaire.tsx +0 -130
  163. package/assets/ui/native/radio-group.tsx +0 -1
  164. package/assets/ui/native/registry.json +0 -1103
  165. package/assets/ui/native/resizable.tsx +0 -1
  166. package/assets/ui/native/scroll-area.tsx +0 -1
  167. package/assets/ui/native/select.tsx +0 -11
  168. package/assets/ui/native/separator.tsx +0 -1
  169. package/assets/ui/native/sheet.tsx +0 -10
  170. package/assets/ui/native/sidebar.tsx +0 -22
  171. package/assets/ui/native/skeleton.tsx +0 -1
  172. package/assets/ui/native/slider.tsx +0 -1
  173. package/assets/ui/native/spinner.tsx +0 -1
  174. package/assets/ui/native/switch.tsx +0 -1
  175. package/assets/ui/native/table.tsx +0 -10
  176. package/assets/ui/native/tabs.tsx +0 -1
  177. package/assets/ui/native/text.tsx +0 -20
  178. package/assets/ui/native/textarea.tsx +0 -1
  179. package/assets/ui/native/theme-switcher.tsx +0 -22
  180. package/assets/ui/native/toast.tsx +0 -11
  181. package/assets/ui/native/toggle-group.tsx +0 -1
  182. package/assets/ui/native/toggle.tsx +0 -1
  183. package/assets/ui/native/tooltip.tsx +0 -1
  184. package/assets/ui/native/trace.tsx +0 -20
  185. package/assets/ui/native/typography.tsx +0 -15
  186. package/assets/ui/theme-storage.ts +0 -25
  187. package/assets/ui/theme.tsx +0 -66
  188. package/dist/platforms/mobile.d.ts +0 -2
  189. package/dist/platforms/mobile.js +0 -137
  190. package/dist/scaffold/expo-runtime.d.ts +0 -3
  191. package/dist/scaffold/expo-runtime.js +0 -42
  192. package/dist/scaffold/native-ui.d.ts +0 -2
  193. package/dist/scaffold/native-ui.js +0 -74
  194. package/docs/anhedral-stack.md +0 -7
  195. package/docs/native-ui.md +0 -102
@@ -1,4 +1,6 @@
1
1
  import { writeProjectSection } from '../project-config.js';
2
+ import { sourceCompositionSchema } from '../contracts/deployment.js';
3
+ import { GENERATOR_VERSION } from '../version.js';
2
4
  import { OPENNEXT_GLOB_VERSION, STACK_DEPENDENCIES, WORKSPACE_NODE_ENGINE, PACKAGE_MANAGER, } from '../dependencies.js';
3
5
  import { writeDependencyAudit } from '../dependency-patches.js';
4
6
  import { setPnpmPolicy } from '../pnpm-policy.js';
@@ -42,10 +44,6 @@ if (result.error) throw result.error;
42
44
  process.exitCode = result.status ?? 1;
43
45
  `);
44
46
  json(root, '.fallowrc.json', {
45
- publicPackages: options.products.includes('expo') ? ['@workspace/native-ui'] : [],
46
- ignoreDependencies: options.products.includes('expo')
47
- ? ['react-native-reanimated', 'react-native-worklets']
48
- : [],
49
47
  ignorePatterns: [
50
48
  'scripts/audit.mjs',
51
49
  'scripts/audit-deps.mjs',
@@ -87,11 +85,9 @@ process.exitCode = result.status ?? 1;
87
85
  });
88
86
  setPnpmPolicy(root, {
89
87
  ...(!updating ? { packages: ['apps/*', 'packages/*'] } : {}),
90
- // OpenNext's node-minify dependency pins the vulnerable glob CLI.
88
+ // Override node-minify's glob with the reviewed cancellation fix.
91
89
  overrides: {
92
90
  '@node-minify/core>glob': OPENNEXT_GLOB_VERSION,
93
- // Expo CLI's two schema consumers use APIs supported by the patched Zod release.
94
- ...(options.products.includes('expo') ? { '@expo/cli>zod': STACK_DEPENDENCIES.zod } : {}),
95
91
  'miniflare>undici': STACK_DEPENDENCIES.undici,
96
92
  },
97
93
  sharedWorkspaceLockfile: true,
@@ -132,6 +128,14 @@ process.exitCode = result.status ?? 1;
132
128
  resourcesProvisioned: false,
133
129
  });
134
130
  writeProjectSection(root, 'setup', createSetupPlan({ ...options, dryRun: false }, registry));
131
+ if (!updating && options.products.every((id) => ['next', 'styling'].includes(id)))
132
+ writeProjectSection(root, 'composition', sourceCompositionSchema.parse({
133
+ contractVersion: 1,
134
+ foundation: 'next-opennext',
135
+ generatorVersion: GENERATOR_VERSION,
136
+ identity: 'none',
137
+ capabilities: {},
138
+ }));
135
139
  if (!updating)
136
140
  writeSetupDocumentation(root, options);
137
141
  }
@@ -2,17 +2,15 @@ import type { ItemDefinition, StackRegistryItem, RecipeContext } from './registr
2
2
  /** Every product owns its source recipe, setup requirements and composition policy here. */
3
3
  declare const PRODUCT_ITEMS: {
4
4
  next: ItemDefinition;
5
- expo: ItemDefinition;
6
5
  hono: ItemDefinition;
7
6
  d1: ItemDefinition;
8
7
  r2: ItemDefinition;
9
8
  styling: ItemDefinition;
10
9
  };
11
10
  export type StandardProduct = keyof typeof PRODUCT_ITEMS;
12
- export declare const STANDARD_PRODUCTS: readonly ("hono" | "expo" | "r2" | "next" | "styling" | "d1")[];
11
+ export declare const STANDARD_PRODUCTS: readonly ("next" | "hono" | "r2" | "styling" | "d1")[];
13
12
  declare const DEFINITIONS: {
14
13
  next: ItemDefinition;
15
- expo: ItemDefinition;
16
14
  hono: ItemDefinition;
17
15
  d1: ItemDefinition;
18
16
  r2: ItemDefinition;
@@ -24,7 +22,7 @@ declare const DEFINITIONS: {
24
22
  export type StackItemId = keyof typeof DEFINITIONS;
25
23
  export declare function getStackDefinition(name: string): ItemDefinition;
26
24
  export declare function getStackItem(name: string): StackRegistryItem;
27
- export declare const STACK_ITEMS: Record<"hono" | "expo" | "r2" | "typescript" | "next" | "eslint" | "workspace" | "styling" | "d1", StackRegistryItem>;
25
+ export declare const STACK_ITEMS: Record<"next" | "hono" | "r2" | "eslint" | "typescript" | "workspace" | "styling" | "d1", StackRegistryItem>;
28
26
  export declare const STACK_REGISTRY: {
29
27
  schemaVersion: number;
30
28
  name: string;
@@ -5,7 +5,6 @@ import { GENERATOR_VERSION } from './version.js';
5
5
  import { scaffoldApi } from './scaffold/api.js';
6
6
  import { scaffoldDatabase } from './scaffold/database.js';
7
7
  import { scaffoldWeb } from './platforms/web.js';
8
- import { scaffoldExpo } from './platforms/mobile.js';
9
8
  import { scaffoldPrivateStorage } from './scaffold/storage.js';
10
9
  import { sharedPackage } from './scaffold/files.js';
11
10
  function requirements(purpose, tools, access, credentials, resources, verify) {
@@ -39,15 +38,6 @@ const PRODUCT_ITEMS = defineItems({
39
38
  install: scaffoldWeb,
40
39
  environment: ['ANHEDRAL_PREVIEW_ORIGIN'],
41
40
  },
42
- expo: {
43
- type: 'application',
44
- description: 'Native Expo iOS and Android application with Anhedral native shadcn UI',
45
- targets: ['apps/mobile', 'packages/native-ui'],
46
- registryDependencies: ['workspace', 'typescript', 'eslint', 'styling'],
47
- setup: requirements('Native iOS and Android application', ['Simulator or device'], ['For requested native distribution only: client-owned Apple/Google developer accounts'], ['For requested native builds only: platform signing credentials and EAS access when used'], ['Expo native client; signing and store configuration'], ['Simulator/device and signed-build acceptance']),
48
- install: scaffoldExpo,
49
- environment: ['EXPO_PUBLIC_API_URL'],
50
- },
51
41
  hono: {
52
42
  type: 'application',
53
43
  description: 'Shared Hono OpenAPI Worker',
@@ -95,7 +85,7 @@ const PRODUCT_ITEMS = defineItems({
95
85
  description: 'Shared platform-independent styling tokens',
96
86
  targets: ['packages/styling'],
97
87
  registryDependencies: ['workspace', 'typescript', 'eslint'],
98
- setup: requirements('Shared styling definitions', [], [], [], ['Shared light/dark tokens, web CSS and Anhedral native shadcn port'], ['Consistency across selected interfaces; preserve platform-specific components']),
88
+ setup: requirements('Shared styling definitions', [], [], [], ['Shared light/dark tokens, web CSS and optional RNR/NativeWind source'], ['Consistency across selected interfaces; preserve platform-specific components']),
99
89
  package: packageSource('styling', `import { light, dark, spacing } from './tokens.cjs';
100
90
 
101
91
  export const styling = {
package/dist/standard.js CHANGED
@@ -14,7 +14,26 @@ import { STANDARD_USAGE } from './registry/usage.js';
14
14
  import { printProgress, printResult } from './cli-output.js';
15
15
  export { parseStandardOptions, STANDARD_USAGE };
16
16
  export { STANDARD_PRODUCTS } from './stack-registry.js';
17
+ function assertInitDestination(root, allowRecovery = false) {
18
+ let info;
19
+ try {
20
+ info = lstatSync(root);
21
+ }
22
+ catch (error) {
23
+ if (error.code === 'ENOENT')
24
+ return;
25
+ throw error;
26
+ }
27
+ if (info.isSymbolicLink() || !info.isDirectory())
28
+ throw Error('Destination must be a real directory.');
29
+ if (allowRecovery)
30
+ return;
31
+ const unexpected = readdirSync(root).filter((name) => !['.git', '.gitignore'].includes(name));
32
+ if (unexpected.length)
33
+ throw Error(`Destination must be empty (apart from .git/.gitignore): ${unexpected[0]}`);
34
+ }
17
35
  export async function scaffoldStandardProject(options, run = execFile, output = {}) {
36
+ assertInitDestination(options.root, !options.dryRun);
18
37
  const plan = createSetupPlan(options);
19
38
  const display = { ...output, json: options.json };
20
39
  if (options.dryRun) {
@@ -32,11 +51,7 @@ export async function scaffoldStandardProject(options, run = execFile, output =
32
51
  mkdirSync(root, { recursive: true });
33
52
  created = true;
34
53
  }
35
- if (lstatSync(root).isSymbolicLink() || !lstatSync(root).isDirectory())
36
- throw new Error('Destination must be a real directory.');
37
- const unexpected = readdirSync(root).filter((name) => !['.git', '.gitignore'].includes(name));
38
- if (unexpected.length)
39
- throw new Error(`Destination must be empty (apart from .git/.gitignore): ${unexpected[0]}`);
54
+ assertInitDestination(root, true);
40
55
  const commitPaths = [];
41
56
  await runStagedTransaction(root, {
42
57
  commitPaths,
@@ -44,7 +59,7 @@ export async function scaffoldStandardProject(options, run = execFile, output =
44
59
  prepare: () => {
45
60
  const entries = readdirSync(root).filter((name) => !['.git', '.gitignore', '.anhedral.lock', '.anhedral-txn'].includes(name));
46
61
  if (entries.length)
47
- throw new Error('Destination changed before generation.');
62
+ throw new Error(`Destination must be empty (apart from .git/.gitignore): ${entries[0]}`);
48
63
  },
49
64
  build: async (stageRoot) => {
50
65
  printProgress('Creating the Next.js and Anhedral UI workspace…', display);
@@ -303,7 +303,13 @@ function validateJournal(root, value) {
303
303
  typeof entry.installed !== 'boolean') {
304
304
  throw new Error(`Invalid transaction journal entry at index ${index}`);
305
305
  }
306
- assertExactObjectKeys(entry, ['relativePath', 'backupPath', 'installed', 'installedFingerprint'], `transaction journal entry at index ${index}`);
306
+ assertExactObjectKeys(entry, [
307
+ 'relativePath',
308
+ 'backupPath',
309
+ 'installed',
310
+ 'installedFingerprint',
311
+ ...(Object.hasOwn(entry, 'backupFingerprint') ? ['backupFingerprint'] : []),
312
+ ], `transaction journal entry at index ${index}`);
307
313
  assertRelativePath(entry.relativePath);
308
314
  if (seen.has(entry.relativePath))
309
315
  throw new Error(`Duplicate transaction journal path: ${entry.relativePath}`);
@@ -311,6 +317,10 @@ function validateJournal(root, value) {
311
317
  if (entry.backupPath !== null && typeof entry.backupPath !== 'string') {
312
318
  throw new Error(`Invalid transaction backup path at index ${index}`);
313
319
  }
320
+ if (Object.hasOwn(entry, 'backupFingerprint') &&
321
+ (typeof entry.backupFingerprint !== 'string' ||
322
+ !/^[a-f0-9]{64}$/.test(entry.backupFingerprint)))
323
+ throw new Error(`Invalid backup transaction fingerprint at index ${index}`);
314
324
  const installedFingerprint = entry.installedFingerprint;
315
325
  if (installedFingerprint !== null &&
316
326
  (typeof installedFingerprint !== 'string' || !/^[a-f0-9]{64}$/.test(installedFingerprint))) {
@@ -327,6 +337,9 @@ function validateJournal(root, value) {
327
337
  return {
328
338
  relativePath: entry.relativePath,
329
339
  backupPath: entry.backupPath,
340
+ ...(typeof entry.backupFingerprint === 'string'
341
+ ? { backupFingerprint: entry.backupFingerprint }
342
+ : {}),
330
343
  installed: entry.installed,
331
344
  installedFingerprint,
332
345
  };
@@ -452,13 +465,24 @@ function restoreJournal(root, journal) {
452
465
  if (entry.backupPath) {
453
466
  assertNoSymlinkComponents(journal.backupRoot, entry.relativePath);
454
467
  if (pathEntryExists(entry.backupPath)) {
468
+ if (pathEntryExists(target))
469
+ throw new Error(`Transaction recovery target was recreated: ${entry.relativePath}. Recovery stopped without modifying it; preserve the journal, target and backup for manual inspection.`);
470
+ const backupFingerprint = fingerprintEntry(entry.backupPath);
471
+ if (entry.backupFingerprint && entry.backupFingerprint !== backupFingerprint)
472
+ throw new Error(`Transaction backup changed: ${entry.relativePath}. Preserve the journal and backup for manual inspection.`);
473
+ // Persist original identity before restore so a crash after rename can be replayed.
474
+ entry.backupFingerprint = backupFingerprint;
475
+ writeJournal(root, journal);
455
476
  mkdirSync(path.dirname(target), { recursive: true });
456
477
  renameDurably(entry.backupPath, target, root);
457
478
  }
458
- else if (!pathEntryExists(target)) {
459
- throw new Error(`Cannot recover missing transaction backup: ${entry.backupPath}`);
479
+ else if (!pathEntryExists(target) ||
480
+ !entry.backupFingerprint ||
481
+ fingerprintEntry(target) !== entry.backupFingerprint) {
482
+ throw new Error(`Cannot recover missing transaction backup or unverified target: ${entry.backupPath}. Recovery stopped; preserve the journal and target for manual inspection.`);
460
483
  }
461
484
  entry.backupPath = null;
485
+ delete entry.backupFingerprint;
462
486
  writeJournal(root, journal);
463
487
  }
464
488
  }
@@ -588,6 +612,7 @@ function commitJournal(root, journal, deletePaths) {
588
612
  const backup = resolveTransactionPath(backupRoot, entry.relativePath);
589
613
  mkdirSync(path.dirname(backup), { recursive: true });
590
614
  entry.backupPath = backup;
615
+ entry.backupFingerprint = fingerprintEntry(target);
591
616
  writeJournal(root, journal);
592
617
  renameDurably(target, backup, root);
593
618
  }
@@ -1,3 +1,5 @@
1
- import type { OutputOptions } from './cli-output.js';
1
+ import { type OutputOptions } from './cli-output.js';
2
2
  export type UiRunner = (args: string[], cwd: string) => string | Promise<string>;
3
- export declare function runUiCommand(args: string[], output: OutputOptions, run?: UiRunner): Promise<void>;
3
+ /** Public UI surface: one Anhedral Stack web target, with no native install fallback. */
4
+ export declare function runAnhedralUiCommand(args: string[], output: OutputOptions, run?: UiRunner): Promise<void>;
5
+ export declare function runUiCommand(args: string[], output: OutputOptions, run?: UiRunner, mode?: 'compatibility' | 'public'): Promise<void>;
@@ -1,11 +1,14 @@
1
1
  import { existsSync, writeFileSync } from 'node:fs';
2
+ import { MAX_PROJECT_JSON_BYTES, readBoundedFile } from './bounded-file.js';
2
3
  import path from 'node:path';
3
4
  import { stripVTControlCharacters } from 'node:util';
4
5
  import { spawn, spawnSync } from 'node:child_process';
5
6
  import { commandArguments, commandArgumentError } from './cli-arguments.js';
6
7
  import { resolveCommand } from './command.js';
8
+ import { ANHEDRAL_STACK } from './capability-catalog.js';
9
+ import { createReporter } from './cli-output.js';
7
10
  import { UI_CATALOG, resolveUiItems } from './ui-catalog.js';
8
- import { detectUiTargets, initializeUiMetadata, inspectUiTarget } from './ui-project.js';
11
+ import { assertUiMetadataPaths, detectUiTargets, initializeUiMetadata, inspectUiTarget, } from './ui-project.js';
9
12
  function runUpstream(args, cwd) {
10
13
  const invocation = resolveCommand('pnpm', [
11
14
  'dlx',
@@ -85,27 +88,65 @@ function runUpstream(args, cwd) {
85
88
  });
86
89
  });
87
90
  }
88
- export async function runUiCommand(args, output, run = runUpstream) {
89
- const parsed = commandArguments('ui', args);
91
+ function assertAnhedralStackTarget(target) {
92
+ const dependencies = { ...target.manifest.devDependencies, ...target.manifest.dependencies };
93
+ if (target.platform !== 'web' || !dependencies['@tanstack/react-start'])
94
+ throw commandArgumentError('ui', 'Anhedral UI requires the Anhedral Stack web foundation. Run anhedral init <directory>.');
95
+ let root = target.root;
96
+ for (;;) {
97
+ const metadata = path.join(root, 'anhedral.json');
98
+ if (existsSync(metadata)) {
99
+ const project = JSON.parse(readBoundedFile(metadata, MAX_PROJECT_JSON_BYTES).toString('utf8'));
100
+ if (project?.schemaVersion !== 1 ||
101
+ ![ANHEDRAL_STACK.id, 'anhedral-web-launch'].includes(project.setup?.stack) ||
102
+ project.composition?.contractVersion !== 2 ||
103
+ project.composition?.foundation !== ANHEDRAL_STACK.foundation.id ||
104
+ path.join(root, 'apps', 'web') !== target.root)
105
+ throw commandArgumentError('ui', 'Select apps/web in an Anhedral Stack project. Run anhedral ui --help.');
106
+ return;
107
+ }
108
+ if (existsSync(path.join(root, '.git')) || path.dirname(root) === root)
109
+ break;
110
+ root = path.dirname(root);
111
+ }
112
+ throw commandArgumentError('ui', 'No Anhedral Stack project found. Run anhedral init <directory>.');
113
+ }
114
+ /** Public UI surface: one Anhedral Stack web target, with no native install fallback. */
115
+ export async function runAnhedralUiCommand(args, output, run = runUpstream) {
116
+ return runUiCommand(args, output, run, 'public');
117
+ }
118
+ export async function runUiCommand(args, output, run = runUpstream, mode = 'compatibility') {
119
+ if (mode === 'public' && args.some((arg) => /^--(?:native|all)(?:=|$)/.test(arg)))
120
+ throw commandArgumentError('ui', 'Anhedral UI supports the Anhedral Stack web application only. Use --web or select apps/web with --cwd.');
121
+ // Retained direct library callers can inspect legacy source; the executable uses public mode.
122
+ const legacySelectors = mode === 'compatibility' ? args.filter((arg) => ['--native', '--all'].includes(arg)) : [];
123
+ if (new Set(legacySelectors).size !== legacySelectors.length)
124
+ throw commandArgumentError('ui', 'Specify each UI selector only once.');
125
+ const parsed = commandArguments('ui', args.filter((arg) => !legacySelectors.includes(arg)));
90
126
  const [action, ...names] = parsed.positional;
91
127
  if (!['init', 'add', 'list', 'diff', 'doctor'].includes(action))
92
128
  throw commandArgumentError('ui', 'Choose ui init, add, list, diff or doctor.');
93
129
  if (['add', 'diff'].includes(action) ? !names.length || names.length > 50 : names.length > 0)
94
130
  throw commandArgumentError('ui', 'Supply component names only for add/diff (at most 50).');
95
- const selectors = ['--web', '--native', '--all'].filter((flag) => parsed.has(flag));
131
+ const selectors = ['--web', '--native', '--all'].filter((flag) => parsed.has(flag) || legacySelectors.includes(flag));
96
132
  if (selectors.length > 1)
97
133
  throw commandArgumentError('ui', 'Choose one of --web, --native or --all.');
98
- const selector = selectors[0]?.slice(2);
134
+ const selector = mode === 'public' ? 'web' : selectors[0]?.slice(2);
99
135
  let result;
100
136
  if (action === 'list') {
101
137
  result = {
102
138
  catalogRevision: UI_CATALOG.revision,
103
- nativeStyling: UI_CATALOG.nativeStyling,
104
- components: UI_CATALOG.components.filter((item) => !selector || selector === 'all' || item[selector]),
139
+ ...(mode === 'public' ? { platform: 'web' } : { nativeStyling: UI_CATALOG.nativeStyling }),
140
+ components: UI_CATALOG.components
141
+ .filter((item) => !selector || selector === 'all' || item[selector])
142
+ .map((item) => (mode === 'public' ? { name: item.name, web: item.web } : item)),
105
143
  };
106
144
  }
107
145
  else {
108
146
  const targets = detectUiTargets(process.cwd(), selector);
147
+ if (mode === 'public')
148
+ for (const target of targets)
149
+ assertAnhedralStackTarget(target);
109
150
  if (action === 'doctor') {
110
151
  const reports = targets.map(inspectUiTarget);
111
152
  result = {
@@ -118,6 +159,7 @@ export async function runUiCommand(args, output, run = runUpstream) {
118
159
  else {
119
160
  // Preflight every target before invoking any installer, including explicit --all.
120
161
  const plans = targets.map((target) => {
162
+ assertUiMetadataPaths(target.root);
121
163
  const report = inspectUiTarget(target);
122
164
  const configExists = existsSync(path.join(target.root, 'components.json'));
123
165
  const nativeInit = action === 'init' && target.platform === 'native';
@@ -185,35 +227,34 @@ export async function runUiCommand(args, output, run = runUpstream) {
185
227
  };
186
228
  }
187
229
  }
188
- if (output.json)
189
- console.log(JSON.stringify(result, null, 2));
190
- else if (!output.quiet)
191
- console.log(action === 'list'
192
- ? UI_CATALOG.components
193
- .filter((item) => !selector || selector === 'all' || item[selector])
194
- .map((item) => `${item.name}\tweb: ${item.web ? 'shadcn' : 'unavailable'}\tnative: ${item.native ? 'RNR (validation required)' : 'unavailable'}`)
195
- .join('\n')
196
- : action === 'doctor'
197
- ? result.targets
198
- .map((report) => [
199
- `${report.platform}: ${report.configurationReady ? 'configuration ready' : 'setup needed'} (${report.root})`,
200
- ...report.issues,
201
- 'Runtime acceptance: not evaluated.',
202
- ].join('\n'))
203
- .join('\n\n')
204
- : result.targets
205
- .map((target) => [
206
- `${action}${parsed.has('--dry-run') ? ' (dry run)' : ''}: ${target.platform} (${target.root})`,
207
- ...(parsed.has('--dry-run')
208
- ? [
209
- target.command.length
210
- ? `shadcn@${UI_CATALOG.shadcnCliVersion} ${target.command.join(' ')}`
211
- : 'Validate existing configuration; initialize metadata and attribution if absent.',
212
- ]
213
- : []),
214
- target.output?.trim() ?? '',
215
- ]
216
- .filter(Boolean)
217
- .join('\n'))
218
- .join('\n\n'));
230
+ createReporter(output, () => action === 'list'
231
+ ? UI_CATALOG.components
232
+ .filter((item) => !selector || selector === 'all' || item[selector])
233
+ .map((item) => mode === 'public'
234
+ ? `${item.name}\tshadcn`
235
+ : `${item.name}\tweb: ${item.web ? 'shadcn' : 'unavailable'}\tnative: ${item.native ? 'RNR (validation required)' : 'unavailable'}`)
236
+ .join('\n')
237
+ : action === 'doctor'
238
+ ? result.targets
239
+ .map((report) => [
240
+ `${report.platform}: ${report.configurationReady ? 'configuration ready' : 'setup needed'} (${report.root})`,
241
+ ...report.issues,
242
+ 'Runtime acceptance: not evaluated.',
243
+ ].join('\n'))
244
+ .join('\n\n')
245
+ : result.targets
246
+ .map((target) => [
247
+ `${action}${parsed.has('--dry-run') ? ' (dry run)' : ''}: ${target.platform} (${target.root})`,
248
+ ...(parsed.has('--dry-run')
249
+ ? [
250
+ target.command.length
251
+ ? `shadcn@${UI_CATALOG.shadcnCliVersion} ${target.command.join(' ')}`
252
+ : 'Validate existing configuration; initialize metadata and attribution if absent.',
253
+ ]
254
+ : []),
255
+ target.output?.trim() ?? '',
256
+ ]
257
+ .filter(Boolean)
258
+ .join('\n'))
259
+ .join('\n\n')).result(result);
219
260
  }
@@ -17,6 +17,8 @@ export declare function inspectUiTarget(target: UiTarget): {
17
17
  runtimeAcceptance: string;
18
18
  guide: string;
19
19
  };
20
+ /** Check CLI-owned destinations before upstream or attribution writes. */
21
+ export declare function assertUiMetadataPaths(root: string): void;
20
22
  /** New metadata and attribution only; never overwrite consumer-owned files. */
21
23
  export declare function initializeUiMetadata(root: string, platform: UiPlatform): void;
22
24
  export {};
@@ -1,6 +1,11 @@
1
- import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync, } from 'node:fs';
1
+ import { readBoundedFile, MAX_PROJECT_JSON_BYTES } from './bounded-file.js';
2
+ import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync, } from 'node:fs';
2
3
  import path from 'node:path';
3
4
  import { UI_CATALOG } from './ui-catalog.js';
5
+ // Consumer JSON links remain supported; the resolved target must be a bounded regular file.
6
+ function readUiJson(file) {
7
+ return JSON.parse(readBoundedFile(realpathSync(file), MAX_PROJECT_JSON_BYTES).toString('utf8'));
8
+ }
4
9
  export function detectUiTargets(cwd, selector) {
5
10
  let root = realpathSync(cwd);
6
11
  let targets = [];
@@ -8,9 +13,9 @@ export function detectUiTargets(cwd, selector) {
8
13
  const file = path.join(directory, 'package.json');
9
14
  if (!existsSync(file))
10
15
  return;
11
- const manifest = JSON.parse(readFileSync(file, 'utf8'));
16
+ const manifest = readUiJson(file);
12
17
  const dependencies = { ...manifest.devDependencies, ...manifest.dependencies };
13
- if (dependencies.next)
18
+ if (dependencies.next || dependencies['@tanstack/react-start'])
14
19
  targets.push({ root: directory, platform: 'web', manifest });
15
20
  if (dependencies.expo)
16
21
  targets.push({ root: directory, platform: 'native', manifest });
@@ -32,7 +37,7 @@ export function detectUiTargets(cwd, selector) {
32
37
  if (selector && selector !== 'all')
33
38
  targets = targets.filter((target) => target.platform === selector);
34
39
  if (!targets.length)
35
- throw Error('No matching Next.js or Expo application found. Use --cwd to select an application.');
40
+ throw Error('No matching Next.js, TanStack Start or Expo application found. Use --cwd to select an application.');
36
41
  if (targets.length > 1 && selector !== 'all')
37
42
  throw Error('Multiple UI applications found. Select --web, --native, --all, or use --cwd for one application.');
38
43
  if (new Set(targets.map((target) => target.root)).size !== targets.length)
@@ -42,13 +47,13 @@ export function detectUiTargets(cwd, selector) {
42
47
  export function inspectUiTarget(target) {
43
48
  const issues = [];
44
49
  const file = path.join(target.root, 'components.json');
45
- const config = existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : null;
50
+ const config = existsSync(file) ? readUiJson(file) : null;
46
51
  if (!config)
47
52
  issues.push('Missing components.json. Run anhedral ui init for this application.');
48
53
  if (config && (!config.aliases?.ui || !config.aliases?.utils || !config.tailwind?.css))
49
54
  issues.push('components.json needs UI/utils aliases and a Tailwind CSS entry.');
50
55
  const marker = path.join(target.root, '.anhedral-ui.json');
51
- if (existsSync(marker) && JSON.parse(readFileSync(marker, 'utf8')).platform !== target.platform)
56
+ if (existsSync(marker) && readUiJson(marker).platform !== target.platform)
52
57
  issues.push('Existing Anhedral UI configuration targets another platform.');
53
58
  if (target.platform === 'native') {
54
59
  const dependencies = { ...target.manifest.devDependencies, ...target.manifest.dependencies };
@@ -76,14 +81,39 @@ export function inspectUiTarget(target) {
76
81
  runtimeAcceptance: 'not evaluated',
77
82
  guide: target.platform === 'native'
78
83
  ? 'https://reactnativereusables.com/docs/installation/manual'
79
- : 'https://ui.shadcn.com/docs/installation/next',
84
+ : target.manifest.dependencies?.['@tanstack/react-start'] ||
85
+ target.manifest.devDependencies?.['@tanstack/react-start']
86
+ ? 'https://ui.shadcn.com/docs/installation/tanstack'
87
+ : 'https://ui.shadcn.com/docs/installation/next',
80
88
  };
81
89
  }
90
+ /** Check CLI-owned destinations before upstream or attribution writes. */
91
+ export function assertUiMetadataPaths(root) {
92
+ for (const [relative, directory] of [
93
+ ['.anhedral-ui.json', false],
94
+ ['ANHEDRAL_UI_LICENSES', true],
95
+ ['ANHEDRAL_UI_LICENSES/LICENSE.shadcn', false],
96
+ ['ANHEDRAL_UI_LICENSES/LICENSE.react-native-reusables', false],
97
+ ]) {
98
+ let info;
99
+ try {
100
+ info = lstatSync(path.join(root, relative));
101
+ }
102
+ catch (error) {
103
+ if (error.code === 'ENOENT')
104
+ continue;
105
+ throw error;
106
+ }
107
+ if (info.isSymbolicLink() || (directory ? !info.isDirectory() : !info.isFile()))
108
+ throw Error(`Unsafe UI metadata path: ${relative}. Preserve it and reconcile before installing.`);
109
+ }
110
+ }
82
111
  /** New metadata and attribution only; never overwrite consumer-owned files. */
83
112
  export function initializeUiMetadata(root, platform) {
113
+ assertUiMetadataPaths(root);
84
114
  const file = path.join(root, '.anhedral-ui.json');
85
115
  if (existsSync(file)) {
86
- const existing = JSON.parse(readFileSync(file, 'utf8'));
116
+ const existing = readUiJson(file);
87
117
  if (existing.platform !== platform)
88
118
  throw Error('Existing Anhedral UI configuration targets another platform.');
89
119
  }
package/dist/util.js CHANGED
@@ -1,7 +1,10 @@
1
- import { chmodSync, closeSync, existsSync, fstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, rmSync, writeFileSync, } from 'node:fs';
1
+ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { readBoundedFile } from './bounded-file.js';
3
+ import { mkdtempSync, rmSync } from 'node:fs';
4
+ import { tmpdir } from 'node:os';
5
+ import { fileURLToPath } from 'node:url';
2
6
  import { resolveCommand } from './command.js';
3
7
  import { spawnSync } from 'node:child_process';
4
- import { tmpdir } from 'node:os';
5
8
  import path from 'node:path';
6
9
  const FAILURE_TAIL_BYTES = 128 * 1024;
7
10
  function commandTimeout() {
@@ -42,77 +45,53 @@ export function appendGitignore(root, lines) {
42
45
  const separator = existing.length > 0 && !/(?:\r\n|\n|\r)$/.test(existing) ? newline : '';
43
46
  writeFile(filePath, `${existing}${separator}${additions.join(newline)}${newline}`);
44
47
  }
45
- function readTail(filePath) {
46
- const file = openSync(filePath, 'r');
47
- try {
48
- const size = fstatSync(file).size;
49
- const length = Math.min(size, FAILURE_TAIL_BYTES);
50
- if (length === 0)
51
- return '';
52
- const buffer = Buffer.allocUnsafe(length);
53
- readSync(file, buffer, 0, length, size - length);
54
- return buffer.toString();
55
- }
56
- finally {
57
- closeSync(file);
58
- }
59
- }
60
- function dumpFailure(cmd, status, stdoutPath, stderrPath, spawnError) {
61
- const stdoutText = readTail(stdoutPath);
62
- const stderrText = readTail(stderrPath);
63
- if (process.env.ANHEDRAL_QUIET !== '1') {
64
- if (stdoutText)
65
- process.stderr.write(stdoutText);
66
- if (stderrText)
67
- process.stderr.write(stderrText);
68
- }
69
- throw commandFailure(cmd, status, spawnError);
70
- }
71
48
  export function execFile(executable, args, cwd) {
72
49
  const invocation = resolveCommand(executable, args);
73
50
  const quiet = process.env.ANHEDRAL_QUIET === '1';
74
51
  const display = [executable, ...args].join(' ');
75
- const deadline = { timeout: commandTimeout(), killSignal: 'SIGKILL' };
76
- if (process.env.ANHEDRAL_VERBOSE === '1' && !quiet) {
77
- console.log(` $ ${display}`);
78
- const result = spawnSync(invocation.command, invocation.args, {
52
+ const verbose = process.env.ANHEDRAL_VERBOSE === '1' && !quiet;
53
+ const requested = Number(process.env.ANHEDRAL_COMMAND_OUTPUT_BYTES);
54
+ const maximum = Number.isSafeInteger(requested) && requested >= 1024 && requested <= 16 * 1024 * 1024
55
+ ? requested
56
+ : 16 * 1024 * 1024;
57
+ const root = mkdtempSync(path.join(tmpdir(), 'anhedral-command-'));
58
+ const configuration = path.join(root, 'input.json'), resultFile = path.join(root, 'result.json');
59
+ try {
60
+ const bytes = JSON.stringify({
61
+ ...invocation,
79
62
  cwd,
80
- stdio: 'inherit',
81
- shell: false,
82
- ...deadline,
63
+ timeout: commandTimeout(),
64
+ maximum,
65
+ verbose,
83
66
  });
84
- if (result.error || result.status !== 0) {
85
- throw commandFailure(display, result.status, result.error);
86
- }
87
- return;
88
- }
89
- const captureRoot = mkdtempSync(path.join(tmpdir(), 'anhedral-exec-'));
90
- const stdoutPath = path.join(captureRoot, 'stdout.log');
91
- const stderrPath = path.join(captureRoot, 'stderr.log');
92
- const stdout = openSync(stdoutPath, 'w');
93
- const stderr = openSync(stderrPath, 'w');
94
- try {
95
- const result = spawnSync(invocation.command, invocation.args, {
67
+ if (Buffer.byteLength(bytes) > 1024 * 1024)
68
+ throw Error('Command configuration exceeds its bound.');
69
+ writeFileSync(configuration, bytes, { flag: 'wx', mode: 0o600 });
70
+ const wrapper = spawnSync(process.execPath, [fileURLToPath(new URL('./command-runner.js', import.meta.url)), configuration, resultFile], {
96
71
  cwd,
97
72
  shell: false,
98
- stdio: ['ignore', stdout, stderr],
99
- ...deadline,
73
+ stdio: verbose ? 'inherit' : 'ignore',
74
+ timeout: commandTimeout() + 10000,
75
+ killSignal: 'SIGKILL',
100
76
  });
101
- closeSync(stdout);
102
- closeSync(stderr);
77
+ if (wrapper.error || wrapper.status !== 0 || !existsSync(resultFile))
78
+ throw commandFailure(display, wrapper.status, wrapper.error);
79
+ const result = JSON.parse(readBoundedFile(resultFile, 1024 * 1024).toString('utf8'));
103
80
  if (result.error || result.status !== 0) {
104
- dumpFailure(display, result.status, stdoutPath, stderrPath, result.error);
81
+ if (!quiet && !verbose)
82
+ for (const value of [result.stdout, result.stderr]) {
83
+ const tail = Buffer.from(value, 'base64');
84
+ if (tail.length)
85
+ process.stderr.write(tail.subarray(-FAILURE_TAIL_BYTES));
86
+ }
87
+ if (result.error === 'ENOBUFS')
88
+ throw Error(`Command output exceeded its capture limit: ${display}. Inspect the tool before retrying.`);
89
+ throw commandFailure(display, result.status, result.error
90
+ ? Object.assign(new Error('Command execution failed'), { code: result.error })
91
+ : undefined);
105
92
  }
106
93
  }
107
94
  finally {
108
- try {
109
- closeSync(stdout);
110
- }
111
- catch { }
112
- try {
113
- closeSync(stderr);
114
- }
115
- catch { }
116
- rmSync(captureRoot, { recursive: true, force: true });
95
+ rmSync(root, { recursive: true, force: true });
117
96
  }
118
97
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const GENERATOR_VERSION = "0.16.0";
1
+ export declare const GENERATOR_VERSION = "0.18.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const GENERATOR_VERSION = '0.16.0';
1
+ export const GENERATOR_VERSION = '0.18.0';