anhedral 0.22.0 → 0.23.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 +37 -51
- package/assets/contracts/deployment-provenance.json +4 -4
- package/assets/contracts/environment-provenance.json +2 -2
- package/dist/cli-commands.js +5 -17
- package/dist/cli-errors.js +1 -1
- package/dist/cli-output.js +1 -1
- package/dist/command-schema.d.ts +1 -0
- package/dist/command-schema.js +19 -1
- package/dist/completion.js +1 -1
- package/dist/{capability-catalog.d.ts → composition/catalog.d.ts} +2 -2
- package/dist/{capability-catalog.js → composition/catalog.js} +2 -2
- package/dist/{capability-command.d.ts → composition/command.d.ts} +3 -3
- package/dist/{capability-command.js → composition/command.js} +29 -22
- package/dist/{composition.d.ts → composition/composition.d.ts} +1 -1
- package/dist/{composition.js → composition/composition.js} +2 -2
- package/dist/{capability-editor.js → composition/editor.js} +1 -1
- package/dist/{capability-recipes.d.ts → composition/recipes.d.ts} +2 -2
- package/dist/{capability-recipes.js → composition/recipes.js} +7 -7
- package/dist/{capability-references.js → composition/references.js} +2 -2
- package/dist/{stack-update.d.ts → composition/update.d.ts} +3 -3
- package/dist/{stack-update.js → composition/update.js} +11 -11
- package/dist/contracts/cli-transport.d.ts +1 -1
- package/dist/contracts/deployment.d.ts +4 -65
- package/dist/contracts/deployment.js +0 -29
- package/dist/contracts/environment-file.d.ts +3 -0
- package/dist/contracts/environment-file.js +8 -5
- package/dist/contracts/production-transport.d.ts +2 -2
- package/dist/contracts/staging-transport.d.ts +2 -2
- package/dist/dependencies.d.ts +1 -1
- package/dist/dependencies.js +1 -1
- package/dist/launch.js +8 -8
- package/dist/platform/auth.d.ts +14 -0
- package/dist/platform/auth.js +62 -0
- package/dist/{platform-command.d.ts → platform/command.d.ts} +2 -2
- package/dist/platform/command.js +279 -0
- package/dist/{credential-helper.js → platform/credential-helper.js} +1 -1
- package/dist/platform/deploy.d.ts +2 -0
- package/dist/platform/deploy.js +158 -0
- package/dist/{platform-environment.d.ts → platform/environment.d.ts} +1 -1
- package/dist/{platform-environment.js → platform/environment.js} +12 -12
- package/dist/platform/http.d.ts +7 -0
- package/dist/platform/http.js +105 -0
- package/dist/{platform-operations.d.ts → platform/operations.d.ts} +1 -1
- package/dist/{platform-operations.js → platform/operations.js} +5 -5
- package/dist/platform/output.d.ts +2 -0
- package/dist/platform/output.js +79 -0
- package/dist/{platform-production.d.ts → platform/production.d.ts} +1 -1
- package/dist/{platform-production.js → platform/production.js} +4 -4
- package/dist/platform/projects.d.ts +12 -0
- package/dist/platform/projects.js +125 -0
- package/dist/{platform-source.js → platform/source.js} +7 -7
- package/dist/platform/state-schema.d.ts +25 -0
- package/dist/platform/state-schema.js +11 -0
- package/dist/{platform-state.d.ts → platform/state.d.ts} +1 -1
- package/dist/{platform-state.js → platform/state.js} +3 -4
- package/dist/platform/types.d.ts +26 -0
- package/dist/platform/upload.d.ts +2 -0
- package/dist/platform/upload.js +60 -0
- package/dist/process/runner.d.ts +1 -0
- package/dist/{command-runner.js → process/runner.js} +1 -1
- package/dist/registry/usage.d.ts +1 -0
- package/dist/{platforms → scaffold}/tanstack.d.ts +2 -2
- package/dist/{platforms → scaffold}/tanstack.js +2 -2
- package/dist/transactions/durable-files.d.ts +8 -0
- package/dist/transactions/durable-files.js +132 -0
- package/dist/transactions/journal.d.ts +4 -0
- package/dist/transactions/journal.js +141 -0
- package/dist/{transaction-lock.js → transactions/lock.js} +2 -2
- package/dist/transactions/model.d.ts +18 -0
- package/dist/transactions/model.js +4 -0
- package/dist/transactions/paths.d.ts +12 -0
- package/dist/transactions/paths.js +155 -0
- package/dist/transactions/recovery.d.ts +7 -0
- package/dist/transactions/recovery.js +132 -0
- package/dist/{transaction.d.ts → transactions/transaction.d.ts} +1 -2
- package/dist/transactions/transaction.js +179 -0
- package/dist/util.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/capabilities.md +8 -6
- package/docs/software-factory.md +36 -6
- package/package.json +22 -22
- package/dist/platform-command.js +0 -787
- package/dist/transaction.js +0 -716
- /package/dist/{capability-editor.d.ts → composition/editor.d.ts} +0 -0
- /package/dist/{capability-references.d.ts → composition/references.d.ts} +0 -0
- /package/dist/{credential-helper.d.ts → platform/credential-helper.d.ts} +0 -0
- /package/dist/{platform-source.d.ts → platform/source.d.ts} +0 -0
- /package/dist/{command-runner.d.ts → platform/types.js} +0 -0
- /package/dist/{command.d.ts → process/resolve-command.d.ts} +0 -0
- /package/dist/{command.js → process/resolve-command.js} +0 -0
- /package/dist/{transaction-lock.d.ts → transactions/lock.d.ts} +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { commandArgumentError } from '../cli-arguments.js';
|
|
6
|
+
import { canonicalCliJson, cliPlanInputSchema, cliPlanSchema, cliPreparationSchema, sourceUploadReceiptSchema, } from '../contracts/cli-transport.js';
|
|
7
|
+
import { deploymentManifestSchema } from '../contracts/deployment.js';
|
|
8
|
+
import { visible } from './output.js';
|
|
9
|
+
import { uploadState } from './state-schema.js';
|
|
10
|
+
import { readPrivate, writePrivate } from './state.js';
|
|
11
|
+
const hash = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
12
|
+
export async function runDeploy({ options, origin, actor, token, stateDir, link, uploadPath, request, emit, platformFailure, }) {
|
|
13
|
+
const command = 'deploy';
|
|
14
|
+
const localPath = join(stateDir, 'deployment.json');
|
|
15
|
+
const stateSchema = z
|
|
16
|
+
.object({
|
|
17
|
+
origin: z.string(),
|
|
18
|
+
principalId: z.uuid(),
|
|
19
|
+
projectId: z.uuid(),
|
|
20
|
+
planInput: cliPlanInputSchema,
|
|
21
|
+
plan: cliPlanSchema.optional(),
|
|
22
|
+
prepareRequestId: z.uuid().optional(),
|
|
23
|
+
candidateId: z.uuid().optional(),
|
|
24
|
+
})
|
|
25
|
+
.strict();
|
|
26
|
+
const stored = stateSchema.safeParse(await readPrivate(localPath));
|
|
27
|
+
const state = stored.success &&
|
|
28
|
+
stored.data.origin === origin &&
|
|
29
|
+
stored.data.principalId === actor.principalId &&
|
|
30
|
+
stored.data.projectId === link.projectId
|
|
31
|
+
? stored.data
|
|
32
|
+
: null;
|
|
33
|
+
const persist = (v) => writePrivate(localPath, v);
|
|
34
|
+
const checkedPlan = (plan, input) => {
|
|
35
|
+
const { digest, ...unsigned } = plan;
|
|
36
|
+
if (hash(new TextEncoder().encode(canonicalCliJson(unsigned))) !== digest ||
|
|
37
|
+
plan.projectId !== link.projectId ||
|
|
38
|
+
plan.uploadId !== input.uploadId ||
|
|
39
|
+
plan.requestId !== input.requestId ||
|
|
40
|
+
canonicalCliJson(plan.manifest) !== canonicalCliJson(input.manifest))
|
|
41
|
+
throw platformFailure('Deployment plan identity or integrity differs.');
|
|
42
|
+
return plan;
|
|
43
|
+
};
|
|
44
|
+
if (state?.plan)
|
|
45
|
+
checkedPlan(state.plan, state.planInput);
|
|
46
|
+
if (options.positional[0] === 'plan') {
|
|
47
|
+
const upload = uploadState.parse(await readPrivate(uploadPath));
|
|
48
|
+
if (upload.origin !== origin ||
|
|
49
|
+
upload.principalId !== actor.principalId ||
|
|
50
|
+
upload.input.projectId !== link.projectId ||
|
|
51
|
+
!upload.uploadId)
|
|
52
|
+
throw platformFailure('Choose a sealed upload for this linked identity.');
|
|
53
|
+
const receipt = sourceUploadReceiptSchema.parse(await request(`/uploads/${upload.uploadId}`, 'GET', undefined, token, link.teamId));
|
|
54
|
+
if (receipt.state !== 'sealed' ||
|
|
55
|
+
receipt.sourceRevision !== upload.input.archiveDigest ||
|
|
56
|
+
receipt.projectId !== link.projectId)
|
|
57
|
+
throw platformFailure('The saved source upload is not sealed.');
|
|
58
|
+
const file = options.value('--manifest');
|
|
59
|
+
if (!file)
|
|
60
|
+
throw commandArgumentError(command, 'Use deploy plan --manifest <file>.');
|
|
61
|
+
const handle = await import('node:fs/promises').then((fs) => fs.open(resolve(file), constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK));
|
|
62
|
+
let manifest;
|
|
63
|
+
try {
|
|
64
|
+
const info = await handle.stat();
|
|
65
|
+
if (!info.isFile() || info.size > 32768)
|
|
66
|
+
throw platformFailure('Deployment manifest exceeds its limit.');
|
|
67
|
+
try {
|
|
68
|
+
manifest = JSON.parse(await handle.readFile('utf8'));
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
throw commandArgumentError(command, 'The deployment manifest is not valid JSON. Review it before retrying.');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
await handle.close();
|
|
76
|
+
}
|
|
77
|
+
const checkedManifest = deploymentManifestSchema.safeParse(manifest);
|
|
78
|
+
if (!checkedManifest.success)
|
|
79
|
+
throw commandArgumentError(command, 'The deployment manifest must match its foundation, capabilities, identity and runtime profile. TanStack Start uses the anhedral-stack runtime profile.');
|
|
80
|
+
const compared = cliPlanInputSchema.parse({
|
|
81
|
+
protocol: 1,
|
|
82
|
+
requestId: state && !options.has('--new') ? state.planInput.requestId : randomUUID(),
|
|
83
|
+
uploadId: upload.uploadId,
|
|
84
|
+
manifest: checkedManifest.data,
|
|
85
|
+
});
|
|
86
|
+
if (state &&
|
|
87
|
+
!options.has('--new') &&
|
|
88
|
+
canonicalCliJson(state.planInput) !== canonicalCliJson(compared))
|
|
89
|
+
throw platformFailure('Plan inputs changed. Use deploy plan --new to create a new request.');
|
|
90
|
+
const local = {
|
|
91
|
+
origin,
|
|
92
|
+
principalId: actor.principalId,
|
|
93
|
+
projectId: link.projectId,
|
|
94
|
+
planInput: compared,
|
|
95
|
+
};
|
|
96
|
+
// Persist before POST so lost plan responses can be recovered by the same request identity.
|
|
97
|
+
await persist({
|
|
98
|
+
...local,
|
|
99
|
+
...(state?.prepareRequestId && !options.has('--new')
|
|
100
|
+
? { prepareRequestId: state.prepareRequestId, candidateId: state.candidateId }
|
|
101
|
+
: {}),
|
|
102
|
+
});
|
|
103
|
+
const plan = cliPlanSchema.parse(await request('/plans', 'POST', compared, token, link.teamId));
|
|
104
|
+
const { digest, ...unsigned } = plan;
|
|
105
|
+
if (hash(new TextEncoder().encode(canonicalCliJson(unsigned))) !== digest ||
|
|
106
|
+
plan.projectId !== link.projectId ||
|
|
107
|
+
plan.uploadId !== compared.uploadId ||
|
|
108
|
+
plan.requestId !== compared.requestId ||
|
|
109
|
+
canonicalCliJson(plan.manifest) !== canonicalCliJson(compared.manifest) ||
|
|
110
|
+
plan.sourceRevision !== receipt.sourceRevision)
|
|
111
|
+
throw platformFailure('Deployment plan identity or integrity differs.');
|
|
112
|
+
await persist({
|
|
113
|
+
...local,
|
|
114
|
+
plan,
|
|
115
|
+
...(state?.prepareRequestId && !options.has('--new')
|
|
116
|
+
? { prepareRequestId: state.prepareRequestId, candidateId: state.candidateId }
|
|
117
|
+
: {}),
|
|
118
|
+
});
|
|
119
|
+
emit(plan);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (!state?.plan)
|
|
123
|
+
throw platformFailure('Create a deployment plan for this linked identity first.');
|
|
124
|
+
if (options.positional[0] === 'status') {
|
|
125
|
+
if (state.candidateId) {
|
|
126
|
+
const result = cliPreparationSchema.parse(await request(`/candidates/${state.candidateId}`, 'GET', undefined, token, link.teamId));
|
|
127
|
+
if (result.planId !== state.plan.id ||
|
|
128
|
+
result.planDigest !== state.plan.digest ||
|
|
129
|
+
result.candidateId !== state.candidateId ||
|
|
130
|
+
result.sourceRevision !== state.plan.sourceRevision)
|
|
131
|
+
throw platformFailure('Candidate receipt identity differs.');
|
|
132
|
+
emit(result);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
const plan = checkedPlan(cliPlanSchema.parse(await request(`/plans/${state.plan.id}`, 'GET', undefined, token, link.teamId)), state.planInput);
|
|
136
|
+
if (plan.digest !== state.plan.digest || plan.id !== state.plan.id)
|
|
137
|
+
throw platformFailure('Plan receipt identity differs.');
|
|
138
|
+
emit(plan);
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (state.plan.admission && state.plan.blockers.length) {
|
|
143
|
+
const issue = state.plan.admission.diagnostics[0];
|
|
144
|
+
throw platformFailure(issue
|
|
145
|
+
? `[${issue.code}] ${visible(issue.message)}`
|
|
146
|
+
: 'This source is not eligible for candidate preparation.', 'conflict', false, issue ? visible(issue.action) : 'Review anhedral deploy plan output before preparing.');
|
|
147
|
+
}
|
|
148
|
+
const requestId = state.prepareRequestId ?? randomUUID();
|
|
149
|
+
await persist({ ...state, prepareRequestId: requestId });
|
|
150
|
+
const prepared = cliPreparationSchema.parse(await request('/candidates', 'POST', { protocol: 1, requestId, planId: state.plan.id, planDigest: state.plan.digest }, token, link.teamId));
|
|
151
|
+
if (prepared.planId !== state.plan.id ||
|
|
152
|
+
prepared.planDigest !== state.plan.digest ||
|
|
153
|
+
prepared.sourceRevision !== state.plan.sourceRevision)
|
|
154
|
+
throw platformFailure('Candidate receipt identity differs.');
|
|
155
|
+
await persist({ ...state, prepareRequestId: requestId, candidateId: prepared.candidateId });
|
|
156
|
+
emit(prepared);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { constants, fstatSync, lstatSync, openSync, readSync, closeSync } from 'node:fs';
|
|
2
|
-
import { dirname, join, resolve } from 'node:path';
|
|
3
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync } from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
-
import {
|
|
6
|
-
import { createReporter } from '
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { platformFailure, readPrivate, writePrivate } from './
|
|
5
|
+
import { commandArgumentError, commandArguments } from '../cli-arguments.js';
|
|
6
|
+
import { createReporter } from '../cli-output.js';
|
|
7
|
+
import { ENVIRONMENT_FILE_MAX_BYTES, inferredEnvironmentKind, parseEnvironmentFile, } from '../contracts/environment-file.js';
|
|
8
|
+
import { environmentImportReceiptSchema, environmentImportSchema, environmentMetadataSchema, environmentNameSchema, projectEnvironmentSchema, } from '../contracts/environment-transport.js';
|
|
9
|
+
import { platformFailure, readPrivate, writePrivate } from './state.js';
|
|
10
10
|
const planSchema = z
|
|
11
11
|
.object({
|
|
12
12
|
origin: z.string(),
|
|
@@ -41,11 +41,11 @@ export function readEnvironmentSecret(file) {
|
|
|
41
41
|
try {
|
|
42
42
|
const info = fstatSync(descriptor);
|
|
43
43
|
if (!info.isFile() ||
|
|
44
|
-
info.size >
|
|
44
|
+
info.size > ENVIRONMENT_FILE_MAX_BYTES ||
|
|
45
45
|
(process.platform !== 'win32' &&
|
|
46
46
|
(info.uid !== process.getuid?.() || (info.mode & 0o077) !== 0)))
|
|
47
47
|
throw platformFailure('Environment input must be your regular owner-only file (mode 0600), at most 64 KiB.');
|
|
48
|
-
const data = Buffer.alloc(
|
|
48
|
+
const data = Buffer.alloc(ENVIRONMENT_FILE_MAX_BYTES + 1);
|
|
49
49
|
let length = 0;
|
|
50
50
|
while (length < data.length) {
|
|
51
51
|
const read = readSync(descriptor, data, length, data.length - length, null);
|
|
@@ -53,7 +53,7 @@ export function readEnvironmentSecret(file) {
|
|
|
53
53
|
break;
|
|
54
54
|
length += read;
|
|
55
55
|
}
|
|
56
|
-
if (length >
|
|
56
|
+
if (length > ENVIRONMENT_FILE_MAX_BYTES)
|
|
57
57
|
throw platformFailure('Environment input exceeds 64 KiB.');
|
|
58
58
|
return data.subarray(0, length);
|
|
59
59
|
}
|
|
@@ -71,7 +71,7 @@ async function stdinBytes() {
|
|
|
71
71
|
for await (const item of process.stdin) {
|
|
72
72
|
const bytes = Buffer.from(item);
|
|
73
73
|
length += bytes.length;
|
|
74
|
-
if (length >
|
|
74
|
+
if (length > ENVIRONMENT_FILE_MAX_BYTES)
|
|
75
75
|
throw platformFailure('Environment input exceeds 64 KiB.');
|
|
76
76
|
chunks.push(bytes);
|
|
77
77
|
}
|
|
@@ -129,7 +129,7 @@ export async function runEnvironmentCommand(args, output, context, request, read
|
|
|
129
129
|
const bytes = options.has('--file')
|
|
130
130
|
? readEnvironmentSecret(options.value('--file'))
|
|
131
131
|
: await readInput();
|
|
132
|
-
if (bytes.length >
|
|
132
|
+
if (bytes.length > ENVIRONMENT_FILE_MAX_BYTES)
|
|
133
133
|
throw new Error('Environment input exceeds 64 KiB.');
|
|
134
134
|
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
135
135
|
entries = operation === 'set' ? [{ name: name, value: text }] : parseEnvironmentFile(text);
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { readSourceBounded } from '../contracts/source-bundle.js';
|
|
3
|
+
import { visible } from './output.js';
|
|
4
|
+
import { platformFailure as createPlatformFailure } from './state.js';
|
|
5
|
+
export function createPlatformRequest({ command, operation, origin, fetch: fetchRequest, }) {
|
|
6
|
+
const platformFailure = (message, category = 'context', retryable = false, nextAction = `Run anhedral ${command} --help.`) => createPlatformFailure(message, nextAction, category, retryable);
|
|
7
|
+
return async (path, method, body, token, team) => {
|
|
8
|
+
let response;
|
|
9
|
+
try {
|
|
10
|
+
response = await (fetchRequest ?? fetch)(`${origin}/api/cli/v1${path}`, {
|
|
11
|
+
method,
|
|
12
|
+
redirect: 'error',
|
|
13
|
+
signal: AbortSignal.timeout(30000),
|
|
14
|
+
headers: {
|
|
15
|
+
'x-anhedral-cli-protocol': '1',
|
|
16
|
+
...(body instanceof Uint8Array
|
|
17
|
+
? { 'content-type': 'application/octet-stream' }
|
|
18
|
+
: { 'content-type': 'application/json' }),
|
|
19
|
+
...(token ? { authorization: `Bearer ${token}` } : {}),
|
|
20
|
+
...(team ? { 'x-anhedral-team': team } : {}),
|
|
21
|
+
},
|
|
22
|
+
body: body === undefined
|
|
23
|
+
? undefined
|
|
24
|
+
: body instanceof Uint8Array
|
|
25
|
+
? Uint8Array.from(body)
|
|
26
|
+
: JSON.stringify(body),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw platformFailure(command === 'projects' && operation === 'create'
|
|
31
|
+
? 'Platform request was interrupted. Retry the saved project request without --new to resume.'
|
|
32
|
+
: 'Platform request was interrupted. Retry the same command to resume.', 'network', true, command === 'projects' && operation === 'create'
|
|
33
|
+
? 'Retry anhedral projects create with the same name, summary, team, API origin, credential store and working directory, omitting --new to reuse the saved request.'
|
|
34
|
+
: `Retry anhedral ${command} with the same API origin, working directory and options to resume.`);
|
|
35
|
+
}
|
|
36
|
+
const data = await readSourceBounded(response.body, /\/projects\/[^/]+\/(environment|staging|production|runtime-logs)(\?|$)/.test(path)
|
|
37
|
+
? 1024 * 1024
|
|
38
|
+
: command === 'projects'
|
|
39
|
+
? 1024 * 1024
|
|
40
|
+
: 65536)
|
|
41
|
+
.then((b) => JSON.parse(new TextDecoder().decode(b)))
|
|
42
|
+
.catch(() => {
|
|
43
|
+
throw platformFailure('Platform returned an invalid response.', 'network');
|
|
44
|
+
});
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
if (path === '/auth/token') {
|
|
47
|
+
const error = z
|
|
48
|
+
.object({
|
|
49
|
+
error: z.enum([
|
|
50
|
+
'authorization_pending',
|
|
51
|
+
'slow_down',
|
|
52
|
+
'access_denied',
|
|
53
|
+
'expired_token',
|
|
54
|
+
'invalid_grant',
|
|
55
|
+
]),
|
|
56
|
+
})
|
|
57
|
+
.safeParse(data);
|
|
58
|
+
if (error.success)
|
|
59
|
+
return error.data;
|
|
60
|
+
}
|
|
61
|
+
const serverMessage = z.object({ error: z.string().max(2000) }).safeParse(data);
|
|
62
|
+
const admissionProblem = serverMessage.success &&
|
|
63
|
+
/^\[(?:RUNTIME_UNAVAILABLE|ARTIFACT_MISMATCH|SOURCE_VERSION_MISMATCH|DEPENDENCY_LOCK_MISMATCH|INDEPENDENT_APPROVAL_REQUIRED|PRODUCTION_PERMISSION_REQUIRED)\] [^\r\n]{1,1500}$/.test(serverMessage.data.error)
|
|
64
|
+
? visible(serverMessage.data.error)
|
|
65
|
+
: null;
|
|
66
|
+
throw platformFailure(admissionProblem ??
|
|
67
|
+
(response.status === 401
|
|
68
|
+
? 'CLI login expired or was revoked. Run anhedral login.'
|
|
69
|
+
: response.status === 409
|
|
70
|
+
? command === 'deploy'
|
|
71
|
+
? 'Deployment plan is stale or inputs conflict. Review deploy plan --new.'
|
|
72
|
+
: command === 'projects'
|
|
73
|
+
? 'Project creation conflicts with the saved request. Preserve retry state; use projects create --new only to create another project.'
|
|
74
|
+
: command === 'staging'
|
|
75
|
+
? 'Candidate, configuration or staging generation changed. Review staging status before starting a new deployment.'
|
|
76
|
+
: command === 'production'
|
|
77
|
+
? 'Candidate, production configuration, permissions or generation changed. Review production status before retrying.'
|
|
78
|
+
: command === 'env'
|
|
79
|
+
? 'Environment versions or import contents conflict. Review env list and preserve saved retry state before starting a new import.'
|
|
80
|
+
: 'Upload conflicts with saved source. Restore the original files or use source upload --new.'
|
|
81
|
+
: response.status === 403
|
|
82
|
+
? command === 'projects'
|
|
83
|
+
? 'Current team project access or project creation permission is unavailable.'
|
|
84
|
+
: command === 'env'
|
|
85
|
+
? 'Current project environment access or administrator permission is unavailable.'
|
|
86
|
+
: command === 'logs'
|
|
87
|
+
? 'Current project log access is unavailable.'
|
|
88
|
+
: command === 'production'
|
|
89
|
+
? 'Current production permission or team approval policy does not allow this deployment. Review production status and the team policy.'
|
|
90
|
+
: 'Current project build access is unavailable.'
|
|
91
|
+
: `Platform request failed (${response.status}).`), response.status === 401
|
|
92
|
+
? 'auth'
|
|
93
|
+
: response.status === 403
|
|
94
|
+
? 'permission'
|
|
95
|
+
: response.status === 409
|
|
96
|
+
? 'conflict'
|
|
97
|
+
: 'network', response.status === 429 || response.status >= 500, response.status === 401
|
|
98
|
+
? 'Run anhedral login with the same API origin and credential store.'
|
|
99
|
+
: response.status === 403 && command === 'production'
|
|
100
|
+
? 'Run anhedral production status and review current production permissions and the team approval policy in Platform.'
|
|
101
|
+
: `Run anhedral ${command} --help.`);
|
|
102
|
+
}
|
|
103
|
+
return data;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -2,11 +2,11 @@ import { randomUUID } from 'node:crypto';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { stripVTControlCharacters } from 'node:util';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
-
import {
|
|
6
|
-
import { createReporter } from '
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { platformFailure, readPrivate, writePrivate } from './
|
|
5
|
+
import { commandArgumentError, commandArguments } from '../cli-arguments.js';
|
|
6
|
+
import { createReporter } from '../cli-output.js';
|
|
7
|
+
import { runtimeLogPageSchema, runtimeLogQuerySchema, } from '../contracts/runtime-logs-transport.js';
|
|
8
|
+
import { stagingCreateReceiptSchema, stagingCreateSchema, stagingStateSchema, } from '../contracts/staging-transport.js';
|
|
9
|
+
import { platformFailure, readPrivate, writePrivate } from './state.js';
|
|
10
10
|
const contextSchema = z.object({
|
|
11
11
|
origin: z.string(),
|
|
12
12
|
principalId: z.uuid(),
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
2
|
+
export function visible(value) {
|
|
3
|
+
return stripVTControlCharacters(String(value ?? '')).replace(/[\x00-\x1f\x7f]/g, ' ');
|
|
4
|
+
}
|
|
5
|
+
export function formatPlatformResult(command, result) {
|
|
6
|
+
const data = result;
|
|
7
|
+
if (data.status === 'authorization_required')
|
|
8
|
+
return `Approve CLI access at ${visible(data.verificationUrl)}\nConfirm code ${visible(data.userCode)}.\nNext: ${visible(data.nextAction)}`;
|
|
9
|
+
if (data.status === 'authenticated')
|
|
10
|
+
return `Signed in to ${visible(data.origin)}.\nExpires: ${visible(data.expiresAt)}.`;
|
|
11
|
+
if (data.status === 'logged_out')
|
|
12
|
+
return `Logged out of ${visible(data.origin)}.`;
|
|
13
|
+
if (data.status === 'unlinked')
|
|
14
|
+
return 'Removed the local project link.';
|
|
15
|
+
if (command === 'whoami') {
|
|
16
|
+
const context = data.context;
|
|
17
|
+
return [
|
|
18
|
+
`Signed in as ${visible(data.name)} (${visible(data.principalId)}).`,
|
|
19
|
+
`API origin: ${visible(data.origin)}.`,
|
|
20
|
+
`Expires: ${visible(data.expiresAt)}.`,
|
|
21
|
+
...(context
|
|
22
|
+
? [
|
|
23
|
+
`Credential store: ${visible(context.credential?.kind)}.`,
|
|
24
|
+
context.project
|
|
25
|
+
? `Saved local project: ${visible(context.project.name)} (${visible(context.project.projectId)}), team ${visible(context.project.teamId)}. Project access has not been verified.`
|
|
26
|
+
: 'No local project link is saved.',
|
|
27
|
+
]
|
|
28
|
+
: []),
|
|
29
|
+
].join('\n');
|
|
30
|
+
}
|
|
31
|
+
if (command === 'projects') {
|
|
32
|
+
if (data.status === 'dry_run')
|
|
33
|
+
return `Project creation preview: ${visible(data.name)}.\nNo project, source or deployment was created.`;
|
|
34
|
+
if (Array.isArray(data.projects)) {
|
|
35
|
+
const projects = data.projects;
|
|
36
|
+
const teams = data.availableTeams;
|
|
37
|
+
return [
|
|
38
|
+
data.team
|
|
39
|
+
? `Team: ${visible(data.team.name)} (${visible(data.team.id)}).`
|
|
40
|
+
: 'No team is selected.',
|
|
41
|
+
...projects.map((project) => `${visible(project.name)} (${visible(project.projectId)})${project.canLink ? '' : ' [cannot link]'}`),
|
|
42
|
+
...(projects.length ? [] : ['No projects found.']),
|
|
43
|
+
'Available teams:',
|
|
44
|
+
...teams.map((team) => `${visible(team.name)} (${visible(team.id)})`),
|
|
45
|
+
...(data.teamsTruncated
|
|
46
|
+
? ['Team list is truncated. Use a known team ID with --team.']
|
|
47
|
+
: []),
|
|
48
|
+
...(data.nextCursor
|
|
49
|
+
? [
|
|
50
|
+
`Next: anhedral projects list --cursor ${visible(data.nextCursor)}${data.team ? ` --team ${visible(data.team.id)}` : ''} (with the same API origin and credential store).`,
|
|
51
|
+
]
|
|
52
|
+
: []),
|
|
53
|
+
].join('\n');
|
|
54
|
+
}
|
|
55
|
+
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.`;
|
|
56
|
+
}
|
|
57
|
+
if (command === 'link')
|
|
58
|
+
return `Linked to ${visible(data.name)} (${visible(data.projectId)}).\nTeam: ${visible(data.teamId)}.`;
|
|
59
|
+
if (data.status === 'dry_run')
|
|
60
|
+
return `Source archive preview: ${visible(data.files)} files, ${visible(data.bytes)} source bytes, ${visible(data.archiveBytes)} archive bytes.\nNo source was uploaded. Review the included paths with --json.`;
|
|
61
|
+
if (command === 'source')
|
|
62
|
+
return `Source ${visible(data.state)} (${visible(data.id)}).\nSource revision: ${visible(data.sourceRevision ?? 'not sealed')}.\nUpload does not activate a runtime or deployment.`;
|
|
63
|
+
if (command === 'deploy')
|
|
64
|
+
return [
|
|
65
|
+
data.state
|
|
66
|
+
? `Candidate ${visible(data.state)} (${visible(data.candidateId)}).`
|
|
67
|
+
: `Deployment plan prepared (${visible(data.id)}).`,
|
|
68
|
+
`Source revision: ${visible(data.sourceRevision)}.`,
|
|
69
|
+
...(data.admission?.diagnostics ?? []).flatMap((item) => [
|
|
70
|
+
`[${visible(item.code)}] ${visible(item.message)}`,
|
|
71
|
+
`Next: ${visible(item.action)}`,
|
|
72
|
+
]),
|
|
73
|
+
...(data.admission && data.blockers?.length === 0
|
|
74
|
+
? ['Source is eligible for candidate preparation. Run anhedral deploy prepare.']
|
|
75
|
+
: []),
|
|
76
|
+
'No preview or deployment was activated.',
|
|
77
|
+
].join('\n');
|
|
78
|
+
return 'Platform command completed.';
|
|
79
|
+
}
|
|
@@ -2,10 +2,10 @@ import { randomUUID } from 'node:crypto';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { stripVTControlCharacters } from 'node:util';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
-
import {
|
|
6
|
-
import { createReporter } from '
|
|
7
|
-
import {
|
|
8
|
-
import { platformFailure, readPrivate,
|
|
5
|
+
import { commandArgumentError, commandArguments } from '../cli-arguments.js';
|
|
6
|
+
import { createReporter } from '../cli-output.js';
|
|
7
|
+
import { productionCreateReceiptSchema, productionCreateSchema, productionStateSchema, } from '../contracts/production-transport.js';
|
|
8
|
+
import { platformFailure, readPrivate, withProjectLock, writePrivate } from './state.js';
|
|
9
9
|
const stateSchema = z
|
|
10
10
|
.object({
|
|
11
11
|
origin: z.string(),
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type commandArguments } from '../cli-arguments.js';
|
|
2
|
+
import type { ProjectOperation } from './types.js';
|
|
3
|
+
export declare function runProjects({ options, origin, actor, token, stateDir, linkPath, request, emit, platformFailure, projectInput, }: ProjectOperation & {
|
|
4
|
+
projectInput?: {
|
|
5
|
+
name: string;
|
|
6
|
+
summary: string;
|
|
7
|
+
};
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare function validateProjects(options: ReturnType<typeof commandArguments>): {
|
|
10
|
+
name: string;
|
|
11
|
+
summary: string;
|
|
12
|
+
} | undefined;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { commandArgumentError } from '../cli-arguments.js';
|
|
5
|
+
import { cliLinkSchema, cliProjectCreateInputSchema, cliProjectCreateReceiptSchema, cliProjectListQuerySchema, cliProjectListSchema, } from '../contracts/cli-transport.js';
|
|
6
|
+
import { linkSchema } from './state-schema.js';
|
|
7
|
+
import { readPrivate, withProjectLock, writePrivate } from './state.js';
|
|
8
|
+
const projectCreateState = z
|
|
9
|
+
.object({
|
|
10
|
+
origin: z.string(),
|
|
11
|
+
principalId: z.uuid(),
|
|
12
|
+
teamId: z.uuid(),
|
|
13
|
+
input: cliProjectCreateInputSchema,
|
|
14
|
+
receipt: cliProjectCreateReceiptSchema.optional(),
|
|
15
|
+
})
|
|
16
|
+
.strict();
|
|
17
|
+
export async function runProjects({ options, origin, actor, token, stateDir, linkPath, request, emit, platformFailure, projectInput, }) {
|
|
18
|
+
const selectedTeam = options.value('--team') ?? actor.teamId;
|
|
19
|
+
if (options.positional[0] === 'list') {
|
|
20
|
+
const query = cliProjectListQuerySchema.parse({
|
|
21
|
+
...(options.has('--limit') ? { limit: options.value('--limit') } : {}),
|
|
22
|
+
...(options.has('--cursor') ? { cursor: options.value('--cursor') } : {}),
|
|
23
|
+
});
|
|
24
|
+
const params = new URLSearchParams({ limit: String(query.limit) });
|
|
25
|
+
if (query.cursor)
|
|
26
|
+
params.set('cursor', query.cursor);
|
|
27
|
+
const result = cliProjectListSchema.parse(await request(`/projects?${params}`, 'GET', undefined, token, selectedTeam ?? undefined));
|
|
28
|
+
if (result.principalId !== actor.principalId ||
|
|
29
|
+
(selectedTeam && result.team?.id !== selectedTeam) ||
|
|
30
|
+
result.projects.some((project) => project.teamId !== result.team?.id))
|
|
31
|
+
throw platformFailure('Project list identity differs.');
|
|
32
|
+
emit(result);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!selectedTeam)
|
|
36
|
+
throw platformFailure('No team is selected. Run anhedral projects list to discover available teams, then use --team <uuid>.');
|
|
37
|
+
await withProjectLock(stateDir, async () => {
|
|
38
|
+
const journalPath = join(stateDir, 'project-create.json');
|
|
39
|
+
const previous = await readPrivate(journalPath);
|
|
40
|
+
let state = previous === null ? null : projectCreateState.parse(previous);
|
|
41
|
+
if (state &&
|
|
42
|
+
!options.has('--new') &&
|
|
43
|
+
(state.origin !== origin ||
|
|
44
|
+
state.principalId !== actor.principalId ||
|
|
45
|
+
state.teamId !== selectedTeam ||
|
|
46
|
+
state.input.name !== projectInput.name ||
|
|
47
|
+
state.input.summary !== projectInput.summary))
|
|
48
|
+
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.');
|
|
49
|
+
if (!state || options.has('--new'))
|
|
50
|
+
state = {
|
|
51
|
+
origin,
|
|
52
|
+
principalId: actor.principalId,
|
|
53
|
+
teamId: selectedTeam,
|
|
54
|
+
input: cliProjectCreateInputSchema.parse({
|
|
55
|
+
protocol: 1,
|
|
56
|
+
requestId: randomUUID(),
|
|
57
|
+
...projectInput,
|
|
58
|
+
}),
|
|
59
|
+
};
|
|
60
|
+
const checkLink = async () => {
|
|
61
|
+
const value = await readPrivate(linkPath);
|
|
62
|
+
if (value === null)
|
|
63
|
+
return;
|
|
64
|
+
const existing = linkSchema.parse(value);
|
|
65
|
+
if (existing.origin !== origin ||
|
|
66
|
+
existing.principalId !== actor.principalId ||
|
|
67
|
+
existing.teamId !== selectedTeam ||
|
|
68
|
+
existing.projectId !== state.input.requestId)
|
|
69
|
+
throw platformFailure('A different local project link exists. Use another working directory or explicitly unlink before creating with --link.');
|
|
70
|
+
};
|
|
71
|
+
if (options.has('--link'))
|
|
72
|
+
await checkLink();
|
|
73
|
+
await writePrivate(journalPath, state);
|
|
74
|
+
const receipt = cliProjectCreateReceiptSchema.parse(await request('/projects', 'POST', state.input, token, selectedTeam));
|
|
75
|
+
if (receipt.requestId !== state.input.requestId ||
|
|
76
|
+
receipt.projectId !== state.input.requestId ||
|
|
77
|
+
receipt.principalId !== actor.principalId ||
|
|
78
|
+
receipt.teamId !== selectedTeam ||
|
|
79
|
+
receipt.name !== state.input.name ||
|
|
80
|
+
receipt.summary !== state.input.summary)
|
|
81
|
+
throw platformFailure('Project creation receipt identity or input differs. Preserve saved retry state.');
|
|
82
|
+
state = { ...state, receipt };
|
|
83
|
+
await writePrivate(journalPath, state);
|
|
84
|
+
if (options.has('--link')) {
|
|
85
|
+
await checkLink();
|
|
86
|
+
const link = cliLinkSchema.parse(await request('/link', 'POST', { projectId: receipt.projectId, teamId: selectedTeam }, token, selectedTeam));
|
|
87
|
+
if (link.principalId !== actor.principalId ||
|
|
88
|
+
link.projectId !== receipt.projectId ||
|
|
89
|
+
link.teamId !== selectedTeam)
|
|
90
|
+
throw platformFailure('Project link identity differs.');
|
|
91
|
+
await checkLink();
|
|
92
|
+
await writePrivate(linkPath, { ...link, origin });
|
|
93
|
+
}
|
|
94
|
+
emit({ ...receipt, linked: options.has('--link') });
|
|
95
|
+
});
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
export function validateProjects(options) {
|
|
99
|
+
const operation = options.positional[0];
|
|
100
|
+
if (options.has('--team') && !z.uuid().safeParse(options.value('--team')).success)
|
|
101
|
+
throw commandArgumentError('projects', 'Supply a team UUID with --team.');
|
|
102
|
+
if (operation === 'list') {
|
|
103
|
+
if (['--name', '--summary', '--link', '--dry-run', '--new'].some((flag) => options.has(flag)))
|
|
104
|
+
throw commandArgumentError('projects', 'Creation options apply to projects create only.');
|
|
105
|
+
const query = cliProjectListQuerySchema.safeParse({
|
|
106
|
+
...(options.has('--limit') ? { limit: options.value('--limit') } : {}),
|
|
107
|
+
...(options.has('--cursor') ? { cursor: options.value('--cursor') } : {}),
|
|
108
|
+
});
|
|
109
|
+
if (!query.success || (options.has('--limit') && !/^[0-9]+$/.test(options.value('--limit'))))
|
|
110
|
+
throw commandArgumentError('projects', 'Use --limit 1–100 and an optional cursor UUID.');
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
if (options.has('--limit') || options.has('--cursor'))
|
|
114
|
+
throw commandArgumentError('projects', 'Pagination options apply to projects list only.');
|
|
115
|
+
const parsed = cliProjectCreateInputSchema.safeParse({
|
|
116
|
+
protocol: 1,
|
|
117
|
+
requestId: randomUUID(),
|
|
118
|
+
name: options.value('--name'),
|
|
119
|
+
summary: options.value('--summary') ?? '',
|
|
120
|
+
});
|
|
121
|
+
if (!parsed.success)
|
|
122
|
+
throw commandArgumentError('projects', 'Supply --name with 1–160 characters and an optional summary up to 2000 characters.');
|
|
123
|
+
return { name: parsed.data.name, summary: parsed.data.summary };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ignore from 'ignore';
|
|
2
2
|
import { constants } from 'node:fs';
|
|
3
|
-
import { lstat, readFile, readdir
|
|
3
|
+
import { lstat, open, readFile, readdir } from 'node:fs/promises';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import
|
|
6
|
-
import { SOURCE_LIMITS, sourceContainsCredential, uploadExcluded, uploadSecret, } from '
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { platformFailure } from './
|
|
5
|
+
import { sourceContainsCredential as localCredentialMaterial } from '../../assets/security/credential-patterns.mjs';
|
|
6
|
+
import { SOURCE_LIMITS, sourceContainsCredential, uploadExcluded, uploadSecret, } from '../contracts/cli-transport.js';
|
|
7
|
+
import { packSource, setSourceExecutable, sourceInventory, validateSourcePath, } from '../contracts/source-bundle.js';
|
|
8
|
+
import { excludedSource, generatedSource, secretSource } from '../contracts/source-profile.js';
|
|
9
|
+
import { platformFailure } from './state.js';
|
|
10
10
|
export async function packageSource(root) {
|
|
11
11
|
const files = new Map();
|
|
12
12
|
let bytes = 0;
|