anhedral 0.21.0 → 0.22.1
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 +4 -2
- package/assets/contracts/deployment-provenance.json +5 -5
- package/assets/launch/router.tsx.txt +1 -0
- package/dist/cli-commands.js +5 -17
- package/dist/cli-errors.js +1 -1
- package/dist/command-schema.d.ts +1 -0
- package/dist/command-schema.js +14 -0
- package/dist/completion.js +1 -1
- package/dist/{capability-command.d.ts → composition/command.d.ts} +3 -3
- package/dist/{capability-command.js → composition/command.js} +12 -12
- 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 -8
- package/dist/contracts/cli-transport.js +0 -11
- package/dist/contracts/deployment.d.ts +4 -65
- package/dist/contracts/deployment.js +9 -60
- package/dist/contracts/production-transport.d.ts +2 -2
- package/dist/contracts/staging-transport.d.ts +2 -2
- package/dist/launch.js +5 -5
- 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} +7 -7
- 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/software-factory.md +45 -8
- package/package.json +19 -19
- package/dist/platform-command.js +0 -787
- package/dist/transaction.js +0 -716
- /package/dist/{capability-catalog.d.ts → composition/catalog.d.ts} +0 -0
- /package/dist/{capability-catalog.js → composition/catalog.js} +0 -0
- /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,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;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const linkSchema: z.ZodObject<{
|
|
3
|
+
protocol: z.ZodLiteral<1>;
|
|
4
|
+
projectId: z.ZodUUID;
|
|
5
|
+
teamId: z.ZodUUID;
|
|
6
|
+
principalId: z.ZodUUID;
|
|
7
|
+
name: z.ZodString;
|
|
8
|
+
origin: z.ZodString;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
export declare const uploadState: z.ZodObject<{
|
|
11
|
+
origin: z.ZodString;
|
|
12
|
+
principalId: z.ZodUUID;
|
|
13
|
+
input: z.ZodObject<{
|
|
14
|
+
protocol: z.ZodLiteral<1>;
|
|
15
|
+
requestId: z.ZodUUID;
|
|
16
|
+
projectId: z.ZodUUID;
|
|
17
|
+
teamId: z.ZodUUID;
|
|
18
|
+
archiveDigest: z.ZodString;
|
|
19
|
+
archiveBytes: z.ZodNumber;
|
|
20
|
+
inventoryDigest: z.ZodString;
|
|
21
|
+
cliVersion: z.ZodString;
|
|
22
|
+
chunks: z.ZodArray<z.ZodString>;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
uploadId: z.ZodOptional<z.ZodUUID>;
|
|
25
|
+
}, z.core.$strict>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { cliLinkSchema, sourceUploadInputSchema } from '../contracts/cli-transport.js';
|
|
3
|
+
export const linkSchema = cliLinkSchema.extend({ origin: z.string() }).strict();
|
|
4
|
+
export const uploadState = z
|
|
5
|
+
.object({
|
|
6
|
+
origin: z.string(),
|
|
7
|
+
principalId: z.uuid(),
|
|
8
|
+
input: sourceUploadInputSchema,
|
|
9
|
+
uploadId: z.uuid().optional(),
|
|
10
|
+
})
|
|
11
|
+
.strict();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CliFailure } from '
|
|
1
|
+
import { CliFailure } from '../cli-errors.js';
|
|
2
2
|
import { trustedLinuxCredentialHelper } from './credential-helper.js';
|
|
3
3
|
export type PlatformFailureCategory = ConstructorParameters<typeof CliFailure>[3];
|
|
4
4
|
export declare const platformFailure: (message: string, nextAction?: string, category?: PlatformFailureCategory, retryable?: boolean) => CliFailure;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
3
|
import { lstat, mkdir, open, readFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { CliArgumentError } from '../cli-arguments.js';
|
|
6
|
+
import { CliFailure } from '../cli-errors.js';
|
|
7
7
|
import { trustedLinuxCredentialHelper } from './credential-helper.js';
|
|
8
8
|
export const platformFailure = (message, nextAction = 'Run anhedral login --help.', category = 'context', retryable = false) => new CliFailure(message, 'PLATFORM_ACCESS_FAILED', nextAction, category, retryable);
|
|
9
9
|
export function platformOrigin(value = 'https://platform.anhedral.com') {
|
|
@@ -46,7 +46,6 @@ async function safeDirectory(path, privateMode = true) {
|
|
|
46
46
|
throw platformFailure('State directory must be owned by you with mode 0700.');
|
|
47
47
|
}
|
|
48
48
|
export async function readPrivate(path) {
|
|
49
|
-
// Validate every existing ancestor before following it.
|
|
50
49
|
for (let p = dirname(path);; p = dirname(p)) {
|
|
51
50
|
const info = await lstat(p).catch(() => null);
|
|
52
51
|
if (info?.isSymbolicLink() || (info && !info.isDirectory()))
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { commandArguments } from '../cli-arguments.js';
|
|
3
|
+
import type { CliFailure } from '../cli-errors.js';
|
|
4
|
+
import type { cliLinkSchema } from '../contracts/cli-transport.js';
|
|
5
|
+
import type { PlatformFailureCategory } from './state.js';
|
|
6
|
+
export type PlatformRequest = (path: string, method: string, body?: unknown, token?: string, team?: string) => Promise<unknown>;
|
|
7
|
+
export type PlatformFailure = (message: string, category?: PlatformFailureCategory, retryable?: boolean, nextAction?: string) => CliFailure;
|
|
8
|
+
export type ProjectOperation = {
|
|
9
|
+
options: ReturnType<typeof commandArguments>;
|
|
10
|
+
origin: string;
|
|
11
|
+
actor: {
|
|
12
|
+
principalId: string;
|
|
13
|
+
teamId?: string | null;
|
|
14
|
+
};
|
|
15
|
+
token: string;
|
|
16
|
+
stateDir: string;
|
|
17
|
+
linkPath: string;
|
|
18
|
+
request: PlatformRequest;
|
|
19
|
+
emit: (result: unknown) => void;
|
|
20
|
+
platformFailure: PlatformFailure;
|
|
21
|
+
};
|
|
22
|
+
export type SourceOperation = ProjectOperation & {
|
|
23
|
+
link: z.infer<typeof cliLinkSchema>;
|
|
24
|
+
uploadPath: string;
|
|
25
|
+
root: string;
|
|
26
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { SOURCE_LIMITS, sourceUploadInputSchema, sourceUploadReceiptSchema, } from '../contracts/cli-transport.js';
|
|
3
|
+
import { packageSource } from './source.js';
|
|
4
|
+
import { uploadState } from './state-schema.js';
|
|
5
|
+
import { readPrivate, writePrivate } from './state.js';
|
|
6
|
+
const hash = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
7
|
+
export async function runSourceUpload({ options, origin, actor, token, link, uploadPath, root, request, emit, platformFailure, }) {
|
|
8
|
+
const state = uploadState.safeParse(await readPrivate(uploadPath));
|
|
9
|
+
const checkedState = state.success &&
|
|
10
|
+
state.data.origin === origin &&
|
|
11
|
+
state.data.principalId === actor.principalId &&
|
|
12
|
+
state.data.input.projectId === link.projectId &&
|
|
13
|
+
state.data.input.teamId === link.teamId
|
|
14
|
+
? state.data
|
|
15
|
+
: null;
|
|
16
|
+
if (options.positional[0] === 'status') {
|
|
17
|
+
if (!checkedState?.uploadId)
|
|
18
|
+
throw platformFailure('No resumable upload is saved for this project.');
|
|
19
|
+
emit(sourceUploadReceiptSchema.parse(await request(`/uploads/${checkedState.uploadId}`, 'GET', undefined, token, link.teamId)));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const source = await packageSource(root), archiveDigest = hash(source.archive);
|
|
23
|
+
if (checkedState && checkedState.input.archiveDigest !== archiveDigest && !options.has('--new'))
|
|
24
|
+
throw platformFailure('Source changed since the saved upload. Restore those files or explicitly use source upload --new.');
|
|
25
|
+
const chunks = Array.from({ length: Math.ceil(source.archive.length / SOURCE_LIMITS.chunkBytes) }, (_, i) => source.archive.subarray(i * SOURCE_LIMITS.chunkBytes, (i + 1) * SOURCE_LIMITS.chunkBytes));
|
|
26
|
+
const input = sourceUploadInputSchema.parse({
|
|
27
|
+
protocol: 1,
|
|
28
|
+
requestId: checkedState && !options.has('--new') ? checkedState.input.requestId : randomUUID(),
|
|
29
|
+
projectId: link.projectId,
|
|
30
|
+
teamId: link.teamId,
|
|
31
|
+
archiveDigest,
|
|
32
|
+
archiveBytes: source.archive.length,
|
|
33
|
+
inventoryDigest: source.inventoryDigest,
|
|
34
|
+
cliVersion: source.cliVersion,
|
|
35
|
+
chunks: chunks.map(hash),
|
|
36
|
+
});
|
|
37
|
+
// Persist the request identity before the first network mutation, including lost responses.
|
|
38
|
+
const local = { origin, principalId: actor.principalId, input };
|
|
39
|
+
await writePrivate(uploadPath, local);
|
|
40
|
+
const receipt = sourceUploadReceiptSchema.parse(await request('/uploads', 'POST', input, token, link.teamId));
|
|
41
|
+
if (receipt.projectId !== link.projectId ||
|
|
42
|
+
receipt.requestId !== input.requestId ||
|
|
43
|
+
receipt.archiveDigest !== input.archiveDigest ||
|
|
44
|
+
receipt.inventoryDigest !== input.inventoryDigest)
|
|
45
|
+
throw platformFailure('Upload receipt identity differs.');
|
|
46
|
+
await writePrivate(uploadPath, { ...local, uploadId: receipt.id });
|
|
47
|
+
if (receipt.state === 'cancelled')
|
|
48
|
+
throw platformFailure('Upload was cancelled. Start source upload --new.');
|
|
49
|
+
if (receipt.state !== 'sealed') {
|
|
50
|
+
for (let i = 0; i < chunks.length; i++)
|
|
51
|
+
if (!receipt.received.includes(i))
|
|
52
|
+
await request(`/uploads/${receipt.id}/chunks/${i}`, 'PUT', chunks[i], token, link.teamId);
|
|
53
|
+
}
|
|
54
|
+
const complete = sourceUploadReceiptSchema.parse(await request(`/uploads/${receipt.id}/complete`, 'POST', {}, token, link.teamId));
|
|
55
|
+
if (complete.id !== receipt.id ||
|
|
56
|
+
complete.sourceRevision !== archiveDigest ||
|
|
57
|
+
complete.state !== 'sealed')
|
|
58
|
+
throw platformFailure('Source completion was not sealed. Resume this upload.');
|
|
59
|
+
emit({ ...complete, hostedAdmission: false });
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Internal synchronous-runner companion. Owns only its spawned command tree.
|
|
2
2
|
import { spawn, spawnSync } from 'node:child_process';
|
|
3
3
|
import { writeFileSync } from 'node:fs';
|
|
4
|
-
import { readBoundedFile } from '
|
|
4
|
+
import { readBoundedFile } from '../bounded-file.js';
|
|
5
5
|
const [configuration, resultFile] = process.argv.slice(2);
|
|
6
6
|
if (!configuration || !resultFile)
|
|
7
7
|
throw Error('Command runner requires private input and result files.');
|
package/dist/registry/usage.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CapabilityEditor } from '../
|
|
2
|
-
import type { Capability } from '../
|
|
1
|
+
import { CapabilityEditor } from '../composition/editor.js';
|
|
2
|
+
import type { Capability } from '../composition/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
5
|
/** One-time source upgrade, planned in the same bounded overlay as each addition. */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { ANHEDRAL_STACK_DEPENDENCIES, WEB_DEPENDENCIES } from '../dependencies.js';
|
|
3
|
-
import { CapabilityEditor, fingerprint } from '../
|
|
3
|
+
import { CapabilityEditor, fingerprint } from '../composition/editor.js';
|
|
4
4
|
import { resourceName } from '../render.js';
|
|
5
|
-
import { json, put, workerConfig } from '
|
|
5
|
+
import { json, put, workerConfig } from './files.js';
|
|
6
6
|
const template = (name) => readFileSync(new URL(`../../assets/launch/${name}`, import.meta.url), 'utf8');
|
|
7
7
|
/** The launch foundation is a web service; Hono owns application services and data. */
|
|
8
8
|
export function scaffoldTanstack(root, name) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { lstatSync } from 'node:fs';
|
|
2
|
+
export declare function lstatIfPresent(target: string): ReturnType<typeof lstatSync> | null;
|
|
3
|
+
export declare function syncDirectory(directory: string): void;
|
|
4
|
+
export declare function syncEntryRecursively(target: string): void;
|
|
5
|
+
export declare function renameDurably(source: string, target: string, root: string): void;
|
|
6
|
+
export declare function removeEntryDurably(target: string): void;
|
|
7
|
+
export declare function pathEntryExists(target: string): boolean;
|
|
8
|
+
export declare function fingerprintEntry(target: string): string;
|