anhedral 0.18.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 (119) hide show
  1. package/README.md +6 -6
  2. package/assets/contracts/deployment-provenance.json +6 -6
  3. package/assets/contracts/operations-provenance.json +2 -1
  4. package/assets/launch/oj/OJ.LICENSE +21 -0
  5. package/assets/launch/oj/run.mjs +82 -0
  6. package/assets/launch/oj/runtime.json +21 -0
  7. package/assets/launch/root.tsx.txt +1 -2
  8. package/assets/launch/server.ts.txt +4 -2
  9. package/assets/ui/catalog.json +36 -324
  10. package/dist/{platforms/web.d.ts → api-proxy.d.ts} +1 -3
  11. package/dist/api-proxy.js +48 -0
  12. package/dist/capability-catalog.d.ts +3 -57
  13. package/dist/capability-catalog.js +3 -90
  14. package/dist/capability-command.d.ts +2 -2
  15. package/dist/capability-command.js +32 -96
  16. package/dist/capability-recipes.js +8 -343
  17. package/dist/cli-commands.js +3 -1
  18. package/dist/command-schema.js +106 -0
  19. package/dist/command-types.d.ts +1 -0
  20. package/dist/composition.d.ts +4 -14
  21. package/dist/composition.js +6 -6
  22. package/dist/contracts/cli-transport.d.ts +139 -40
  23. package/dist/contracts/cli-transport.js +96 -27
  24. package/dist/contracts/deployment.d.ts +7 -56
  25. package/dist/contracts/deployment.js +9 -45
  26. package/dist/contracts/production-transport.d.ts +71 -0
  27. package/dist/contracts/production-transport.js +56 -0
  28. package/dist/contracts/source-profile.js +1 -1
  29. package/dist/contracts/staging-transport.d.ts +2 -2
  30. package/dist/dependencies.d.ts +0 -27
  31. package/dist/dependencies.js +3 -67
  32. package/dist/index.d.ts +0 -4
  33. package/dist/index.js +0 -2
  34. package/dist/launch.d.ts +11 -5
  35. package/dist/launch.js +21 -9
  36. package/dist/platform-command.js +245 -42
  37. package/dist/platform-production.d.ts +16 -0
  38. package/dist/platform-production.js +135 -0
  39. package/dist/platform-state.d.ts +2 -0
  40. package/dist/platform-state.js +23 -1
  41. package/dist/platforms/tanstack.d.ts +2 -0
  42. package/dist/platforms/tanstack.js +113 -20
  43. package/dist/registry/usage.js +1 -0
  44. package/dist/scaffold/bootstrap.d.ts +3 -3
  45. package/dist/scaffold/styling.d.ts +3 -2
  46. package/dist/ui-catalog.d.ts +3 -5
  47. package/dist/ui-catalog.js +8 -24
  48. package/dist/ui-command.d.ts +1 -1
  49. package/dist/ui-command.js +18 -57
  50. package/dist/ui-project.d.ts +2 -2
  51. package/dist/ui-project.js +8 -36
  52. package/dist/version.d.ts +1 -1
  53. package/dist/version.js +1 -1
  54. package/docs/capabilities.md +7 -7
  55. package/docs/software-factory.md +55 -16
  56. package/docs/stack-standard.md +1 -1
  57. package/package.json +1 -4
  58. package/assets/stack/ai-schema.ts.txt +0 -5
  59. package/assets/stack/ai.ts.txt +0 -30
  60. package/assets/stack/desktop.rs.txt +0 -21
  61. package/assets/stack/event-retention.sql.txt +0 -10
  62. package/assets/stack/events-schema.ts.txt +0 -12
  63. package/assets/stack/events.ts.txt +0 -59
  64. package/assets/stack/mobile-auth.ts.txt +0 -25
  65. package/assets/stack/mobile-billing.tsx.txt +0 -63
  66. package/assets/stack/mobile-session.tsx.txt +0 -83
  67. package/assets/stack/native-button.tsx.txt +0 -108
  68. package/assets/stack/native-global.css.txt +0 -4
  69. package/assets/stack/native-lib-utils.ts.txt +0 -5
  70. package/assets/stack/native-metro.config.js.txt +0 -6
  71. package/assets/stack/native-nativewind-env.d.ts.txt +0 -1
  72. package/assets/stack/native-tailwind.config.js.txt +0 -73
  73. package/assets/stack/native-text.tsx.txt +0 -89
  74. package/assets/stack/purchases.ts.txt +0 -65
  75. package/assets/stack/revenuecat.ts.txt +0 -88
  76. package/assets/stack/rtc-schema.ts.txt +0 -10
  77. package/assets/stack/rtc.ts.txt +0 -122
  78. package/assets/stack/web-sign-in.tsx.txt +0 -51
  79. package/dist/capabilities.d.ts +0 -11
  80. package/dist/capabilities.js +0 -14
  81. package/dist/dependency-order.d.ts +0 -2
  82. package/dist/dependency-order.js +0 -24
  83. package/dist/platforms/lint.d.ts +0 -1
  84. package/dist/platforms/lint.js +0 -5
  85. package/dist/platforms/web.js +0 -251
  86. package/dist/project-config.d.ts +0 -3
  87. package/dist/project-config.js +0 -16
  88. package/dist/registry/context.d.ts +0 -3
  89. package/dist/registry/context.js +0 -20
  90. package/dist/registry/options.d.ts +0 -2
  91. package/dist/registry/options.js +0 -47
  92. package/dist/registry/resolve.d.ts +0 -11
  93. package/dist/registry/resolve.js +0 -46
  94. package/dist/registry/types.d.ts +0 -60
  95. package/dist/scaffold/api.d.ts +0 -2
  96. package/dist/scaffold/api.js +0 -38
  97. package/dist/scaffold/backend.d.ts +0 -2
  98. package/dist/scaffold/backend.js +0 -36
  99. package/dist/scaffold/compose.d.ts +0 -4
  100. package/dist/scaffold/compose.js +0 -30
  101. package/dist/scaffold/database.d.ts +0 -2
  102. package/dist/scaffold/database.js +0 -41
  103. package/dist/scaffold/documentation.d.ts +0 -2
  104. package/dist/scaffold/documentation.js +0 -71
  105. package/dist/scaffold/environment.d.ts +0 -4
  106. package/dist/scaffold/environment.js +0 -22
  107. package/dist/scaffold/stack-documentation.d.ts +0 -2
  108. package/dist/scaffold/stack-documentation.js +0 -6
  109. package/dist/scaffold/storage.d.ts +0 -2
  110. package/dist/scaffold/storage.js +0 -21
  111. package/dist/scaffold/workspace.d.ts +0 -3
  112. package/dist/scaffold/workspace.js +0 -141
  113. package/dist/stack-registry.d.ts +0 -35
  114. package/dist/stack-registry.js +0 -189
  115. package/dist/standard.d.ts +0 -8
  116. package/dist/standard.js +0 -109
  117. package/dist/workspace-graph.d.ts +0 -7
  118. package/dist/workspace-graph.js +0 -74
  119. /package/dist/{registry/types.js → command-types.js} +0 -0
