anhedral 0.17.0 → 0.19.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 (174) hide show
  1. package/README.md +33 -68
  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 +12 -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/oj/OJ.LICENSE +21 -0
  14. package/assets/launch/oj/run.mjs +82 -0
  15. package/assets/launch/oj/runtime.json +21 -0
  16. package/assets/launch/request-context.ts.txt +3 -0
  17. package/assets/launch/root.tsx.txt +26 -0
  18. package/assets/launch/router.tsx.txt +21 -0
  19. package/assets/launch/server.ts.txt +15 -0
  20. package/assets/launch/sign-in.tsx.txt +53 -0
  21. package/assets/launch/styles.css.txt +19 -0
  22. package/assets/security/credential-patterns.d.mts +3 -0
  23. package/assets/security/credential-patterns.mjs +59 -0
  24. package/assets/stack/api-index.ts.txt +6 -1
  25. package/assets/stack/stripe.ts.txt +30 -13
  26. package/assets/ui/catalog.json +36 -324
  27. package/dist/{platforms/web.d.ts → api-proxy.d.ts} +1 -3
  28. package/dist/api-proxy.js +48 -0
  29. package/dist/bin.js +55 -36
  30. package/dist/capability-catalog.d.ts +36 -57
  31. package/dist/capability-catalog.js +65 -67
  32. package/dist/capability-command.d.ts +3 -3
  33. package/dist/capability-command.js +146 -59
  34. package/dist/capability-editor.js +6 -5
  35. package/dist/capability-recipes.js +9 -296
  36. package/dist/cli-arguments.d.ts +2 -0
  37. package/dist/cli-arguments.js +101 -50
  38. package/dist/cli-commands.d.ts +1 -1
  39. package/dist/cli-commands.js +31 -5
  40. package/dist/cli-errors.d.ts +18 -0
  41. package/dist/cli-errors.js +63 -0
  42. package/dist/cli-output.d.ts +22 -0
  43. package/dist/cli-output.js +42 -7
  44. package/dist/command-runner.js +88 -0
  45. package/dist/command-schema.d.ts +16 -0
  46. package/dist/command-schema.js +496 -21
  47. package/dist/command-types.d.ts +1 -0
  48. package/dist/command-types.js +1 -0
  49. package/dist/completion.d.ts +2 -0
  50. package/dist/completion.js +201 -0
  51. package/dist/composition.d.ts +25 -0
  52. package/dist/composition.js +28 -0
  53. package/dist/contracts/cli-transport.d.ts +316 -0
  54. package/dist/contracts/cli-transport.js +236 -0
  55. package/dist/contracts/deployment.d.ts +233 -0
  56. package/dist/contracts/deployment.js +198 -0
  57. package/dist/contracts/environment-file.d.ts +7 -0
  58. package/dist/contracts/environment-file.js +112 -0
  59. package/dist/contracts/environment-transport.d.ts +79 -0
  60. package/dist/contracts/environment-transport.js +110 -0
  61. package/dist/contracts/production-transport.d.ts +71 -0
  62. package/dist/contracts/production-transport.js +56 -0
  63. package/dist/contracts/runtime-logs-transport.d.ts +127 -0
  64. package/dist/contracts/runtime-logs-transport.js +50 -0
  65. package/dist/contracts/source-bundle.d.ts +11 -0
  66. package/dist/contracts/source-bundle.js +197 -0
  67. package/dist/contracts/source-profile.d.ts +4 -0
  68. package/dist/contracts/source-profile.js +5 -0
  69. package/dist/contracts/staging-transport.d.ts +79 -0
  70. package/dist/contracts/staging-transport.js +43 -0
  71. package/dist/dependencies.d.ts +9 -27
  72. package/dist/dependencies.js +19 -66
  73. package/dist/index.d.ts +4 -2
  74. package/dist/index.js +3 -1
  75. package/dist/launch.d.ts +27 -0
  76. package/dist/launch.js +262 -0
  77. package/dist/platform-command.d.ts +9 -0
  78. package/dist/platform-command.js +787 -0
  79. package/dist/platform-environment.d.ts +18 -0
  80. package/dist/platform-environment.js +257 -0
  81. package/dist/platform-operations.d.ts +26 -0
  82. package/dist/platform-operations.js +155 -0
  83. package/dist/platform-production.d.ts +16 -0
  84. package/dist/platform-production.js +135 -0
  85. package/dist/platform-source.d.ts +8 -0
  86. package/dist/platform-source.js +111 -0
  87. package/dist/platform-state.d.ts +15 -0
  88. package/dist/platform-state.js +229 -0
  89. package/dist/platforms/tanstack.d.ts +10 -0
  90. package/dist/platforms/tanstack.js +248 -0
  91. package/dist/registry/usage.d.ts +4 -1
  92. package/dist/registry/usage.js +59 -4
  93. package/dist/scaffold/bootstrap.d.ts +3 -3
  94. package/dist/scaffold/styling.d.ts +3 -2
  95. package/dist/transaction.js +28 -3
  96. package/dist/ui-catalog.d.ts +3 -5
  97. package/dist/ui-catalog.js +8 -24
  98. package/dist/ui-command.d.ts +3 -1
  99. package/dist/ui-command.js +74 -72
  100. package/dist/ui-project.d.ts +4 -2
  101. package/dist/ui-project.js +40 -38
  102. package/dist/util.js +40 -61
  103. package/dist/version.d.ts +1 -1
  104. package/dist/version.js +1 -1
  105. package/docs/capabilities.md +23 -89
  106. package/docs/software-factory.md +208 -9
  107. package/docs/stack-standard.md +7 -17
  108. package/docs/ui.md +9 -22
  109. package/package.json +26 -22
  110. package/assets/stack/ai-schema.ts.txt +0 -5
  111. package/assets/stack/ai.ts.txt +0 -30
  112. package/assets/stack/desktop.rs.txt +0 -21
  113. package/assets/stack/events-schema.ts.txt +0 -12
  114. package/assets/stack/events.ts.txt +0 -59
  115. package/assets/stack/mobile-auth.ts.txt +0 -25
  116. package/assets/stack/mobile-billing.tsx.txt +0 -63
  117. package/assets/stack/mobile-session.tsx.txt +0 -83
  118. package/assets/stack/native-button.tsx.txt +0 -108
  119. package/assets/stack/native-global.css.txt +0 -4
  120. package/assets/stack/native-lib-utils.ts.txt +0 -5
  121. package/assets/stack/native-metro.config.js.txt +0 -6
  122. package/assets/stack/native-nativewind-env.d.ts.txt +0 -1
  123. package/assets/stack/native-tailwind.config.js.txt +0 -73
  124. package/assets/stack/native-text.tsx.txt +0 -89
  125. package/assets/stack/purchases.ts.txt +0 -65
  126. package/assets/stack/revenuecat.ts.txt +0 -88
  127. package/assets/stack/rtc-schema.ts.txt +0 -10
  128. package/assets/stack/rtc.ts.txt +0 -122
  129. package/assets/stack/web-sign-in.tsx.txt +0 -51
  130. package/dist/capabilities.d.ts +0 -11
  131. package/dist/capabilities.js +0 -14
  132. package/dist/dependency-order.d.ts +0 -2
  133. package/dist/dependency-order.js +0 -24
  134. package/dist/platforms/lint.d.ts +0 -1
  135. package/dist/platforms/lint.js +0 -5
  136. package/dist/platforms/web.js +0 -251
  137. package/dist/project-config.d.ts +0 -3
  138. package/dist/project-config.js +0 -16
  139. package/dist/registry/context.d.ts +0 -3
  140. package/dist/registry/context.js +0 -20
  141. package/dist/registry/options.d.ts +0 -2
  142. package/dist/registry/options.js +0 -44
  143. package/dist/registry/resolve.d.ts +0 -11
  144. package/dist/registry/resolve.js +0 -46
  145. package/dist/registry/types.d.ts +0 -60
  146. package/dist/scaffold/api.d.ts +0 -2
  147. package/dist/scaffold/api.js +0 -38
  148. package/dist/scaffold/backend.d.ts +0 -2
  149. package/dist/scaffold/backend.js +0 -36
  150. package/dist/scaffold/compose.d.ts +0 -4
  151. package/dist/scaffold/compose.js +0 -30
  152. package/dist/scaffold/database.d.ts +0 -2
  153. package/dist/scaffold/database.js +0 -41
  154. package/dist/scaffold/documentation.d.ts +0 -2
  155. package/dist/scaffold/documentation.js +0 -71
  156. package/dist/scaffold/environment.d.ts +0 -4
  157. package/dist/scaffold/environment.js +0 -22
  158. package/dist/scaffold/stack-documentation.d.ts +0 -2
  159. package/dist/scaffold/stack-documentation.js +0 -6
  160. package/dist/scaffold/storage.d.ts +0 -2
  161. package/dist/scaffold/storage.js +0 -21
  162. package/dist/scaffold/workspace.d.ts +0 -3
  163. package/dist/scaffold/workspace.js +0 -131
  164. package/dist/stack-registry.d.ts +0 -35
  165. package/dist/stack-registry.js +0 -189
  166. package/dist/standard.d.ts +0 -8
  167. package/dist/standard.js +0 -94
  168. package/dist/workspace-graph.d.ts +0 -7
  169. package/dist/workspace-graph.js +0 -74
  170. package/docs/anhedral-stack.md +0 -12
  171. package/docs/assets/anhedral-stack-light.png +0 -0
  172. package/docs/assets/anhedral-stack.png +0 -0
  173. package/docs/native-ui.md +0 -47
  174. /package/dist/{registry/types.js → command-runner.d.ts} +0 -0
