anhedral 0.19.0 → 0.21.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 +11 -7
- package/dist/capability-catalog.d.ts +1 -1
- package/dist/capability-catalog.js +1 -1
- package/dist/capability-command.d.ts +8 -0
- package/dist/capability-command.js +3 -3
- package/dist/capability-editor.js +21 -1
- package/dist/cli-arguments.js +2 -0
- package/dist/cli-commands.js +4 -4
- package/dist/cli-errors.js +3 -5
- package/dist/command-schema.js +35 -39
- package/dist/completion.js +0 -3
- package/dist/credential-helper.d.ts +2 -0
- package/dist/credential-helper.js +44 -0
- package/dist/launch.js +4 -2
- package/dist/platform-state.d.ts +2 -1
- package/dist/platform-state.js +5 -4
- package/dist/platforms/tanstack.js +0 -3
- package/dist/registry/usage.js +2 -1
- package/dist/release-artifact.d.ts +18 -0
- package/dist/release-artifact.js +169 -0
- 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/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/capabilities.md +1 -1
- package/docs/software-factory.md +29 -1
- package/docs/stack-standard.md +1 -1
- package/docs/ui.md +10 -13
- package/package.json +1 -4
- package/assets/ui/LICENSE.react-native-reusables +0 -21
- package/assets/ui/catalog.json +0 -603
- package/assets/ui/extensions/registry.json +0 -6
- package/dist/ui-catalog.d.ts +0 -24
- package/dist/ui-catalog.js +0 -15
- package/dist/ui-command.d.ts +0 -5
- package/dist/ui-command.js +0 -221
- package/dist/ui-project.d.ts +0 -24
- package/dist/ui-project.js +0 -112
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { resolvePublishedCliArtifact, type PublishedCliArtifact } from './release-artifact.js';
|
|
2
|
+
import { type OutputOptions } from './cli-output.js';
|
|
3
|
+
import { CapabilityEditor } from './capability-editor.js';
|
|
4
|
+
/** One exact replacement hunk without unchanged project configuration context. */
|
|
5
|
+
export declare function updateDiff(file: string, before: string | null, after: string): string;
|
|
6
|
+
export declare function planStackUpdate(root: string, artifact?: PublishedCliArtifact): {
|
|
7
|
+
editor: CapabilityEditor;
|
|
8
|
+
entries: [string, string][];
|
|
9
|
+
plan: {
|
|
10
|
+
planId: string;
|
|
11
|
+
schemaVersion: number;
|
|
12
|
+
root: string;
|
|
13
|
+
fromVersion: any;
|
|
14
|
+
toVersion: string;
|
|
15
|
+
changes: {
|
|
16
|
+
path: string;
|
|
17
|
+
beforeDigest: string | null;
|
|
18
|
+
afterDigest: string;
|
|
19
|
+
diff: string;
|
|
20
|
+
}[];
|
|
21
|
+
conflicts: {
|
|
22
|
+
code: string;
|
|
23
|
+
message: string;
|
|
24
|
+
}[];
|
|
25
|
+
sourceOnly: boolean;
|
|
26
|
+
dependenciesInstalled: boolean;
|
|
27
|
+
resourcesProvisionedByCli: boolean;
|
|
28
|
+
deployment: {
|
|
29
|
+
provenanceReady: boolean;
|
|
30
|
+
artifactRequired: boolean;
|
|
31
|
+
artifact: PublishedCliArtifact | null;
|
|
32
|
+
message: string;
|
|
33
|
+
};
|
|
34
|
+
nextAction: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare function runStackUpdate(args: string[], output: OutputOptions, dependencies?: {
|
|
38
|
+
resolveArtifact?: typeof resolvePublishedCliArtifact;
|
|
39
|
+
}): Promise<void>;
|
|
@@ -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/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const GENERATOR_VERSION = "0.
|
|
1
|
+
export declare const GENERATOR_VERSION = "0.21.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const GENERATOR_VERSION = '0.
|
|
1
|
+
export const GENERATOR_VERSION = '0.21.0';
|
package/docs/capabilities.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Anhedral Stack additions
|
|
2
2
|
|
|
3
|
-
There is one current **Anhedral Stack**. `anhedral init` creates its web foundation with TanStack Start SSR/server functions and
|
|
3
|
+
There is one current **Anhedral Stack**. `anhedral init` creates its web foundation with TanStack Start SSR/server functions and editable shadcn components. Add the remaining services only when needed.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
anhedral init my-app
|
package/docs/software-factory.md
CHANGED
|
@@ -9,7 +9,7 @@ The Anhedral Stack has one current web foundation and progressive backend/storag
|
|
|
9
9
|
3. Preview and add [capabilities](capabilities.md) as needed. Configure selected
|
|
10
10
|
providers/auth methods, apply reviewed migrations and validate actual runtime
|
|
11
11
|
behavior before deployment. Source installation is not provider activation.
|
|
12
|
-
4.
|
|
12
|
+
4. Choose or extend [web UI](ui.md), implement features and run consumer checks.
|
|
13
13
|
|
|
14
14
|
## Evidence-driven maintenance
|
|
15
15
|
|
|
@@ -74,11 +74,36 @@ Backend server entries call TanStack’s `createStartHandler(defaultStreamHandle
|
|
|
74
74
|
|
|
75
75
|
OJ dev commands attach an explicit host value with `--host=<hostname>`, as required by the pinned runtime. Generated workspaces explicitly allow dependency build scripts only for esbuild and workerd through the pnpm `allowBuilds` map. This keeps installation noninteractive under the pinned pnpm release and pnpm11 without allowing arbitrary dependency scripts.
|
|
76
76
|
|
|
77
|
+
## Updating existing source
|
|
78
|
+
|
|
79
|
+
Plugin updates refresh agent guidance; select its matching published CLI separately.
|
|
80
|
+
Use the host's configured marketplace: Codex refreshes its marketplace with
|
|
81
|
+
`codex plugin marketplace upgrade <marketplace>` and installs the refreshed
|
|
82
|
+
`codex plugin add anhedral@<marketplace>`; Claude Code uses
|
|
83
|
+
`claude plugin marketplace update <marketplace>` and
|
|
84
|
+
`claude plugin update anhedral@<marketplace>`. Verify the installed manifest version
|
|
85
|
+
and reload/restart the host when required before relying on its new guidance.
|
|
86
|
+
Run `stack update --dry-run --json`, inspect the bounded file diffs and conflicts,
|
|
87
|
+
then apply `stack update --expect-plan <planId> --json`. The plan binds source
|
|
88
|
+
preimages, target generator and resolved release artifact. Changed plans and
|
|
89
|
+
customized generated files stop the update; authored routes and assets remain
|
|
90
|
+
owned by the application. This operation uses the existing journaled transaction
|
|
91
|
+
without installing dependencies or running project scripts. Resolve source
|
|
92
|
+
conflicts before another preview, then install dependencies and run application
|
|
93
|
+
checks/build separately. It never changes authentication or deployment authority.
|
|
94
|
+
Official release metadata and npm integrity establish deployment provenance;
|
|
95
|
+
project-supplied metadata cannot select another registry, credential destination
|
|
96
|
+
or executable. Offline source inspection cannot attest a newly published artifact.
|
|
97
|
+
|
|
77
98
|
## Platform CLI access and source upload
|
|
78
99
|
|
|
79
100
|
`login --start` prints browser approval instructions; `login --resume` redeems the
|
|
80
101
|
saved approval. Interactive `login` polls after showing the URL and confirmation
|
|
81
102
|
code. Tokens and device secrets use macOS Keychain or Linux Secret Service;
|
|
103
|
+
Linux selects a validated root-owned system helper without searching project
|
|
104
|
+
`PATH`. `ANHEDRAL_CLI_SECRET_TOOL_PATH` can select an absolute trusted system
|
|
105
|
+
installation; its executable and path ownership/permissions are validated.
|
|
106
|
+
Untrusted or unavailable helpers fail closed.
|
|
82
107
|
`--credential-file <path>` explicitly selects an owner-only file. Credential
|
|
83
108
|
storage is currently unsupported on Windows. Credentials are
|
|
84
109
|
bound to the explicit `--api-url` origin (HTTPS, with literal loopback for fixtures).
|
|
@@ -193,6 +218,9 @@ reviewed skills, references, assets and host manifests, and rejects connection f
|
|
|
193
218
|
or executable declarations. `tests/test-plugin-codex.test.mjs` installs the exact
|
|
194
219
|
archive in an isolated Codex home and verifies both skills with no MCP, app or hook
|
|
195
220
|
registration when Codex is available (`ANHEDRAL_CODEX_BIN` overrides the binary).
|
|
221
|
+
`ANHEDRAL_CLAUDE_BIN` selects an explicitly installed Claude validator; use a current
|
|
222
|
+
version supporting `plugin validate --strict`. Installed older validators fail the
|
|
223
|
+
gate rather than silently dropping strict validation.
|
|
196
224
|
|
|
197
225
|
One distribution directory, `plugin/`, serves Codex and Claude Code. Codex reads
|
|
198
226
|
`plugin.json` and `skills/*/agents/openai.yaml`; Claude Code reads
|
package/docs/stack-standard.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Anhedral Stack** is the single current stack. The CLI generates its editable source; Platform independently owns managed builds, resource admission, deployment and operations. There is no public multi-stack registry or framework selector.
|
|
4
4
|
|
|
5
|
-
The web foundation uses TanStack Start SSR/server functions and
|
|
5
|
+
The web foundation uses TanStack Start SSR/server functions and editable shadcn components. `anhedral init` creates only that foundation. `add backend` composes Hono, Drizzle/D1 and Better Auth together. Add private R2 or Stripe subscriptions later when needed. See [additions](capabilities.md).
|
|
6
6
|
|
|
7
7
|
When selected, Hono owns privileged business/auth/data/storage operations. Web server functions call its scoped service binding; application source is never imported across application boundaries. Keep resources private, enforce identity/ownership/limits and configure secrets per environment.
|
|
8
8
|
|
package/docs/ui.md
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Web UI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`anhedral init` defaults to standard shadcn components. It creates web `components.json`, the `cn` utility, semantic theme tokens, and editable Button, Input and Label source. These defaults are optional: consumers may extend, replace or remove them and use any UI library. There is no separate Anhedral UI library, catalog, ownership marker or `anhedral ui` command.
|
|
4
|
+
|
|
5
|
+
Use upstream shadcn directly from the web application:
|
|
4
6
|
|
|
5
7
|
```sh
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
anhedral ui doctor --web
|
|
8
|
+
cd apps/web
|
|
9
|
+
pnpm dlx shadcn@4.22.1 add card
|
|
10
|
+
pnpm dlx shadcn@4.22.1 diff card
|
|
10
11
|
```
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
`--dry-run --json` previews configuration/installation without network or writes. Selected destinations, metadata and attribution paths are preflighted before installation. CLI-owned writes refuse symlinked metadata destinations. Bounded consumer manifest/configuration links remain supported where their targets are regular files. Ambiguous or invalid targets stop before installation.
|
|
15
|
-
|
|
16
|
-
The pinned official shadcn CLI resolves registry dependencies and copies source. `add` never requests overwrite; review diffs and reconcile customizations explicitly. `diff` delegates to the upstream preview. Installer failure can leave partial upstream changes, so inspect Git before retrying.
|
|
13
|
+
Inspect the consuming project's instructions and existing source first. Review upstream changes and reconcile customized files; do not request automatic overwrite. Upstream installation can change dependencies and source, so inspect Git and run consumer checks afterward. Validate browser behavior, keyboard focus and interactions as well as types.
|
|
17
14
|
|
|
18
|
-
`
|
|
15
|
+
The shipped starter components remain MIT-licensed shadcn source. Init preserves their notice in `apps/web/LICENSE.shadcn` and provenance in `apps/web/UPSTREAM.json`; customization and rebranding do not remove those notices. This is upstream attribution, not an Anhedral UI license. Preserve applicable licenses for any replacement dependencies too. Existing projects may retain `.anhedral-ui.json` or `ANHEDRAL_UI_LICENSES/`; do not delete authored source or required notices during migration. New initialization does not create those legacy paths.
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
UI selection does not activate backend services or hosting. See [stack additions](capabilities.md). The MVP is web-only. If Expo returns after MVP, React Native Reusables is the intended native default; it is not a current CLI capability.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anhedral",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Generate the Anhedral Stack as editable source: start with web UI, then add backend, storage and payments.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -34,10 +34,7 @@
|
|
|
34
34
|
"assets/stack",
|
|
35
35
|
"docs/capabilities.md",
|
|
36
36
|
"assets/ui/web",
|
|
37
|
-
"assets/ui/catalog.json",
|
|
38
|
-
"assets/ui/extensions",
|
|
39
37
|
"assets/ui/LICENSE.shadcn",
|
|
40
|
-
"assets/ui/LICENSE.react-native-reusables",
|
|
41
38
|
"assets/ui/UPSTREAM.json",
|
|
42
39
|
"assets/contracts",
|
|
43
40
|
"assets/security",
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Founded Labs
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|