anhedral 0.18.0 → 0.20.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 (128) hide show
  1. package/README.md +10 -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 +10 -2
  15. package/dist/capability-command.js +35 -99
  16. package/dist/capability-editor.js +21 -1
  17. package/dist/capability-recipes.js +8 -343
  18. package/dist/cli-commands.js +6 -1
  19. package/dist/command-schema.js +141 -2
  20. package/dist/command-types.d.ts +1 -0
  21. package/dist/composition.d.ts +4 -14
  22. package/dist/composition.js +6 -6
  23. package/dist/contracts/cli-transport.d.ts +139 -40
  24. package/dist/contracts/cli-transport.js +96 -27
  25. package/dist/contracts/deployment.d.ts +7 -56
  26. package/dist/contracts/deployment.js +9 -45
  27. package/dist/contracts/production-transport.d.ts +71 -0
  28. package/dist/contracts/production-transport.js +56 -0
  29. package/dist/contracts/source-profile.js +1 -1
  30. package/dist/contracts/staging-transport.d.ts +2 -2
  31. package/dist/credential-helper.d.ts +2 -0
  32. package/dist/credential-helper.js +44 -0
  33. package/dist/dependencies.d.ts +0 -27
  34. package/dist/dependencies.js +3 -67
  35. package/dist/index.d.ts +0 -4
  36. package/dist/index.js +0 -2
  37. package/dist/launch.d.ts +11 -5
  38. package/dist/launch.js +21 -9
  39. package/dist/platform-command.js +245 -42
  40. package/dist/platform-production.d.ts +16 -0
  41. package/dist/platform-production.js +135 -0
  42. package/dist/platform-state.d.ts +4 -1
  43. package/dist/platform-state.js +28 -5
  44. package/dist/platforms/tanstack.d.ts +2 -0
  45. package/dist/platforms/tanstack.js +113 -20
  46. package/dist/registry/usage.js +3 -1
  47. package/dist/release-artifact.d.ts +18 -0
  48. package/dist/release-artifact.js +169 -0
  49. package/dist/scaffold/bootstrap.d.ts +3 -3
  50. package/dist/scaffold/styling.d.ts +3 -2
  51. package/dist/stack-update.d.ts +39 -0
  52. package/dist/stack-update.js +346 -0
  53. package/dist/transaction.d.ts +1 -0
  54. package/dist/transaction.js +2 -0
  55. package/dist/ui-catalog.d.ts +3 -5
  56. package/dist/ui-catalog.js +8 -24
  57. package/dist/ui-command.d.ts +1 -1
  58. package/dist/ui-command.js +18 -57
  59. package/dist/ui-project.d.ts +2 -2
  60. package/dist/ui-project.js +8 -36
  61. package/dist/version.d.ts +1 -1
  62. package/dist/version.js +1 -1
  63. package/docs/capabilities.md +7 -7
  64. package/docs/software-factory.md +83 -16
  65. package/docs/stack-standard.md +1 -1
  66. package/package.json +1 -4
  67. package/assets/stack/ai-schema.ts.txt +0 -5
  68. package/assets/stack/ai.ts.txt +0 -30
  69. package/assets/stack/desktop.rs.txt +0 -21
  70. package/assets/stack/event-retention.sql.txt +0 -10
  71. package/assets/stack/events-schema.ts.txt +0 -12
  72. package/assets/stack/events.ts.txt +0 -59
  73. package/assets/stack/mobile-auth.ts.txt +0 -25
  74. package/assets/stack/mobile-billing.tsx.txt +0 -63
  75. package/assets/stack/mobile-session.tsx.txt +0 -83
  76. package/assets/stack/native-button.tsx.txt +0 -108
  77. package/assets/stack/native-global.css.txt +0 -4
  78. package/assets/stack/native-lib-utils.ts.txt +0 -5
  79. package/assets/stack/native-metro.config.js.txt +0 -6
  80. package/assets/stack/native-nativewind-env.d.ts.txt +0 -1
  81. package/assets/stack/native-tailwind.config.js.txt +0 -73
  82. package/assets/stack/native-text.tsx.txt +0 -89
  83. package/assets/stack/purchases.ts.txt +0 -65
  84. package/assets/stack/revenuecat.ts.txt +0 -88
  85. package/assets/stack/rtc-schema.ts.txt +0 -10
  86. package/assets/stack/rtc.ts.txt +0 -122
  87. package/assets/stack/web-sign-in.tsx.txt +0 -51
  88. package/dist/capabilities.d.ts +0 -11
  89. package/dist/capabilities.js +0 -14
  90. package/dist/dependency-order.d.ts +0 -2
  91. package/dist/dependency-order.js +0 -24
  92. package/dist/platforms/lint.d.ts +0 -1
  93. package/dist/platforms/lint.js +0 -5
  94. package/dist/platforms/web.js +0 -251
  95. package/dist/project-config.d.ts +0 -3
  96. package/dist/project-config.js +0 -16
  97. package/dist/registry/context.d.ts +0 -3
  98. package/dist/registry/context.js +0 -20
  99. package/dist/registry/options.d.ts +0 -2
  100. package/dist/registry/options.js +0 -47
  101. package/dist/registry/resolve.d.ts +0 -11
  102. package/dist/registry/resolve.js +0 -46
  103. package/dist/registry/types.d.ts +0 -60
  104. package/dist/scaffold/api.d.ts +0 -2
  105. package/dist/scaffold/api.js +0 -38
  106. package/dist/scaffold/backend.d.ts +0 -2
  107. package/dist/scaffold/backend.js +0 -36
  108. package/dist/scaffold/compose.d.ts +0 -4
  109. package/dist/scaffold/compose.js +0 -30
  110. package/dist/scaffold/database.d.ts +0 -2
  111. package/dist/scaffold/database.js +0 -41
  112. package/dist/scaffold/documentation.d.ts +0 -2
  113. package/dist/scaffold/documentation.js +0 -71
  114. package/dist/scaffold/environment.d.ts +0 -4
  115. package/dist/scaffold/environment.js +0 -22
  116. package/dist/scaffold/stack-documentation.d.ts +0 -2
  117. package/dist/scaffold/stack-documentation.js +0 -6
  118. package/dist/scaffold/storage.d.ts +0 -2
  119. package/dist/scaffold/storage.js +0 -21
  120. package/dist/scaffold/workspace.d.ts +0 -3
  121. package/dist/scaffold/workspace.js +0 -141
  122. package/dist/stack-registry.d.ts +0 -35
  123. package/dist/stack-registry.js +0 -189
  124. package/dist/standard.d.ts +0 -8
  125. package/dist/standard.js +0 -109
  126. package/dist/workspace-graph.d.ts +0 -7
  127. package/dist/workspace-graph.js +0 -74
  128. /package/dist/{registry/types.js → command-types.js} +0 -0