@@ -1,11 +1,10 @@
1
1
  import { readFileSync } from 'node:fs';
2
- import { parseDocument } from 'yaml';
3
- import { CapabilityEditor, fingerprint } from './capability-editor.js';
2
+ import { CapabilityEditor } from './capability-editor.js';
4
3
  import { CAPABILITY_DEPENDENCIES as P } from './dependencies.js';
5
4
  import { STACK_DEPENDENCIES as D } from './dependencies.js';
6
5
  import { resourceName } from './render.js';
7
6
  import { composeTanstack, addTanstackAuth } from './platforms/tanstack.js';
8
- import { WEB_API_PROXY } from './platforms/web.js';
7
+ import { WEB_API_PROXY } from './api-proxy.js';
9
8
  const template = (name) => readFileSync(new URL(`../assets/stack/${name}`, import.meta.url), 'utf8');
10
9
  const json = (value) => JSON.stringify(value, null, 2) + '\n';
11
10
  function dependency(e, app, dependencies) {
@@ -97,28 +96,8 @@ export function addCapabilityRecipe(e, id, name) {
97
96
  });
98
97
  else
99
98
  e.set(web, ['services'], [{ binding: 'ANHEDRAL_API', service: resourceName(name, 'api') }]);
100
- const tanstack = !!e.json('apps/web/package.json').dependencies?.['@tanstack/react-start'];
101
- if (tanstack)
102
- e.set('apps/api/package.json', ['devDependencies', 'wrangler'], e.json('apps/web/package.json').devDependencies.wrangler);
103
- e.create(tanstack ? 'apps/web/src/lib/api-proxy.ts' : 'apps/web/lib/api-proxy.ts', WEB_API_PROXY.replace("'idempotency-key'", "'idempotency-key', 'stripe-signature', 'last-event-id'").replace('AbortSignal.timeout(15000)', "AbortSignal.timeout(request.headers.get('accept')?.includes('text/event-stream') ? 35000 : 15000)"));
104
- if (!tanstack) {
105
- e.create('apps/web/lib/server-api.ts', `import 'server-only';
106
- import { getCloudflareContext } from '@opennextjs/cloudflare';
107
- import { proxyApi,type ApiBinding } from './api-proxy';
108
- function apiBinding(candidate:unknown):ApiBinding|undefined {
109
- if(typeof candidate !== 'object' || candidate===null)return undefined;
110
- if(typeof Reflect.get(candidate,'fetch') !== 'function')return undefined;
111
- return candidate as ApiBinding;
112
- }
113
- export async function apiRequest(request:Request):Promise<Response>{
114
- if(process.env.NODE_ENV==='development')return proxyApi(request,{development:true,devOrigin:process.env.API_INTERNAL_URL});
115
- const {env}=await getCloudflareContext({async:true});
116
- return proxyApi(request,{development:false,binding:apiBinding(Reflect.get(env,'ANHEDRAL_API'))});
117
- }
118
- `);
119
- e.create('apps/web/app/api/[[...path]]/route.ts', "import { apiRequest } from '@/lib/server-api';\nexport const dynamic = 'force-dynamic';\nexport const GET = apiRequest;\nexport const POST = apiRequest;\nexport const PUT = apiRequest;\nexport const PATCH = apiRequest;\nexport const DELETE = apiRequest;\nexport const HEAD = apiRequest;\nexport const OPTIONS = apiRequest;\n");
120
- e.create('apps/web/README.hono.md', '# Hono development\n\nSet this in apps/web/.env.local for local development:\n\n```dotenv\nAPI_INTERNAL_URL=http://127.0.0.1:8787\n```\n\nProduction uses the ANHEDRAL_API service binding.\n');
121
- }
99
+ e.set('apps/api/package.json', ['devDependencies', 'wrangler'], e.json('apps/web/package.json').devDependencies.wrangler);
100
+ e.create('apps/web/src/lib/api-proxy.ts', WEB_API_PROXY.replace("'idempotency-key'", "'idempotency-key', 'stripe-signature', 'last-event-id'").replace('AbortSignal.timeout(15000)', "AbortSignal.timeout(request.headers.get('accept')?.includes('text/event-stream') ? 35000 : 15000)"));
122
101
  break;
123
102
  }
