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
@@ -0,0 +1,111 @@
1
+ import { sourceContainsCredential as localCredentialMaterial } from '../assets/security/credential-patterns.mjs';
2
+ import { constants } from 'node:fs';
3
+ import { lstat, readFile, readdir, open } from 'node:fs/promises';
4
+ import { join } from 'node:path';
5
+ import ignore from 'ignore';
6
+ import { SOURCE_LIMITS, sourceContainsCredential, uploadExcluded, uploadSecret, } from './contracts/cli-transport.js';
7
+ import { excludedSource, generatedSource, secretSource } from './contracts/source-profile.js';
8
+ import { packSource, setSourceExecutable, sourceInventory, validateSourcePath, } from './contracts/source-bundle.js';
9
+ import { platformFailure } from './platform-state.js';
10
+ export async function packageSource(root) {
11
+ const files = new Map();
12
+ 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);
16
+ if (gitignore && (!gitignore.isFile() || gitignore.isSymbolicLink()))
17
+ throw platformFailure('Source ignore file is unsafe.');
18
+ if (gitignore) {
19
+ if (gitignore.size > 65536)
20
+ throw platformFailure('Source ignore file exceeds its limit.');
21
+ rules = [
22
+ ...rules,
23
+ {
24
+ base: relative,
25
+ matcher: ignore().add(await readFile(join(directory, '.gitignore'), 'utf8')),
26
+ },
27
+ ];
28
+ }
29
+ for (const entry of (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
30
+ const path = relative ? `${relative}/${entry.name}` : entry.name;
31
+ if (excludedSource.test(path) ||
32
+ generatedSource.test(path) ||
33
+ secretSource.test(path) ||
34
+ uploadExcluded.test(path) ||
35
+ uploadSecret.test(path))
36
+ continue;
37
+ let ignored = false;
38
+ for (const { base, matcher } of rules) {
39
+ const match = matcher.test(path.slice(base ? base.length + 1 : 0) + (entry.isDirectory() ? '/' : ''));
40
+ if (match.ignored)
41
+ ignored = true;
42
+ else if (match.unignored)
43
+ ignored = false;
44
+ }
45
+ if (ignored)
46
+ continue;
47
+ const info = await lstat(join(root, path));
48
+ if (info.isSymbolicLink() || (!info.isFile() && !info.isDirectory()))
49
+ throw platformFailure('Source contains a symbolic link or special file. Exclude it before uploading.');
50
+ validateSourcePath(path);
51
+ if (info.isDirectory()) {
52
+ await walk(path, rules);
53
+ continue;
54
+ }
55
+ if (files.size >= SOURCE_LIMITS.files || (bytes += info.size) > SOURCE_LIMITS.bytes)
56
+ throw platformFailure('Source exceeds its file or byte limit.');
57
+ const handle = await open(join(root, path), constants.O_RDONLY | constants.O_NOFOLLOW);
58
+ let content;
59
+ try {
60
+ const before = await handle.stat();
61
+ if (!before.isFile() ||
62
+ before.dev !== info.dev ||
63
+ before.ino !== info.ino ||
64
+ before.size !== info.size)
65
+ throw platformFailure('Source changed during packaging.');
66
+ content = Buffer.alloc(info.size);
67
+ let offset = 0;
68
+ while (offset < content.length) {
69
+ const read = await handle.read(content, offset, content.length - offset, offset);
70
+ if (!read.bytesRead)
71
+ break;
72
+ offset += read.bytesRead;
73
+ }
74
+ const after = await handle.stat();
75
+ if (offset !== info.size || after.size !== info.size || after.mtimeMs !== before.mtimeMs)
76
+ throw platformFailure('Source changed during packaging.');
77
+ }
78
+ finally {
79
+ await handle.close();
80
+ }
81
+ if (content.length !== info.size)
82
+ throw platformFailure('Source changed during packaging. Retry after saving your files.');
83
+ if (sourceContainsCredential(content) || localCredentialMaterial(content))
84
+ throw platformFailure('Source contains credential material. Remove it before uploading.');
85
+ files.set(path, content);
86
+ setSourceExecutable(files, path, Boolean(info.mode & 0o111));
87
+ }
88
+ }
89
+ await walk('', []);
90
+ const config = files.get('anhedral.json');
91
+ if (!config || !files.has('pnpm-lock.yaml'))
92
+ throw platformFailure('Upload requires anhedral.json and pnpm-lock.yaml.');
93
+ let cliVersion;
94
+ try {
95
+ cliVersion = JSON.parse(new TextDecoder().decode(config)).setup?.cliVersion;
96
+ }
97
+ catch {
98
+ throw platformFailure('Workspace configuration is invalid.');
99
+ }
100
+ if (typeof cliVersion !== 'string')
101
+ throw platformFailure('The workspace must declare setup.cliVersion.');
102
+ const inventory = await sourceInventory(files), archive = await packSource(files);
103
+ return {
104
+ archive,
105
+ inventoryDigest: inventory.digest,
106
+ cliVersion,
107
+ files: files.size,
108
+ paths: [...files.keys()].sort(),
109
+ bytes,
110
+ };
111
+ }
@@ -0,0 +1,15 @@
1
+ import { CliFailure } from './cli-errors.js';
2
+ export type PlatformFailureCategory = ConstructorParameters<typeof CliFailure>[3];
3
+ export declare const platformFailure: (message: string, nextAction?: string, category?: PlatformFailureCategory, retryable?: boolean) => CliFailure;
4
+ export declare function platformOrigin(value?: string): string;
5
+ export declare function readPrivate(path: string): Promise<unknown | null>;
6
+ export declare function writePrivate(path: string, data: unknown): Promise<void>;
7
+ /** Serialize project selection and request journals; never steal a potentially live lock. */
8
+ export declare function withProjectLock<T>(directory: string, operation: () => Promise<T>): Promise<T>;
9
+ export interface SecretStore {
10
+ read(): Promise<unknown | null>;
11
+ write(data: unknown): Promise<void>;
12
+ clear(): Promise<void>;
13
+ }
14
+ export declare function runCredentialProcess(binary: string, args: string[], input?: string, timeoutMs?: number): Promise<string>;
15
+ export declare function secretStore(origin: string, file?: string, runProcess?: typeof runCredentialProcess, platform?: NodeJS.Platform): SecretStore;
@@ -0,0 +1,229 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { createHash, randomUUID } from 'node:crypto';
3
+ import { dirname, join } from 'node:path';
4
+ import { lstat, mkdir, open, readFile, rename, unlink, writeFile } from 'node:fs/promises';
5
+ import { CliArgumentError } from './cli-arguments.js';
6
+ import { CliFailure } from './cli-errors.js';
7
+ export const platformFailure = (message, nextAction = 'Run anhedral login --help.', category = 'context', retryable = false) => new CliFailure(message, 'PLATFORM_ACCESS_FAILED', nextAction, category, retryable);
8
+ export function platformOrigin(value = 'https://platform.anhedral.com') {
9
+ let url;
10
+ try {
11
+ url = new URL(value);
12
+ }
13
+ catch {
14
+ throw new CliArgumentError('Choose a valid HTTPS API origin with --api-url.', 'Run anhedral login --help.');
15
+ }
16
+ if (url.username ||
17
+ url.password ||
18
+ url.search ||
19
+ url.hash ||
20
+ url.pathname !== '/' ||
21
+ (url.protocol !== 'https:' &&
22
+ !(url.protocol === 'http:' && ['127.0.0.1', '[::1]'].includes(url.hostname))))
23
+ throw new CliArgumentError('Choose an HTTPS API origin (literal loopback is allowed for local testing).', 'Run anhedral login --help.');
24
+ return url.origin;
25
+ }
26
+ async function safeDirectory(path, privateMode = true) {
27
+ const parent = dirname(path);
28
+ if (parent !== path) {
29
+ const info = await lstat(parent).catch(() => null);
30
+ if (!info)
31
+ await safeDirectory(parent, false);
32
+ else if (info.isSymbolicLink() || !info.isDirectory())
33
+ throw platformFailure('State directory is unsafe.');
34
+ }
35
+ await mkdir(path, { mode: 0o700 }).catch(async (error) => {
36
+ if (error.code !== 'EEXIST')
37
+ throw error;
38
+ });
39
+ const info = await lstat(path);
40
+ if (!info.isDirectory() ||
41
+ info.isSymbolicLink() ||
42
+ (privateMode &&
43
+ process.platform !== 'win32' &&
44
+ ((info.mode & 0o077) !== 0 || info.uid !== process.getuid?.())))
45
+ throw platformFailure('State directory must be owned by you with mode 0700.');
46
+ }
47
+ export async function readPrivate(path) {
48
+ // Validate every existing ancestor before following it.
49
+ for (let p = dirname(path);; p = dirname(p)) {
50
+ const info = await lstat(p).catch(() => null);
51
+ if (info?.isSymbolicLink() || (info && !info.isDirectory()))
52
+ throw platformFailure('State directory is unsafe.');
53
+ if (dirname(p) === p)
54
+ break;
55
+ }
56
+ const info = await lstat(path).catch((error) => {
57
+ if (error.code === 'ENOENT')
58
+ return null;
59
+ throw error;
60
+ });
61
+ if (!info)
62
+ return null;
63
+ if (!info.isFile() ||
64
+ info.isSymbolicLink() ||
65
+ info.size > 65536 ||
66
+ (process.platform !== 'win32' && ((info.mode & 0o077) !== 0 || info.uid !== process.getuid?.())))
67
+ throw platformFailure('State file must be owned by you with mode 0600.');
68
+ const text = await readFile(path, 'utf8');
69
+ try {
70
+ return JSON.parse(text);
71
+ }
72
+ catch {
73
+ throw platformFailure('Saved Platform state is not valid JSON. Preserve the file and reconcile the selected context.', 'Run anhedral whoami --context --help.');
74
+ }
75
+ }
76
+ export async function writePrivate(path, data) {
77
+ await safeDirectory(dirname(path));
78
+ await readPrivate(path);
79
+ const temp = join(dirname(path), `.state-${randomUUID()}`);
80
+ try {
81
+ await writeFile(temp, JSON.stringify(data) + '\n', { mode: 0o600, flag: 'wx' });
82
+ await rename(temp, path);
83
+ }
84
+ finally {
85
+ await unlink(temp).catch(() => { });
86
+ }
87
+ }
88
+ /** Serialize project selection and request journals; never steal a potentially live lock. */
89
+ export async function withProjectLock(directory, operation) {
90
+ await safeDirectory(directory);
91
+ const lockPath = join(directory, 'project-operation.lock');
92
+ let file;
93
+ try {
94
+ file = await open(lockPath, 'wx', 0o600);
95
+ }
96
+ catch (error) {
97
+ if (error.code === 'EEXIST')
98
+ throw platformFailure('Another project operation holds the workspace lock.', 'Wait for the operation to finish. After an interrupted process, inspect .anhedral/platform/project-operation.lock and remove it only after confirming no project operation is running; preserve the saved operation state, then retry the same command without --new.', 'conflict', true);
99
+ throw error;
100
+ }
101
+ try {
102
+ await file.writeFile(JSON.stringify({ pid: process.pid, startedAt: new Date().toISOString() }) + '\n');
103
+ return await operation();
104
+ }
105
+ finally {
106
+ await file.close();
107
+ await unlink(lockPath);
108
+ }
109
+ }
110
+ export function runCredentialProcess(binary, args, input = '', timeoutMs = 30000) {
111
+ return new Promise((resolve, reject) => {
112
+ const child = spawn(binary, args, { stdio: ['pipe', 'pipe', 'pipe'] });
113
+ let result = '';
114
+ let failure;
115
+ const timer = setTimeout(() => {
116
+ failure = platformFailure('System credential storage timed out. Check the credential service before retrying.');
117
+ child.kill('SIGKILL');
118
+ }, timeoutMs);
119
+ child.stdout.on('data', (data) => {
120
+ result += data;
121
+ if (result.length > 65536) {
122
+ failure = platformFailure('System credential storage returned too much data.');
123
+ child.kill('SIGKILL');
124
+ }
125
+ });
126
+ child.on('error', () => {
127
+ clearTimeout(timer);
128
+ reject(platformFailure('System credential storage is unavailable. Choose an explicit --credential-file if needed.'));
129
+ });
130
+ child.on('close', (code) => {
131
+ clearTimeout(timer);
132
+ if (failure)
133
+ reject(failure);
134
+ else if (code === 0)
135
+ resolve(result.trim());
136
+ else
137
+ reject(platformFailure('System credential storage could not be accessed.'));
138
+ });
139
+ child.stdin.on('error', () => { });
140
+ child.stdin.end(input);
141
+ });
142
+ }
143
+ export function secretStore(origin, file, runProcess = runCredentialProcess, platform = process.platform) {
144
+ if (file && platform === 'win32')
145
+ throw platformFailure('Secure Windows credential storage is not implemented. Use macOS Keychain or Linux Secret Service for this preview.');
146
+ if (file)
147
+ return {
148
+ read: () => readPrivate(file),
149
+ write: (data) => writePrivate(file, data),
150
+ clear: async () => {
151
+ await readPrivate(file);
152
+ await unlink(file).catch((e) => {
153
+ if (e.code !== 'ENOENT')
154
+ throw e;
155
+ });
156
+ },
157
+ };
158
+ const account = createHash('sha256').update(origin).digest('hex');
159
+ if (platform === 'darwin') {
160
+ // -i reads commands on stdin, keeping secret values out of process argv.
161
+ const run = (command) => runProcess('/usr/bin/security', ['-i'], command + '\n');
162
+ const quote = (v) => '"' + v.replaceAll('\\', '\\\\').replaceAll('"', '\\"') + '"';
163
+ return {
164
+ read: async () => {
165
+ try {
166
+ return JSON.parse(await runProcess('/usr/bin/security', [
167
+ 'find-generic-password',
168
+ '-s',
169
+ 'dev.anhedral.cli.v1',
170
+ '-a',
171
+ account,
172
+ '-w',
173
+ ]));
174
+ }
175
+ catch {
176
+ return null;
177
+ }
178
+ },
179
+ write: async (data) => {
180
+ await run(`add-generic-password -U -s dev.anhedral.cli.v1 -a ${account} -w ${quote(JSON.stringify(data))}`);
181
+ const stored = await runProcess('/usr/bin/security', [
182
+ 'find-generic-password',
183
+ '-s',
184
+ 'dev.anhedral.cli.v1',
185
+ '-a',
186
+ account,
187
+ '-w',
188
+ ]);
189
+ if (stored !== JSON.stringify(data))
190
+ throw platformFailure('Credential storage could not be verified.');
191
+ },
192
+ clear: async () => {
193
+ await runProcess('/usr/bin/security', [
194
+ 'delete-generic-password',
195
+ '-s',
196
+ 'dev.anhedral.cli.v1',
197
+ '-a',
198
+ account,
199
+ ]);
200
+ },
201
+ };
202
+ }
203
+ if (platform === 'linux')
204
+ return {
205
+ read: async () => {
206
+ const value = await runProcess('secret-tool', [
207
+ 'lookup',
208
+ 'service',
209
+ 'dev.anhedral.cli.v1',
210
+ 'origin',
211
+ account,
212
+ ]).catch(() => '');
213
+ return value ? JSON.parse(value) : null;
214
+ },
215
+ write: async (data) => {
216
+ await runProcess('secret-tool', ['store', '--label=Anhedral CLI', 'service', 'dev.anhedral.cli.v1', 'origin', account], JSON.stringify(data));
217
+ },
218
+ clear: async () => {
219
+ await runProcess('secret-tool', [
220
+ 'clear',
221
+ 'service',
222
+ 'dev.anhedral.cli.v1',
223
+ 'origin',
224
+ account,
225
+ ]);
226
+ },
227
+ };
228
+ throw platformFailure('Secure credential storage is unsupported on this platform.');
229
+ }
@@ -0,0 +1,10 @@
1
+ import { CapabilityEditor } from '../capability-editor.js';
2
+ import type { Capability } from '../capability-catalog.js';
3
+ /** The launch foundation is a web service; Hono owns application services and data. */
4
+ export declare function scaffoldTanstack(root: string, name: string): void;
5
+ /** One-time source upgrade, planned in the same bounded overlay as each addition. */
6
+ export declare function normalizeOjFoundation(e: CapabilityEditor, installed: readonly Capability[], refreshConfiguration?: boolean): boolean;
7
+ /** Fingerprinted composition adapters; application routes stay source-owned. */
8
+ export declare function composeTanstack(e: CapabilityEditor, installed: readonly Capability[]): void;
9
+ /** Install account source only when the backend authentication capability is added. */
10
+ export declare function addTanstackAuth(e: CapabilityEditor): void;
@@ -0,0 +1,248 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { ANHEDRAL_STACK_DEPENDENCIES, WEB_DEPENDENCIES } from '../dependencies.js';
4
+ import { CapabilityEditor, fingerprint } from '../capability-editor.js';
5
+ import { resourceName } from '../render.js';
6
+ import { json, put, workerConfig } from '../scaffold/files.js';
7
+ import { initializeUiMetadata } from '../ui-project.js';
8
+ const template = (name) => readFileSync(new URL(`../../assets/launch/${name}`, import.meta.url), 'utf8');
9
+ /** The launch foundation is a web service; Hono owns application services and data. */
10
+ export function scaffoldTanstack(root, name) {
11
+ const app = 'apps/web';
12
+ const web = WEB_DEPENDENCIES.dependencies;
13
+ const dev = WEB_DEPENDENCIES.devDependencies;
14
+ json(root, `${app}/package.json`, {
15
+ name: '@workspace/web',
16
+ private: true,
17
+ version: '0.1.0',
18
+ type: 'module',
19
+ scripts: {
20
+ dev: 'node ../../scripts/oj.mjs dev . --host=0.0.0.0 --port 3000',
21
+ build: 'node ../../scripts/oj.mjs build .',
22
+ preview: 'wrangler dev --config dist/ssr/wrangler.json --port 3000',
23
+ deploy: 'wrangler deploy --config dist/ssr/wrangler.json',
24
+ typecheck: 'wrangler types && tsr generate && tsc --noEmit',
25
+ lint: 'eslint . --max-warnings 0',
26
+ },
27
+ dependencies: {
28
+ '@tanstack/react-start': ANHEDRAL_STACK_DEPENDENCIES['@tanstack/react-start'],
29
+ '@tanstack/react-router': ANHEDRAL_STACK_DEPENDENCIES['@tanstack/react-router'],
30
+ react: web.react,
31
+ 'react-dom': web['react-dom'],
32
+ '@base-ui/react': web['@base-ui/react'],
33
+ 'class-variance-authority': web['class-variance-authority'],
34
+ clsx: web.clsx,
35
+ 'tailwind-merge': web['tailwind-merge'],
36
+ '@workspace/styling': 'workspace:*',
37
+ },
38
+ devDependencies: {
39
+ '@cloudflare/vite-plugin': ANHEDRAL_STACK_DEPENDENCIES['@cloudflare/vite-plugin'],
40
+ '@tanstack/router-cli': ANHEDRAL_STACK_DEPENDENCIES['@tanstack/router-cli'],
41
+ '@vitejs/plugin-react': ANHEDRAL_STACK_DEPENDENCIES['@vitejs/plugin-react'],
42
+ vite: ANHEDRAL_STACK_DEPENDENCIES.vite,
43
+ wrangler: ANHEDRAL_STACK_DEPENDENCIES.wrangler,
44
+ typescript: dev.typescript,
45
+ '@types/node': dev['@types/node'],
46
+ '@types/react': dev['@types/react'],
47
+ '@types/react-dom': dev['@types/react-dom'],
48
+ tailwindcss: dev.tailwindcss,
49
+ '@tailwindcss/postcss': dev['@tailwindcss/postcss'],
50
+ eslint: dev.eslint,
51
+ '@workspace/eslint-config': 'workspace:*',
52
+ },
53
+ });
54
+ json(root, `${app}/wrangler.jsonc`, {
55
+ ...workerConfig(resourceName(name, 'web')),
56
+ main: 'src/server.ts',
57
+ compatibility_date: '2026-11-02',
58
+ services: [],
59
+ });
60
+ json(root, `${app}/tsconfig.json`, {
61
+ compilerOptions: {
62
+ target: 'ES2022',
63
+ lib: ['DOM', 'DOM.Iterable', 'ES2022'],
64
+ skipLibCheck: true,
65
+ strict: true,
66
+ noEmit: true,
67
+ esModuleInterop: true,
68
+ module: 'ESNext',
69
+ moduleResolution: 'Bundler',
70
+ resolveJsonModule: true,
71
+ isolatedModules: true,
72
+ jsx: 'react-jsx',
73
+ types: ['vite/client'],
74
+ paths: { '@/*': ['./src/*'] },
75
+ },
76
+ include: ['src/**/*.ts', 'src/**/*.tsx', 'vite.config.ts', 'worker-configuration.d.ts'],
77
+ exclude: ['node_modules', 'dist'],
78
+ });
79
+ json(root, `${app}/tsr.config.json`, {
80
+ routesDirectory: './src/routes',
81
+ generatedRouteTree: './src/routeTree.gen.ts',
82
+ });
83
+ put(root, `${app}/eslint.config.mjs`, `import { config } from '@workspace/eslint-config/react-internal';
84
+ export default [...config, { ignores: ['dist/**', '.wrangler/**', 'src/routeTree.gen.ts', 'worker-configuration.d.ts'] }];
85
+ `);
86
+ json(root, `${app}/components.json`, {
87
+ $schema: 'https://ui.shadcn.com/schema.json',
88
+ style: 'base-nova',
89
+ rsc: false,
90
+ tsx: true,
91
+ tailwind: { config: '', css: 'src/styles.css', baseColor: 'neutral', cssVariables: true },
92
+ aliases: {
93
+ components: '@/components',
94
+ ui: '@/components/ui',
95
+ utils: '@/lib/utils',
96
+ lib: '@/lib',
97
+ hooks: '@/hooks',
98
+ },
99
+ iconLibrary: 'lucide',
100
+ });
101
+ initializeUiMetadata(path.join(root, app), 'web');
102
+ put(root, `${app}/src/lib/utils.ts`, `import { clsx, type ClassValue } from 'clsx';
103
+ import { twMerge } from 'tailwind-merge';
104
+ export function cn(...values: ClassValue[]) { return twMerge(clsx(values)); }
105
+ `);
106
+ for (const component of ['button', 'input', 'label'])
107
+ put(root, `${app}/src/components/ui/${component}.tsx`, readFileSync(new URL(`../../assets/ui/web/${component}.tsx`, import.meta.url), 'utf8'));
108
+ for (const file of ['LICENSE.shadcn', 'UPSTREAM.json'])
109
+ put(root, `${app}/${file}`, readFileSync(new URL(`../../assets/ui/${file}`, import.meta.url), 'utf8'));
110
+ put(root, `${app}/postcss.config.mjs`, "export default { plugins: { '@tailwindcss/postcss': {} } };\n");
111
+ put(root, `${app}/src/starter.ts`, `export const starterTitle = ${JSON.stringify(name)};\n`);
112
+ const files = {
113
+ 'src/router.tsx': 'router.tsx.txt',
114
+ 'src/lib/request-context.ts': 'request-context.ts.txt',
115
+ 'src/routes/__root.tsx': 'root.tsx.txt',
116
+ 'src/routes/index.tsx': 'home.tsx.txt',
117
+ 'src/styles.css': 'styles.css.txt',
118
+ };
119
+ for (const [destination, source] of Object.entries(files))
120
+ put(root, `${app}/${destination}`, template(source).replaceAll('__APPLICATION_NAME__', JSON.stringify(name)));
121
+ put(root, `${app}/public/robots.txt`, 'User-agent: *\nAllow: /\n');
122
+ put(root, `${app}/public/_headers`, '/assets/*\n Cache-Control: public, max-age=31536000, immutable\n/*\n X-Content-Type-Options: nosniff\n');
123
+ }
124
+ function assertTanstack(e) {
125
+ if (!e.json('apps/web/package.json').dependencies?.['@tanstack/react-start'])
126
+ throw Error('Only the Anhedral Stack TanStack Start foundation is supported.');
127
+ }
128
+ const ojScripts = {
129
+ dev: 'node ../../scripts/oj.mjs dev . --host=0.0.0.0 --port 3000',
130
+ build: 'node ../../scripts/oj.mjs build .',
131
+ preview: 'wrangler dev --config dist/ssr/wrangler.json --port 3000',
132
+ deploy: 'wrangler deploy --config dist/ssr/wrangler.json',
133
+ };
134
+ const previousScripts = {
135
+ dev: 'vite dev --host 0.0.0.0 --port 3000',
136
+ build: 'vite build',
137
+ preview: 'vite preview --host 0.0.0.0 --port 3000',
138
+ };
139
+ const ojFiles = {
140
+ 'scripts/oj.mjs': 'oj/run.mjs',
141
+ 'scripts/oj-runtime.json': 'oj/runtime.json',
142
+ 'scripts/OJ.LICENSE': 'oj/OJ.LICENSE',
143
+ };
144
+ function tanstackViteConfiguration(installed) {
145
+ const backend = installed.includes('hono');
146
+ return `import { fileURLToPath } from 'node:url';
147
+ import { defineConfig } from 'vite';
148
+ import { cloudflare } from '@cloudflare/vite-plugin';
149
+ import { tanstackStart } from '@tanstack/react-start/plugin/vite';
150
+ import react from '@vitejs/plugin-react';
151
+ export default defineConfig(${backend ? '({ command }) => (' : ''}{
152
+ resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
153
+ plugins: [
154
+ cloudflare({ viteEnvironment: { name: 'ssr' }, ${backend ? "auxiliaryWorkers: command === 'serve' ? [{ configPath: '../api/wrangler.jsonc' }] : [], persistState: { path: fileURLToPath(new URL('../api/.wrangler/state', import.meta.url)) }, " : ''}remoteBindings: false }),
155
+ tanstackStart({ server: { entry: './server.ts' } }),
156
+ react(),
157
+ ],
158
+ }${backend ? ')' : ''});
159
+ `;
160
+ }
161
+ /** One-time source upgrade, planned in the same bounded overlay as each addition. */
162
+ export function normalizeOjFoundation(e, installed, refreshConfiguration = false) {
163
+ assertTanstack(e);
164
+ const file = 'apps/web/package.json';
165
+ const scripts = e.json(file).scripts;
166
+ if (!scripts || typeof scripts !== 'object' || Array.isArray(scripts))
167
+ throw Error('Preserve invalid web scripts; reconcile the Anhedral Stack launcher first.');
168
+ // Never overwrite a customer launcher while claiming the runtime was upgraded.
169
+ for (const [name, desired] of Object.entries(ojScripts)) {
170
+ const current = scripts[name];
171
+ const previous = Reflect.get(previousScripts, name);
172
+ const previousOjDev = name === 'dev' && current === 'node ../../scripts/oj.mjs dev . --host 0.0.0.0 --port 3000';
173
+ if (current !== undefined && current !== desired && current !== previous && !previousOjDev)
174
+ throw Error(`Preserve customized web launcher scripts.${name}. Reconcile it with the pinned OJ runtime before adding capabilities. No files were changed.`);
175
+ }
176
+ let changed = false;
177
+ const serverEntry = 'apps/web/src/server.ts';
178
+ const currentEntry = e.read(serverEntry);
179
+ // Repair only the exact shipped adapter whose default-entry shim drops Start context in OJ.
180
+ if (installed.includes('hono') &&
181
+ currentEntry !== null &&
182
+ fingerprint(currentEntry) ===
183
+ '703adff2e57adfbbdb7fa90b4dadffde8617c86cc31a185943931ef7c623eca7' &&
184
+ e.managed[serverEntry] === fingerprint(currentEntry)) {
185
+ e.owned(serverEntry, template('server.ts.txt'));
186
+ changed = true;
187
+ }
188
+ const rootRoute = 'apps/web/src/routes/__root.tsx';
189
+ const rootSource = e.read(rootRoute);
190
+ // A one-way repair of the exact shipped document, without owning customer routes.
191
+ if (rootSource !== null &&
192
+ fingerprint(rootSource) === '21af7892e39130c9ec3d7ffb583b3f5d24bee771440ca253d8d7b8ce41be9801') {
193
+ e.writes.set(rootRoute, template('root.tsx.txt'));
194
+ changed = true;
195
+ }
196
+ else if (rootSource !== null && /\bfrom\s*(['"])\.\.\/styles\.css\?url\1/.test(rootSource))
197
+ throw Error('Preserve customized root route CSS. Reconcile its stylesheet URL import with the OJ side-effect CSS pattern before adding capabilities. No files were changed.');
198
+ for (const [name, desired] of Object.entries(ojScripts)) {
199
+ if (scripts[name] !== desired) {
200
+ e.set(file, ['scripts', name], desired);
201
+ changed = true;
202
+ }
203
+ }
204
+ for (const [destination, asset] of Object.entries(ojFiles)) {
205
+ const desired = template(asset);
206
+ if (e.read(destination) !== desired) {
207
+ e.owned(destination, desired);
208
+ changed = true;
209
+ }
210
+ else if (e.managed[destination] !== fingerprint(desired)) {
211
+ e.managed[destination] = fingerprint(desired);
212
+ changed = true;
213
+ }
214
+ }
215
+ const ignore = e.read('.gitignore') ?? '';
216
+ if (!ignore.split(/\r?\n/).includes('.oj-cache/')) {
217
+ e.writes.set('.gitignore', ignore + (ignore && !ignore.endsWith('\n') ? '\n' : '') + '.oj-cache/\n');
218
+ changed = true;
219
+ }
220
+ const configuration = 'apps/web/vite.config.ts';
221
+ const currentConfiguration = e.read(configuration);
222
+ const desiredConfiguration = tanstackViteConfiguration(installed);
223
+ if (currentConfiguration !== desiredConfiguration &&
224
+ (changed ||
225
+ refreshConfiguration ||
226
+ (currentConfiguration !== null &&
227
+ e.managed[configuration] === fingerprint(currentConfiguration)))) {
228
+ e.owned(configuration, desiredConfiguration);
229
+ changed = true;
230
+ }
231
+ return changed;
232
+ }
233
+ /** Fingerprinted composition adapters; application routes stay source-owned. */
234
+ export function composeTanstack(e, installed) {
235
+ assertTanstack(e);
236
+ normalizeOjFoundation(e, installed);
237
+ const backend = installed.includes('hono');
238
+ const auth = installed.includes('database-auth');
239
+ e.owned('apps/web/src/server.ts', template(backend ? 'server.ts.txt' : 'minimal-server.ts.txt'));
240
+ e.owned('apps/web/src/lib/application.server.ts', template(backend ? 'application.server.ts.txt' : 'minimal-application.server.ts.txt').replaceAll('__AUTHENTICATION__', String(auth)));
241
+ e.owned('apps/web/vite.config.ts', tanstackViteConfiguration(installed));
242
+ }
243
+ /** Install account source only when the backend authentication capability is added. */
244
+ export function addTanstackAuth(e) {
245
+ assertTanstack(e);
246
+ e.create('apps/web/src/lib/auth-client.ts', template('auth-client.ts.txt'));
247
+ e.create('apps/web/src/routes/sign-in.tsx', template('sign-in.tsx.txt'));
248
+ }
@@ -5,7 +5,10 @@ export declare const COMMAND_HELP: {
5
5
  usage: string;
6
6
  examples: readonly string[];
7
7
  note?: string;
8
+ children?: Readonly<Record<string, import("../command-schema.js").CommandDefinition>>;
9
+ positional?: import("../command-schema.js").CommandPositional;
10
+ conflicts?: readonly (readonly string[])[];
8
11
  };
9
12
  };
10
- export declare function commandHelp(command: string): string | undefined;
13
+ export declare function commandHelp(command: string | readonly string[]): string | undefined;
11
14
  export declare const STANDARD_USAGE: string;