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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { ANHEDRAL_STACK_DEPENDENCIES, WEB_DEPENDENCIES } from '../dependencies.js';
|
|
4
|
-
import { CapabilityEditor } from '../capability-editor.js';
|
|
4
|
+
import { CapabilityEditor, fingerprint } from '../capability-editor.js';
|
|
5
5
|
import { resourceName } from '../render.js';
|
|
6
6
|
import { json, put, workerConfig } from '../scaffold/files.js';
|
|
7
7
|
import { initializeUiMetadata } from '../ui-project.js';
|
|
@@ -17,9 +17,10 @@ export function scaffoldTanstack(root, name) {
|
|
|
17
17
|
version: '0.1.0',
|
|
18
18
|
type: 'module',
|
|
19
19
|
scripts: {
|
|
20
|
-
dev: '
|
|
21
|
-
build: '
|
|
22
|
-
preview: '
|
|
20
|
+
dev: 'node ../../scripts/oj.mjs dev . --host=0.0.0.0 --port 3000',
|
|
21
|
+
build: 'node ../../scripts/oj.mjs build .',
|
|
22
|
+
preview: 'wrangler dev --config dist/ssr/wrangler.json --port 3000',
|
|
23
|
+
deploy: 'wrangler deploy --config dist/ssr/wrangler.json',
|
|
23
24
|
typecheck: 'wrangler types && tsr generate && tsc --noEmit',
|
|
24
25
|
lint: 'eslint . --max-warnings 0',
|
|
25
26
|
},
|
|
@@ -120,36 +121,128 @@ export function cn(...values: ClassValue[]) { return twMerge(clsx(values)); }
|
|
|
120
121
|
put(root, `${app}/public/robots.txt`, 'User-agent: *\nAllow: /\n');
|
|
121
122
|
put(root, `${app}/public/_headers`, '/assets/*\n Cache-Control: public, max-age=31536000, immutable\n/*\n X-Content-Type-Options: nosniff\n');
|
|
122
123
|
}
|
|
123
|
-
function
|
|
124
|
-
|
|
124
|
+
function assertTanstack(e) {
|
|
125
|
+
if (!e.json('apps/web/package.json').dependencies?.['@tanstack/react-start'])
|
|
126
|
+
throw Error('Only the Anhedral Stack TanStack Start foundation is supported.');
|
|
125
127
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
const ojScripts = {
|
|
129
|
+
dev: 'node ../../scripts/oj.mjs dev . --host=0.0.0.0 --port 3000',
|
|
130
|
+
build: 'node ../../scripts/oj.mjs build .',
|
|
131
|
+
preview: 'wrangler dev --config dist/ssr/wrangler.json --port 3000',
|
|
132
|
+
deploy: 'wrangler deploy --config dist/ssr/wrangler.json',
|
|
133
|
+
};
|
|
134
|
+
const previousScripts = {
|
|
135
|
+
dev: 'vite dev --host 0.0.0.0 --port 3000',
|
|
136
|
+
build: 'vite build',
|
|
137
|
+
preview: 'vite preview --host 0.0.0.0 --port 3000',
|
|
138
|
+
};
|
|
139
|
+
const ojFiles = {
|
|
140
|
+
'scripts/oj.mjs': 'oj/run.mjs',
|
|
141
|
+
'scripts/oj-runtime.json': 'oj/runtime.json',
|
|
142
|
+
'scripts/OJ.LICENSE': 'oj/OJ.LICENSE',
|
|
143
|
+
};
|
|
144
|
+
function tanstackViteConfiguration(installed) {
|
|
130
145
|
const backend = installed.includes('hono');
|
|
131
|
-
|
|
132
|
-
e.owned('apps/web/src/server.ts', template(backend ? 'server.ts.txt' : 'minimal-server.ts.txt'));
|
|
133
|
-
e.owned('apps/web/src/lib/application.server.ts', template(backend ? 'application.server.ts.txt' : 'minimal-application.server.ts.txt').replaceAll('__AUTHENTICATION__', String(auth)));
|
|
134
|
-
e.owned('apps/web/vite.config.ts', `import { fileURLToPath } from 'node:url';
|
|
146
|
+
return `import { fileURLToPath } from 'node:url';
|
|
135
147
|
import { defineConfig } from 'vite';
|
|
136
148
|
import { cloudflare } from '@cloudflare/vite-plugin';
|
|
137
149
|
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
|
|
138
150
|
import react from '@vitejs/plugin-react';
|
|
139
|
-
export default defineConfig({
|
|
151
|
+
export default defineConfig(${backend ? '({ command }) => (' : ''}{
|
|
140
152
|
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
|
|
141
153
|
plugins: [
|
|
142
|
-
cloudflare({ viteEnvironment: { name: 'ssr' }, ${backend ? "auxiliaryWorkers: [{ configPath: '../api/wrangler.jsonc' }], persistState: { path: fileURLToPath(new URL('../api/.wrangler/state', import.meta.url)) }, " : ''}remoteBindings: false }),
|
|
154
|
+
cloudflare({ viteEnvironment: { name: 'ssr' }, ${backend ? "auxiliaryWorkers: command === 'serve' ? [{ configPath: '../api/wrangler.jsonc' }] : [], persistState: { path: fileURLToPath(new URL('../api/.wrangler/state', import.meta.url)) }, " : ''}remoteBindings: false }),
|
|
143
155
|
tanstackStart({ server: { entry: './server.ts' } }),
|
|
144
156
|
react(),
|
|
145
157
|
],
|
|
146
|
-
});
|
|
147
|
-
|
|
158
|
+
}${backend ? ')' : ''});
|
|
159
|
+
`;
|
|
160
|
+
}
|
|
161
|
+
/** One-time source upgrade, planned in the same bounded overlay as each addition. */
|
|
162
|
+
export function normalizeOjFoundation(e, installed, refreshConfiguration = false) {
|
|
163
|
+
assertTanstack(e);
|
|
164
|
+
const file = 'apps/web/package.json';
|
|
165
|
+
const scripts = e.json(file).scripts;
|
|
166
|
+
if (!scripts || typeof scripts !== 'object' || Array.isArray(scripts))
|
|
167
|
+
throw Error('Preserve invalid web scripts; reconcile the Anhedral Stack launcher first.');
|
|
168
|
+
// Never overwrite a customer launcher while claiming the runtime was upgraded.
|
|
169
|
+
for (const [name, desired] of Object.entries(ojScripts)) {
|
|
170
|
+
const current = scripts[name];
|
|
171
|
+
const previous = Reflect.get(previousScripts, name);
|
|
172
|
+
const previousOjDev = name === 'dev' && current === 'node ../../scripts/oj.mjs dev . --host 0.0.0.0 --port 3000';
|
|
173
|
+
if (current !== undefined && current !== desired && current !== previous && !previousOjDev)
|
|
174
|
+
throw Error(`Preserve customized web launcher scripts.${name}. Reconcile it with the pinned OJ runtime before adding capabilities. No files were changed.`);
|
|
175
|
+
}
|
|
176
|
+
let changed = false;
|
|
177
|
+
const serverEntry = 'apps/web/src/server.ts';
|
|
178
|
+
const currentEntry = e.read(serverEntry);
|
|
179
|
+
// Repair only the exact shipped adapter whose default-entry shim drops Start context in OJ.
|
|
180
|
+
if (installed.includes('hono') &&
|
|
181
|
+
currentEntry !== null &&
|
|
182
|
+
fingerprint(currentEntry) ===
|
|
183
|
+
'703adff2e57adfbbdb7fa90b4dadffde8617c86cc31a185943931ef7c623eca7' &&
|
|
184
|
+
e.managed[serverEntry] === fingerprint(currentEntry)) {
|
|
185
|
+
e.owned(serverEntry, template('server.ts.txt'));
|
|
186
|
+
changed = true;
|
|
187
|
+
}
|
|
188
|
+
const rootRoute = 'apps/web/src/routes/__root.tsx';
|
|
189
|
+
const rootSource = e.read(rootRoute);
|
|
190
|
+
// A one-way repair of the exact shipped document, without owning customer routes.
|
|
191
|
+
if (rootSource !== null &&
|
|
192
|
+
fingerprint(rootSource) === '21af7892e39130c9ec3d7ffb583b3f5d24bee771440ca253d8d7b8ce41be9801') {
|
|
193
|
+
e.writes.set(rootRoute, template('root.tsx.txt'));
|
|
194
|
+
changed = true;
|
|
195
|
+
}
|
|
196
|
+
else if (rootSource !== null && /\bfrom\s*(['"])\.\.\/styles\.css\?url\1/.test(rootSource))
|
|
197
|
+
throw Error('Preserve customized root route CSS. Reconcile its stylesheet URL import with the OJ side-effect CSS pattern before adding capabilities. No files were changed.');
|
|
198
|
+
for (const [name, desired] of Object.entries(ojScripts)) {
|
|
199
|
+
if (scripts[name] !== desired) {
|
|
200
|
+
e.set(file, ['scripts', name], desired);
|
|
201
|
+
changed = true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
for (const [destination, asset] of Object.entries(ojFiles)) {
|
|
205
|
+
const desired = template(asset);
|
|
206
|
+
if (e.read(destination) !== desired) {
|
|
207
|
+
e.owned(destination, desired);
|
|
208
|
+
changed = true;
|
|
209
|
+
}
|
|
210
|
+
else if (e.managed[destination] !== fingerprint(desired)) {
|
|
211
|
+
e.managed[destination] = fingerprint(desired);
|
|
212
|
+
changed = true;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const ignore = e.read('.gitignore') ?? '';
|
|
216
|
+
if (!ignore.split(/\r?\n/).includes('.oj-cache/')) {
|
|
217
|
+
e.writes.set('.gitignore', ignore + (ignore && !ignore.endsWith('\n') ? '\n' : '') + '.oj-cache/\n');
|
|
218
|
+
changed = true;
|
|
219
|
+
}
|
|
220
|
+
const configuration = 'apps/web/vite.config.ts';
|
|
221
|
+
const currentConfiguration = e.read(configuration);
|
|
222
|
+
const desiredConfiguration = tanstackViteConfiguration(installed);
|
|
223
|
+
if (currentConfiguration !== desiredConfiguration &&
|
|
224
|
+
(changed ||
|
|
225
|
+
refreshConfiguration ||
|
|
226
|
+
(currentConfiguration !== null &&
|
|
227
|
+
e.managed[configuration] === fingerprint(currentConfiguration)))) {
|
|
228
|
+
e.owned(configuration, desiredConfiguration);
|
|
229
|
+
changed = true;
|
|
230
|
+
}
|
|
231
|
+
return changed;
|
|
232
|
+
}
|
|
233
|
+
/** Fingerprinted composition adapters; application routes stay source-owned. */
|
|
234
|
+
export function composeTanstack(e, installed) {
|
|
235
|
+
assertTanstack(e);
|
|
236
|
+
normalizeOjFoundation(e, installed);
|
|
237
|
+
const backend = installed.includes('hono');
|
|
238
|
+
const auth = installed.includes('database-auth');
|
|
239
|
+
e.owned('apps/web/src/server.ts', template(backend ? 'server.ts.txt' : 'minimal-server.ts.txt'));
|
|
240
|
+
e.owned('apps/web/src/lib/application.server.ts', template(backend ? 'application.server.ts.txt' : 'minimal-application.server.ts.txt').replaceAll('__AUTHENTICATION__', String(auth)));
|
|
241
|
+
e.owned('apps/web/vite.config.ts', tanstackViteConfiguration(installed));
|
|
148
242
|
}
|
|
149
243
|
/** Install account source only when the backend authentication capability is added. */
|
|
150
244
|
export function addTanstackAuth(e) {
|
|
151
|
-
|
|
152
|
-
return;
|
|
245
|
+
assertTanstack(e);
|
|
153
246
|
e.create('apps/web/src/lib/auth-client.ts', template('auth-client.ts.txt'));
|
|
154
247
|
e.create('apps/web/src/routes/sign-in.tsx', template('sign-in.tsx.txt'));
|
|
155
248
|
}
|
package/dist/registry/usage.js
CHANGED
|
@@ -35,17 +35,19 @@ Start a project:
|
|
|
35
35
|
add Add backend, private storage or payments.
|
|
36
36
|
|
|
37
37
|
Inspect source and UI:
|
|
38
|
-
stack Inspect the Anhedral Stack
|
|
38
|
+
stack Inspect, update or diagnose the Anhedral Stack.
|
|
39
39
|
ui Initialize, add, list, diff or check UI components.
|
|
40
40
|
|
|
41
41
|
Optional Platform access:
|
|
42
42
|
login/logout Approve or revoke a CLI session.
|
|
43
43
|
whoami Inspect the current identity and optional local context.
|
|
44
|
+
projects List or create Platform projects.
|
|
44
45
|
link/unlink Select an existing project or remove its local link.
|
|
45
46
|
source Upload source or inspect its receipt.
|
|
46
47
|
deploy Plan, prepare or inspect a candidate; never activates it.
|
|
47
48
|
env Import private configuration or list variable metadata.
|
|
48
49
|
staging Deploy verified candidates to persistent staging.
|
|
50
|
+
production Publish ready candidates with current project permissions.
|
|
49
51
|
logs Read redacted runtime logs for a linked project.
|
|
50
52
|
|
|
51
53
|
Shell setup:
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type CliArtifact } from './contracts/deployment.js';
|
|
2
|
+
declare const publishedArtifact: unique symbol;
|
|
3
|
+
export type PublishedCliArtifact = Readonly<CliArtifact> & {
|
|
4
|
+
readonly [publishedArtifact]: true;
|
|
5
|
+
};
|
|
6
|
+
export type ReleaseArtifactOptions = {
|
|
7
|
+
fetch?: typeof globalThis.fetch;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare class ArtifactUnavailableError extends Error {
|
|
12
|
+
readonly code = "ARTIFACT_UNAVAILABLE";
|
|
13
|
+
constructor();
|
|
14
|
+
}
|
|
15
|
+
export declare function isPublishedCliArtifact(value: unknown): value is PublishedCliArtifact;
|
|
16
|
+
/** Only fixed official public release endpoints may supply provenance. No project context is read. */
|
|
17
|
+
export declare function resolvePublishedCliArtifact(options?: ReleaseArtifactOptions): Promise<PublishedCliArtifact>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { cliArtifactSchema } from './contracts/deployment.js';
|
|
2
|
+
import { GENERATOR_VERSION } from './version.js';
|
|
3
|
+
const MAX_JSON_BYTES = 256 * 1024;
|
|
4
|
+
const MAX_TIMEOUT_MS = 15000;
|
|
5
|
+
const sourceRevision = /^[a-f0-9]{40}$/;
|
|
6
|
+
const releaseVersion = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
7
|
+
const verified = new WeakSet();
|
|
8
|
+
export class ArtifactUnavailableError extends Error {
|
|
9
|
+
code = 'ARTIFACT_UNAVAILABLE';
|
|
10
|
+
constructor() {
|
|
11
|
+
super('The running CLI release artifact could not be verified from official GitHub and npm metadata. Retry after publication or use --offline for a source-only update; deployment will remain unavailable.');
|
|
12
|
+
this.name = 'ArtifactUnavailableError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function isPublishedCliArtifact(value) {
|
|
16
|
+
return typeof value === 'object' && value !== null && verified.has(value);
|
|
17
|
+
}
|
|
18
|
+
function object(value) {
|
|
19
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
20
|
+
throw new ArtifactUnavailableError();
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function abortable(signal, operation) {
|
|
24
|
+
signal.throwIfAborted();
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const abort = () => reject(new ArtifactUnavailableError());
|
|
27
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
28
|
+
Promise.resolve()
|
|
29
|
+
.then(operation)
|
|
30
|
+
.then((value) => {
|
|
31
|
+
signal.removeEventListener('abort', abort);
|
|
32
|
+
resolve(value);
|
|
33
|
+
}, (error) => {
|
|
34
|
+
signal.removeEventListener('abort', abort);
|
|
35
|
+
reject(error);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async function readJson(response, signal) {
|
|
40
|
+
if (!response.ok || !response.body) {
|
|
41
|
+
void response.body?.cancel().catch(() => undefined);
|
|
42
|
+
throw new ArtifactUnavailableError();
|
|
43
|
+
}
|
|
44
|
+
const length = response.headers.get('content-length');
|
|
45
|
+
if (length !== null && Number(length) > MAX_JSON_BYTES) {
|
|
46
|
+
void response.body.cancel().catch(() => undefined);
|
|
47
|
+
throw new ArtifactUnavailableError();
|
|
48
|
+
}
|
|
49
|
+
const reader = response.body.getReader();
|
|
50
|
+
const chunks = [];
|
|
51
|
+
let size = 0;
|
|
52
|
+
try {
|
|
53
|
+
for (;;) {
|
|
54
|
+
signal.throwIfAborted();
|
|
55
|
+
const result = await abortable(signal, () => reader.read());
|
|
56
|
+
if (result.done)
|
|
57
|
+
break;
|
|
58
|
+
size += result.value.byteLength;
|
|
59
|
+
if (size > MAX_JSON_BYTES)
|
|
60
|
+
throw new ArtifactUnavailableError();
|
|
61
|
+
chunks.push(result.value);
|
|
62
|
+
}
|
|
63
|
+
const bytes = new Uint8Array(size);
|
|
64
|
+
let offset = 0;
|
|
65
|
+
for (const chunk of chunks) {
|
|
66
|
+
bytes.set(chunk, offset);
|
|
67
|
+
offset += chunk.byteLength;
|
|
68
|
+
}
|
|
69
|
+
return object(JSON.parse(new TextDecoder('utf8', { fatal: true }).decode(bytes)));
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
void reader.cancel().catch(() => undefined);
|
|
73
|
+
reader.releaseLock();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Only fixed official public release endpoints may supply provenance. No project context is read. */
|
|
77
|
+
export async function resolvePublishedCliArtifact(options = {}) {
|
|
78
|
+
const timeout = options.timeoutMs ?? MAX_TIMEOUT_MS;
|
|
79
|
+
if (!Number.isInteger(timeout) ||
|
|
80
|
+
timeout < 1 ||
|
|
81
|
+
timeout > MAX_TIMEOUT_MS ||
|
|
82
|
+
!releaseVersion.test(GENERATOR_VERSION))
|
|
83
|
+
throw new ArtifactUnavailableError();
|
|
84
|
+
const controller = new AbortController();
|
|
85
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
86
|
+
const signal = AbortSignal.any([controller.signal, ...(options.signal ? [options.signal] : [])]);
|
|
87
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
88
|
+
async function request(url, redirects = false) {
|
|
89
|
+
for (let count = 0;; count++) {
|
|
90
|
+
signal.throwIfAborted();
|
|
91
|
+
const response = await abortable(signal, () => fetcher(url.href, {
|
|
92
|
+
method: 'GET',
|
|
93
|
+
redirect: 'manual',
|
|
94
|
+
credentials: 'omit',
|
|
95
|
+
cache: 'no-store',
|
|
96
|
+
referrerPolicy: 'no-referrer',
|
|
97
|
+
signal,
|
|
98
|
+
headers: { accept: 'application/json', 'user-agent': 'anhedral-cli' },
|
|
99
|
+
}));
|
|
100
|
+
if (response.redirected || (response.url && new URL(response.url).href !== url.href))
|
|
101
|
+
throw new ArtifactUnavailableError();
|
|
102
|
+
if (response.status >= 300 && response.status < 400) {
|
|
103
|
+
const location = response.headers.get('location');
|
|
104
|
+
void response.body?.cancel().catch(() => undefined);
|
|
105
|
+
if (!redirects || count >= 2 || !location)
|
|
106
|
+
throw new ArtifactUnavailableError();
|
|
107
|
+
const next = new URL(location, url);
|
|
108
|
+
if (next.protocol !== 'https:' ||
|
|
109
|
+
next.hostname !== 'release-assets.githubusercontent.com' ||
|
|
110
|
+
next.port ||
|
|
111
|
+
next.username ||
|
|
112
|
+
next.password ||
|
|
113
|
+
next.hash)
|
|
114
|
+
throw new ArtifactUnavailableError();
|
|
115
|
+
url = next;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
return readJson(response, signal);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const version = GENERATOR_VERSION;
|
|
123
|
+
const metadata = await request(new URL(`https://github.com/anhedral/anhedral-cli/releases/download/v${version}/metadata.json`), true);
|
|
124
|
+
if (metadata.schemaVersion !== 1 ||
|
|
125
|
+
metadata.name !== 'anhedral' ||
|
|
126
|
+
metadata.version !== version ||
|
|
127
|
+
metadata.filename !== `anhedral-${version}.tgz` ||
|
|
128
|
+
typeof metadata.sourceRevision !== 'string' ||
|
|
129
|
+
!sourceRevision.test(metadata.sourceRevision))
|
|
130
|
+
throw new ArtifactUnavailableError();
|
|
131
|
+
const artifact = cliArtifactSchema.parse({
|
|
132
|
+
version,
|
|
133
|
+
sourceRevision: metadata.sourceRevision,
|
|
134
|
+
packageIntegrity: metadata.integrity,
|
|
135
|
+
});
|
|
136
|
+
const registry = await request(new URL(`https://registry.npmjs.org/anhedral/${version}`));
|
|
137
|
+
const dist = object(registry.dist);
|
|
138
|
+
if (registry.name !== 'anhedral' ||
|
|
139
|
+
registry.version !== version ||
|
|
140
|
+
dist.integrity !== artifact.packageIntegrity ||
|
|
141
|
+
dist.tarball !== `https://registry.npmjs.org/anhedral/-/anhedral-${version}.tgz`)
|
|
142
|
+
throw new ArtifactUnavailableError();
|
|
143
|
+
if (registry.gitHead !== undefined && registry.gitHead !== artifact.sourceRevision)
|
|
144
|
+
throw new ArtifactUnavailableError();
|
|
145
|
+
const ref = await request(new URL(`https://api.github.com/repos/anhedral/anhedral-cli/git/ref/tags/v${version}`));
|
|
146
|
+
if (ref.ref !== `refs/tags/v${version}`)
|
|
147
|
+
throw new ArtifactUnavailableError();
|
|
148
|
+
let target = object(ref.object);
|
|
149
|
+
if (target.type === 'tag') {
|
|
150
|
+
if (typeof target.sha !== 'string' || !sourceRevision.test(target.sha))
|
|
151
|
+
throw new ArtifactUnavailableError();
|
|
152
|
+
const tag = await request(new URL(`https://api.github.com/repos/anhedral/anhedral-cli/git/tags/${target.sha}`));
|
|
153
|
+
if (tag.tag !== `v${version}`)
|
|
154
|
+
throw new ArtifactUnavailableError();
|
|
155
|
+
target = object(tag.object);
|
|
156
|
+
}
|
|
157
|
+
if (target.type !== 'commit' || target.sha !== artifact.sourceRevision)
|
|
158
|
+
throw new ArtifactUnavailableError();
|
|
159
|
+
const result = Object.freeze(artifact);
|
|
160
|
+
verified.add(result);
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
throw new ArtifactUnavailableError();
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
clearTimeout(timer);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function assertWorkspaceRuntime(run:
|
|
1
|
+
import type { CommandRunner } from '../command-types.js';
|
|
2
|
+
export declare function assertWorkspaceRuntime(run: CommandRunner, version?: string): void;
|
|
3
3
|
/** No downloaded template, disposable Next app or initialization-time cloud operation. */
|
|
4
|
-
export declare function bootstrapWorkspace(root: string, name: string, run:
|
|
4
|
+
export declare function bootstrapWorkspace(root: string, name: string, run: CommandRunner): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { RecipeContext } from '../registry/types.js';
|
|
2
1
|
/** One shared token source for native components and DOM CSS. */
|
|
3
|
-
export declare function scaffoldStyling({ root }:
|
|
2
|
+
export declare function scaffoldStyling({ root }: {
|
|
3
|
+
root: string;
|
|
4
|
+
}): void;
|
|
@@ -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>;
|