@@ -1,12 +1,67 @@
1
- import { COMMANDS, GLOBAL_OPTIONS, optionHelp } from '../command-schema.js';
1
+ import { COMMANDS, GLOBAL_OPTIONS, optionHelp, commandTopic } from '../command-schema.js';
2
2
  export const COMMAND_HELP = Object.fromEntries(Object.entries(COMMANDS).map(([name, entry]) => [
3
3
  name,
4
4
  { ...entry, options: entry.options.map(optionHelp) },
5
5
  ]));
6
6
  export function commandHelp(command) {
7
- const entry = COMMAND_HELP[command];
7
+ const topic = typeof command === 'string' ? command.trim().split(/\s+/) : command;
8
+ const entry = commandTopic(topic);
8
9
  if (!entry)
9
10
  return undefined;
10
- return `${entry.description}\n\nUsage: anhedral ${entry.usage}\n\nOptions:\n${[...entry.options, ...GLOBAL_OPTIONS.map(optionHelp)].map((option) => ` ${option}`).join('\n')}\n\n${entry.note}\n`;
11
+ const children = entry.children
12
+ ? '\nCommands:\n' +
13
+ Object.entries(entry.children)
14
+ .map(([name, child]) => ` ${name.padEnd(10)} ${child.description}`)
15
+ .join('\n') +
16
+ '\n'
17
+ : '';
18
+ const examples = entry.examples.length
19
+ ? '\nExamples:\n' + entry.examples.map((example) => ` anhedral ${example}`).join('\n') + '\n'
20
+ : '';
21
+ return `${entry.description}\n\nUsage: anhedral ${entry.usage}\n${children}${examples}\nOptions:\n${[
22
+ ...entry.options,
23
+ ...GLOBAL_OPTIONS,
24
+ ]
25
+ .filter((option) => !option.hidden)
26
+ .map((option) => ` ${optionHelp(option)}`)
27
+ .join('\n')}\n${entry.note ? `\n${entry.note}\n` : ''}\nDocs: https://github.com/anhedral/anhedral-cli#readme\n`;
11
28
  }