124
103
  case 'database-auth': {
@@ -176,12 +155,7 @@ export async function apiRequest(request:Request):Promise<Response>{
176
155
  e.create('apps/api/src/auth-features.ts', template('auth-features.ts.txt'));
177
156
  e.create('apps/api/src/security.ts', template('security.ts.txt'));
178
157
  e.create('apps/api/src/features/auth.ts', template('auth-routes.ts.txt'));
179
- if (e.json('apps/web/package.json').dependencies?.['@tanstack/react-start'])
180
- addTanstackAuth(e);
181
- else {
182
- e.create('apps/web/app/sign-in/page.tsx', template('web-sign-in.tsx.txt'));
183
- e.create('apps/web/lib/auth-client.ts', "'use client';\nimport { createAuthClient } from 'better-auth/react';\nexport const authClient = createAuthClient();\n");
184
- }
158
+ addTanstackAuth(e);
185
159
  e.merge('package.json', 'scripts', {
186
160
  'db:generate': 'pnpm --dir packages/db db:generate',
187
161
  'db:migrate': 'pnpm --dir packages/db db:migrate',
@@ -205,269 +179,17 @@ export async function apiRequest(request:Request):Promise<Response>{
205
179
  e.create('packages/db/src/billing-schema.ts', template('billing-schema.ts.txt'));
206
180
  schemaExport(e, 'billing-schema');
207
181
  break;
208
- case 'revenuecat':
209
- dependency(e, 'apps/mobile', { 'react-native-purchases': P['react-native-purchases'] });
210
- e.create('apps/api/src/features/revenuecat.ts', template('revenuecat.ts.txt'));
211
- e.create('apps/mobile/lib/purchases.ts', template('purchases.ts.txt'));
212
- appendExample(e, 'apps/mobile/.env.example', [
213
- 'EXPO_PUBLIC_REVENUECAT_IOS_KEY',
214
- 'EXPO_PUBLIC_REVENUECAT_ANDROID_KEY',
215
- ]);
216
- e.create('apps/mobile/components/billing-controls.tsx', template('mobile-billing.tsx.txt'));
217
- break;
218
- case 'realtime':
219
- e.create('packages/db/src/events-schema.ts', template('events-schema.ts.txt'));
220
- schemaExport(e, 'events-schema');
221
- e.create('apps/api/src/features/events.ts', template('events.ts.txt'));
222
- e.create('packages/db/operations/event-retention.sql.example', template('event-retention.sql.txt'));
223
- break;
224
- case 'rtc':
225
- e.create('apps/api/src/features/rtc.ts', template('rtc.ts.txt'));
226
- e.create('packages/db/src/rtc-schema.ts', template('rtc-schema.ts.txt'));
227
- schemaExport(e, 'rtc-schema');
228
- break;
229
- case 'ai':
230
- apiConfig(e, 'ai', { binding: 'AI', remote: true });
231
- e.create('apps/api/src/features/ai.ts', template('ai.ts.txt'));
232
- e.create('packages/db/src/ai-schema.ts', template('ai-schema.ts.txt'));
233
- schemaExport(e, 'ai-schema');
234
- break;
235
- case 'expo':
236
- addExpo(e, name);
237
- break;
238
- case 'native-ui':
239
- addNativeUi(e);
240
- break;
241
- case 'wxt':
242
- addExtension(e);
243
- break;
244
- case 'side-panel':
245
- e.create('apps/extension/entrypoints/sidepanel/index.html', '<!doctype html><html><head><meta charset="UTF-8"><title>Side panel</title></head><body><div id="root"></div><script type="module" src="./main.tsx"></script></body></html>\n');
246
- e.create('apps/extension/entrypoints/sidepanel/main.tsx', "import { createRoot } from 'react-dom/client';\nimport { App } from '../../components/App';\ncreateRoot(document.getElementById('root')!).render(<App />);\n");
247
- break;
248
- case 'gpui':
249
- addDesktop(e);
250
- break;
251
- }
252
- }
253
- function addExpo(e, name) {
254
- project(e, 'apps/mobile', '@workspace/mobile', {
255
- dev: 'expo start',
256
- start: 'expo start',
257
- android: 'expo run:android',
258
- ios: 'expo run:ios',
259
- typecheck: 'tsc --noEmit',
260
- lint: 'tsc --noEmit',
261
- build: 'expo export --platform ios --platform android',
262
- }, {
263
- expo: P.expo,
264
- react: P.react,
265
- 'react-native': P['react-native'],
266
- 'expo-secure-store': P['expo-secure-store'],
267
- 'expo-linking': P['expo-linking'],
268
- 'better-auth': P['better-auth'],
269
- '@better-auth/expo': P['@better-auth/expo'],
270
- }, { '@types/react': P['@types/react'], 'babel-preset-expo': P['babel-preset-expo'] });
271
- e.set('apps/mobile/package.json', ['type'], 'commonjs');
272
- e.set('apps/mobile/package.json', ['main'], 'index.ts');
273
- const workspaceSource = e.read('pnpm-workspace.yaml');
274
- if (workspaceSource === null)
275
- throw Error('Missing pnpm workspace');
276
- const workspace = parseDocument(workspaceSource);
277
- if (workspace.errors.length)
278
- throw Error('Invalid pnpm workspace configuration');
279
- const existing = workspace.getIn(['overrides', '@expo/cli>zod']);
280
- if (existing !== undefined && existing !== D.zod)
281
- throw Error('Preserve the custom Expo Zod override; reconcile it first.');
282
- workspace.setIn(['overrides', '@expo/cli>zod'], D.zod);
283
- e.writes.set('pnpm-workspace.yaml', workspace.toString());
284
- e.create('apps/mobile/app.json', json({
285
- expo: {
286
- name,
287
- slug: resourceName(name, 'mobile'),
288
- scheme: resourceName(name, 'mobile'),
289
- version: '1.0.0',
290
- userInterfaceStyle: 'automatic',
291
- plugins: ['expo-secure-store'],
292
- },
293
- }));
294
- e.create('apps/mobile/tsconfig.json', json({
295
- extends: 'expo/tsconfig.base',
296
- compilerOptions: { strict: true, baseUrl: '.', paths: { '@/*': ['./*'] } },
297
- }));
298
- e.create('apps/mobile/babel.config.js', "module.exports = function(api) {api.cache(true);return {presets:['babel-preset-expo']};};\n");
299
- e.create('apps/mobile/index.ts', "import './anhedral-entry';\n");
300
- e.create('apps/mobile/App.tsx', "import { View, Text } from 'react-native';\nexport default function App() { return <View style={{flex:1,alignItems:'center',justifyContent:'center'}}><Text>Your Expo application</Text></View>; }\n");
301
- e.create('apps/mobile/components/session-controls.tsx', template('mobile-session.tsx.txt'));
302
- e.create('apps/mobile/lib/auth-client.ts', template('mobile-auth.ts.txt').replaceAll('__SCHEME__', JSON.stringify(resourceName(name, 'mobile'))));
303
- e.create('apps/mobile/.env.example', '# Public application URL only, never a server secret. Use a device-reachable development origin.\nEXPO_PUBLIC_API_URL=https://your-app.example\n');
304
- dependency(e, 'apps/api', { '@better-auth/expo': P['@better-auth/expo'] });
305
- }
306
- function addNativeUi(e) {
307
- dependency(e, 'apps/mobile', {
308
- nativewind: P.nativewind,
309
- 'react-native-css-interop': P['react-native-css-interop'],
310
- 'react-native-reanimated': P['react-native-reanimated'],
311
- 'react-native-worklets': P['react-native-worklets'],
312
- 'react-native-safe-area-context': P['react-native-safe-area-context'],
313
- 'class-variance-authority': P['class-variance-authority'],
314
- clsx: P.clsx,
315
- 'tailwind-merge': P['tailwind-merge'],
316
- 'tailwindcss-animate': P['tailwindcss-animate'],
317
- '@rn-primitives/portal': P['@rn-primitives/portal'],
318
- '@rn-primitives/slot': P['@rn-primitives/slot'],
319
- });
320
- e.merge('apps/mobile/package.json', 'devDependencies', { tailwindcss: P.tailwindcss });
321
- e.create('apps/mobile/components.json', json({
322
- $schema: 'https://ui.shadcn.com/schema.json',
323
- style: 'new-york',
324
- rsc: false,
325
- tsx: true,
326
- tailwind: {
327
- config: 'tailwind.config.js',
328
- css: 'global.css',
329
- baseColor: 'neutral',
330
- cssVariables: true,
331
- },
332
- aliases: {
333
- components: '@/components',
334
- ui: '@/components/ui',
335
- utils: '@/lib/utils',
336
- lib: '@/lib',
337
- hooks: '@/hooks',
338
- },
339
- }));
340
- for (const file of [
341
- 'global.css',
342
- 'tailwind.config.js',
343
- 'metro.config.js',
344
- 'nativewind-env.d.ts',
345
- 'lib/utils.ts',
346
- ])
347
- e.create(`apps/mobile/${file}`, template('native-' + file.replaceAll('/', '-') + '.txt'));
348
- // Dedicated entry: NativeWind/PortalHost integration never replaces the user's App.
349
- if (e.json('apps/mobile/package.json').main !== 'index.ts')
350
- throw Error('Preserve the custom Expo entry; reconcile NativeWind/PortalHost setup first.');
351
- e.set('apps/mobile/package.json', ['main'], 'anhedral-entry.tsx');
352
- for (const name of ['button', 'text'])
353
- e.create(`apps/mobile/components/ui/${name}.tsx`, template(`native-${name}.tsx.txt`));
354
- if (e.read('apps/mobile/App.tsx') === null)
355
- throw Error('Preserve the custom Expo layout; reconcile the NativeWind root entry first.');
356
- const babel = 'apps/mobile/babel.config.js';
357
- const expected = "module.exports = function(api) {api.cache(true);return {presets:['babel-preset-expo']};};\n";
358
- if (e.read(babel) !== expected)
359
- throw Error('Preserve edited Expo Babel configuration; reconcile NativeWind first.');
360
- e.writes.set(babel, "module.exports = function(api) {api.cache(true);return {presets:[['babel-preset-expo',{jsxImportSource:'nativewind'}],'nativewind/babel']};};\n");
361
- e.create('apps/mobile/.anhedral-ui.json', json({
362
- schemaVersion: 1,
363
- platform: 'native',
364
- catalogRevision: '2026-10-26.1',
365
- nativeStyling: 'nativewind4',
366
- sourceOwned: true,
367
- automaticUpdates: false,
368
- }));
369
- e.create('apps/mobile/UPSTREAM.json', json({
370
- catalogRevision: '2026-10-26.1',
371
- source: 'https://github.com/founded-labs/react-native-reusables/tree/385834c2196f8a303cbc9057d1ac768f3bde0a3b',
372
- automaticUpdates: false,
373
- files: Object.fromEntries(['button', 'text'].map((name) => [
374
- `components/ui/${name}.tsx`,
375
- { sha256: fingerprint(template(`native-${name}.tsx.txt`)) },
376
- ])),
377
- }));
378
- for (const name of ['LICENSE.react-native-reusables', 'LICENSE.shadcn'])
379
- e.create(`apps/mobile/ANHEDRAL_UI_LICENSES/${name}`, readFileSync(new URL(`../assets/ui/${name}`, import.meta.url), 'utf8'));
380
- }
381
- function addExtension(e) {
382
- project(e, 'apps/extension', '@workspace/extension', {
383
- dev: 'wxt',
384
- build: 'wxt build',
385
- zip: 'wxt zip',
386
- typecheck: 'wxt prepare && tsc --noEmit',
387
- lint: 'wxt prepare && tsc --noEmit',
388
- postinstall: 'wxt prepare',
389
- }, { react: P.react, 'react-dom': P.react }, {
390
- wxt: P.wxt,
391
- '@wxt-dev/module-react': P['@wxt-dev/module-react'],
392
- '@types/react': P['@types/react'],
393
- '@types/react-dom': P['@types/react-dom'],
394
- });
395
- e.create('apps/extension/entrypoints/background.ts', "import {configureCapabilities} from '../anhedral-background';\nexport default defineBackground(()=>{configureCapabilities();});\n");
396
- e.create('apps/extension/wxt.config.ts', "import {defineConfig} from 'wxt';\nconst origin=process.env.WXT_API_ORIGIN || 'https://your-app.example';\nconst url=new URL(origin);\nif(url.protocol !== 'https:' && !(url.protocol === 'http:' && ['localhost','127.0.0.1'].includes(url.hostname)))throw Error('Choose a secure API origin');\nexport default defineConfig({modules:['@wxt-dev/module-react'], manifest:{name:'Anhedral application extension',permissions:['storage'],host_permissions:[url.origin+'/*']}});\n");
397
- e.create('apps/extension/tsconfig.json', json({ extends: './.wxt/tsconfig.json', compilerOptions: { strict: true, jsx: 'react-jsx' } }));
398
- e.create('apps/extension/entrypoints/popup/index.html', '<!doctype html><html><head><meta charset="UTF-8"><title>Application</title></head><body><div id="root"></div><script type="module" src="./main.tsx"></script></body></html>\n');
399
- e.create('apps/extension/entrypoints/popup/main.tsx', "import {createRoot} from 'react-dom/client';\nimport {App} from '../../components/App';\ncreateRoot(document.getElementById('root')!).render(<App />);\n");
400
- e.create('apps/extension/components/App.tsx', 'export function App(){return <main><h1>Your application</h1><p>Configure the API origin and an explicit sign-in flow before accessing private data.</p></main>;}\n');
401
- e.create('apps/extension/.env.example', 'WXT_API_ORIGIN=https://your-app.example\n');
402
- }
403
- function addDesktop(e) {
404
- project(e, 'apps/desktop', '@workspace/desktop', {
405
- dev: 'cargo run',
406
- build: 'cargo build',
407
- typecheck: 'cargo check',
408
- lint: 'cargo fmt --check',
409
- test: 'cargo test',
410
- }, {});
411
- e.create('apps/desktop/Cargo.toml', '[package]\nname = "anhedral-desktop"\nversion = "0.1.0"\nedition = "2024"\n\n[dependencies]\ngpui = { version = "=0.2.2", features = ["runtime_shaders"] }\n');
412
- e.create('apps/desktop/src/main.rs', template('desktop.rs.txt'));
413
- e.create('apps/desktop/.gitignore', '/target/\n');
414
- e.create('apps/desktop/.env.example', '# Desktop binaries run natively, not on Workers.\nANHEDRAL_API_ORIGIN=https://your-app.example\n');
415
- }
416
- function taskContract(e, name, patch) {
417
- const previous = e.json('turbo.json').tasks?.[name] ?? {};
418
- if (!previous || typeof previous !== 'object' || Array.isArray(previous))
419
- throw Error(`Preserve invalid task ${name}; reconcile turbo.json first.`);
420
- const next = { ...previous };
421
- for (const [key, value] of Object.entries(patch)) {
422
- if (Array.isArray(value)) {
423
- const old = previous[key] ?? [];
424
- if (!Array.isArray(old) || old.some((item) => typeof item !== 'string'))
425
- throw Error(`Preserve ${name}.${key}; reconcile turbo.json first.`);
426
- next[key] = [...new Set([...old, ...value])];
427
- }
428
- else {
429
- if (previous[key] !== undefined && previous[key] !== value)
430
- throw Error(`Preserve ${name}.${key}; reconcile turbo.json first.`);
431
- next[key] = value;
432
- }
433
182
  }
434
- e.set('turbo.json', ['tasks', name], next);
435
183
  }
436
184
  export function composeCapabilities(e, installed) {
437
- if (e.json('apps/web/package.json').dependencies?.['@tanstack/react-start'])
438
- composeTanstack(e, installed);
439
- if (installed.includes('wxt')) {
440
- taskContract(e, '@workspace/extension#build', {
441
- outputs: ['.output/**'],
442
- env: ['WXT_API_ORIGIN'],
443
- });
444
- taskContract(e, '@workspace/extension#dev', {
445
- cache: false,
446
- persistent: true,
447
- env: ['WXT_API_ORIGIN'],
448
- });
449
- taskContract(e, '@workspace/extension#typecheck', { outputs: ['.wxt/**'] });
450
- taskContract(e, '@workspace/extension#lint', { outputs: ['.wxt/**'] });
451
- }
452
- if (installed.includes('gpui'))
453
- taskContract(e, '@workspace/desktop#build', { cache: false });
185
+ composeTanstack(e, installed);
454
186
  if (!installed.includes('hono'))
455
187
  return;
456
- if (installed.includes('expo'))
457
- composeMobile(e, installed);
458
- if (installed.includes('wxt'))
459
- e.owned('apps/extension/anhedral-background.ts', installed.includes('side-panel')
460
- ? "import {browser} from 'wxt/browser';\nexport function configureCapabilities(){if(browser.sidePanel)void browser.sidePanel.setPanelBehavior({openPanelOnActionClick:true}).catch(()=>console.error('Side Panel setup failed'));}\n"
461
- : 'export function configureCapabilities(){}\n');
462
188
  const features = [
463
189
  ['database-auth', 'authRoutes', 'auth'],
464
190
  ['r2', 'storageRoutes', 'storage'],
465
191
  ['stripe', 'stripeRoutes', 'stripe'],
466
192
  ['stripe', 'entitlementRoutes', 'entitlements'],
467
- ['revenuecat', 'revenuecatRoutes', 'revenuecat'],
468
- ['realtime', 'eventRoutes', 'events'],
469
- ['rtc', 'rtcRoutes', 'rtc'],
470
- ['ai', 'aiRoutes', 'ai'],
471
193
  ];
472
194
  const chosen = features.filter(([id]) => installed.includes(id));
473
195
  e.owned('apps/api/src/capabilities.ts', "// CLI-owned composition. Add custom routes in index.ts; edited composition is never overwritten.\nimport { Hono } from 'hono';\nimport type { AppEnv } from './environment';\n" +
@@ -477,17 +199,9 @@ export function composeCapabilities(e, installed) {
477
199
  'export const capabilities = new Hono<AppEnv>();\n' +
478
200
  chosen.map(([, symbol]) => `capabilities.route('/', ${symbol});\n`).join(''));
479
201
  if (installed.includes('database-auth'))
480
- e.owned('apps/api/src/auth-platform.ts', installed.includes('expo')
481
- ? "import { expo } from '@better-auth/expo';\nexport const platformAuthPlugins = () => [expo()];\n"
482
- : 'export const platformAuthPlugins = () => [];\n');
202
+ e.owned('apps/api/src/auth-platform.ts', 'export const platformAuthPlugins = () => [];\n');
483
203
  if (installed.includes('stripe'))
484
- e.owned('apps/api/src/billing-providers.ts', "import type {AppEnv} from './environment';\nimport {stripeEntitled} from './features/stripe';\n" +
485
- (installed.includes('revenuecat')
486
- ? "import {revenuecatEntitled} from './features/revenuecat';\n"
487
- : '') +
488
- "export const billingProviders:Record<string,(env:AppEnv['Bindings'],userId:string)=>Promise<boolean>>={stripe:stripeEntitled" +
489
- (installed.includes('revenuecat') ? ',revenuecat:revenuecatEntitled' : '') +
490
- '};\n');
204
+ e.owned('apps/api/src/billing-providers.ts', "import type {AppEnv} from './environment';\nimport {stripeEntitled} from './features/stripe';\nexport const billingProviders:Record<string,(env:AppEnv['Bindings'],userId:string)=>Promise<boolean>>={stripe:stripeEntitled};\n");
491
205
  const bindings = [
492
206
  'PUBLIC_APP_URL?: string',
493
207
  'BETTER_AUTH_SECRET?: string',
@@ -499,60 +213,11 @@ export function composeCapabilities(e, installed) {
499
213
  bindings.push('FILES: R2Bucket');
500
214
  if (installed.includes('stripe'))
501
215
  bindings.push('STRIPE_SECRET_KEY?: string', 'STRIPE_WEBHOOK_SECRET?: string', 'STRIPE_PRICE_ID?: string', 'BILLING_ENVIRONMENT?: string', 'BILLING_PROVIDER?: string');
502
- if (installed.includes('revenuecat'))
503
- bindings.push('REVENUECAT_SECRET_KEY?: string', 'REVENUECAT_WEBHOOK_AUTH?: string', 'REVENUECAT_APP_ID?: string', 'REVENUECAT_ENTITLEMENT?: string');
504
- if (installed.includes('rtc'))
505
- bindings.push('RTC_APP_ID?: string', 'RTC_APP_SECRET?: string');
506
- if (installed.includes('ai'))
507
- bindings.push('AI: Ai', 'AI_MODEL?: string', 'AI_DAILY_LIMIT?: string');
508
216
  e.owned('apps/api/src/environment.ts', `import type { CustomBindings, CustomVariables } from './custom-environment';\nexport type AppEnv = { Bindings: CustomBindings & {${bindings.join(';\n')}}; Variables: CustomVariables & {userId:string;fileKey:string} };\n`);
509
217
  appendExample(e, 'apps/api/.dev.vars.example', bindings
510
218
  .filter((binding) => binding.includes('string'))
511
219
  .map((binding) => binding.split('?')[0]));
512
220
  }
513
- function composeMobile(e, installed) {
514
- const ui = installed.includes('native-ui');
515
- const billing = installed.includes('revenuecat');
516
- e.owned('apps/mobile/anhedral-entry.tsx', (ui
517
- ? "import './global.css';\nimport {PortalHost} from '@rn-primitives/portal';\nimport {SafeAreaProvider} from 'react-native-safe-area-context';\n"
518
- : '') +
519
- "import {registerRootComponent} from 'expo';\nimport {View} from 'react-native';\nimport App from './App';\nimport {SessionControls} from './components/session-controls';\n" +
520
- (billing
521
- ? "import {BillingControls} from './components/billing-controls';\nimport {disconnectPurchases} from './lib/purchases';\n"
522
- : '') +
523
- 'function Root(){return ' +
524
- (ui ? '<SafeAreaProvider>' : '') +
525
- '<View style={{flex:1}}><App /><SessionControls' +
526
- (billing ? ' onSignOut={disconnectPurchases}' : '') +
527
- '>' +
528
- (billing ? '<BillingControls/>' : '') +
529
- '</SessionControls></View>' +
530
- (ui ? '<PortalHost/></SafeAreaProvider>' : '') +
531
- ';}\nregisterRootComponent(Root);\n');
532
- e.owned('apps/mobile/components/action-button.tsx', ui
533
- ? "import {Button} from './ui/button';\nimport {Text} from './ui/text';\nexport function ActionButton({label,...props}:{label:string;onPress:()=>void;disabled?:boolean}) {return <Button {...props}><Text>{label}</Text></Button>;}\n"
534
- : "import {Button} from 'react-native';\nexport function ActionButton({label,...props}:{label:string;onPress:()=>void;disabled?:boolean}) {return <Button title={label} {...props}/>;}\n");
535
- const file = '.fallowrc.json';
536
- const current = e.json(file).ignoreDependencies ?? [];
537
- const peers = ui
538
- ? [
539
- 'babel-preset-expo',
540
- 'react-native-css-interop',
541
- 'react-native-reanimated',
542
- 'react-native-worklets',
543
- ]
544
- : ['babel-preset-expo'];
545
- e.set(file, ['ignoreDependencies'], [...new Set([...current, ...peers])]);
546
- if (ui) {
547
- const rules = e.json(file).ignoreExports ?? [];
548
- const rule = {
549
- file: 'apps/mobile/components/ui/button.tsx',
550
- exports: ['buttonVariants', 'buttonTextVariants'],
551
- };
552
- if (!rules.some((value) => JSON.stringify(value) === JSON.stringify(rule)))
553
- e.set(file, ['ignoreExports'], [...rules, rule]);
554
- }
555
- }
556
221
  function appendExample(e, file, keys) {
557
222
  const current = e.read(file);
558
223
  const source = current ?? '# Copy selected values to the local environment. Never commit secrets.\n';
@@ -18,17 +18,19 @@ export async function runCommand(command, args, output) {
18
18
  'login',
19
19
  'logout',
20
20
  'whoami',
21
+ 'projects',
21
22
  'link',
22
23
  'unlink',
23
24
  'source',
24
25
  'deploy',
25
26
  'env',
26
27
  'staging',
28
+ 'production',
27
29
  'logs',
28
30
  ].includes(command))
29
31
  return runPlatformCommand(command, args, output);
30
32
  if (command === 'add' || command === 'stack')
31
- return runCapabilityCommand(command, args, output, undefined, 'public');
33
+ return runCapabilityCommand(command, args, output);
32
34
  if (command === 'ui')
33
35
  return runAnhedralUiCommand(args, output);
34
36
  if (command !== 'init')
@@ -86,6 +86,64 @@ const STAGING_OPTIONS = [
86
86
  },
87
87
  { flag: '--new', description: 'Start a new staging deployment using the current generation.' },
88
88
  ];
89
+ const PRODUCTION_OPTIONS = [
90
+ ...PLATFORM_OPTIONS,
91
+ {
92
+ flag: '--candidate',
93
+ value: 'uuid',
94
+ arity: 'required',
95
+ description: 'Select a ready, runtime-verified deployment candidate.',
96
+ },
97
+ {
98
+ flag: '--name',
99
+ value: 'slug',
100
+ arity: 'required',
101
+ description: 'Select the public application name for production.',
102
+ },
103
+ {
104
+ flag: '--new',
105
+ description: 'Start another production deployment using the current generation.',
106
+ },
107
+ ];
108
+ const PROJECT_OPTIONS = [
109
+ ...PLATFORM_OPTIONS,
110
+ {
111
+ flag: '--team',
112
+ value: 'uuid',
113
+ arity: 'required',
114
+ description: 'Team ID; defaults to your selected team.',
115
+ },
116
+ {
117
+ flag: '--limit',
118
+ value: 'count',
119
+ arity: 'required',
120
+ description: 'List 1–100 projects (default 50).',
121
+ },
122
+ {
123
+ flag: '--cursor',
124
+ value: 'uuid',
125
+ arity: 'required',
126
+ description: 'Resume listing after this project ID.',
127
+ },
128
+ {
129
+ flag: '--name',
130
+ value: 'text',
131
+ arity: 'required',
132
+ description: 'New project name (1–160 characters).',
133
+ },
134
+ {
135
+ flag: '--summary',
136
+ value: 'text',
137
+ arity: 'required',
138
+ description: 'Optional project summary (up to 2000 characters).',
139
+ },
140
+ { flag: '--link', description: 'Verify build access and save a local link after creation.' },
141
+ { flag: '--dry-run', description: 'Validate creation locally without authentication or writes.' },
142
+ {
143
+ flag: '--new',
144
+ description: 'Start a new creation request instead of retrying the saved request.',
145
+ },
146
+ ];
89
147
  export const COMMANDS = {
90
148
  completion: {
91
149
  description: 'Print an offline shell completion script.',
@@ -126,6 +184,30 @@ export const COMMANDS = {
126
184
  ],
127
185
  examples: ['whoami --json', 'whoami --context --human'],
128
186
  },
187
+ projects: {
188
+ description: 'List or create Platform projects.',
189
+ usage: 'projects <list|create> [options]',
190
+ options: PROJECT_OPTIONS,
191
+ children: {
192
+ list: {
193
+ description: 'List accessible projects and available teams.',
194
+ usage: 'projects list [--team <uuid>] [--limit <count>] [--cursor <uuid>]',
195
+ options: PROJECT_OPTIONS.filter((option) => ['--api-url', '--credential-file', '--team', '--limit', '--cursor'].includes(option.flag)),
196
+ examples: ['projects list --human'],
197
+ },
198
+ create: {
199
+ description: 'Create a source-upload project with a durable retry identity.',
200
+ usage: 'projects create --name <text> [--summary <text>] [--team <uuid>] [--link] [--dry-run] [--new]',
201
+ options: PROJECT_OPTIONS.filter((option) => !['--limit', '--cursor'].includes(option.flag)),
202
+ examples: [
203
+ 'projects create --name "My app" --dry-run',
204
+ 'projects create --name "My app" --link',
205
+ ],
206
+ note: 'Retries reuse the saved request. Changed input or context requires --new. Creation does not generate source or deploy.',
207
+ },
208
+ },
209
+ examples: ['projects list', 'projects create --name "My app"'],
210
+ },
129
211
  link: {
130
212
  description: 'Link this workspace to an existing project.',
131
213
  usage: 'link --project <uuid> --team <uuid>',
@@ -252,6 +334,30 @@ export const COMMANDS = {
252
334
  examples: ['staging status', 'staging deploy --candidate <uuid>'],
253
335
  note: 'Retried requests retain the same identity and generation. Configuration is frozen for each new staging deployment; production approval stays in Platform.',
254
336
  },
337
+ production: {
338
+ description: 'Deploy a ready candidate with your current production permissions.',
339
+ usage: 'production <status|deploy> [options]',
340
+ options: PRODUCTION_OPTIONS,
341
+ positional: { name: 'operation', min: 1, max: 1, choices: ['status', 'deploy'] },
342
+ children: {
343
+ status: {
344
+ description: 'Read production history and active deployment.',
345
+ usage: 'production status',
346
+ options: PLATFORM_OPTIONS,
347
+ positional: { name: 'operation', min: 0, max: 0 },
348
+ examples: ['production status --json'],
349
+ },
350
+ deploy: {
351
+ description: 'Request production publication of a ready candidate.',
352
+ usage: 'production deploy --candidate <uuid> --name <slug> [--new]',
353
+ options: PRODUCTION_OPTIONS,
354
+ positional: { name: 'operation', min: 0, max: 0 },
355
+ examples: ['production deploy --candidate <uuid> --name my-app'],
356
+ },
357
+ },
358
+ examples: ['production status', 'production deploy --candidate <uuid> --name my-app'],
359
+ note: 'Platform checks current production permissions and freezes configuration. Self-service teams need no second approver; an explicitly required independent review remains enforced.',
360
+ },
255
361
  logs: {
256
362
  description: 'Read redacted runtime logs for the linked project.',
257
363
  usage: 'logs [options]',
@@ -0,0 +1 @@
1
+ export type CommandRunner = (command: string, args: string[], cwd: string) => void;
@@ -5,31 +5,21 @@ export declare const launchCompositionSchema: z.ZodObject<{
5
5
  identity: z.ZodEnum<{
6
6
  none: "none";
7
7
  "better-auth-d1-v1": "better-auth-d1-v1";
8
- "platform-application-services-v1": "platform-application-services-v1";
9
8
  }>;
10
9
  capabilities: z.ZodRecord<z.ZodEnum<{
11
10
  hono: "hono";
12
11
  "database-auth": "database-auth";
13
12
  r2: "r2";
14
13
  stripe: "stripe";
15
- realtime: "realtime";
16
- rtc: "rtc";
17
- ai: "ai";
18
- expo: "expo";
19
- "native-ui": "native-ui";
20
- revenuecat: "revenuecat";
21
- wxt: "wxt";
22
- "side-panel": "side-panel";
23
- gpui: "gpui";
24
14
  }> & z.core.$partial, z.ZodNullable<z.ZodString>>;
25
15
  contractVersion: z.ZodLiteral<2>;
26
16
  foundation: z.ZodLiteral<"tanstack-start">;
27
17
  }, z.core.$strict>;
28
18
  /** Local source provenance is never a hosting receipt or a provider activation claim. */
29
19
  export declare function composeSourceProvenance(previous: unknown, installed: readonly Capability[], additions: readonly Capability[]): {
30
- contractVersion: 1 | 2;
31
- foundation: "next-opennext" | "tanstack-start";
32
20
  generatorVersion: string | null;
33
- identity: "none" | "better-auth-d1-v1" | "platform-application-services-v1";
34
- capabilities: Partial<Record<"hono" | "database-auth" | "r2" | "stripe" | "realtime" | "rtc" | "ai" | "expo" | "native-ui" | "revenuecat" | "wxt" | "side-panel" | "gpui", string | null>>;
21
+ identity: "none" | "better-auth-d1-v1";
22
+ capabilities: Partial<Record<"hono" | "database-auth" | "r2" | "stripe", string | null>>;
23
+ contractVersion: 2;
24
+ foundation: "tanstack-start";
35
25
  };
@@ -6,23 +6,23 @@ export const launchCompositionSchema = sourceCompositionSchema.safeExtend({
6
6
  contractVersion: z.literal(2),
7
7
  foundation: z.literal('tanstack-start'),
8
8
  });
9
- const compositionSchema = sourceCompositionSchema;
9
+ const compositionSchema = launchCompositionSchema;
10
10
  /** Local source provenance is never a hosting receipt or a provider activation claim. */
11
11
  export function composeSourceProvenance(previous, installed, additions) {
12
- const old = previous === undefined ? undefined : compositionSchema.parse(previous);
12
+ const old = compositionSchema.parse(previous);
13
13
  if (old && Object.keys(old.capabilities).some((id) => !installed.includes(id)))
14
14
  throw Error('Composition provenance disagrees with installed source; reconcile anhedral.json.');
15
15
  const identity = installed.includes('database-auth') ? 'better-auth-d1-v1' : 'none';
16
16
  if (old && old.identity !== 'none' && old.identity !== identity)
17
17
  throw Error('Preserve existing application identity; an explicit adapter is required.');
18
18
  return compositionSchema.parse({
19
- contractVersion: old?.contractVersion ?? 1,
20
- foundation: old?.foundation ?? 'next-opennext',
21
- generatorVersion: old?.generatorVersion ?? null,
19
+ contractVersion: 2,
20
+ foundation: 'tanstack-start',
21
+ generatorVersion: GENERATOR_VERSION,
22
22
  identity,
23
23
  capabilities: Object.fromEntries(installed.map((id) => [
24
24
  id,
25
- additions.includes(id) ? GENERATOR_VERSION : (old?.capabilities[id] ?? null),
25
+ additions.includes(id) ? GENERATOR_VERSION : old.capabilities[id],
26
26
  ])),
27
27
  });
28
28
  }