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.
- package/README.md +10 -6
- package/assets/contracts/deployment-provenance.json +6 -6
- package/assets/contracts/operations-provenance.json +2 -1
- package/assets/launch/oj/OJ.LICENSE +21 -0
- package/assets/launch/oj/run.mjs +82 -0
- package/assets/launch/oj/runtime.json +21 -0
- package/assets/launch/root.tsx.txt +1 -2
- package/assets/launch/server.ts.txt +4 -2
- package/assets/ui/catalog.json +36 -324
- package/dist/{platforms/web.d.ts → api-proxy.d.ts} +1 -3
- package/dist/api-proxy.js +48 -0
- package/dist/capability-catalog.d.ts +3 -57
- package/dist/capability-catalog.js +3 -90
- package/dist/capability-command.d.ts +10 -2
- package/dist/capability-command.js +35 -99
- package/dist/capability-editor.js +21 -1
- package/dist/capability-recipes.js +8 -343
- package/dist/cli-commands.js +6 -1
- package/dist/command-schema.js +141 -2
- package/dist/command-types.d.ts +1 -0
- package/dist/composition.d.ts +4 -14
- package/dist/composition.js +6 -6
- package/dist/contracts/cli-transport.d.ts +139 -40
- package/dist/contracts/cli-transport.js +96 -27
- package/dist/contracts/deployment.d.ts +7 -56
- package/dist/contracts/deployment.js +9 -45
- package/dist/contracts/production-transport.d.ts +71 -0
- package/dist/contracts/production-transport.js +56 -0
- package/dist/contracts/source-profile.js +1 -1
- package/dist/contracts/staging-transport.d.ts +2 -2
- package/dist/credential-helper.d.ts +2 -0
- package/dist/credential-helper.js +44 -0
- package/dist/dependencies.d.ts +0 -27
- package/dist/dependencies.js +3 -67
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -2
- package/dist/launch.d.ts +11 -5
- package/dist/launch.js +21 -9
- package/dist/platform-command.js +245 -42
- package/dist/platform-production.d.ts +16 -0
- package/dist/platform-production.js +135 -0
- package/dist/platform-state.d.ts +4 -1
- package/dist/platform-state.js +28 -5
- package/dist/platforms/tanstack.d.ts +2 -0
- package/dist/platforms/tanstack.js +113 -20
- package/dist/registry/usage.js +3 -1
- package/dist/release-artifact.d.ts +18 -0
- package/dist/release-artifact.js +169 -0
- package/dist/scaffold/bootstrap.d.ts +3 -3
- package/dist/scaffold/styling.d.ts +3 -2
- package/dist/stack-update.d.ts +39 -0
- package/dist/stack-update.js +346 -0
- package/dist/transaction.d.ts +1 -0
- package/dist/transaction.js +2 -0
- package/dist/ui-catalog.d.ts +3 -5
- package/dist/ui-catalog.js +8 -24
- package/dist/ui-command.d.ts +1 -1
- package/dist/ui-command.js +18 -57
- package/dist/ui-project.d.ts +2 -2
- package/dist/ui-project.js +8 -36
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/capabilities.md +7 -7
- package/docs/software-factory.md +83 -16
- package/docs/stack-standard.md +1 -1
- package/package.json +1 -4
- package/assets/stack/ai-schema.ts.txt +0 -5
- package/assets/stack/ai.ts.txt +0 -30
- package/assets/stack/desktop.rs.txt +0 -21
- package/assets/stack/event-retention.sql.txt +0 -10
- package/assets/stack/events-schema.ts.txt +0 -12
- package/assets/stack/events.ts.txt +0 -59
- package/assets/stack/mobile-auth.ts.txt +0 -25
- package/assets/stack/mobile-billing.tsx.txt +0 -63
- package/assets/stack/mobile-session.tsx.txt +0 -83
- package/assets/stack/native-button.tsx.txt +0 -108
- package/assets/stack/native-global.css.txt +0 -4
- package/assets/stack/native-lib-utils.ts.txt +0 -5
- package/assets/stack/native-metro.config.js.txt +0 -6
- package/assets/stack/native-nativewind-env.d.ts.txt +0 -1
- package/assets/stack/native-tailwind.config.js.txt +0 -73
- package/assets/stack/native-text.tsx.txt +0 -89
- package/assets/stack/purchases.ts.txt +0 -65
- package/assets/stack/revenuecat.ts.txt +0 -88
- package/assets/stack/rtc-schema.ts.txt +0 -10
- package/assets/stack/rtc.ts.txt +0 -122
- package/assets/stack/web-sign-in.tsx.txt +0 -51
- package/dist/capabilities.d.ts +0 -11
- package/dist/capabilities.js +0 -14
- package/dist/dependency-order.d.ts +0 -2
- package/dist/dependency-order.js +0 -24
- package/dist/platforms/lint.d.ts +0 -1
- package/dist/platforms/lint.js +0 -5
- package/dist/platforms/web.js +0 -251
- package/dist/project-config.d.ts +0 -3
- package/dist/project-config.js +0 -16
- package/dist/registry/context.d.ts +0 -3
- package/dist/registry/context.js +0 -20
- package/dist/registry/options.d.ts +0 -2
- package/dist/registry/options.js +0 -47
- package/dist/registry/resolve.d.ts +0 -11
- package/dist/registry/resolve.js +0 -46
- package/dist/registry/types.d.ts +0 -60
- package/dist/scaffold/api.d.ts +0 -2
- package/dist/scaffold/api.js +0 -38
- package/dist/scaffold/backend.d.ts +0 -2
- package/dist/scaffold/backend.js +0 -36
- package/dist/scaffold/compose.d.ts +0 -4
- package/dist/scaffold/compose.js +0 -30
- package/dist/scaffold/database.d.ts +0 -2
- package/dist/scaffold/database.js +0 -41
- package/dist/scaffold/documentation.d.ts +0 -2
- package/dist/scaffold/documentation.js +0 -71
- package/dist/scaffold/environment.d.ts +0 -4
- package/dist/scaffold/environment.js +0 -22
- package/dist/scaffold/stack-documentation.d.ts +0 -2
- package/dist/scaffold/stack-documentation.js +0 -6
- package/dist/scaffold/storage.d.ts +0 -2
- package/dist/scaffold/storage.js +0 -21
- package/dist/scaffold/workspace.d.ts +0 -3
- package/dist/scaffold/workspace.js +0 -141
- package/dist/stack-registry.d.ts +0 -35
- package/dist/stack-registry.js +0 -189
- package/dist/standard.d.ts +0 -8
- package/dist/standard.js +0 -109
- package/dist/workspace-graph.d.ts +0 -7
- package/dist/workspace-graph.js +0 -74
- /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
|
+
}
|
package/dist/transaction.d.ts
CHANGED
|
@@ -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;
|
package/dist/transaction.js
CHANGED
|
@@ -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);
|
package/dist/ui-catalog.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type UiPlatform = 'web'
|
|
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
|
|
22
|
-
export declare function resolveUiItems(names: string[], platform: UiPlatform
|
|
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;
|
package/dist/ui-catalog.js
CHANGED
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
15
|
-
|
|
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
|
}
|
package/dist/ui-command.d.ts
CHANGED
|
@@ -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
|
|
5
|
+
export declare function runUiCommand(args: string[], output: OutputOptions, run?: UiRunner): Promise<void>;
|
package/dist/ui-command.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync
|
|
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
|
-
|
|
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
|
|
116
|
+
return runUiCommand(args, output, run);
|
|
117
117
|
}
|
|
118
|
-
export async function runUiCommand(args, output, run = runUpstream
|
|
119
|
-
if (
|
|
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
|
-
|
|
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
|
|
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
|
-
...
|
|
132
|
+
...{ platform: 'web' },
|
|
140
133
|
components: UI_CATALOG.components
|
|
141
|
-
.filter((item) =>
|
|
142
|
-
.map((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
|
-
|
|
148
|
-
|
|
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,
|
|
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
|
|
166
|
-
|
|
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
|
|
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) =>
|
|
233
|
-
.map((item) =>
|
|
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
|
package/dist/ui-project.d.ts
CHANGED
|
@@ -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
|
|
11
|
+
export declare function detectUiTargets(cwd: string, selector?: UiPlatform): UiTarget[];
|
|
12
12
|
export declare function inspectUiTarget(target: UiTarget): {
|
|
13
13
|
root: string;
|
|
14
|
-
platform:
|
|
14
|
+
platform: "web";
|
|
15
15
|
configurationReady: boolean;
|
|
16
16
|
issues: string[];
|
|
17
17
|
runtimeAcceptance: string;
|