12
- export const STANDARD_USAGE = `Anhedral — an open-source stack foundation\n\n${commandHelp('init')}\n${commandHelp('ui')}\n${commandHelp('add')}\n${commandHelp('stack')}\n -v, --version Show the CLI version.\n`;
29
+ export const STANDARD_USAGE = `Anhedral CLI — source generation and optional Platform access
30
+
31
+ Usage: anhedral <command> [options]
32
+
33
+ Start a project:
34
+ init Create the Anhedral Stack with web UI.
35
+ add Add backend, private storage or payments.
36
+
37
+ Inspect source and UI:
38
+ stack Inspect the Anhedral Stack or run doctor.
39
+ ui Initialize, add, list, diff or check UI components.
40
+
41
+ Optional Platform access:
42
+ login/logout Approve or revoke a CLI session.
43
+ whoami Inspect the current identity and optional local context.
44
+ projects List or create Platform projects.
45
+ link/unlink Select an existing project or remove its local link.
46
+ source Upload source or inspect its receipt.
47
+ deploy Plan, prepare or inspect a candidate; never activates it.
48
+ env Import private configuration or list variable metadata.
49
+ staging Deploy verified candidates to persistent staging.
50
+ logs Read redacted runtime logs for a linked project.
51
+
52
+ Shell setup:
53
+ completion Print Bash or zsh completion without editing profiles.
54
+
55
+ Examples:
56
+ anhedral init my-app
57
+ anhedral add backend --dry-run
58
+ anhedral stack list
59
+
60
+ Global options:
61
+ ${GLOBAL_OPTIONS.map((option) => ' ' + optionHelp(option)).join('\n')}
62
+ -v, --version Show the CLI version.
63
+
64
+ Run anhedral <command> --help for options and examples.
65
+ Docs: https://github.com/anhedral/anhedral-cli#readme
66
+ Issues: https://github.com/anhedral/anhedral-cli/issues
67
+ `;
@@ -1,4 +1,4 @@
1
- import type { StandardRunner } from '../registry/types.js';
2
- export declare function assertWorkspaceRuntime(run: StandardRunner, version?: string): void;
1
+ import type { CommandRunner } from '../command-types.js';
2
+ export declare function assertWorkspaceRuntime(run: CommandRunner, version?: string): void;
3
3
  /** No downloaded template, disposable Next app or initialization-time cloud operation. */
