anhedral 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -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 +2 -2
- package/dist/capability-command.js +32 -96
- package/dist/capability-recipes.js +8 -343
- package/dist/cli-commands.js +3 -1
- package/dist/command-schema.js +106 -0
- 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/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 +2 -0
- package/dist/platform-state.js +23 -1
- package/dist/platforms/tanstack.d.ts +2 -0
- package/dist/platforms/tanstack.js +113 -20
- package/dist/registry/usage.js +1 -0
- package/dist/scaffold/bootstrap.d.ts +3 -3
- package/dist/scaffold/styling.d.ts +3 -2
- 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 +55 -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
package/dist/platform-command.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runProductionCommand, validateProductionArguments } from './platform-production.js';
|
|
1
2
|
import { runEnvironmentCommand, validateEnvironmentArguments } from './platform-environment.js';
|
|
2
3
|
import { runStagingCommand, runLogsCommand, validateStagingArguments, validateLogsArguments, } from './platform-operations.js';
|
|
3
4
|
import { constants } from 'node:fs';
|
|
@@ -9,16 +10,25 @@ import { CliArgumentError, commandArguments, commandArgumentError } from './cli-
|
|
|
9
10
|
import { CliFailure } from './cli-errors.js';
|
|
10
11
|
import { stripVTControlCharacters } from 'node:util';
|
|
11
12
|
import { createReporter } from './cli-output.js';
|
|
12
|
-
import { canonicalCliJson, cliPlanInputSchema, cliPlanSchema, cliPreparationSchema, cliDeviceSchema, cliLinkSchema, cliLoginSchema, SOURCE_LIMITS, sourceUploadInputSchema, sourceUploadReceiptSchema, } from './contracts/cli-transport.js';
|
|
13
|
+
import { canonicalCliJson, cliProjectListQuerySchema, cliProjectCreateInputSchema, cliProjectListSchema, cliProjectCreateReceiptSchema, cliPlanInputSchema, cliPlanSchema, cliPreparationSchema, cliDeviceSchema, cliLinkSchema, cliLoginSchema, SOURCE_LIMITS, sourceUploadInputSchema, sourceUploadReceiptSchema, } from './contracts/cli-transport.js';
|
|
13
14
|
import { readSourceBounded } from './contracts/source-bundle.js';
|
|
14
15
|
import { deploymentManifestSchema } from './contracts/deployment.js';
|
|
15
16
|
import { packageSource } from './platform-source.js';
|
|
16
|
-
import { platformFailure as createPlatformFailure, platformOrigin, readPrivate, secretStore, writePrivate, } from './platform-state.js';
|
|
17
|
+
import { platformFailure as createPlatformFailure, platformOrigin, readPrivate, secretStore, writePrivate, withProjectLock, } from './platform-state.js';
|
|
17
18
|
const credential = cliLoginSchema.extend({ origin: z.string() });
|
|
18
19
|
const pending = z
|
|
19
20
|
.object({ origin: z.string(), device: cliDeviceSchema, expiresAt: z.number() })
|
|
20
21
|
.strict();
|
|
21
22
|
const linkSchema = cliLinkSchema.extend({ origin: z.string() }).strict();
|
|
23
|
+
const projectCreateState = z
|
|
24
|
+
.object({
|
|
25
|
+
origin: z.string(),
|
|
26
|
+
principalId: z.uuid(),
|
|
27
|
+
teamId: z.uuid(),
|
|
28
|
+
input: cliProjectCreateInputSchema,
|
|
29
|
+
receipt: cliProjectCreateReceiptSchema.optional(),
|
|
30
|
+
})
|
|
31
|
+
.strict();
|
|
22
32
|
const uploadState = z
|
|
23
33
|
.object({
|
|
24
34
|
origin: z.string(),
|
|
@@ -57,6 +67,32 @@ function formatPlatformResult(command, result) {
|
|
|
57
67
|
: []),
|
|
58
68
|
].join('\n');
|
|
59
69
|
}
|
|
70
|
+
if (command === 'projects') {
|
|
71
|
+
if (data.status === 'dry_run')
|
|
72
|
+
return `Project creation preview: ${visible(data.name)}.\nNo project, source or deployment was created.`;
|
|
73
|
+
if (Array.isArray(data.projects)) {
|
|
74
|
+
const projects = data.projects;
|
|
75
|
+
const teams = data.availableTeams;
|
|
76
|
+
return [
|
|
77
|
+
data.team
|
|
78
|
+
? `Team: ${visible(data.team.name)} (${visible(data.team.id)}).`
|
|
79
|
+
: 'No team is selected.',
|
|
80
|
+
...projects.map((project) => `${visible(project.name)} (${visible(project.projectId)})${project.canLink ? '' : ' [cannot link]'}`),
|
|
81
|
+
...(projects.length ? [] : ['No projects found.']),
|
|
82
|
+
'Available teams:',
|
|
83
|
+
...teams.map((team) => `${visible(team.name)} (${visible(team.id)})`),
|
|
84
|
+
...(data.teamsTruncated
|
|
85
|
+
? ['Team list is truncated. Use a known team ID with --team.']
|
|
86
|
+
: []),
|
|
87
|
+
...(data.nextCursor
|
|
88
|
+
? [
|
|
89
|
+
`Next: anhedral projects list --cursor ${visible(data.nextCursor)}${data.team ? ` --team ${visible(data.team.id)}` : ''} (with the same API origin and credential store).`,
|
|
90
|
+
]
|
|
91
|
+
: []),
|
|
92
|
+
].join('\n');
|
|
93
|
+
}
|
|
94
|
+
return `Created project ${visible(data.name)} (${visible(data.projectId)}).\nTeam: ${visible(data.teamId)}.${data.linked ? '\nSaved verified local project link.' : ''}\n${data.linked ? 'Next: anhedral source upload --dry-run' : `Next: anhedral link --project ${visible(data.projectId)} --team ${visible(data.teamId)}`} (with the same API origin and credential store).\nNo source was generated or deployment started.`;
|
|
95
|
+
}
|
|
60
96
|
if (command === 'link')
|
|
61
97
|
return `Linked to ${visible(data.name)} (${visible(data.projectId)}).\nTeam: ${visible(data.teamId)}.`;
|
|
62
98
|
if (data.status === 'dry_run')
|
|
@@ -69,7 +105,14 @@ function formatPlatformResult(command, result) {
|
|
|
69
105
|
? `Candidate ${visible(data.state)} (${visible(data.candidateId)}).`
|
|
70
106
|
: `Deployment plan prepared (${visible(data.id)}).`,
|
|
71
107
|
`Source revision: ${visible(data.sourceRevision)}.`,
|
|
72
|
-
|
|
108
|
+
...(data.admission?.diagnostics ?? []).flatMap((item) => [
|
|
109
|
+
`[${visible(item.code)}] ${visible(item.message)}`,
|
|
110
|
+
`Next: ${visible(item.action)}`,
|
|
111
|
+
]),
|
|
112
|
+
...(data.admission && data.blockers?.length === 0
|
|
113
|
+
? ['Source is eligible for candidate preparation. Run anhedral deploy prepare.']
|
|
114
|
+
: []),
|
|
115
|
+
'No preview or deployment was activated.',
|
|
73
116
|
].join('\n');
|
|
74
117
|
return 'Platform command completed.';
|
|
75
118
|
}
|
|
@@ -97,6 +140,8 @@ async function runPlatformOperation(command, args, output, dependencies) {
|
|
|
97
140
|
validateEnvironmentArguments(args);
|
|
98
141
|
if (command === 'staging')
|
|
99
142
|
validateStagingArguments(args);
|
|
143
|
+
if (command === 'production')
|
|
144
|
+
validateProductionArguments(args);
|
|
100
145
|
if (command === 'logs')
|
|
101
146
|
validateLogsArguments(args);
|
|
102
147
|
const emit = (result) => reporter.result(result);
|
|
@@ -120,12 +165,57 @@ async function runPlatformOperation(command, args, output, dependencies) {
|
|
|
120
165
|
(!z.uuid().safeParse(options.value('--project')).success ||
|
|
121
166
|
!z.uuid().safeParse(options.value('--team')).success))
|
|
122
167
|
throw commandArgumentError(command, 'Supply existing project and team UUIDs with --project and --team.');
|
|
168
|
+
let projectInput;
|
|
169
|
+
if (command === 'projects') {
|
|
170
|
+
const operation = options.positional[0];
|
|
171
|
+
if (options.has('--team') && !z.uuid().safeParse(options.value('--team')).success)
|
|
172
|
+
throw commandArgumentError(command, 'Supply a team UUID with --team.');
|
|
173
|
+
if (operation === 'list') {
|
|
174
|
+
if (['--name', '--summary', '--link', '--dry-run', '--new'].some((flag) => options.has(flag)))
|
|
175
|
+
throw commandArgumentError(command, 'Creation options apply to projects create only.');
|
|
176
|
+
const query = cliProjectListQuerySchema.safeParse({
|
|
177
|
+
...(options.has('--limit') ? { limit: options.value('--limit') } : {}),
|
|
178
|
+
...(options.has('--cursor') ? { cursor: options.value('--cursor') } : {}),
|
|
179
|
+
});
|
|
180
|
+
if (!query.success || (options.has('--limit') && !/^[0-9]+$/.test(options.value('--limit'))))
|
|
181
|
+
throw commandArgumentError(command, 'Use --limit 1–100 and an optional cursor UUID.');
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
if (options.has('--limit') || options.has('--cursor'))
|
|
185
|
+
throw commandArgumentError(command, 'Pagination options apply to projects list only.');
|
|
186
|
+
const parsed = cliProjectCreateInputSchema.safeParse({
|
|
187
|
+
protocol: 1,
|
|
188
|
+
requestId: randomUUID(),
|
|
189
|
+
name: options.value('--name'),
|
|
190
|
+
summary: options.value('--summary') ?? '',
|
|
191
|
+
});
|
|
192
|
+
if (!parsed.success)
|
|
193
|
+
throw commandArgumentError(command, 'Supply --name with 1–160 characters and an optional summary up to 2000 characters.');
|
|
194
|
+
projectInput = { name: parsed.data.name, summary: parsed.data.summary };
|
|
195
|
+
if (options.has('--dry-run')) {
|
|
196
|
+
emit({
|
|
197
|
+
status: 'dry_run',
|
|
198
|
+
...projectInput,
|
|
199
|
+
teamId: options.value('--team') ?? null,
|
|
200
|
+
link: options.has('--link'),
|
|
201
|
+
initialization: 'source-upload',
|
|
202
|
+
});
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
123
207
|
const root = process.cwd(), stateDir = join(root, '.anhedral', 'platform'), linkPath = join(stateDir, 'project.json'), uploadPath = join(stateDir, 'upload.json');
|
|
124
208
|
if (command === 'unlink') {
|
|
125
|
-
await readPrivate(linkPath)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
209
|
+
if ((await readPrivate(linkPath)) === null) {
|
|
210
|
+
emit({ status: 'unlinked' });
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
await withProjectLock(stateDir, async () => {
|
|
214
|
+
await readPrivate(linkPath);
|
|
215
|
+
await unlink(linkPath).catch((e) => {
|
|
216
|
+
if (e.code !== 'ENOENT')
|
|
217
|
+
throw e;
|
|
218
|
+
});
|
|
129
219
|
});
|
|
130
220
|
emit({ status: 'unlinked' });
|
|
131
221
|
return;
|
|
@@ -182,11 +272,17 @@ async function runPlatformOperation(command, args, output, dependencies) {
|
|
|
182
272
|
});
|
|
183
273
|
}
|
|
184
274
|
catch {
|
|
185
|
-
throw platformFailure(
|
|
275
|
+
throw platformFailure(command === 'projects' && options.positional[0] === 'create'
|
|
276
|
+
? 'Platform request was interrupted. Retry the saved project request without --new to resume.'
|
|
277
|
+
: 'Platform request was interrupted. Retry the same command to resume.', 'network', true, command === 'projects' && options.positional[0] === 'create'
|
|
278
|
+
? 'Retry anhedral projects create with the same name, summary, team, API origin, credential store and working directory, omitting --new to reuse the saved request.'
|
|
279
|
+
: `Retry anhedral ${command} with the same API origin, working directory and options to resume.`);
|
|
186
280
|
}
|
|
187
|
-
const data = await readSourceBounded(response.body, /\/projects\/[^/]+\/(environment|staging|runtime-logs)(\?|$)/.test(path)
|
|
281
|
+
const data = await readSourceBounded(response.body, /\/projects\/[^/]+\/(environment|staging|production|runtime-logs)(\?|$)/.test(path)
|
|
188
282
|
? 1024 * 1024
|
|
189
|
-
:
|
|
283
|
+
: command === 'projects'
|
|
284
|
+
? 1024 * 1024
|
|
285
|
+
: 65536)
|
|
190
286
|
.then((b) => JSON.parse(new TextDecoder().decode(b)))
|
|
191
287
|
.catch(() => {
|
|
192
288
|
throw platformFailure('Platform returned an invalid response.', 'network');
|
|
@@ -207,23 +303,37 @@ async function runPlatformOperation(command, args, output, dependencies) {
|
|
|
207
303
|
if (error.success)
|
|
208
304
|
return error.data;
|
|
209
305
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
306
|
+
const serverMessage = z.object({ error: z.string().max(2000) }).safeParse(data);
|
|
307
|
+
const admissionProblem = serverMessage.success &&
|
|
308
|
+
/^\[(?:RUNTIME_UNAVAILABLE|ARTIFACT_MISMATCH|SOURCE_VERSION_MISMATCH|DEPENDENCY_LOCK_MISMATCH|INDEPENDENT_APPROVAL_REQUIRED|PRODUCTION_PERMISSION_REQUIRED)\] [^\r\n]{1,1500}$/.test(serverMessage.data.error)
|
|
309
|
+
? visible(serverMessage.data.error)
|
|
310
|
+
: null;
|
|
311
|
+
throw platformFailure(admissionProblem ??
|
|
312
|
+
(response.status === 401
|
|
313
|
+
? 'CLI login expired or was revoked. Run anhedral login.'
|
|
314
|
+
: response.status === 409
|
|
315
|
+
? command === 'deploy'
|
|
316
|
+
? 'Deployment plan is stale or inputs conflict. Review deploy plan --new.'
|
|
317
|
+
: command === 'projects'
|
|
318
|
+
? 'Project creation conflicts with the saved request. Preserve retry state; use projects create --new only to create another project.'
|
|
319
|
+
: command === 'staging'
|
|
320
|
+
? 'Candidate, configuration or staging generation changed. Review staging status before starting a new deployment.'
|
|
321
|
+
: command === 'production'
|
|
322
|
+
? 'Candidate, production configuration, permissions or generation changed. Review production status before retrying.'
|
|
323
|
+
: command === 'env'
|
|
324
|
+
? 'Environment versions or import contents conflict. Review env list and preserve saved retry state before starting a new import.'
|
|
325
|
+
: 'Upload conflicts with saved source. Restore the original files or use source upload --new.'
|
|
326
|
+
: response.status === 403
|
|
327
|
+
? command === 'projects'
|
|
328
|
+
? 'Current team project access or project creation permission is unavailable.'
|
|
329
|
+
: command === 'env'
|
|
330
|
+
? 'Current project environment access or administrator permission is unavailable.'
|
|
331
|
+
: command === 'logs'
|
|
332
|
+
? 'Current project log access is unavailable.'
|
|
333
|
+
: command === 'production'
|
|
334
|
+
? 'Current production permission or team approval policy does not allow this deployment. Review production status and the team policy.'
|
|
335
|
+
: 'Current project build access is unavailable.'
|
|
336
|
+
: `Platform request failed (${response.status}).`), response.status === 401
|
|
227
337
|
? 'auth'
|
|
228
338
|
: response.status === 403
|
|
229
339
|
? 'permission'
|
|
@@ -231,7 +341,9 @@ async function runPlatformOperation(command, args, output, dependencies) {
|
|
|
231
341
|
? 'conflict'
|
|
232
342
|
: 'network', response.status === 429 || response.status >= 500, response.status === 401
|
|
233
343
|
? 'Run anhedral login with the same API origin and credential store.'
|
|
234
|
-
:
|
|
344
|
+
: response.status === 403 && command === 'production'
|
|
345
|
+
? 'Run anhedral production status and review current production permissions and the team approval policy in Platform.'
|
|
346
|
+
: `Run anhedral ${command} --help.`);
|
|
235
347
|
}
|
|
236
348
|
return data;
|
|
237
349
|
};
|
|
@@ -356,22 +468,105 @@ async function runPlatformOperation(command, args, output, dependencies) {
|
|
|
356
468
|
});
|
|
357
469
|
return;
|
|
358
470
|
}
|
|
471
|
+
if (command === 'projects') {
|
|
472
|
+
const selectedTeam = options.value('--team') ?? actor.teamId;
|
|
473
|
+
if (options.positional[0] === 'list') {
|
|
474
|
+
const query = cliProjectListQuerySchema.parse({
|
|
475
|
+
...(options.has('--limit') ? { limit: options.value('--limit') } : {}),
|
|
476
|
+
...(options.has('--cursor') ? { cursor: options.value('--cursor') } : {}),
|
|
477
|
+
});
|
|
478
|
+
const params = new URLSearchParams({ limit: String(query.limit) });
|
|
479
|
+
if (query.cursor)
|
|
480
|
+
params.set('cursor', query.cursor);
|
|
481
|
+
const result = cliProjectListSchema.parse(await request(`/projects?${params}`, 'GET', undefined, token, selectedTeam ?? undefined));
|
|
482
|
+
if (result.principalId !== actor.principalId ||
|
|
483
|
+
(selectedTeam && result.team?.id !== selectedTeam) ||
|
|
484
|
+
result.projects.some((project) => project.teamId !== result.team?.id))
|
|
485
|
+
throw platformFailure('Project list identity differs.');
|
|
486
|
+
emit(result);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (!selectedTeam)
|
|
490
|
+
throw platformFailure('No team is selected. Run anhedral projects list to discover available teams, then use --team <uuid>.');
|
|
491
|
+
await withProjectLock(stateDir, async () => {
|
|
492
|
+
const journalPath = join(stateDir, 'project-create.json');
|
|
493
|
+
const previous = await readPrivate(journalPath);
|
|
494
|
+
let state = previous === null ? null : projectCreateState.parse(previous);
|
|
495
|
+
if (state &&
|
|
496
|
+
!options.has('--new') &&
|
|
497
|
+
(state.origin !== origin ||
|
|
498
|
+
state.principalId !== actor.principalId ||
|
|
499
|
+
state.teamId !== selectedTeam ||
|
|
500
|
+
state.input.name !== projectInput.name ||
|
|
501
|
+
state.input.summary !== projectInput.summary))
|
|
502
|
+
throw platformFailure('Saved project creation belongs to different input or context. Restore the original options to retry, or explicitly use --new to create another project.');
|
|
503
|
+
if (!state || options.has('--new'))
|
|
504
|
+
state = {
|
|
505
|
+
origin,
|
|
506
|
+
principalId: actor.principalId,
|
|
507
|
+
teamId: selectedTeam,
|
|
508
|
+
input: cliProjectCreateInputSchema.parse({
|
|
509
|
+
protocol: 1,
|
|
510
|
+
requestId: randomUUID(),
|
|
511
|
+
...projectInput,
|
|
512
|
+
}),
|
|
513
|
+
};
|
|
514
|
+
const checkLink = async () => {
|
|
515
|
+
const value = await readPrivate(linkPath);
|
|
516
|
+
if (value === null)
|
|
517
|
+
return;
|
|
518
|
+
const existing = linkSchema.parse(value);
|
|
519
|
+
if (existing.origin !== origin ||
|
|
520
|
+
existing.principalId !== actor.principalId ||
|
|
521
|
+
existing.teamId !== selectedTeam ||
|
|
522
|
+
existing.projectId !== state.input.requestId)
|
|
523
|
+
throw platformFailure('A different local project link exists. Use another working directory or explicitly unlink before creating with --link.');
|
|
524
|
+
};
|
|
525
|
+
if (options.has('--link'))
|
|
526
|
+
await checkLink();
|
|
527
|
+
await writePrivate(journalPath, state);
|
|
528
|
+
const receipt = cliProjectCreateReceiptSchema.parse(await request('/projects', 'POST', state.input, token, selectedTeam));
|
|
529
|
+
if (receipt.requestId !== state.input.requestId ||
|
|
530
|
+
receipt.projectId !== state.input.requestId ||
|
|
531
|
+
receipt.principalId !== actor.principalId ||
|
|
532
|
+
receipt.teamId !== selectedTeam ||
|
|
533
|
+
receipt.name !== state.input.name ||
|
|
534
|
+
receipt.summary !== state.input.summary)
|
|
535
|
+
throw platformFailure('Project creation receipt identity or input differs. Preserve saved retry state.');
|
|
536
|
+
state = { ...state, receipt };
|
|
537
|
+
await writePrivate(journalPath, state);
|
|
538
|
+
if (options.has('--link')) {
|
|
539
|
+
await checkLink();
|
|
540
|
+
const link = cliLinkSchema.parse(await request('/link', 'POST', { projectId: receipt.projectId, teamId: selectedTeam }, token, selectedTeam));
|
|
541
|
+
if (link.principalId !== actor.principalId ||
|
|
542
|
+
link.projectId !== receipt.projectId ||
|
|
543
|
+
link.teamId !== selectedTeam)
|
|
544
|
+
throw platformFailure('Project link identity differs.');
|
|
545
|
+
await checkLink();
|
|
546
|
+
await writePrivate(linkPath, { ...link, origin });
|
|
547
|
+
}
|
|
548
|
+
emit({ ...receipt, linked: options.has('--link') });
|
|
549
|
+
});
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
359
552
|
if (command === 'link') {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
link.
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
553
|
+
await withProjectLock(stateDir, async () => {
|
|
554
|
+
const input = z
|
|
555
|
+
.object({ projectId: z.uuid(), teamId: z.uuid() })
|
|
556
|
+
.parse({ projectId: options.value('--project'), teamId: options.value('--team') });
|
|
557
|
+
if (options.positional.length)
|
|
558
|
+
throw commandArgumentError(command, 'Use --project and --team.');
|
|
559
|
+
const link = cliLinkSchema.parse(await request('/link', 'POST', input, token, input.teamId));
|
|
560
|
+
if (link.principalId !== actor.principalId ||
|
|
561
|
+
link.projectId !== input.projectId ||
|
|
562
|
+
link.teamId !== input.teamId)
|
|
563
|
+
throw platformFailure('Project link identity differs.');
|
|
564
|
+
await writePrivate(linkPath, { ...link, origin });
|
|
565
|
+
emit({ ...link, origin });
|
|
566
|
+
});
|
|
372
567
|
return;
|
|
373
568
|
}
|
|
374
|
-
if (['env', 'staging', 'logs'].includes(command)) {
|
|
569
|
+
if (['env', 'staging', 'production', 'logs'].includes(command)) {
|
|
375
570
|
const link = linkSchema.parse(await readPrivate(linkPath));
|
|
376
571
|
if (link.origin !== origin || link.principalId !== actor.principalId)
|
|
377
572
|
throw platformFailure('Link this project to the selected API origin and signed-in identity.');
|
|
@@ -379,7 +574,9 @@ async function runPlatformOperation(command, args, output, dependencies) {
|
|
|
379
574
|
? runEnvironmentCommand
|
|
380
575
|
: command === 'staging'
|
|
381
576
|
? runStagingCommand
|
|
382
|
-
:
|
|
577
|
+
: command === 'production'
|
|
578
|
+
? runProductionCommand
|
|
579
|
+
: runLogsCommand;
|
|
383
580
|
return operation(args, output, { origin, principalId: actor.principalId, projectId: link.projectId, teamId: link.teamId }, (path, method, body) => request(path, method, body, token, link.teamId));
|
|
384
581
|
}
|
|
385
582
|
if (!['source', 'deploy'].includes(command) ||
|
|
@@ -518,6 +715,12 @@ async function runPlatformOperation(command, args, output, dependencies) {
|
|
|
518
715
|
}
|
|
519
716
|
return;
|
|
520
717
|
}
|
|
718
|
+
if (state.plan.admission && state.plan.blockers.length) {
|
|
719
|
+
const issue = state.plan.admission.diagnostics[0];
|
|
720
|
+
throw platformFailure(issue
|
|
721
|
+
? `[${issue.code}] ${visible(issue.message)}`
|
|
722
|
+
: 'This source is not eligible for candidate preparation.', 'conflict', false, issue ? visible(issue.action) : 'Review anhedral deploy plan output before preparing.');
|
|
723
|
+
}
|
|
521
724
|
const requestId = state.prepareRequestId ?? randomUUID();
|
|
522
725
|
await persist({ ...state, prepareRequestId: requestId });
|
|
523
726
|
const prepared = cliPreparationSchema.parse(await request('/candidates', 'POST', { protocol: 1, requestId, planId: state.plan.id, planDigest: state.plan.digest }, token, link.teamId));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type OutputOptions } from './cli-output.js';
|
|
2
|
+
type Context = {
|
|
3
|
+
origin: string;
|
|
4
|
+
principalId: string;
|
|
5
|
+
projectId: string;
|
|
6
|
+
teamId: string;
|
|
7
|
+
};
|
|
8
|
+
type Request = (path: string, method: string, body?: unknown) => Promise<unknown>;
|
|
9
|
+
export declare function validateProductionArguments(args: string[]): {
|
|
10
|
+
positional: string[];
|
|
11
|
+
has: (flag: string) => boolean;
|
|
12
|
+
value: (flag: string) => string | undefined;
|
|
13
|
+
values: (flag: string) => string[];
|
|
14
|
+
};
|
|
15
|
+
export declare function runProductionCommand(args: string[], output: OutputOptions, context: Context, request: Request): Promise<void>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { commandArguments, commandArgumentError } from './cli-arguments.js';
|
|
6
|
+
import { createReporter } from './cli-output.js';
|
|
7
|
+
import { productionCreateSchema, productionCreateReceiptSchema, productionStateSchema, } from './contracts/production-transport.js';
|
|
8
|
+
import { platformFailure, readPrivate, writePrivate, withProjectLock } from './platform-state.js';
|
|
9
|
+
const stateSchema = z
|
|
10
|
+
.object({
|
|
11
|
+
origin: z.string(),
|
|
12
|
+
principalId: z.uuid(),
|
|
13
|
+
projectId: z.uuid(),
|
|
14
|
+
teamId: z.uuid(),
|
|
15
|
+
input: productionCreateSchema,
|
|
16
|
+
receipt: productionCreateReceiptSchema.optional(),
|
|
17
|
+
})
|
|
18
|
+
.strict();
|
|
19
|
+
const visible = (value) => stripVTControlCharacters(String(value ?? '')).replace(/[\x00-\x1f\x7f]/g, ' ');
|
|
20
|
+
export function validateProductionArguments(args) {
|
|
21
|
+
const options = commandArguments('production', args);
|
|
22
|
+
const [operation] = options.positional;
|
|
23
|
+
if (operation === 'status' &&
|
|
24
|
+
['--candidate', '--name', '--new'].some((flag) => options.has(flag)))
|
|
25
|
+
throw commandArgumentError('production', 'Candidate, name and --new apply to production deploy only.');
|
|
26
|
+
if (operation === 'deploy') {
|
|
27
|
+
if (!z.uuid().safeParse(options.value('--candidate')).success)
|
|
28
|
+
throw commandArgumentError('production', 'Select a ready candidate UUID with --candidate.');
|
|
29
|
+
if (!productionCreateSchema.shape.name.safeParse(options.value('--name')).success)
|
|
30
|
+
throw commandArgumentError('production', 'Select a valid application name with --name.');
|
|
31
|
+
}
|
|
32
|
+
return options;
|
|
33
|
+
}
|
|
34
|
+
async function runProductionOperation(args, output, context, request) {
|
|
35
|
+
const options = validateProductionArguments(args);
|
|
36
|
+
const [operation] = options.positional;
|
|
37
|
+
const reporter = createReporter(output, (value) => {
|
|
38
|
+
const data = value;
|
|
39
|
+
if (data.status === 'requested' || data.status === 'already_requested')
|
|
40
|
+
return `Production deployment requested (${visible(data.deployment.id)}).\nRun anhedral production status to follow publication.`;
|
|
41
|
+
const state = data.production;
|
|
42
|
+
return [
|
|
43
|
+
`Production generation ${state.generation}.`,
|
|
44
|
+
state.enabled === false
|
|
45
|
+
? 'Production deployment is not configured.'
|
|
46
|
+
: `Active deployment: ${visible(state.activeDeploymentId ?? 'none')}.`,
|
|
47
|
+
...(state.requiresIndependentApproval
|
|
48
|
+
? ['This team requires an independent production approver.']
|
|
49
|
+
: []),
|
|
50
|
+
...state.deployments.map((entry) => `${visible(entry.id)} ${visible(entry.status)} ${visible(entry.sourceRevision.slice(0, 12))}`),
|
|
51
|
+
].join('\n');
|
|
52
|
+
}, true);
|
|
53
|
+
const path = `/projects/${context.projectId}/production`;
|
|
54
|
+
const checkedState = (value) => {
|
|
55
|
+
const state = productionStateSchema.parse(value);
|
|
56
|
+
if (state.deployments.some((entry) => entry.developmentId !== context.projectId))
|
|
57
|
+
throw platformFailure('Production history belongs to another project.');
|
|
58
|
+
return state;
|
|
59
|
+
};
|
|
60
|
+
if (operation === 'status') {
|
|
61
|
+
reporter.result({
|
|
62
|
+
status: 'read',
|
|
63
|
+
environment: 'production',
|
|
64
|
+
projectId: context.projectId,
|
|
65
|
+
production: checkedState(await request(path, 'GET')),
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const candidateId = options.value('--candidate'), name = options.value('--name');
|
|
70
|
+
const file = join(process.cwd(), '.anhedral', 'platform', 'production.json');
|
|
71
|
+
const raw = await readPrivate(file), parsed = raw === null ? null : stateSchema.safeParse(raw);
|
|
72
|
+
if (parsed && !parsed.success)
|
|
73
|
+
throw platformFailure('Saved production deployment state is invalid. Preserve it before retrying.');
|
|
74
|
+
const previous = parsed?.success ? parsed.data : null;
|
|
75
|
+
if (previous &&
|
|
76
|
+
Object.entries(context).some(([key, value]) => previous[key] !== value))
|
|
77
|
+
throw platformFailure('Saved production deployment belongs to a different identity, team or project. Restore its original context.');
|
|
78
|
+
if (previous &&
|
|
79
|
+
!options.has('--new') &&
|
|
80
|
+
(previous.input.candidateId !== candidateId || previous.input.name !== name))
|
|
81
|
+
throw platformFailure('The candidate or name differs from the pending production deployment. Use --new for another deployment.');
|
|
82
|
+
const validReceipt = (receipt, input) => receipt.developmentId === context.projectId &&
|
|
83
|
+
receipt.requestId === input.requestId &&
|
|
84
|
+
receipt.candidateId === input.candidateId &&
|
|
85
|
+
receipt.generation === input.expectedGeneration + 1;
|
|
86
|
+
if (previous?.receipt && !validReceipt(previous.receipt, previous.input))
|
|
87
|
+
throw platformFailure('Saved production receipt differs from its request. Preserve state and reconcile before retrying.');
|
|
88
|
+
if (previous?.receipt && !options.has('--new')) {
|
|
89
|
+
reporter.result({
|
|
90
|
+
status: 'already_requested',
|
|
91
|
+
environment: 'production',
|
|
92
|
+
projectId: context.projectId,
|
|
93
|
+
requestId: previous.input.requestId,
|
|
94
|
+
deployment: previous.receipt,
|
|
95
|
+
});
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
let state;
|
|
99
|
+
if (previous && !options.has('--new'))
|
|
100
|
+
state = previous;
|
|
101
|
+
else {
|
|
102
|
+
const current = checkedState(await request(path, 'GET'));
|
|
103
|
+
if (current.requiresIndependentApproval)
|
|
104
|
+
throw platformFailure('This team requires an independent production approver. Request approval in Platform before production publication.', 'Review the team production approval policy in Platform.', 'permission');
|
|
105
|
+
if (current.enabled !== true || !current.canDeploy)
|
|
106
|
+
throw platformFailure('Production deployment is not configured or current production permission is unavailable.');
|
|
107
|
+
state = {
|
|
108
|
+
...context,
|
|
109
|
+
input: productionCreateSchema.parse({
|
|
110
|
+
requestId: randomUUID(),
|
|
111
|
+
candidateId,
|
|
112
|
+
name,
|
|
113
|
+
expectedGeneration: current.generation,
|
|
114
|
+
}),
|
|
115
|
+
};
|
|
116
|
+
await writePrivate(file, state);
|
|
117
|
+
}
|
|
118
|
+
const receipt = productionCreateReceiptSchema.parse(await request(`${path}/deployments`, 'POST', state.input));
|
|
119
|
+
if (!validReceipt(receipt, state.input))
|
|
120
|
+
throw platformFailure('Production receipt differs from this request. Preserve saved state before retrying.');
|
|
121
|
+
await writePrivate(file, { ...state, receipt });
|
|
122
|
+
reporter.result({
|
|
123
|
+
status: 'requested',
|
|
124
|
+
environment: 'production',
|
|
125
|
+
projectId: context.projectId,
|
|
126
|
+
requestId: state.input.requestId,
|
|
127
|
+
deployment: receipt,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
export async function runProductionCommand(args, output, context, request) {
|
|
131
|
+
const options = validateProductionArguments(args);
|
|
132
|
+
if (options.positional[0] === 'deploy')
|
|
133
|
+
return withProjectLock(join(process.cwd(), '.anhedral', 'platform'), () => runProductionOperation(args, output, context, request));
|
|
134
|
+
return runProductionOperation(args, output, context, request);
|
|
135
|
+
}
|
package/dist/platform-state.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export declare const platformFailure: (message: string, nextAction?: string, cat
|
|
|
4
4
|
export declare function platformOrigin(value?: string): string;
|
|
5
5
|
export declare function readPrivate(path: string): Promise<unknown | null>;
|
|
6
6
|
export declare function writePrivate(path: string, data: unknown): Promise<void>;
|
|
7
|
+
/** Serialize project selection and request journals; never steal a potentially live lock. */
|
|
8
|
+
export declare function withProjectLock<T>(directory: string, operation: () => Promise<T>): Promise<T>;
|
|
7
9
|
export interface SecretStore {
|
|
8
10
|
read(): Promise<unknown | null>;
|
|
9
11
|
write(data: unknown): Promise<void>;
|
package/dist/platform-state.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
|
-
import { lstat, mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { lstat, mkdir, open, readFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
5
5
|
import { CliArgumentError } from './cli-arguments.js';
|
|
6
6
|
import { CliFailure } from './cli-errors.js';
|
|
7
7
|
export const platformFailure = (message, nextAction = 'Run anhedral login --help.', category = 'context', retryable = false) => new CliFailure(message, 'PLATFORM_ACCESS_FAILED', nextAction, category, retryable);
|
|
@@ -85,6 +85,28 @@ export async function writePrivate(path, data) {
|
|
|
85
85
|
await unlink(temp).catch(() => { });
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
+
/** Serialize project selection and request journals; never steal a potentially live lock. */
|
|
89
|
+
export async function withProjectLock(directory, operation) {
|
|
90
|
+
await safeDirectory(directory);
|
|
91
|
+
const lockPath = join(directory, 'project-operation.lock');
|
|
92
|
+
let file;
|
|
93
|
+
try {
|
|
94
|
+
file = await open(lockPath, 'wx', 0o600);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (error.code === 'EEXIST')
|
|
98
|
+
throw platformFailure('Another project operation holds the workspace lock.', 'Wait for the operation to finish. After an interrupted process, inspect .anhedral/platform/project-operation.lock and remove it only after confirming no project operation is running; preserve the saved operation state, then retry the same command without --new.', 'conflict', true);
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
await file.writeFile(JSON.stringify({ pid: process.pid, startedAt: new Date().toISOString() }) + '\n');
|
|
103
|
+
return await operation();
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
await file.close();
|
|
107
|
+
await unlink(lockPath);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
88
110
|
export function runCredentialProcess(binary, args, input = '', timeoutMs = 30000) {
|
|
89
111
|
return new Promise((resolve, reject) => {
|
|
90
112
|
const child = spawn(binary, args, { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
@@ -2,6 +2,8 @@ import { CapabilityEditor } from '../capability-editor.js';
|
|
|
2
2
|
import type { Capability } from '../capability-catalog.js';
|
|
3
3
|
/** The launch foundation is a web service; Hono owns application services and data. */
|
|
4
4
|
export declare function scaffoldTanstack(root: string, name: string): void;
|
|
5
|
+
/** One-time source upgrade, planned in the same bounded overlay as each addition. */
|
|
6
|
+
export declare function normalizeOjFoundation(e: CapabilityEditor, installed: readonly Capability[], refreshConfiguration?: boolean): boolean;
|
|
5
7
|
/** Fingerprinted composition adapters; application routes stay source-owned. */
|
|
6
8
|
export declare function composeTanstack(e: CapabilityEditor, installed: readonly Capability[]): void;
|
|
7
9
|
/** Install account source only when the backend authentication capability is added. */
|