@@ -0,0 +1,346 @@
1
+ import { chmodSync, existsSync, statSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { isDeepStrictEqual, stripVTControlCharacters } from 'node:util';
4
+ import { deploymentManifestSchema } from './contracts/deployment.js';
5
+ import { ArtifactUnavailableError, resolvePublishedCliArtifact, isPublishedCliArtifact, } from './release-artifact.js';
6
+ import { isMap, parseDocument } from 'yaml';
7
+ import { commandArgumentError, commandArguments } from './cli-arguments.js';
8
+ import { CliFailure } from './cli-errors.js';
9
+ import { createReporter } from './cli-output.js';
10
+ import { assertPublicWorkspace, projectRoot, readState } from './capability-command.js';
11
+ import { CapabilityEditor, fingerprint } from './capability-editor.js';
12
+ import { normalizeOjFoundation } from './platforms/tanstack.js';
13
+ import { composeSourceProvenance } from './composition.js';
14
+ import { GENERATOR_VERSION } from './version.js';
15
+ import { runStagedTransaction } from './transaction.js';
16
+ import { put } from './scaffold/files.js';
17
+ const MAX_UPDATE_BYTES = 256 * 1024;
18
+ const MAX_UPDATE_FILES = 32;
19
+ /** One exact replacement hunk without unchanged project configuration context. */
20
+ export function updateDiff(file, before, after) {
21
+ const old = before === null || before === '' ? [] : before.split('\n');
22
+ const next = after === '' ? [] : after.split('\n');
23
+ if (old.at(-1) === '')
24
+ old.pop();
25
+ if (next.at(-1) === '')
26
+ next.pop();
27
+ const newlineChanged = before !== null && before.endsWith('\n') !== after.endsWith('\n');
28
+ let prefix = 0;
29
+ while (prefix < old.length && prefix < next.length && old[prefix] === next[prefix])
30
+ prefix++;
31
+ if (newlineChanged && prefix === old.length && prefix === next.length && prefix > 0)
32
+ prefix--;
33
+ let suffix = 0;
34
+ while (suffix < old.length - prefix &&
35
+ suffix < next.length - prefix &&
36
+ old[old.length - suffix - 1] === next[next.length - suffix - 1] &&
37
+ !(newlineChanged && suffix === 0))
38
+ suffix++;
39
+ const oldEnd = old.length - suffix;
40
+ const nextEnd = next.length - suffix;
41
+ const oldCount = oldEnd - prefix;
42
+ const nextCount = nextEnd - prefix;
43
+ const lines = [
44
+ `--- ${before === null ? '/dev/null' : `a/${file}`}`,
45
+ `+++ b/${file}`,
46
+ `@@ -${oldCount ? prefix + 1 : prefix},${oldCount} +${nextCount ? prefix + 1 : prefix},${nextCount} @@`,
47
+ ];
48
+ for (let index = prefix; index < oldEnd; index++) {
49
+ lines.push(`-${old[index]}`);
50
+ if (index === old.length - 1 && before !== null && !before.endsWith('\n'))
51
+ lines.push('\');
52
+ }
53
+ for (let index = prefix; index < nextEnd; index++) {
54
+ lines.push(`+${next[index]}`);
55
+ if (index === next.length - 1 && !after.endsWith('\n'))
56
+ lines.push('\');
57
+ }
58
+ return lines.join('\n') + '\n';
59
+ }
60
+ function updatePnpmPolicy(e) {
61
+ const file = 'pnpm-workspace.yaml';
62
+ const source = e.read(file);
63
+ if (source === null)
64
+ throw Error('Missing pnpm-workspace.yaml; preserve and reconcile workspace policy.');
65
+ const document = parseDocument(source);
66
+ if (document.errors.length || !isMap(document.contents))
67
+ throw Error('Invalid pnpm-workspace.yaml; preserve existing policy.');
68
+ let policy;
69
+ try {
70
+ policy = document.toJS();
71
+ }
72
+ catch {
73
+ throw Error('Invalid or ambiguous pnpm workspace aliases; preserve existing policy.');
74
+ }
75
+ const expected = { esbuild: true, workerd: true };
76
+ if (policy.dangerouslyAllowAllBuilds !== undefined ||
77
+ policy.ignoredBuiltDependencies !== undefined ||
78
+ policy.neverBuiltDependencies !== undefined ||
79
+ policy.onlyBuiltDependenciesFile !== undefined)
80
+ throw Error('Customized pnpm build policy requires review; no source was changed.');
81
+ const previous = policy.onlyBuiltDependencies;
82
+ if (previous !== undefined &&
83
+ (!Array.isArray(previous) ||
84
+ previous.length !== 2 ||
85
+ new Set(previous).size !== 2 ||
86
+ !previous.includes('esbuild') ||
87
+ !previous.includes('workerd')))
88
+ throw Error('Customized onlyBuiltDependencies requires review; no source was changed.');
89
+ const allowed = policy.allowBuilds;
90
+ if (allowed !== undefined &&
91
+ (allowed === null ||
92
+ typeof allowed !== 'object' ||
93
+ Array.isArray(allowed) ||
94
+ Object.keys(allowed).length !== 2 ||
95
+ Reflect.get(allowed, 'esbuild') !== true ||
96
+ Reflect.get(allowed, 'workerd') !== true))
97
+ throw Error('Customized allowBuilds requires review; no source was changed.');
98
+ if (previous === undefined && allowed !== undefined)
99
+ return;
100
+ // Missing policy is not permission to enable lifecycle scripts.
101
+ if (previous === undefined && allowed === undefined)
102
+ throw Error('Missing reviewed pnpm build policy; reconcile it explicitly before updating.');
103
+ const pair = document.contents.items.find((item) => item.key &&
104
+ typeof item.key === 'object' &&
105
+ 'value' in item.key &&
106
+ item.key.value === 'onlyBuiltDependencies');
107
+ const key = pair?.key;
108
+ const value = pair?.value;
109
+ if (!key?.range || !value?.range)
110
+ throw Error('Cannot safely locate canonical pnpm build policy.');
111
+ const replacement = allowed === undefined ? `allowBuilds: ${JSON.stringify(expected)}\n` : '';
112
+ const updated = source.slice(0, key.range[0]) + replacement + source.slice(value.range[2]);
113
+ const updatedDocument = parseDocument(updated);
114
+ const expectedPolicy = { ...policy, allowBuilds: expected };
115
+ delete expectedPolicy.onlyBuiltDependencies;
116
+ let validPolicy = false;
117
+ try {
118
+ validPolicy =
119
+ !updatedDocument.errors.length && isDeepStrictEqual(updatedDocument.toJS(), expectedPolicy);
120
+ }
121
+ catch {
122
+ /* Never expose untrusted YAML alias details in a conflict. */
123
+ }
124
+ if (!validPolicy)
125
+ throw Error('The pnpm policy uses aliases or custom syntax that cannot be safely upgraded; preserve and reconcile it explicitly.');
126
+ e.writes.set(file, updated);
127
+ }
128
+ /** Remove only the previous canonical CSS URL adapter, retaining the authored document. */
129
+ function updateRootStylesheet(e) {
130
+ const file = 'apps/web/src/routes/__root.tsx';
131
+ const source = e.read(file);
132
+ if (source === null || !/\bfrom\s*(['"])\.\.\/styles\.css\?url\1/.test(source))
133
+ return;
134
+ const imports = [
135
+ ...source.matchAll(/^import[ \t]+styles[ \t]+from[ \t]+(['"])\.\.\/styles\.css\?url\1;[ \t]*\r?$/gm),
136
+ ];
137
+ const links = [
138
+ ...source.matchAll(/^[ \t]*links:[ \t]*\[[ \t]*\{[ \t]*rel:[ \t]*(['"])stylesheet\1[ \t]*,[ \t]*href:[ \t]*styles[ \t]*\}[ \t]*\],[ \t]*\r?\n/gm),
139
+ ];
140
+ const head = source.indexOf('head: () => ({');
141
+ const component = source.indexOf('component: Root', head);
142
+ if (imports.length !== 1 ||
143
+ links.length !== 1 ||
144
+ head < 0 ||
145
+ component < 0 ||
146
+ links[0].index < head ||
147
+ links[0].index > component ||
148
+ source.split('export const Route = createRootRoute({').length !== 2)
149
+ throw Error('Customized root stylesheet adapter needs review; preserve the authored root document.');
150
+ const imported = imports[0];
151
+ const linked = links[0];
152
+ const remainder = source.replace(imported[0], '').replace(linked[0], '');
153
+ if (/\bstyles\b/.test(remainder))
154
+ throw Error('The root stylesheet URL has additional uses; preserve and reconcile them explicitly.');
155
+ const updated = source
156
+ .replace(imported[0], `import ${imported[1]}../styles.css${imported[1]};`)
157
+ .replace(linked[0], '');
158
+ e.writes.set(file, updated);
159
+ }
160
+ export function planStackUpdate(root, artifact) {
161
+ if (artifact !== undefined &&
162
+ (!isPublishedCliArtifact(artifact) || artifact.version !== GENERATOR_VERSION))
163
+ throw Error('Only a verified published artifact matching this CLI can update deployment provenance.');
164
+ assertPublicWorkspace(root, false, 'stack');
165
+ const e = new CapabilityEditor(root, {});
166
+ const state = readState(e);
167
+ Object.assign(e.managed, state.managedFiles);
168
+ const configuration = e.json('anhedral.json');
169
+ const previousVersion = configuration.composition.generatorVersion;
170
+ const conflicts = [];
171
+ if (typeof previousVersion === 'string') {
172
+ const old = previousVersion.split(/[.-]/).slice(0, 3).map(Number);
173
+ const current = GENERATOR_VERSION.split(/[.-]/).slice(0, 3).map(Number);
174
+ const differing = old.findIndex((value, index) => value !== current[index]);
175
+ if (differing >= 0 && old[differing] > current[differing])
176
+ conflicts.push({
177
+ code: 'NEWER_SOURCE',
178
+ message: 'This source was generated by a newer CLI. Use that version or a newer published CLI; source downgrades are not supported.',
179
+ });
180
+ }
181
+ const attempt = (action) => {
182
+ try {
183
+ action();
184
+ }
185
+ catch (error) {
186
+ conflicts.push({
187
+ code: 'SOURCE_CONFLICT',
188
+ message: (error instanceof Error ? error.message : String(error)).slice(0, 1000),
189
+ });
190
+ }
191
+ };
192
+ if (existsSync(path.join(root, '.anhedral-journal.json')))
193
+ conflicts.push({
194
+ code: 'RECOVERY_REQUIRED',
195
+ message: 'An interrupted source transaction exists. Recover the original command before updating.',
196
+ });
197
+ attempt(() => {
198
+ updateRootStylesheet(e);
199
+ normalizeOjFoundation(e, state.installed, true);
200
+ });
201
+ attempt(() => updatePnpmPolicy(e));
202
+ let artifactRequired = true;
203
+ attempt(() => {
204
+ const source = e.read('deployment.json');
205
+ const composition = composeSourceProvenance(configuration.composition, state.installed, []);
206
+ if (source !== null) {
207
+ const manifest = deploymentManifestSchema.parse(e.json('deployment.json'));
208
+ if (manifest.foundation !== composition.foundation ||
209
+ manifest.identity !== composition.identity ||
210
+ JSON.stringify([...manifest.capabilities].sort()) !==
211
+ JSON.stringify([...state.installed].sort()))
212
+ throw Error('Deployment identity or capabilities disagree with installed source; preserve and reconcile deployment.json.');
213
+ if (artifact) {
214
+ artifactRequired = false;
215
+ if (JSON.stringify(manifest.cliArtifact) !== JSON.stringify(artifact))
216
+ e.set('deployment.json', ['cliArtifact'], artifact);
217
+ if (JSON.stringify(deploymentManifestSchema.parse(e.json('deployment.json')).cliArtifact) !==
218
+ JSON.stringify(artifact))
219
+ throw Error('Deployment artifact has ambiguous source keys; preserve and reconcile deployment.json.');
220
+ }
221
+ }
222
+ else if (artifact) {
223
+ const manifest = deploymentManifestSchema.parse({
224
+ contractVersion: 1,
225
+ foundation: composition.foundation,
226
+ capabilities: state.installed,
227
+ identity: composition.identity,
228
+ cliArtifact: artifact,
229
+ intent: {
230
+ contractVersion: 1,
231
+ runtimeProfile: 'anhedral-stack',
232
+ environment: 'preview',
233
+ visibility: 'protected',
234
+ },
235
+ });
236
+ e.create('deployment.json', JSON.stringify(manifest, null, 2) + '\n');
237
+ artifactRequired = false;
238
+ }
239
+ });
240
+ if (!conflicts.length)
241
+ attempt(() => {
242
+ const composition = composeSourceProvenance(configuration.composition, state.installed, []);
243
+ if (configuration.setup.cliVersion !== GENERATOR_VERSION)
244
+ e.set('anhedral.json', ['setup', 'cliVersion'], GENERATOR_VERSION);
245
+ if (JSON.stringify(composition) !== JSON.stringify(configuration.composition))
246
+ e.set('anhedral.json', ['composition'], composition);
247
+ if (JSON.stringify(e.managed) !== JSON.stringify(state.managedFiles))
248
+ e.set('anhedral.json', ['capabilities', 'managedFiles'], e.managed);
249
+ const updatedConfiguration = e.json('anhedral.json');
250
+ if (updatedConfiguration.setup.cliVersion !== GENERATOR_VERSION ||
251
+ !isDeepStrictEqual(updatedConfiguration.composition, composition) ||
252
+ !isDeepStrictEqual(updatedConfiguration.capabilities.managedFiles, e.managed))
253
+ throw Error('Ambiguous source provenance keys; preserve and reconcile anhedral.json before updating.');
254
+ });
255
+ const entries = [...e.writes]
256
+ .filter(([file, after]) => e.before.get(file) !== after)
257
+ .sort(([a], [b]) => a.localeCompare(b));
258
+ const total = entries.reduce((bytes, [file, after]) => bytes + Buffer.byteLength(e.before.get(file) ?? '') + Buffer.byteLength(after), 0);
259
+ if (entries.length > MAX_UPDATE_FILES || total > MAX_UPDATE_BYTES)
260
+ conflicts.push({
261
+ code: 'PREVIEW_LIMIT',
262
+ message: `Update exceeds the bounded preview (${MAX_UPDATE_FILES} files/${MAX_UPDATE_BYTES} bytes); preserve source and reconcile it explicitly.`,
263
+ });
264
+ let changes = total > MAX_UPDATE_BYTES || entries.length > MAX_UPDATE_FILES
265
+ ? []
266
+ : entries.map(([file, after]) => ({
267
+ path: file,
268
+ beforeDigest: e.before.get(file) === null ? null : fingerprint(e.before.get(file)),
269
+ afterDigest: fingerprint(after),
270
+ diff: updateDiff(file, e.before.get(file) ?? null, after),
271
+ }));
272
+ if (changes.some((change) => /["']?[A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|PRIVATE_KEY|API_KEY|AUTHORIZATION)[A-Z0-9_]*["']?\s*[:=]/i.test(change.diff))) {
273
+ conflicts.push({
274
+ code: 'SENSITIVE_PREVIEW',
275
+ message: 'A changed configuration block may contain private values. Preserve it and reconcile that owned configuration before updating.',
276
+ });
277
+ changes = [];
278
+ }
279
+ const plan = {
280
+ schemaVersion: 1,
281
+ root,
282
+ fromVersion: previousVersion,
283
+ toVersion: GENERATOR_VERSION,
284
+ changes,
285
+ conflicts,
286
+ sourceOnly: true,
287
+ dependenciesInstalled: false,
288
+ resourcesProvisionedByCli: false,
289
+ deployment: {
290
+ provenanceReady: !artifactRequired && conflicts.length === 0,
291
+ artifactRequired,
292
+ artifact: artifact ?? null,
293
+ message: artifactRequired
294
+ ? 'Resolve the published CLI artifact before refreshing deployment provenance. Rerun without --offline when online.'
295
+ : 'CLI artifact verified against official release metadata and npm. Hosting and build admission remain server-owned.',
296
+ },
297
+ nextAction: 'Review the diff, apply with --expect-plan, then install dependencies and validate the application separately.',
298
+ };
299
+ return { editor: e, entries, plan: { ...plan, planId: fingerprint(JSON.stringify(plan)) } };
300
+ }
301
+ export async function runStackUpdate(args, output, dependencies = {}) {
302
+ const parsed = commandArguments('stack', args);
303
+ const expected = parsed.value('--expect-plan');
304
+ if (expected !== undefined && !/^[a-f0-9]{64}$/.test(expected))
305
+ throw commandArgumentError('stack', '--expect-plan requires a SHA-256 plan ID.');
306
+ const root = projectRoot(process.cwd());
307
+ assertPublicWorkspace(root, false, 'stack');
308
+ let artifact;
309
+ if (!parsed.has('--offline')) {
310
+ try {
311
+ artifact = await (dependencies.resolveArtifact ?? resolvePublishedCliArtifact)();
312
+ }
313
+ catch (error) {
314
+ if (error instanceof ArtifactUnavailableError)
315
+ throw new CliFailure(error.message, 'ARTIFACT_UNAVAILABLE', 'Retry after publication or preview with stack update --offline --dry-run --json. Deployment provenance stays pending offline.', 'network', true);
316
+ throw error;
317
+ }
318
+ }
319
+ const { editor, entries, plan } = planStackUpdate(root, artifact);
320
+ if (expected !== undefined && expected !== plan.planId)
321
+ throw new CliFailure('The source update plan changed. Review a fresh --dry-run before applying.', 'UPDATE_PLAN_CHANGED', 'Run anhedral stack update --dry-run --json and review the new plan before applying.', 'conflict', false);
322
+ let applied = false;
323
+ if (!parsed.has('--dry-run') && !plan.conflicts.length) {
324
+ if (entries.length)
325
+ await runStagedTransaction(root, {
326
+ commitPaths: entries.map(([file]) => file),
327
+ recover: false,
328
+ prepare: () => editor.verify(),
329
+ build: async (stage) => {
330
+ for (const [file, source] of entries) {
331
+ put(stage, file, source);
332
+ if (editor.before.get(file) !== null)
333
+ chmodSync(path.join(stage, file), statSync(path.join(root, file)).mode & 0o777);
334
+ }
335
+ editor.verify();
336
+ },
337
+ });
338
+ else
339
+ editor.verify();
340
+ applied = true;
341
+ }
342
+ if (plan.conflicts.length)
343
+ process.exitCode = 1;
344
+ const terminalSafe = (value) => stripVTControlCharacters(value.replace(/\r\n/g, '\n')).replace(/[\x00-\x08\x0b-\x1f\x7f]/g, '');
345
+ createReporter(output, () => terminalSafe(`${applied ? 'Applied' : 'Preview'} source update ${plan.fromVersion ?? 'unknown'} → ${plan.toVersion}\nPlan: ${plan.planId}\n${plan.changes.map((change) => change.diff).join('\n')}${plan.conflicts.map((conflict) => conflict.message).join('\n')}\n${plan.nextAction}`)).result({ ...plan, dryRun: parsed.has('--dry-run'), applied });
346
+ }
@@ -15,6 +15,7 @@ export declare function runStagedTransaction(root: string, options: {
15
15
  deletePaths?: string[];
16
16
  seedPaths?: string[];
17
17
  dryRun?: boolean;
18
+ recover?: boolean;
18
19
  prepare?: () => boolean | void | Promise<boolean | void>;
19
20
  afterCommit?: () => void | Promise<void>;
20
21
  onPlan?: (paths: readonly string[]) => void;
@@ -642,6 +642,8 @@ export async function runStagedTransaction(root, options) {
642
642
  if (options.dryRun && pathEntryExists(path.join(root, JOURNAL_FILE))) {
643
643
  throw new Error('Dry-run cannot recover an interrupted transaction. Re-run the original command without --dry-run first.');
644
644
  }
645
+ if (options.recover === false && pathEntryExists(path.join(root, JOURNAL_FILE)))
646
+ throw new Error('An interrupted transaction requires recovery before this operation.');
645
647
  recoverInterruptedTransactionUnlocked(root);
646
648
  if (!options.dryRun)
647
649
  cleanupOrphanTransactionRoots(root);
@@ -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
  }
@@ -2,4 +2,4 @@ import { type OutputOptions } from './cli-output.js';
2
2
  export type UiRunner = (args: string[], cwd: string) => string | Promise<string>;
3
3
  /** Public UI surface: one Anhedral Stack web target, with no native install fallback. */
4
4
  export declare function runAnhedralUiCommand(args: string[], output: OutputOptions, run?: UiRunner): Promise<void>;
5
- export declare function runUiCommand(args: string[], output: OutputOptions, run?: UiRunner, mode?: 'compatibility' | 'public'): Promise<void>;
5
+ export declare function runUiCommand(args: string[], output: OutputOptions, run?: UiRunner): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { existsSync, writeFileSync } from 'node:fs';
1
+ import { existsSync } from 'node:fs';
2
2
  import { MAX_PROJECT_JSON_BYTES, readBoundedFile } from './bounded-file.js';
3
3
  import path from 'node:path';
4
4
  import { stripVTControlCharacters } from 'node:util';
@@ -98,7 +98,7 @@ function assertAnhedralStackTarget(target) {
98
98
  if (existsSync(metadata)) {
99
99
  const project = JSON.parse(readBoundedFile(metadata, MAX_PROJECT_JSON_BYTES).toString('utf8'));
100
100
  if (project?.schemaVersion !== 1 ||
101
- ![ANHEDRAL_STACK.id, 'anhedral-web-launch'].includes(project.setup?.stack) ||
101
+ project.setup?.stack !== ANHEDRAL_STACK.id ||
102
102
  project.composition?.contractVersion !== 2 ||
103
103
  project.composition?.foundation !== ANHEDRAL_STACK.foundation.id ||
104
104
  path.join(root, 'apps', 'web') !== target.root)
@@ -113,40 +113,32 @@ function assertAnhedralStackTarget(target) {
113
113
  }
114
114
  /** Public UI surface: one Anhedral Stack web target, with no native install fallback. */
115
115
  export async function runAnhedralUiCommand(args, output, run = runUpstream) {
116
- return runUiCommand(args, output, run, 'public');
116
+ return runUiCommand(args, output, run);
117
117
  }
118
- export async function runUiCommand(args, output, run = runUpstream, mode = 'compatibility') {
119
- if (mode === 'public' && args.some((arg) => /^--(?:native|all)(?:=|$)/.test(arg)))
118
+ export async function runUiCommand(args, output, run = runUpstream) {
119
+ if (args.some((arg) => /^--(?:native|all)(?:=|$)/.test(arg)))
120
120
  throw commandArgumentError('ui', 'Anhedral UI supports the Anhedral Stack web application only. Use --web or select apps/web with --cwd.');
121
- // Retained direct library callers can inspect legacy source; the executable uses public mode.
122
- const legacySelectors = mode === 'compatibility' ? args.filter((arg) => ['--native', '--all'].includes(arg)) : [];
123
- if (new Set(legacySelectors).size !== legacySelectors.length)
124
- throw commandArgumentError('ui', 'Specify each UI selector only once.');
125
- const parsed = commandArguments('ui', args.filter((arg) => !legacySelectors.includes(arg)));
121
+ const parsed = commandArguments('ui', args);
126
122
  const [action, ...names] = parsed.positional;
127
123
  if (!['init', 'add', 'list', 'diff', 'doctor'].includes(action))
128
124
  throw commandArgumentError('ui', 'Choose ui init, add, list, diff or doctor.');
129
125
  if (['add', 'diff'].includes(action) ? !names.length || names.length > 50 : names.length > 0)
130
126
  throw commandArgumentError('ui', 'Supply component names only for add/diff (at most 50).');
131
- const selectors = ['--web', '--native', '--all'].filter((flag) => parsed.has(flag) || legacySelectors.includes(flag));
132
- if (selectors.length > 1)
133
- throw commandArgumentError('ui', 'Choose one of --web, --native or --all.');
134
- const selector = mode === 'public' ? 'web' : selectors[0]?.slice(2);
127
+ const selector = 'web';
135
128
  let result;
136
129
  if (action === 'list') {
137
130
  result = {
138
131
  catalogRevision: UI_CATALOG.revision,
139
- ...(mode === 'public' ? { platform: 'web' } : { nativeStyling: UI_CATALOG.nativeStyling }),
132
+ ...{ platform: 'web' },
140
133
  components: UI_CATALOG.components
141
- .filter((item) => !selector || selector === 'all' || item[selector])
142
- .map((item) => (mode === 'public' ? { name: item.name, web: item.web } : item)),
134
+ .filter((item) => item[selector])
135
+ .map((item) => ({ name: item.name, web: item.web })),
143
136
  };
144
137
  }
145
138
  else {
146
139
  const targets = detectUiTargets(process.cwd(), selector);
147
- if (mode === 'public')
148
- for (const target of targets)
149
- assertAnhedralStackTarget(target);
140
+ for (const target of targets)
141
+ assertAnhedralStackTarget(target);
150
142
  if (action === 'doctor') {
151
143
  const reports = targets.map(inspectUiTarget);
152
144
  result = {
@@ -157,27 +149,21 @@ export async function runUiCommand(args, output, run = runUpstream, mode = 'comp
157
149
  process.exitCode = 1;
158
150
  }
159
151
  else {
160
- // Preflight every target before invoking any installer, including explicit --all.
152
+ // Preflight every target before invoking any installer, before source installation.
161
153
  const plans = targets.map((target) => {
162
154
  assertUiMetadataPaths(target.root);
163
155
  const report = inspectUiTarget(target);
164
156
  const configExists = existsSync(path.join(target.root, 'components.json'));
165
- const nativeInit = action === 'init' && target.platform === 'native';
166
- const issues = nativeInit
167
- ? report.issues.filter((issue) => !issue.startsWith('Missing components.json'))
168
- : report.issues;
169
- if ((action !== 'init' || target.platform === 'native' || configExists) && issues.length)
157
+ const issues = report.issues;
158
+ if ((action !== 'init' || configExists) && issues.length)
170
159
  throw Error(issues.join('\n') + '\n' + report.guide);
171
- if (nativeInit && !configExists && !existsSync(path.join(target.root, 'global.css')))
172
- throw Error('Native init needs the upstream NativeWind global.css. Complete the RNR setup first.');
173
160
  const items = action === 'init' ? [] : resolveUiItems(names, target.platform);
174
161
  return {
175
162
  root: target.root,
176
163
  platform: target.platform,
177
164
  items,
178
- nativeInit,
179
165
  command: action === 'init'
180
- ? configExists || nativeInit
166
+ ? configExists
181
167
  ? []
182
168
  : ['init', '--base', 'base', '--defaults', '--no-reinstall', '--no-monorepo']
183
169
  : [
@@ -190,29 +176,6 @@ export async function runUiCommand(args, output, run = runUpstream, mode = 'comp
190
176
  });
191
177
  if (!parsed.has('--dry-run')) {
192
178
  for (const plan of plans) {
193
- if (plan.nativeInit && !existsSync(path.join(plan.root, 'components.json'))) {
194
- if (!existsSync(path.join(plan.root, 'global.css')))
195
- throw Error('Native init needs the upstream NativeWind global.css. Complete the RNR setup first.');
196
- writeFileSync(path.join(plan.root, 'components.json'), JSON.stringify({
197
- $schema: 'https://ui.shadcn.com/schema.json',
198
- style: 'new-york',
199
- rsc: false,
200
- tsx: true,
201
- tailwind: {
202
- config: 'tailwind.config.js',
203
- css: 'global.css',
204
- baseColor: 'neutral',
205
- cssVariables: true,
206
- },
207
- aliases: {
208
- components: '@/components',
209
- ui: '@/components/ui',
210
- utils: '@/lib/utils',
211
- lib: '@/lib',
212
- hooks: '@/hooks',
213
- },
214
- }, null, 2) + '\n', { flag: 'wx' });
215
- }
216
179
  const vendorOutput = plan.command.length ? await run(plan.command, plan.root) : '';
217
180
  if (action === 'init' || action === 'add')
218
181
  initializeUiMetadata(plan.root, plan.platform);
@@ -229,10 +192,8 @@ export async function runUiCommand(args, output, run = runUpstream, mode = 'comp
229
192
  }
230
193
  createReporter(output, () => action === 'list'
231
194
  ? UI_CATALOG.components
232
- .filter((item) => !selector || selector === 'all' || item[selector])
233
- .map((item) => mode === 'public'
234
- ? `${item.name}\tshadcn`
235
- : `${item.name}\tweb: ${item.web ? 'shadcn' : 'unavailable'}\tnative: ${item.native ? 'RNR (validation required)' : 'unavailable'}`)
195
+ .filter((item) => item[selector])
196
+ .map((item) => `${item.name}\tshadcn`)
236
197
  .join('\n')
237
198
  : action === 'doctor'
238
199
  ? result.targets
@@ -8,10 +8,10 @@ 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;