4
- export declare function bootstrapWorkspace(root: string, name: string, run: StandardRunner): void;
4
+ export declare function bootstrapWorkspace(root: string, name: string, run: CommandRunner): void;
@@ -1,3 +1,4 @@
1
- import type { RecipeContext } from '../registry/types.js';
2
1
  /** One shared token source for native components and DOM CSS. */
3
- export declare function scaffoldStyling({ root }: RecipeContext): void;
2
+ export declare function scaffoldStyling({ root }: {
3
+ root: string;
4
+ }): void;
@@ -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,4 +1,4 @@
1
- export type UiPlatform = 'web' | 'native';
1
+ export type UiPlatform = 'web';
2
2
  export interface UiSource {
3
3
  item: string;
4
4
  dependencies: string[];
@@ -8,18 +8,16 @@ export interface UiSource {
8
8
  export interface UiComponent {
9
9
  name: string;
10
10
  web: UiSource | null;
11
- native: UiSource | null;
12
11
  }
13
12
  export declare const UI_CATALOG: {
14
13
  schemaVersion: number;
15
14
  revision: string;
16
- nativeStyling: string;
17
15
  shadcnCliVersion: string;
18
16
  sources: Record<string, string>;
19
17
  components: UiComponent[];
20
18
  };
21
- /** Resolve names only. Upstream shadcn owns dependency resolution and source installation. */
22
- export declare function resolveUiItems(names: string[], platform: UiPlatform, extensionRoot?: string): {
19
+ /** Resolve source-owned shadcn names for the single Anhedral Stack web foundation. */
20
+ export declare function resolveUiItems(names: string[], platform: UiPlatform): {
23
21
  name: string;
24
22
  source: string;
25
23
  item: string;
@@ -1,31 +1,15 @@
1
- import { existsSync, readFileSync } from 'node:fs';
2
- import { fileURLToPath } from 'node:url';
3
- import path from 'node:path';
1
+ import { readFileSync } from 'node:fs';
4
2
  export const UI_CATALOG = JSON.parse(readFileSync(new URL('../assets/ui/catalog.json', import.meta.url), 'utf8'));
5
- const extensions = fileURLToPath(new URL('../assets/ui/extensions/', import.meta.url));
6
- /** Resolve names only. Upstream shadcn owns dependency resolution and source installation. */
7
- export function resolveUiItems(names, platform, extensionRoot = extensions) {
8
- const registry = JSON.parse(readFileSync(path.join(extensionRoot, 'registry.json'), 'utf8'));
3
+ /** Resolve source-owned shadcn names for the single Anhedral Stack web foundation. */
4
+ export function resolveUiItems(names, platform) {
5
+ if (platform !== 'web')
6
+ throw Error('Only the Anhedral Stack web UI is supported.');
9
7
  return [...new Set(names)].map((name) => {
10
8
  if (!/^[a-z][a-z0-9-]{0,79}$/.test(name))
11
9
  throw Error(`Invalid component name: ${name}.`);
12
10
  const component = UI_CATALOG.components.find((item) => item.name === name);
13
- if (!component)
14
- throw Error(`Unknown UI component: ${name}. Run anhedral ui list.`);
15
- if (platform === 'native' && registry.items.some((item) => item.name === name)) {
16
- const file = path.join(extensionRoot, `${name}.json`);
17
- if (!existsSync(file))
18
- throw Error(`Missing reviewed Anhedral extension: ${name}.`);
19
- return { name, source: 'anhedral', item: file };
20
- }
21
- if (!component[platform])
22
- throw Error(`${name} is not yet available for ${platform}. No substitute was installed.`);
23
- return {
24
- name,
25
- source: platform === 'web' ? 'shadcn' : 'react-native-reusables',
26
- item: platform === 'web'
27
- ? name
28
- : `https://reactnativereusables.com/r/nativewind/${component.native.item}.json`,
29
- };
11
+ if (!component?.web)
12
+ throw Error(`Unknown shadcn component: ${name}. Run anhedral ui list.`);
13
+ return { name, source: 'shadcn', item: name };
30
14
  });
31
15
  }
@@ -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
+ /** 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>;
3
5
  export declare function runUiCommand(args: string[], output: OutputOptions, run?: UiRunner): Promise<void>;
@@ -1,11 +1,14 @@
1
- import { existsSync, writeFileSync } from 'node:fs';
1
+ import { existsSync } 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,57 @@ function runUpstream(args, cwd) {
85
88
  });
86
89
  });
87
90
  }
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
+ project.setup?.stack !== ANHEDRAL_STACK.id ||
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);
117
+ }
88
118
  export async function runUiCommand(args, output, run = runUpstream) {
119
+ if (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.');
89
121
  const parsed = commandArguments('ui', args);
90
122
  const [action, ...names] = parsed.positional;
91
123
  if (!['init', 'add', 'list', 'diff', 'doctor'].includes(action))
92
124
  throw commandArgumentError('ui', 'Choose ui init, add, list, diff or doctor.');
93
125
  if (['add', 'diff'].includes(action) ? !names.length || names.length > 50 : names.length > 0)
94
126
  throw commandArgumentError('ui', 'Supply component names only for add/diff (at most 50).');
95
- const selectors = ['--web', '--native', '--all'].filter((flag) => parsed.has(flag));
96
- if (selectors.length > 1)
97
- throw commandArgumentError('ui', 'Choose one of --web, --native or --all.');
98
- const selector = selectors[0]?.slice(2);
127
+ const selector = 'web';
99
128
  let result;
100
129
  if (action === 'list') {
101
130
  result = {
102
131
  catalogRevision: UI_CATALOG.revision,
103
- nativeStyling: UI_CATALOG.nativeStyling,
104
- components: UI_CATALOG.components.filter((item) => !selector || selector === 'all' || item[selector]),
132
+ ...{ platform: 'web' },
133
+ components: UI_CATALOG.components
134
+ .filter((item) => item[selector])
135
+ .map((item) => ({ name: item.name, web: item.web })),
105
136
  };
106
137
  }
107
138
  else {
108
139
  const targets = detectUiTargets(process.cwd(), selector);
140
+ for (const target of targets)
141
+ assertAnhedralStackTarget(target);
109
142
  if (action === 'doctor') {
110
143
  const reports = targets.map(inspectUiTarget);
111
144
  result = {
@@ -116,26 +149,21 @@ export async function runUiCommand(args, output, run = runUpstream) {
116
149
  process.exitCode = 1;
117
150
  }
118
151
  else {
119
- // Preflight every target before invoking any installer, including explicit --all.
152
+ // Preflight every target before invoking any installer, before source installation.
120
153
  const plans = targets.map((target) => {
154
+ assertUiMetadataPaths(target.root);
121
155
  const report = inspectUiTarget(target);
122
156
  const configExists = existsSync(path.join(target.root, 'components.json'));
123
- const nativeInit = action === 'init' && target.platform === 'native';
124
- const issues = nativeInit
125
- ? report.issues.filter((issue) => !issue.startsWith('Missing components.json'))
126
- : report.issues;
127
- if ((action !== 'init' || target.platform === 'native' || configExists) && issues.length)
157
+ const issues = report.issues;
158
+ if ((action !== 'init' || configExists) && issues.length)
128
159
  throw Error(issues.join('\n') + '\n' + report.guide);
129
- if (nativeInit && !configExists && !existsSync(path.join(target.root, 'global.css')))
130
- throw Error('Native init needs the upstream NativeWind global.css. Complete the RNR setup first.');
131
160
  const items = action === 'init' ? [] : resolveUiItems(names, target.platform);
132
161
  return {
133
162
  root: target.root,
134
163
  platform: target.platform,
135
164
  items,
136
- nativeInit,
137
165
  command: action === 'init'
138
- ? configExists || nativeInit
166
+ ? configExists
139
167
  ? []
140
168
  : ['init', '--base', 'base', '--defaults', '--no-reinstall', '--no-monorepo']
141
169
  : [
@@ -148,29 +176,6 @@ export async function runUiCommand(args, output, run = runUpstream) {
148
176
  });
149
177
  if (!parsed.has('--dry-run')) {
150
178
  for (const plan of plans) {
151
- if (plan.nativeInit && !existsSync(path.join(plan.root, 'components.json'))) {
152
- if (!existsSync(path.join(plan.root, 'global.css')))
153
- throw Error('Native init needs the upstream NativeWind global.css. Complete the RNR setup first.');
154
- writeFileSync(path.join(plan.root, 'components.json'), JSON.stringify({
155
- $schema: 'https://ui.shadcn.com/schema.json',
156
- style: 'new-york',
157
- rsc: false,
158
- tsx: true,
159
- tailwind: {
160
- config: 'tailwind.config.js',
161
- css: 'global.css',
162
- baseColor: 'neutral',
163
- cssVariables: true,
164
- },
165
- aliases: {
166
- components: '@/components',
167
- ui: '@/components/ui',
168
- utils: '@/lib/utils',
169
- lib: '@/lib',
170
- hooks: '@/hooks',
171
- },
172
- }, null, 2) + '\n', { flag: 'wx' });
173
- }
174
179
  const vendorOutput = plan.command.length ? await run(plan.command, plan.root) : '';
175
180
  if (action === 'init' || action === 'add')
176
181
  initializeUiMetadata(plan.root, plan.platform);
@@ -185,35 +190,32 @@ export async function runUiCommand(args, output, run = runUpstream) {
185
190
  };
186
191
  }
187
192
  }
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'));
193
+ createReporter(output, () => action === 'list'
194
+ ? UI_CATALOG.components
195
+ .filter((item) => item[selector])
196
+ .map((item) => `${item.name}\tshadcn`)
197
+ .join('\n')
198
+ : action === 'doctor'
199
+ ? result.targets
200
+ .map((report) => [
201
+ `${report.platform}: ${report.configurationReady ? 'configuration ready' : 'setup needed'} (${report.root})`,
202
+ ...report.issues,
203
+ 'Runtime acceptance: not evaluated.',
204
+ ].join('\n'))
205
+ .join('\n\n')
206
+ : result.targets
207
+ .map((target) => [
208
+ `${action}${parsed.has('--dry-run') ? ' (dry run)' : ''}: ${target.platform} (${target.root})`,
209
+ ...(parsed.has('--dry-run')
210
+ ? [
211
+ target.command.length
212
+ ? `shadcn@${UI_CATALOG.shadcnCliVersion} ${target.command.join(' ')}`
213
+ : 'Validate existing configuration; initialize metadata and attribution if absent.',
214
+ ]
215
+ : []),
216
+ target.output?.trim() ?? '',
217
+ ]
218
+ .filter(Boolean)
219
+ .join('\n'))
220
+ .join('\n\n')).result(result);
219
221
  }
@@ -8,15 +8,17 @@ export interface UiTarget {
8
8
  platform: UiPlatform;
9
9
  manifest: Manifest;
10
10
  }
11
- export declare function detectUiTargets(cwd: string, selector?: UiPlatform | 'all'): UiTarget[];
11
+ export declare function detectUiTargets(cwd: string, selector?: UiPlatform): UiTarget[];
12
12
  export declare function inspectUiTarget(target: UiTarget): {
13
13
  root: string;
14
- platform: UiPlatform;
14
+ platform: "web";
15
15
  configurationReady: boolean;
16
16
  issues: string[];
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,12 +13,10 @@ 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['@tanstack/react-start'])
14
19
  targets.push({ root: directory, platform: 'web', manifest });
15
- if (dependencies.expo)
16
- targets.push({ root: directory, platform: 'native', manifest });
17
20
  }
18
21
  for (;;) {
19
22
  inspect(root);
@@ -29,61 +32,63 @@ export function detectUiTargets(cwd, selector) {
29
32
  break;
30
33
  root = parent;
31
34
  }
32
- if (selector && selector !== 'all')
35
+ if (selector)
33
36
  targets = targets.filter((target) => target.platform === selector);
34
37
  if (!targets.length)
35
- throw Error('No matching Next.js or Expo application found. Use --cwd to select an application.');
36
- if (targets.length > 1 && selector !== 'all')
37
- throw Error('Multiple UI applications found. Select --web, --native, --all, or use --cwd for one application.');
38
+ throw Error('No Anhedral Stack TanStack Start application found. Use --cwd to select apps/web.');
39
+ if (targets.length > 1)
40
+ throw Error('Multiple web applications found. Use --cwd to select apps/web.');
38
41
  if (new Set(targets.map((target) => target.root)).size !== targets.length)
39
- throw Error('Web and native UI must use separate application directories.');
42
+ throw Error('UI application directories must be distinct.');
40
43
  return targets;
41
44
  }
42
45
  export function inspectUiTarget(target) {
43
46
  const issues = [];
44
47
  const file = path.join(target.root, 'components.json');
45
- const config = existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : null;
48
+ const config = existsSync(file) ? readUiJson(file) : null;
46
49
  if (!config)
47
50
  issues.push('Missing components.json. Run anhedral ui init for this application.');
48
51
  if (config && (!config.aliases?.ui || !config.aliases?.utils || !config.tailwind?.css))
49
52
  issues.push('components.json needs UI/utils aliases and a Tailwind CSS entry.');
50
53
  const marker = path.join(target.root, '.anhedral-ui.json');
51
- if (existsSync(marker) && JSON.parse(readFileSync(marker, 'utf8')).platform !== target.platform)
54
+ if (existsSync(marker) && readUiJson(marker).platform !== target.platform)
52
55
  issues.push('Existing Anhedral UI configuration targets another platform.');
53
- if (target.platform === 'native') {
54
- const dependencies = { ...target.manifest.devDependencies, ...target.manifest.dependencies };
55
- for (const dependency of [
56
- 'class-variance-authority',
57
- 'clsx',
58
- 'tailwind-merge',
59
- 'tailwindcss-animate',
60
- '@rn-primitives/portal',
61
- ])
62
- if (!dependencies[dependency])
63
- issues.push(`Missing RNR baseline dependency: ${dependency}. Complete the upstream setup first.`);
64
- if (!/^\D*4\./.test(dependencies.nativewind ?? ''))
65
- issues.push('Set up NativeWind 4 using the RNR manual guide before native UI installation.');
66
- if (!['metro.config.js', 'metro.config.cjs', 'metro.config.ts'].some((name) => existsSync(path.join(target.root, name))))
67
- issues.push('Missing Metro configuration. Complete the upstream NativeWind setup first.');
68
- if (config?.rsc)
69
- issues.push('Native components.json must set rsc to false.');
70
- }
71
56
  return {
72
57
  root: target.root,
73
58
  platform: target.platform,
74
59
  configurationReady: issues.length === 0,
75
60
  issues,
76
61
  runtimeAcceptance: 'not evaluated',
77
- guide: target.platform === 'native'
78
- ? 'https://reactnativereusables.com/docs/installation/manual'
79
- : 'https://ui.shadcn.com/docs/installation/next',
62
+ guide: 'https://ui.shadcn.com/docs/installation/tanstack',
80
63
  };
81
64
  }
65
+ /** Check CLI-owned destinations before upstream or attribution writes. */
66
+ export function assertUiMetadataPaths(root) {
67
+ for (const [relative, directory] of [
68
+ ['.anhedral-ui.json', false],
69
+ ['ANHEDRAL_UI_LICENSES', true],
70
+ ['ANHEDRAL_UI_LICENSES/LICENSE.shadcn', false],
71
+ ['ANHEDRAL_UI_LICENSES/LICENSE.react-native-reusables', false],
72
+ ]) {
73
+ let info;
74
+ try {
75
+ info = lstatSync(path.join(root, relative));
76
+ }
77
+ catch (error) {
78
+ if (error.code === 'ENOENT')
79
+ continue;
80
+ throw error;
81
+ }
82
+ if (info.isSymbolicLink() || (directory ? !info.isDirectory() : !info.isFile()))
83
+ throw Error(`Unsafe UI metadata path: ${relative}. Preserve it and reconcile before installing.`);
84
+ }
85
+ }
82
86
  /** New metadata and attribution only; never overwrite consumer-owned files. */
83
87
  export function initializeUiMetadata(root, platform) {
88
+ assertUiMetadataPaths(root);
84
89
  const file = path.join(root, '.anhedral-ui.json');
85
90
  if (existsSync(file)) {
86
- const existing = JSON.parse(readFileSync(file, 'utf8'));
91
+ const existing = readUiJson(file);
87
92
  if (existing.platform !== platform)
88
93
  throw Error('Existing Anhedral UI configuration targets another platform.');
89
94
  }
@@ -92,15 +97,12 @@ export function initializeUiMetadata(root, platform) {
92
97
  schemaVersion: 1,
93
98
  platform,
94
99
  catalogRevision: UI_CATALOG.revision,
95
- nativeStyling: platform === 'native' ? UI_CATALOG.nativeStyling : undefined,
96
100
  sourceOwned: true,
97
101
  automaticUpdates: false,
98
102
  }, null, 2) + '\n', { flag: 'wx' });
99
103
  const licenses = path.join(root, 'ANHEDRAL_UI_LICENSES');
100
104
  mkdirSync(licenses, { recursive: true });
101
- for (const name of platform === 'native'
102
- ? ['LICENSE.react-native-reusables', 'LICENSE.shadcn']
103
- : ['LICENSE.shadcn']) {
105
+ for (const name of ['LICENSE.shadcn']) {
104
106
  const destination = path.join(licenses, name);
105
107
  if (!existsSync(destination))
106
108
  writeFileSync(destination, readFileSync(new URL(`../assets/ui/${name}`, import.meta.url)), {