@sequenceholdings/studio-cli 0.3.0 → 0.4.2
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 +506 -32
- package/dist/agents/commands.d.ts +1 -1
- package/dist/agents/commands.js +5 -0
- package/dist/agents/scaffold.js +5 -7
- package/dist/agents/voice-authoring.d.ts +5 -0
- package/dist/agents/voice-authoring.js +75 -0
- package/dist/agents/voice-publication.d.ts +5 -0
- package/dist/agents/voice-publication.js +63 -0
- package/dist/agents/voice-shared.d.ts +20 -0
- package/dist/agents/voice-shared.js +112 -0
- package/dist/agents/voice.d.ts +3 -0
- package/dist/agents/voice.js +57 -0
- package/dist/app/adapters.d.ts +6 -0
- package/dist/app/adapters.js +17 -2
- package/dist/app/agent-refs.d.ts +16 -0
- package/dist/app/agent-refs.js +36 -0
- package/dist/app/application-registration.d.ts +45 -8
- package/dist/app/application-registration.js +112 -22
- package/dist/app/commands.js +19 -2
- package/dist/app/deploy.d.ts +3 -0
- package/dist/app/deploy.js +18 -4
- package/dist/app/env-bindings.d.ts +21 -0
- package/dist/app/env-bindings.js +184 -0
- package/dist/app/manifest-validation.d.ts +8 -0
- package/dist/app/manifest-validation.js +97 -5
- package/dist/app/manifest.d.ts +45 -9
- package/dist/app/manifest.js +27 -1
- package/dist/app/primitive-scaffold.d.ts +4 -1
- package/dist/app/primitive-scaffold.js +4 -4
- package/dist/app/readme.js +11 -0
- package/dist/app/scaffold-files.js +1 -1
- package/dist/app/scaffold.d.ts +6 -4
- package/dist/app/scaffold.js +7 -4
- package/dist/app/workspace-scaffold.js +12 -7
- package/dist/argv.d.ts +7 -0
- package/dist/argv.js +56 -0
- package/dist/artifact/delegate.js +8 -4
- package/dist/atlas-client.d.ts +6 -0
- package/dist/atlas-client.js +39 -2
- package/dist/auth.d.ts +32 -0
- package/dist/auth.js +170 -33
- package/dist/bin.js +23 -4
- package/dist/command-contract.d.ts +137 -0
- package/dist/command-contract.js +43 -0
- package/dist/command-help.d.ts +8 -0
- package/dist/command-help.js +71 -0
- package/dist/functions/commands.d.ts +1 -1
- package/dist/functions/commands.js +19 -3
- package/dist/functions/deploy-preflight.d.ts +21 -0
- package/dist/functions/deploy-preflight.js +58 -0
- package/dist/functions/egress-postgres.d.ts +7 -0
- package/dist/functions/egress-postgres.js +36 -0
- package/dist/functions/manifest.d.ts +8 -0
- package/dist/functions/manifest.js +9 -0
- package/dist/functions/source-selection.js +4 -1
- package/dist/main.js +58 -20
- package/dist/orm/delegate.d.ts +16 -0
- package/dist/orm/delegate.js +140 -7
- package/dist/pipeline/clone-deploy.d.ts +37 -0
- package/dist/pipeline/clone-deploy.js +125 -0
- package/dist/pipeline/codegen.js +6 -2
- package/dist/pipeline/commands.js +21 -5
- package/dist/pipeline/lifecycle.d.ts +1 -0
- package/dist/pipeline/lifecycle.js +95 -44
- package/dist/pipeline/repin-orm.js +6 -2
- package/dist/pipeline/stage-secrets.js +1 -1
- package/dist/process/build.js +17 -0
- package/dist/process/codegen.js +16 -0
- package/dist/process/commands.d.ts +15 -7
- package/dist/process/commands.js +291 -99
- package/dist/process/lint.js +35 -0
- package/dist/process/plan-diff.js +9 -0
- package/dist/process/simulate.js +8 -0
- package/dist/release-age.d.ts +12 -0
- package/dist/release-age.js +24 -0
- package/dist/repos/commands.d.ts +1 -1
- package/dist/repos/commands.js +36 -7
- package/dist/scaffold-guidance.d.ts +4 -0
- package/dist/scaffold-guidance.js +15 -0
- package/dist/storage/commands.js +23 -1
- package/dist/storage/gcs-download.d.ts +13 -0
- package/dist/storage/gcs-download.js +41 -0
- package/dist/storage/import-cycle.d.ts +41 -0
- package/dist/storage/import-cycle.js +123 -0
- package/dist/storage/import-files.d.ts +30 -0
- package/dist/storage/import-files.js +133 -0
- package/dist/storage/import-gcloud.d.ts +12 -0
- package/dist/storage/import-gcloud.js +54 -0
- package/dist/storage/import-identity.d.ts +12 -0
- package/dist/storage/import-identity.js +15 -0
- package/dist/storage/import-plan.d.ts +120 -0
- package/dist/storage/import-plan.js +189 -0
- package/dist/storage/import-preflight.d.ts +36 -0
- package/dist/storage/import-preflight.js +62 -0
- package/dist/storage/import-progress-map.d.ts +5 -0
- package/dist/storage/import-progress-map.js +22 -0
- package/dist/storage/import-recover.d.ts +97 -0
- package/dist/storage/import-recover.js +186 -0
- package/dist/storage/import-run.d.ts +14 -0
- package/dist/storage/import-run.js +140 -0
- package/dist/templates/guidance/AGENTS.md +10 -0
- package/dist/templates/guidance/CLAUDE.md +1 -0
- package/dist/templates/process/package.json +2 -2
- package/dist/templates/process/pnpm-workspace.yaml +7 -4
- package/dist/validation-detail.d.ts +2 -0
- package/dist/validation-detail.js +20 -0
- package/package.json +10 -10
- package/templates/guidance/AGENTS.md +10 -0
- package/templates/guidance/CLAUDE.md +1 -0
- package/templates/process/package.json +2 -2
- package/templates/process/pnpm-workspace.yaml +7 -4
|
@@ -2,40 +2,56 @@
|
|
|
2
2
|
* Registering a schema_version 3 app with Atlas as an Application, after its
|
|
3
3
|
* primitives deploy (`PUT /api/custom-roles/applications/<app.id>`).
|
|
4
4
|
*
|
|
5
|
+
* Members the deployer doesn't administer aren't an error: Atlas records a
|
|
6
|
+
* consent request for their admins and the deploy succeeds with those
|
|
7
|
+
* members' includes dormant. The log says who to ask.
|
|
8
|
+
*
|
|
5
9
|
* The YAML's `role: end_user | invoker` alias becomes the server's single
|
|
6
10
|
* `{ type: 'end_user' }` spelling here, so the API has one contract. Members
|
|
7
|
-
* are the artifact/function/ORM primitives
|
|
8
|
-
* referenced by the stable names that resolve in every environment
|
|
11
|
+
* are the artifact/function/ORM primitives, single-process entries and
|
|
12
|
+
* pipelines, referenced by the stable names that resolve in every environment,
|
|
13
|
+
* single-agent entries, referenced by the agent id they deploy to the target
|
|
14
|
+
* environment (agent-refs.ts), the app's `secrets`, by name, and its
|
|
15
|
+
* `service_accounts`, by slug.
|
|
9
16
|
*/
|
|
10
17
|
import { AtlasApiError, putJson } from '../atlas-client.js';
|
|
11
18
|
import { buildContext, clientOptions } from '../functions/commands.js';
|
|
19
|
+
import { pipelineReleaseUnit } from './adapters.js';
|
|
12
20
|
import { isFloorRoleAlias } from './manifest.js';
|
|
13
21
|
const LOG = '[seq-studio]';
|
|
14
22
|
/**
|
|
15
|
-
* The member ref Atlas resolves: project slug, function slug, namespace,
|
|
16
|
-
* — for a process entry that deploys exactly one
|
|
23
|
+
* The member ref Atlas resolves: project slug, function slug, namespace, a
|
|
24
|
+
* pipeline's release unit, or — for a process entry that deploys exactly one
|
|
25
|
+
* process — its process id, or — for an agent entry that deploys exactly one
|
|
26
|
+
* agent — that agent's id here.
|
|
17
27
|
*/
|
|
18
|
-
function memberOf(entry) {
|
|
28
|
+
function memberOf(entry, agentRefs) {
|
|
29
|
+
const agentId = entry.kind === 'agent' ? agentRefs.get(entry.id) : undefined;
|
|
30
|
+
if (agentId)
|
|
31
|
+
return { key: entry.id, kind: 'agent', ref: agentId };
|
|
19
32
|
if (entry.kind === 'artifact' && entry.project_id)
|
|
20
33
|
return { key: entry.id, kind: 'artifact', ref: entry.project_id };
|
|
21
34
|
if (entry.kind === 'function' && entry.slug)
|
|
22
35
|
return { key: entry.id, kind: 'function', ref: entry.slug };
|
|
23
36
|
if (entry.kind === 'orm' && entry.namespace)
|
|
24
37
|
return { key: entry.id, kind: 'orm', ref: entry.namespace };
|
|
38
|
+
const releaseUnit = entry.kind === 'pipeline' ? pipelineReleaseUnit(entry) : undefined;
|
|
39
|
+
if (releaseUnit)
|
|
40
|
+
return { key: entry.id, kind: 'pipeline', ref: releaseUnit };
|
|
25
41
|
const [processId, ...more] = entry.kind === 'process' ? (entry.only ?? []) : [];
|
|
26
42
|
if (processId && more.length === 0)
|
|
27
43
|
return { key: entry.id, kind: 'lattice', ref: processId };
|
|
28
44
|
return null;
|
|
29
45
|
}
|
|
30
|
-
function componentRef(entry) {
|
|
46
|
+
function componentRef(entry, agentRefs) {
|
|
31
47
|
switch (entry.kind) {
|
|
32
48
|
case 'artifact': return entry.project_id;
|
|
33
49
|
case 'function': return entry.slug;
|
|
34
50
|
case 'orm': return entry.namespace;
|
|
35
51
|
case 'workspace': return entry.name;
|
|
36
52
|
case 'process': return entry.only?.length === 1 ? entry.only[0] : undefined;
|
|
37
|
-
case '
|
|
38
|
-
case '
|
|
53
|
+
case 'pipeline': return pipelineReleaseUnit(entry);
|
|
54
|
+
case 'agent': return agentRefs.get(entry.id) ?? (entry.only?.length === 1 ? entry.only[0] : undefined);
|
|
39
55
|
}
|
|
40
56
|
}
|
|
41
57
|
function collaboratorRolesOf(manifest) {
|
|
@@ -48,7 +64,12 @@ function collaboratorRolesOf(manifest) {
|
|
|
48
64
|
},
|
|
49
65
|
]));
|
|
50
66
|
}
|
|
51
|
-
|
|
67
|
+
/**
|
|
68
|
+
* `agentRefs`: primitive id -> the agent an agent entry deploys (see
|
|
69
|
+
* agent-refs.ts). Without it, an agent component names its agent only when
|
|
70
|
+
* `only` selects exactly one.
|
|
71
|
+
*/
|
|
72
|
+
export function buildApplicationDeployBody(manifest, { agentRefs = new Map() } = {}) {
|
|
52
73
|
const roles = {};
|
|
53
74
|
for (const [key, definition] of Object.entries(manifest.roles?.definitions ?? {})) {
|
|
54
75
|
roles[key] = {
|
|
@@ -68,14 +89,22 @@ export function buildApplicationDeployBody(manifest) {
|
|
|
68
89
|
return {
|
|
69
90
|
title: manifest.app.title,
|
|
70
91
|
...(manifest.app.description !== undefined ? { description: manifest.app.description } : {}),
|
|
71
|
-
members:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
92
|
+
members: [
|
|
93
|
+
...manifest.primitives.flatMap((entry) => {
|
|
94
|
+
const member = memberOf(entry, agentRefs);
|
|
95
|
+
return member ? [member] : [];
|
|
96
|
+
}),
|
|
97
|
+
...(manifest.secrets ?? []).map((secret) => ({ key: secret.id, kind: 'secret', ref: secret.name })),
|
|
98
|
+
...(manifest.service_accounts ?? []).map((account) => ({ key: account.id, kind: 'service_account', ref: account.slug })),
|
|
99
|
+
],
|
|
100
|
+
components: [
|
|
101
|
+
...manifest.primitives.map((entry) => {
|
|
102
|
+
const ref = componentRef(entry, agentRefs);
|
|
103
|
+
return { key: entry.id, kind: entry.kind, ...(ref !== undefined ? { ref } : {}) };
|
|
104
|
+
}),
|
|
105
|
+
...(manifest.secrets ?? []).map((secret) => ({ key: secret.id, kind: 'secret', ref: secret.name })),
|
|
106
|
+
...(manifest.service_accounts ?? []).map((account) => ({ key: account.id, kind: 'service_account', ref: account.slug })),
|
|
107
|
+
],
|
|
79
108
|
edges: manifest.primitives.flatMap((entry) => entry.uses.map((use) => ({ from: entry.id, to: use.primitive, ...(use.as !== undefined ? { label: use.as } : {}) }))),
|
|
80
109
|
roles,
|
|
81
110
|
collaborators: collaboratorRolesOf(manifest),
|
|
@@ -86,6 +115,18 @@ function asRecord(value) {
|
|
|
86
115
|
return value && typeof value === 'object' ? Object.fromEntries(Object.entries(value)) : {};
|
|
87
116
|
}
|
|
88
117
|
const isString = (value) => typeof value === 'string';
|
|
118
|
+
const MEMBER_KINDS = ['artifact', 'function', 'orm', 'lattice', 'pipeline', 'agent', 'secret', 'service_account'];
|
|
119
|
+
const isMemberKind = (value) => MEMBER_KINDS.some((kind) => kind === value);
|
|
120
|
+
const MEMBER_KIND_LABEL = {
|
|
121
|
+
artifact: 'artifact',
|
|
122
|
+
function: 'function',
|
|
123
|
+
orm: 'ORM namespace',
|
|
124
|
+
lattice: 'Lattice process',
|
|
125
|
+
pipeline: 'pipeline',
|
|
126
|
+
agent: 'agent',
|
|
127
|
+
secret: 'secret',
|
|
128
|
+
service_account: 'service account',
|
|
129
|
+
};
|
|
89
130
|
/** Server-side detail worth printing beyond the error message. */
|
|
90
131
|
function errorDetailLines(error) {
|
|
91
132
|
const record = asRecord(error.body);
|
|
@@ -101,13 +142,42 @@ function errorDetailLines(error) {
|
|
|
101
142
|
}
|
|
102
143
|
return lines;
|
|
103
144
|
}
|
|
104
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Agent entries a role or collaborator role includes that didn't resolve to
|
|
147
|
+
* exactly one agent (a directory of several, or one the deploy couldn't read):
|
|
148
|
+
* such a role would reach no agent, so registering it is refused up front.
|
|
149
|
+
*/
|
|
150
|
+
export function unresolvedAgentIncludes(manifest, agentRefs) {
|
|
151
|
+
const agentEntries = new Set(manifest.primitives.filter((entry) => entry.kind === 'agent').map((entry) => entry.id));
|
|
152
|
+
const included = [
|
|
153
|
+
...Object.values(manifest.roles?.definitions ?? {}).flatMap((definition) => definition.includes),
|
|
154
|
+
...Object.values(manifest.collaborators?.definitions ?? {}).flatMap((definition) => definition.includes),
|
|
155
|
+
].map((include) => include.primitive);
|
|
156
|
+
return [...new Set(included.filter((id) => agentEntries.has(id) && !agentRefs.has(id)))];
|
|
157
|
+
}
|
|
158
|
+
export async function putApplication({ client, manifest, agentRefs = new Map(), }) {
|
|
159
|
+
const unresolved = unresolvedAgentIncludes(manifest, agentRefs);
|
|
160
|
+
if (unresolved.length > 0) {
|
|
161
|
+
return {
|
|
162
|
+
status: 'failed',
|
|
163
|
+
message: `roles include agent entries that don't deploy exactly one agent here: ${unresolved.join(', ')}. ` +
|
|
164
|
+
'Set only: [<agent-id>] on each so its roles reach one agent.',
|
|
165
|
+
};
|
|
166
|
+
}
|
|
105
167
|
const path = `/api/custom-roles/applications/${encodeURIComponent(manifest.app.id)}`;
|
|
106
168
|
try {
|
|
107
169
|
const response = await putJson({
|
|
108
170
|
...client,
|
|
109
171
|
path,
|
|
110
|
-
body: buildApplicationDeployBody(manifest),
|
|
172
|
+
body: buildApplicationDeployBody(manifest, { agentRefs }),
|
|
173
|
+
});
|
|
174
|
+
const consent = asRecord(response.consent);
|
|
175
|
+
const requested = (Array.isArray(consent.requested) ? consent.requested : []).flatMap((entry) => {
|
|
176
|
+
const { member, hostType, naturalKey, level, previously } = asRecord(entry);
|
|
177
|
+
const kind = isMemberKind(hostType) ? hostType : null;
|
|
178
|
+
return isString(member) && kind && isString(naturalKey) && isString(level)
|
|
179
|
+
? [{ member, kind, ref: naturalKey, level, previously: isString(previously) ? previously : null }]
|
|
180
|
+
: [];
|
|
111
181
|
});
|
|
112
182
|
const warnings = (Array.isArray(response.warnings) ? response.warnings : []).flatMap((warning) => {
|
|
113
183
|
const { type, role, kind, detail } = asRecord(warning);
|
|
@@ -120,7 +190,8 @@ export async function putApplication({ client, manifest, }) {
|
|
|
120
190
|
}]
|
|
121
191
|
: [];
|
|
122
192
|
});
|
|
123
|
-
|
|
193
|
+
const accessUrl = new URL(`/permissions/applications/application/${encodeURIComponent(manifest.app.id)}?tab=roles`, client.baseUrl).toString();
|
|
194
|
+
return { status: 'registered', created: response.created === true, warnings, requested, accessUrl };
|
|
124
195
|
}
|
|
125
196
|
catch (error) {
|
|
126
197
|
if (!(error instanceof AtlasApiError))
|
|
@@ -135,12 +206,31 @@ export function logApplicationRegistration({ appId, registration, }) {
|
|
|
135
206
|
}
|
|
136
207
|
console.log(`${LOG} ✓ Application "${appId}" ${registration.created ? 'registered' : 'synced'}`);
|
|
137
208
|
for (const warning of registration.warnings) {
|
|
209
|
+
// Consent requests print below, with who to ask.
|
|
210
|
+
if (warning.type === 'consent_requested')
|
|
211
|
+
continue;
|
|
138
212
|
const section = warning.kind === 'collaborator' ? 'collaborators' : warning.kind === 'capability' ? 'capabilities' : 'roles';
|
|
139
213
|
console.warn(`${LOG} ! ${section}.${warning.role}: ${warning.detail}`);
|
|
140
214
|
}
|
|
215
|
+
// Roles live in Atlas, so that's where a gap is closed: each offers adding the missing "Can use".
|
|
216
|
+
if (registration.accessUrl && registration.warnings.some((warning) => warning.type === 'access_gap')) {
|
|
217
|
+
console.warn(`${LOG} Fix access gaps from Runtime access, one click each: ${registration.accessUrl}`);
|
|
218
|
+
}
|
|
219
|
+
const requested = registration.requested ?? [];
|
|
220
|
+
if (requested.length > 0) {
|
|
221
|
+
console.warn(`${LOG} Waiting for consent — roles that include these members take effect once their admins allow "${appId}":`);
|
|
222
|
+
for (const request of requested) {
|
|
223
|
+
const what = request.kind === 'service_account'
|
|
224
|
+
? 'to let collaborator roles give Actor'
|
|
225
|
+
: request.level === 'collaborator' ? 'to bundle its edit tiers' : 'to give people access';
|
|
226
|
+
const before = request.previously ? ` (previously ${request.previously})` : '';
|
|
227
|
+
console.warn(`${LOG} ${request.member}: ${MEMBER_KIND_LABEL[request.kind]} "${request.ref}" — ask its admins ${what}${before}`);
|
|
228
|
+
}
|
|
229
|
+
console.warn(`${LOG} Admins approve from Permissions → the member → Applications, or by redeploying as someone who administers it.`);
|
|
230
|
+
}
|
|
141
231
|
}
|
|
142
232
|
/** Default registrar: authenticate against `env` the same way the primitive deployers do. */
|
|
143
|
-
export const registerApplicationWithAtlas = async ({ manifest, env }) => {
|
|
233
|
+
export const registerApplicationWithAtlas = async ({ manifest, env, agentRefs }) => {
|
|
144
234
|
const context = await buildContext({ positional: [], flags: { env } });
|
|
145
|
-
return putApplication({ client: clientOptions(context), manifest });
|
|
235
|
+
return putApplication({ client: clientOptions(context), manifest, agentRefs });
|
|
146
236
|
};
|
package/dist/app/commands.js
CHANGED
|
@@ -18,7 +18,7 @@ export const APP_INIT_USAGE = `usage:
|
|
|
18
18
|
seq-studio init <dir> --orm --function --artifact [options]
|
|
19
19
|
|
|
20
20
|
Scaffold an app monorepo with ${APP_MANIFEST_FILENAME}, a Sequence app
|
|
21
|
-
README.md
|
|
21
|
+
README.md, AGENTS.md + CLAUDE.md guidance, and one subfolder per
|
|
22
22
|
selected primitive. At least one kind is required. A git-service clone
|
|
23
23
|
whose README.md contains the seq-studio seed marker is a valid target;
|
|
24
24
|
ordinary docs-only repositories are refused so we do not overwrite them.
|
|
@@ -30,6 +30,7 @@ export const APP_INIT_USAGE = `usage:
|
|
|
30
30
|
--orm --function … boolean aliases for --with
|
|
31
31
|
--function-name <n> name/slug for the first function (default: hello)
|
|
32
32
|
--pipeline-type <t> ingestion, transformation (default), or serving
|
|
33
|
+
--template <t> artifact template: react-vite (default) or nextjs
|
|
33
34
|
--description <text> optional app.description in the manifest
|
|
34
35
|
|
|
35
36
|
Examples:
|
|
@@ -39,7 +40,7 @@ export const APP_INIT_USAGE = `usage:
|
|
|
39
40
|
seq-studio init review-app --with orm,function,agent,process,pipeline,artifact
|
|
40
41
|
`;
|
|
41
42
|
export const APP_ADD_USAGE = `usage:
|
|
42
|
-
seq-studio add <kind> <name> [--depends-on <ids>] [--pipeline-type <type>]
|
|
43
|
+
seq-studio add <kind> <name> [--depends-on <ids>] [--pipeline-type <type>] [--template <t>]
|
|
43
44
|
seq-studio add package <name>
|
|
44
45
|
|
|
45
46
|
Scaffold another primitive into the current app monorepo (must contain
|
|
@@ -49,10 +50,14 @@ export const APP_ADD_USAGE = `usage:
|
|
|
49
50
|
|
|
50
51
|
--depends-on <ids> comma-separated prerequisite primitive ids
|
|
51
52
|
--pipeline-type <t> ingestion, transformation (default), or serving
|
|
53
|
+
--template <t> artifact template: react-vite (default) or nextjs. A
|
|
54
|
+
Next.js artifact keeps its own pnpm-lock.yaml outside
|
|
55
|
+
the app workspace, as hosted builds require.
|
|
52
56
|
|
|
53
57
|
Examples:
|
|
54
58
|
seq-studio add function list-types
|
|
55
59
|
seq-studio add artifact ui
|
|
60
|
+
seq-studio add artifact portal --template nextjs
|
|
56
61
|
seq-studio add agent reviewer --depends-on list-types
|
|
57
62
|
seq-studio add process approvals --depends-on reviewer-agent
|
|
58
63
|
seq-studio add orm audit
|
|
@@ -105,6 +110,16 @@ function pipelineTypeFlag(flags) {
|
|
|
105
110
|
return value;
|
|
106
111
|
throw new Error('--pipeline-type requires ingestion, transformation, or serving');
|
|
107
112
|
}
|
|
113
|
+
function artifactTemplateFlag({ flags, kinds }) {
|
|
114
|
+
const value = flags.template;
|
|
115
|
+
if (value === undefined)
|
|
116
|
+
return undefined;
|
|
117
|
+
if (value !== 'react-vite' && value !== 'nextjs')
|
|
118
|
+
throw new Error('--template requires react-vite or nextjs');
|
|
119
|
+
if (!kinds.includes('artifact'))
|
|
120
|
+
throw new Error('--template only applies when scaffolding an artifact');
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
108
123
|
function printError(error) {
|
|
109
124
|
const message = error instanceof Error ? error.message : String(error);
|
|
110
125
|
console.error(`${LOG} ${message}`);
|
|
@@ -160,6 +175,7 @@ export async function runAppInitCommand(args) {
|
|
|
160
175
|
names,
|
|
161
176
|
description,
|
|
162
177
|
pipelineType: pipelineTypeFlag(args.flags),
|
|
178
|
+
artifactTemplate: artifactTemplateFlag({ flags: args.flags, kinds }),
|
|
163
179
|
});
|
|
164
180
|
printInitNextSteps({ appRoot, manifest });
|
|
165
181
|
return 0;
|
|
@@ -209,6 +225,7 @@ export async function runAppAddCommand({ kindArg, args, }) {
|
|
|
209
225
|
kind: kindArg,
|
|
210
226
|
name,
|
|
211
227
|
pipelineType: pipelineTypeFlag(args.flags),
|
|
228
|
+
artifactTemplate: artifactTemplateFlag({ flags: args.flags, kinds: [kindArg] }),
|
|
212
229
|
dependsOn,
|
|
213
230
|
});
|
|
214
231
|
console.log(`${LOG} added ${entry.kind} "${entry.id}" at ${entry.path}`);
|
package/dist/app/deploy.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { resolveContainedPrimitivePath } from './paths.js';
|
|
|
8
8
|
import { type ApplicationRegistration, type RegisterApplication } from './application-registration.js';
|
|
9
9
|
export { createDefaultDeployers } from './adapters.js';
|
|
10
10
|
import { type AppManifest, type PrimitiveEntry, type PrimitiveKind } from './manifest.js';
|
|
11
|
+
import { type EnvironmentBindingContext } from './env-bindings.js';
|
|
11
12
|
export type DeployPrimitiveArgs = {
|
|
12
13
|
entry: PrimitiveEntry;
|
|
13
14
|
/** Absolute path to the primitive directory. */
|
|
@@ -34,6 +35,8 @@ export type DeployAppOptions = {
|
|
|
34
35
|
waitTimeout?: string;
|
|
35
36
|
/** Registers a schema_version 3 app with Atlas after its primitives deploy. */
|
|
36
37
|
registerApplication?: RegisterApplication;
|
|
38
|
+
/** Resolves environment origins and workspace names. Tests inject this; deploys discover it. */
|
|
39
|
+
environmentBindings?: () => Promise<EnvironmentBindingContext>;
|
|
37
40
|
};
|
|
38
41
|
export type DeployAppResult = {
|
|
39
42
|
attempted: string[];
|
package/dist/app/deploy.js
CHANGED
|
@@ -9,6 +9,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
9
9
|
import { existsSync } from 'node:fs';
|
|
10
10
|
import { join, resolve } from 'node:path';
|
|
11
11
|
import { ensureAppOutputDirectory, resolveContainedPrimitivePath } from './paths.js';
|
|
12
|
+
import { agentComponentRefs } from './agent-refs.js';
|
|
12
13
|
export { resolveContainedPrimitivePath } from './paths.js';
|
|
13
14
|
import { executeDeployment } from './run-deployment.js';
|
|
14
15
|
import { buildApplicationDeployBody, logApplicationRegistration, registerApplicationWithAtlas, } from './application-registration.js';
|
|
@@ -20,6 +21,7 @@ import { assertActiveDeployProvenance } from '@sequenceholdings/artifact-studio/
|
|
|
20
21
|
export { createDefaultDeployers } from './adapters.js';
|
|
21
22
|
import { defaultDeployOrder, loadAppManifest, usesAppGraph, } from './manifest.js';
|
|
22
23
|
import { warnOnManifestRoles } from '../manifest-roles-notice.js';
|
|
24
|
+
import { assertAppEnvironmentBindings } from './env-bindings.js';
|
|
23
25
|
const LOG = '[seq-studio]';
|
|
24
26
|
const APP_MANIFEST_HINT = 'sequence.app.yml';
|
|
25
27
|
/**
|
|
@@ -28,7 +30,7 @@ const APP_MANIFEST_HINT = 'sequence.app.yml';
|
|
|
28
30
|
* fails the deploy. Never throws: the primitives have already deployed, so
|
|
29
31
|
* even a network or auth failure must reach the deployment report.
|
|
30
32
|
*/
|
|
31
|
-
async function registerApplicationStep({ manifest, options, result, }) {
|
|
33
|
+
async function registerApplicationStep({ manifest, options, result, rootDir, }) {
|
|
32
34
|
if (manifest.schema_version !== 3)
|
|
33
35
|
return;
|
|
34
36
|
if (result.exitCode !== 0) {
|
|
@@ -37,7 +39,8 @@ async function registerApplicationStep({ manifest, options, result, }) {
|
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
39
41
|
const register = options.registerApplication ?? registerApplicationWithAtlas;
|
|
40
|
-
const
|
|
42
|
+
const agentRefs = await agentComponentRefs({ manifest, rootDir, env: options.env });
|
|
43
|
+
const registration = await register({ manifest, env: options.env, agentRefs }).catch((error) => ({
|
|
41
44
|
status: 'failed',
|
|
42
45
|
message: error instanceof Error ? error.message : String(error),
|
|
43
46
|
}));
|
|
@@ -84,7 +87,10 @@ function assertAppDeploymentSource({ manifest, options, rootDir, entries }) {
|
|
|
84
87
|
// Shared sources live outside the UI directory. Check the entire original
|
|
85
88
|
// app before packaging so ignored staging cannot conceal a dirty package.
|
|
86
89
|
if (usesAppGraph(manifest) && options.env !== 'local' && entries.some((entry) => entry.kind === 'artifact')) {
|
|
87
|
-
assertActiveDeployProvenance(
|
|
90
|
+
assertActiveDeployProvenance({
|
|
91
|
+
...localGitMetadata(rootDir),
|
|
92
|
+
environment: options.env,
|
|
93
|
+
});
|
|
88
94
|
}
|
|
89
95
|
if (usesAppGraph(manifest) && manifest.packages?.length && options.env !== 'local' && !options.dryRun && !existsSync(join(rootDir, 'pnpm-lock.yaml'))) {
|
|
90
96
|
throw new Error('App workspace deployment requires a root pnpm-lock.yaml. Run pnpm install at the app root and commit the lockfile before deploying.');
|
|
@@ -111,6 +117,14 @@ export async function deployApp(options) {
|
|
|
111
117
|
console.log(`${LOG} - ${entry.kind.padEnd(9)} ${entry.id} (${entry.path})`);
|
|
112
118
|
}
|
|
113
119
|
assertAppDeploymentSource({ manifest, options, rootDir, entries });
|
|
120
|
+
await assertAppEnvironmentBindings({
|
|
121
|
+
manifest,
|
|
122
|
+
entries,
|
|
123
|
+
paths: resolvedPaths,
|
|
124
|
+
rootDir,
|
|
125
|
+
deployEnvironment: options.env,
|
|
126
|
+
...(options.environmentBindings ? { loadContext: options.environmentBindings } : {}),
|
|
127
|
+
});
|
|
114
128
|
const provenance = localGitMetadata(rootDir);
|
|
115
129
|
const prepared = usesAppGraph(manifest)
|
|
116
130
|
? await prepareAppWorkspace({ rootDir, manifest, entries, paths: resolvedPaths })
|
|
@@ -148,7 +162,7 @@ export async function deployApp(options) {
|
|
|
148
162
|
const reportDir = usesAppGraph(manifest)
|
|
149
163
|
? await ensureAppOutputDirectory({ rootDir, entryPath: '.sequence/deployments' }) : undefined;
|
|
150
164
|
const result = await executeDeployment({ entries, onError, deployers, argsFor });
|
|
151
|
-
await registerApplicationStep({ manifest, options, result });
|
|
165
|
+
await registerApplicationStep({ manifest, options, result, rootDir });
|
|
152
166
|
if (reportDir) {
|
|
153
167
|
result.reportPath = join(reportDir, `${encodeURIComponent(options.env)}.json`);
|
|
154
168
|
const temporaryReport = join(reportDir, `${randomUUID()}.tmp`);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type NamedOrigin } from '@sequenceholdings/artifact-studio/deployment-validation';
|
|
2
|
+
import type { AppManifest, PrimitiveEntry } from './manifest.js';
|
|
3
|
+
export interface EnvironmentBindingContext {
|
|
4
|
+
deployOrigin: string;
|
|
5
|
+
origins: readonly NamedOrigin[];
|
|
6
|
+
resolveWorkspaceByName: (workspaceName: string) => Promise<string | undefined>;
|
|
7
|
+
workspaceExists: (workspaceId: string) => Promise<boolean>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Resolve `uses` workspace names and artifact `targets` in the selected
|
|
11
|
+
* environment, then refuse the deploy when source still points elsewhere.
|
|
12
|
+
* Apps with no scannable source and no workspace edges skip the lookup.
|
|
13
|
+
*/
|
|
14
|
+
export declare function assertAppEnvironmentBindings({ manifest, entries, paths, rootDir, deployEnvironment, loadContext, }: {
|
|
15
|
+
manifest: AppManifest;
|
|
16
|
+
entries: readonly PrimitiveEntry[];
|
|
17
|
+
paths: ReadonlyMap<string, string>;
|
|
18
|
+
rootDir: string;
|
|
19
|
+
deployEnvironment: string;
|
|
20
|
+
loadContext?: () => Promise<EnvironmentBindingContext>;
|
|
21
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { existsSync, lstatSync } from 'node:fs';
|
|
2
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
3
|
+
import { join, relative } from 'node:path';
|
|
4
|
+
import { assertNoCrossEnvironmentBindings, canonicalDeploymentOrigin, readArtifactStudioSource, } from '@sequenceholdings/artifact-studio/deployment-validation';
|
|
5
|
+
import { loadWorkspacePackages, packageClosure, readWorkspacePackage } from './workspace-model.js';
|
|
6
|
+
const SKIP_DIRS = new Set(['node_modules', '.git', 'dist', '.next', '.artifact-studio', 'coverage']);
|
|
7
|
+
const TEXT_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs', '.json', '.yml', '.yaml']);
|
|
8
|
+
/**
|
|
9
|
+
* Resolve `uses` workspace names and artifact `targets` in the selected
|
|
10
|
+
* environment, then refuse the deploy when source still points elsewhere.
|
|
11
|
+
* Apps with no scannable source and no workspace edges skip the lookup.
|
|
12
|
+
*/
|
|
13
|
+
export async function assertAppEnvironmentBindings({ manifest, entries, paths, rootDir, deployEnvironment, loadContext, }) {
|
|
14
|
+
const files = [
|
|
15
|
+
...(await Promise.all(entries.map(async (entry) => {
|
|
16
|
+
const directory = paths.get(entry.id);
|
|
17
|
+
return directory ? primitiveBindingFiles({ entry, directory }) : [];
|
|
18
|
+
}))).flat(),
|
|
19
|
+
...await sharedPackageFiles({ rootDir, manifest, entries, paths }),
|
|
20
|
+
];
|
|
21
|
+
const workspaces = namedWorkspaces({ manifest, entries });
|
|
22
|
+
if (files.length === 0 && workspaces.length === 0)
|
|
23
|
+
return;
|
|
24
|
+
const context = await (loadContext ?? (() => defaultBindingContext(deployEnvironment)))();
|
|
25
|
+
const resolved = await Promise.all(workspaces.map(async (workspace) => ({
|
|
26
|
+
...workspace,
|
|
27
|
+
workspaceId: await context.resolveWorkspaceByName(workspace.workspaceName),
|
|
28
|
+
})));
|
|
29
|
+
await assertNoCrossEnvironmentBindings({
|
|
30
|
+
deployEnvironment,
|
|
31
|
+
deployOrigin: context.deployOrigin,
|
|
32
|
+
origins: context.origins,
|
|
33
|
+
workspaces: resolved,
|
|
34
|
+
files,
|
|
35
|
+
workspaceExists: context.workspaceExists,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function namedWorkspaces({ manifest, entries, }) {
|
|
39
|
+
const selected = new Set(entries.map((entry) => entry.id));
|
|
40
|
+
const byId = new Map(manifest.primitives.map((entry) => [entry.id, entry]));
|
|
41
|
+
const seen = new Set();
|
|
42
|
+
const workspaces = [];
|
|
43
|
+
for (const entry of manifest.primitives) {
|
|
44
|
+
if (!selected.has(entry.id))
|
|
45
|
+
continue;
|
|
46
|
+
for (const use of entry.uses) {
|
|
47
|
+
const target = byId.get(use.primitive);
|
|
48
|
+
if (target?.kind !== 'workspace' || !target.name || seen.has(target.name))
|
|
49
|
+
continue;
|
|
50
|
+
seen.add(target.name);
|
|
51
|
+
workspaces.push({
|
|
52
|
+
name: target.id,
|
|
53
|
+
workspaceName: target.name,
|
|
54
|
+
provisioned: selected.has(target.id),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return workspaces;
|
|
59
|
+
}
|
|
60
|
+
async function sharedPackageFiles({ rootDir, manifest, entries, paths, }) {
|
|
61
|
+
if (!manifest.packages?.length)
|
|
62
|
+
return [];
|
|
63
|
+
const packages = await loadWorkspacePackages({ rootDir, manifest });
|
|
64
|
+
const directories = new Map();
|
|
65
|
+
for (const entry of entries) {
|
|
66
|
+
const directory = paths.get(entry.id);
|
|
67
|
+
if (!directory || !existsSync(join(directory, 'package.json')))
|
|
68
|
+
continue;
|
|
69
|
+
const json = await readWorkspacePackage({ dir: directory });
|
|
70
|
+
for (const pkg of packageClosure({ json, packages })) {
|
|
71
|
+
directories.set(pkg.dir, pkg.path);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return (await Promise.all([...directories].map(([directory, label]) => readBindingFiles({ directory, label })))).flat();
|
|
75
|
+
}
|
|
76
|
+
async function primitiveBindingFiles({ entry, directory, }) {
|
|
77
|
+
if (entry.kind !== 'artifact' || !existsSync(join(directory, 'artifact.bundle.yml'))) {
|
|
78
|
+
return readBindingFiles({ directory, label: entry.path });
|
|
79
|
+
}
|
|
80
|
+
const source = await readArtifactStudioSource(directory);
|
|
81
|
+
return source.files.map((file) => ({
|
|
82
|
+
path: `${entry.path}/${file.path}`,
|
|
83
|
+
content: file.content,
|
|
84
|
+
...(file.encoding ? { encoding: file.encoding } : {}),
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
async function readBindingFiles({ directory, label, }) {
|
|
88
|
+
if (!existsSync(directory))
|
|
89
|
+
return [];
|
|
90
|
+
const files = [];
|
|
91
|
+
async function walk(current) {
|
|
92
|
+
const entries = await readdir(current, { withFileTypes: true });
|
|
93
|
+
for (const entry of entries) {
|
|
94
|
+
if (entry.isSymbolicLink() || SKIP_DIRS.has(entry.name))
|
|
95
|
+
continue;
|
|
96
|
+
const absolute = join(current, entry.name);
|
|
97
|
+
if (entry.isDirectory()) {
|
|
98
|
+
await walk(absolute);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (!entry.isFile() || !isBindingText(entry.name))
|
|
102
|
+
continue;
|
|
103
|
+
const stat = lstatSync(absolute);
|
|
104
|
+
if (!stat.isFile() || stat.size > 2_000_000)
|
|
105
|
+
continue;
|
|
106
|
+
files.push({
|
|
107
|
+
path: `${label}/${relative(directory, absolute)}`,
|
|
108
|
+
content: await readFile(absolute, 'utf8'),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
await walk(directory);
|
|
113
|
+
return files;
|
|
114
|
+
}
|
|
115
|
+
function isBindingText(name) {
|
|
116
|
+
if (name === 'pnpm-lock.yaml' || name === 'package-lock.json' || name === 'yarn.lock' || name.endsWith('.md'))
|
|
117
|
+
return false;
|
|
118
|
+
if (name === '.env')
|
|
119
|
+
return true;
|
|
120
|
+
const extension = name.includes('.') ? name.slice(name.lastIndexOf('.')) : '';
|
|
121
|
+
return TEXT_EXTENSIONS.has(extension);
|
|
122
|
+
}
|
|
123
|
+
async function defaultBindingContext(envName) {
|
|
124
|
+
const { readConfig, resolveEnvWithDiscovery } = await import('../config.js');
|
|
125
|
+
const { getAccessTokenWithMode } = await import('../auth.js');
|
|
126
|
+
const { getJson, patchJson, postJson, putJson, deleteJson } = await import('../atlas-client.js');
|
|
127
|
+
const { storageClient } = await import('@sequenceholdings/storage');
|
|
128
|
+
const env = await resolveEnvWithDiscovery({ requested: envName });
|
|
129
|
+
const deployOrigin = canonicalDeploymentOrigin(env.url);
|
|
130
|
+
if (!deployOrigin)
|
|
131
|
+
throw new Error(`Invalid deployment URL '${env.url}'.`);
|
|
132
|
+
const config = await readConfig();
|
|
133
|
+
const origins = Object.entries(config.envs).flatMap(([name, value]) => {
|
|
134
|
+
const origin = canonicalDeploymentOrigin(value.url);
|
|
135
|
+
return origin ? [{ name, origin }] : [];
|
|
136
|
+
});
|
|
137
|
+
const { token } = await getAccessTokenWithMode({ env: env.name, targetUrl: env.url });
|
|
138
|
+
const client = storageClient({
|
|
139
|
+
async request(method, path, body) {
|
|
140
|
+
const options = { baseUrl: env.url, token, path, body };
|
|
141
|
+
switch (method) {
|
|
142
|
+
case 'GET': return getJson(options);
|
|
143
|
+
case 'POST': return postJson(options);
|
|
144
|
+
case 'PUT': return putJson(options);
|
|
145
|
+
case 'PATCH': return patchJson(options);
|
|
146
|
+
case 'DELETE': return deleteJson(options);
|
|
147
|
+
default: throw new Error(`Unsupported storage method ${method}`);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
deployOrigin,
|
|
153
|
+
origins,
|
|
154
|
+
resolveWorkspaceByName: (workspaceName) => findWorkspaceId({ client, workspaceName }),
|
|
155
|
+
workspaceExists: async (workspaceId) => {
|
|
156
|
+
try {
|
|
157
|
+
await client.workspace(workspaceId).get();
|
|
158
|
+
// A successful read is already limited to this API's storage environment.
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
if (isNotFound(error))
|
|
163
|
+
return false;
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async function findWorkspaceId({ client, workspaceName, }) {
|
|
170
|
+
let cursor;
|
|
171
|
+
for (let page = 0; page < 20; page += 1) {
|
|
172
|
+
const listed = await client.list({ q: workspaceName, limit: 100, cursor });
|
|
173
|
+
const match = listed.items.find((item) => item.name === workspaceName);
|
|
174
|
+
if (match)
|
|
175
|
+
return match.id;
|
|
176
|
+
if (!listed.nextCursor)
|
|
177
|
+
return undefined;
|
|
178
|
+
cursor = listed.nextCursor;
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
function isNotFound(error) {
|
|
183
|
+
return typeof error === 'object' && error !== null && 'status' in error && error.status === 404;
|
|
184
|
+
}
|
|
@@ -11,6 +11,14 @@ type ManifestGraph = {
|
|
|
11
11
|
order?: string[];
|
|
12
12
|
on_error: 'stop' | 'continue';
|
|
13
13
|
};
|
|
14
|
+
secrets?: {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
}[];
|
|
18
|
+
service_accounts?: {
|
|
19
|
+
id: string;
|
|
20
|
+
slug: string;
|
|
21
|
+
}[];
|
|
14
22
|
roles?: {
|
|
15
23
|
definitions: Record<string, {
|
|
16
24
|
inherits: string[];
|