@sequenceholdings/studio-cli 0.2.1 → 0.3.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.
Files changed (49) hide show
  1. package/README.md +333 -29
  2. package/dist/access/commands.d.ts +3 -0
  3. package/dist/access/commands.js +91 -0
  4. package/dist/app/adapters.js +27 -5
  5. package/dist/app/application-registration.d.ts +96 -0
  6. package/dist/app/application-registration.js +146 -0
  7. package/dist/app/deploy.d.ts +8 -0
  8. package/dist/app/deploy.js +42 -8
  9. package/dist/app/manifest-validation.d.ts +20 -1
  10. package/dist/app/manifest-validation.js +130 -6
  11. package/dist/app/manifest.d.ts +110 -2
  12. package/dist/app/manifest.js +109 -3
  13. package/dist/app/primitive-scaffold.js +11 -1
  14. package/dist/app/readme.js +2 -0
  15. package/dist/app/scaffold.js +3 -2
  16. package/dist/app/workspace-scaffold.js +3 -3
  17. package/dist/artifact/delegate.js +8 -4
  18. package/dist/auth-cmds/commands.d.ts +1 -1
  19. package/dist/auth-cmds/commands.js +16 -0
  20. package/dist/cli-errors.js +4 -0
  21. package/dist/command-input.d.ts +15 -0
  22. package/dist/command-input.js +33 -0
  23. package/dist/functions/commands.d.ts +2 -1
  24. package/dist/functions/commands.js +61 -30
  25. package/dist/functions/manifest.d.ts +7 -1
  26. package/dist/functions/manifest.js +40 -12
  27. package/dist/functions/secret-reconcile.d.ts +3 -3
  28. package/dist/functions/secret-reconcile.js +5 -7
  29. package/dist/main.d.ts +3 -1
  30. package/dist/main.js +19 -7
  31. package/dist/manifest-roles-notice.d.ts +33 -0
  32. package/dist/manifest-roles-notice.js +75 -0
  33. package/dist/orm/delegate.js +2 -0
  34. package/dist/pipeline/commands.js +11 -0
  35. package/dist/pipeline/discovery.d.ts +8 -0
  36. package/dist/pipeline/discovery.js +249 -0
  37. package/dist/pipeline/lifecycle.js +35 -10
  38. package/dist/pipeline/stage-secrets.d.ts +4 -1
  39. package/dist/pipeline/stage-secrets.js +6 -2
  40. package/dist/process/commands.js +4 -0
  41. package/dist/repos/commands.d.ts +10 -1
  42. package/dist/repos/commands.js +16 -8
  43. package/dist/repos/pulls.d.ts +3 -0
  44. package/dist/repos/pulls.js +131 -0
  45. package/dist/secrets/commands.d.ts +1 -1
  46. package/dist/secrets/commands.js +97 -16
  47. package/dist/service-accounts/commands.d.ts +3 -0
  48. package/dist/service-accounts/commands.js +50 -0
  49. package/package.json +5 -5
@@ -28,6 +28,12 @@ async function validatePrimitiveIdentity({ entry, path }) {
28
28
  actual = artifactIdentitySchema.parse(raw).artifact.project_id;
29
29
  expected = entry.project_id;
30
30
  }
31
+ else if (entry.kind === 'workspace' && entry.name) {
32
+ const { workspaceManifestSchema } = await import('@sequenceholdings/storage');
33
+ const raw = loadYaml(await readFile(join(path, 'workspace.yml'), 'utf8'));
34
+ actual = workspaceManifestSchema.parse(raw).workspace.name;
35
+ expected = entry.name;
36
+ }
31
37
  else if (entry.kind === 'orm' && entry.namespace) {
32
38
  if (existsSync(join(path, 'sequence.config.ts'))) {
33
39
  const { loadNamespaceFromDir } = await import('@sequenceholdings/orm/authoring');
@@ -49,19 +55,22 @@ async function validatePrimitiveIdentity({ entry, path }) {
49
55
  function requirePipelineSource({ entry }) {
50
56
  if (!entry.repo || !entry.ref) {
51
57
  throw new Error(`Pipeline "${entry.id}" requires repo and ref in sequence.app.yml. ` +
52
- 'Push its source to a pipelines/<name> repository and pin that repository/ref; ' +
58
+ 'Push its source to a pipelines/<name> or apps/<name> repository and pin that repository/ref; ' +
53
59
  'pipeline deployment reads committed source from the platform git service.');
54
60
  }
55
61
  return { repo: entry.repo, ref: entry.ref };
56
62
  }
63
+ function pipelineRoot(entry) {
64
+ return entry.repo?.startsWith('apps/') ? entry.path : undefined;
65
+ }
57
66
  /** Pin the source validated during preflight so a moving branch cannot swap it. */
58
67
  async function validatePipelineSource(args) {
59
68
  const { repo, ref } = requirePipelineSource(args);
60
69
  const { buildContext, clientOptions } = await import('../functions/commands.js');
61
70
  const context = await buildContext({ positional: [], flags: { env: args.env } });
62
71
  const [namespace, name] = repo.split('/');
63
- if (namespace !== 'pipelines' || !name || repo.split('/').length !== 2) {
64
- throw new Error(`Pipeline "${args.entry.id}" requires a pipelines/<name> repository.`);
72
+ if ((namespace !== 'pipelines' && namespace !== 'apps') || !name || repo.split('/').length !== 2) {
73
+ throw new Error(`Pipeline "${args.entry.id}" requires a pipelines/<name> or apps/<name> repository.`);
65
74
  }
66
75
  const source = await resolveArtifactSource({ kind: 'git-service', namespace, name, ref }, { ...clientOptions(context), ...(context.authMode ? { authMode: context.authMode } : {}) });
67
76
  try {
@@ -70,7 +79,8 @@ async function validatePipelineSource(args) {
70
79
  throw new Error(`Pipeline "${args.entry.id}" source did not resolve to a commit; retry with a full commit SHA.`);
71
80
  }
72
81
  const { pipelineValidateCommand } = await import('../pipeline/commands.js');
73
- const code = await pipelineValidateCommand({ positional: [source.dir], flags: {} });
82
+ const root = pipelineRoot(args.entry);
83
+ const code = await pipelineValidateCommand({ positional: [root ? join(source.dir, root) : source.dir], flags: {} });
74
84
  assertValidationSucceeded({ args, code });
75
85
  console.log(`[seq-studio] pinned pipeline ${args.entry.id}: ${repo}@${commit}`);
76
86
  return { ...args.entry, ref: commit };
@@ -124,6 +134,11 @@ export async function validateAppPrimitive(args) {
124
134
  code = await lintCommand({ positional: [], flags: { dir: path, offline: true, ...selectedFlags(args) } });
125
135
  break;
126
136
  }
137
+ case 'workspace': {
138
+ const { runStorageCommand } = await import('../storage/commands.js');
139
+ code = await runStorageCommand('validate', { positional: [join(path, 'workspace.yml')], flags: {} });
140
+ break;
141
+ }
127
142
  case 'artifact': {
128
143
  if (env !== 'local')
129
144
  assertActiveDeployProvenance(localGitMetadata(path));
@@ -161,10 +176,11 @@ export async function createDefaultDeployers() {
161
176
  async pipeline(args) {
162
177
  const { repo, ref } = requirePipelineSource(args);
163
178
  const { env, approvedBy, waitTimeout } = args;
179
+ const root = pipelineRoot(args.entry);
164
180
  return pipelineDeployCommand({ positional: [], flags: {
165
181
  // Validated above. Preserve the primitive's repo-only deployment
166
182
  // boundary and wait for terminal deployment status before dependents.
167
- repo, ref, env, ...selectedFlags(args),
183
+ repo, ref, ...(root ? { root } : {}), env, ...selectedFlags(args),
168
184
  ...(approvedBy ? { 'approved-by': approvedBy } : {}),
169
185
  ...(waitTimeout ? { 'wait-timeout': waitTimeout } : {}),
170
186
  } });
@@ -172,5 +188,11 @@ export async function createDefaultDeployers() {
172
188
  async artifact({ path, env }) {
173
189
  return runArtifactCommand('deploy', [path, '--env', env]);
174
190
  },
191
+ async workspace({ path, env }) {
192
+ // `storage apply` is an idempotent upsert by name: creates the workspace
193
+ // the first time, updates its description after.
194
+ const { runStorageCommand } = await import('../storage/commands.js');
195
+ return runStorageCommand('apply', { positional: [join(path, 'workspace.yml')], flags: { env } });
196
+ },
175
197
  };
176
198
  }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Registering a schema_version 3 app with Atlas as an Application, after its
3
+ * primitives deploy (`PUT /api/custom-roles/applications/<app.id>`).
4
+ *
5
+ * The YAML's `role: end_user | invoker` alias becomes the server's single
6
+ * `{ type: 'end_user' }` spelling here, so the API has one contract. Members
7
+ * are the artifact/function/ORM primitives and single-process entries,
8
+ * referenced by the stable names that resolve in every environment.
9
+ */
10
+ import { type ClientOptions } from '../atlas-client.js';
11
+ import { type AppManifest, type PrimitiveEntry } from './manifest.js';
12
+ type MemberKind = 'artifact' | 'function' | 'orm' | 'lattice';
13
+ export interface ApplicationDeployMember {
14
+ key: string;
15
+ kind: MemberKind;
16
+ ref: string;
17
+ }
18
+ export type ApplicationDeployInclude = {
19
+ type: 'end_user';
20
+ member: string;
21
+ } | {
22
+ type: 'role';
23
+ member: string;
24
+ key: string;
25
+ } | {
26
+ type: 'capability';
27
+ member: string;
28
+ key: string;
29
+ } | {
30
+ type: 'tier';
31
+ member: string;
32
+ tier: string;
33
+ };
34
+ type ApplicationDeployRole = {
35
+ description?: string;
36
+ inherits: string[];
37
+ includes: ApplicationDeployInclude[];
38
+ };
39
+ /** Every primitive, members or not — the nodes of the Dependencies graph. */
40
+ export interface ApplicationDeployComponent {
41
+ key: string;
42
+ kind: PrimitiveEntry['kind'];
43
+ /** The stable name Atlas can resolve: slug, project id, namespace, workspace name, or process id. */
44
+ ref?: string;
45
+ }
46
+ /** A runtime dependency (`uses`): `from` uses `to` while it runs. */
47
+ export interface ApplicationDeployEdge {
48
+ from: string;
49
+ to: string;
50
+ label?: string;
51
+ }
52
+ export interface ApplicationDeployBody {
53
+ title: string;
54
+ description?: string;
55
+ members: ApplicationDeployMember[];
56
+ components: ApplicationDeployComponent[];
57
+ edges: ApplicationDeployEdge[];
58
+ roles: Record<string, ApplicationDeployRole>;
59
+ /** Collaborator roles: member tiers only. */
60
+ collaborators: Record<string, ApplicationDeployRole>;
61
+ /** The Application's own capabilities; members pin them as `app/<id>/<key>`. */
62
+ capabilities: Record<string, {
63
+ description?: string;
64
+ }>;
65
+ }
66
+ export interface ApplicationDeployWarning {
67
+ type: string;
68
+ role: string;
69
+ /** `collaborator` for a collaborator role, `capability` for an Application capability (`role` is then its key); older servers send none. */
70
+ kind?: string;
71
+ detail: string;
72
+ }
73
+ export declare function buildApplicationDeployBody(manifest: AppManifest): ApplicationDeployBody;
74
+ export type ApplicationRegistration = {
75
+ status: 'registered';
76
+ created: boolean;
77
+ warnings: ApplicationDeployWarning[];
78
+ } | {
79
+ status: 'failed';
80
+ message: string;
81
+ };
82
+ export type RegisterApplication = (args: {
83
+ manifest: AppManifest;
84
+ env: string;
85
+ }) => Promise<ApplicationRegistration>;
86
+ export declare function putApplication({ client, manifest, }: {
87
+ client: ClientOptions;
88
+ manifest: AppManifest;
89
+ }): Promise<ApplicationRegistration>;
90
+ export declare function logApplicationRegistration({ appId, registration, }: {
91
+ appId: string;
92
+ registration: ApplicationRegistration;
93
+ }): void;
94
+ /** Default registrar: authenticate against `env` the same way the primitive deployers do. */
95
+ export declare const registerApplicationWithAtlas: RegisterApplication;
96
+ export {};
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Registering a schema_version 3 app with Atlas as an Application, after its
3
+ * primitives deploy (`PUT /api/custom-roles/applications/<app.id>`).
4
+ *
5
+ * The YAML's `role: end_user | invoker` alias becomes the server's single
6
+ * `{ type: 'end_user' }` spelling here, so the API has one contract. Members
7
+ * are the artifact/function/ORM primitives and single-process entries,
8
+ * referenced by the stable names that resolve in every environment.
9
+ */
10
+ import { AtlasApiError, putJson } from '../atlas-client.js';
11
+ import { buildContext, clientOptions } from '../functions/commands.js';
12
+ import { isFloorRoleAlias } from './manifest.js';
13
+ const LOG = '[seq-studio]';
14
+ /**
15
+ * The member ref Atlas resolves: project slug, function slug, namespace, or
16
+ * — for a process entry that deploys exactly one process — its process id.
17
+ */
18
+ function memberOf(entry) {
19
+ if (entry.kind === 'artifact' && entry.project_id)
20
+ return { key: entry.id, kind: 'artifact', ref: entry.project_id };
21
+ if (entry.kind === 'function' && entry.slug)
22
+ return { key: entry.id, kind: 'function', ref: entry.slug };
23
+ if (entry.kind === 'orm' && entry.namespace)
24
+ return { key: entry.id, kind: 'orm', ref: entry.namespace };
25
+ const [processId, ...more] = entry.kind === 'process' ? (entry.only ?? []) : [];
26
+ if (processId && more.length === 0)
27
+ return { key: entry.id, kind: 'lattice', ref: processId };
28
+ return null;
29
+ }
30
+ function componentRef(entry) {
31
+ switch (entry.kind) {
32
+ case 'artifact': return entry.project_id;
33
+ case 'function': return entry.slug;
34
+ case 'orm': return entry.namespace;
35
+ case 'workspace': return entry.name;
36
+ case 'process': return entry.only?.length === 1 ? entry.only[0] : undefined;
37
+ case 'agent':
38
+ case 'pipeline': return undefined;
39
+ }
40
+ }
41
+ function collaboratorRolesOf(manifest) {
42
+ return Object.fromEntries(Object.entries(manifest.collaborators?.definitions ?? {}).map(([key, definition]) => [
43
+ key,
44
+ {
45
+ ...(definition.description !== undefined ? { description: definition.description } : {}),
46
+ inherits: definition.inherits,
47
+ includes: definition.includes.map((include) => ({ type: 'tier', member: include.primitive, tier: include.tier })),
48
+ },
49
+ ]));
50
+ }
51
+ export function buildApplicationDeployBody(manifest) {
52
+ const roles = {};
53
+ for (const [key, definition] of Object.entries(manifest.roles?.definitions ?? {})) {
54
+ roles[key] = {
55
+ ...(definition.description !== undefined ? { description: definition.description } : {}),
56
+ inherits: definition.inherits,
57
+ includes: definition.includes.map((include) => {
58
+ if (include.capability !== undefined) {
59
+ return { type: 'capability', member: include.primitive, key: include.capability };
60
+ }
61
+ const role = include.role ?? '';
62
+ return isFloorRoleAlias(role)
63
+ ? { type: 'end_user', member: include.primitive }
64
+ : { type: 'role', member: include.primitive, key: role };
65
+ }),
66
+ };
67
+ }
68
+ return {
69
+ title: manifest.app.title,
70
+ ...(manifest.app.description !== undefined ? { description: manifest.app.description } : {}),
71
+ members: manifest.primitives.flatMap((entry) => {
72
+ const member = memberOf(entry);
73
+ return member ? [member] : [];
74
+ }),
75
+ components: manifest.primitives.map((entry) => {
76
+ const ref = componentRef(entry);
77
+ return { key: entry.id, kind: entry.kind, ...(ref !== undefined ? { ref } : {}) };
78
+ }),
79
+ edges: manifest.primitives.flatMap((entry) => entry.uses.map((use) => ({ from: entry.id, to: use.primitive, ...(use.as !== undefined ? { label: use.as } : {}) }))),
80
+ roles,
81
+ collaborators: collaboratorRolesOf(manifest),
82
+ capabilities: manifest.capabilities ?? {},
83
+ };
84
+ }
85
+ function asRecord(value) {
86
+ return value && typeof value === 'object' ? Object.fromEntries(Object.entries(value)) : {};
87
+ }
88
+ const isString = (value) => typeof value === 'string';
89
+ /** Server-side detail worth printing beyond the error message. */
90
+ function errorDetailLines(error) {
91
+ const record = asRecord(error.body);
92
+ const lines = [];
93
+ if (Array.isArray(record.issues)) {
94
+ for (const issue of record.issues.filter(isString))
95
+ lines.push(` - ${issue}`);
96
+ }
97
+ if (Array.isArray(record.members)) {
98
+ const members = record.members.filter(isString);
99
+ if (members.length > 0)
100
+ lines.push(` members lacking your consent: ${members.join(', ')}`);
101
+ }
102
+ return lines;
103
+ }
104
+ export async function putApplication({ client, manifest, }) {
105
+ const path = `/api/custom-roles/applications/${encodeURIComponent(manifest.app.id)}`;
106
+ try {
107
+ const response = await putJson({
108
+ ...client,
109
+ path,
110
+ body: buildApplicationDeployBody(manifest),
111
+ });
112
+ const warnings = (Array.isArray(response.warnings) ? response.warnings : []).flatMap((warning) => {
113
+ const { type, role, kind, detail } = asRecord(warning);
114
+ return isString(detail)
115
+ ? [{
116
+ type: isString(type) ? type : 'warning',
117
+ role: isString(role) ? role : '',
118
+ ...(isString(kind) ? { kind } : {}),
119
+ detail,
120
+ }]
121
+ : [];
122
+ });
123
+ return { status: 'registered', created: response.created === true, warnings };
124
+ }
125
+ catch (error) {
126
+ if (!(error instanceof AtlasApiError))
127
+ throw error;
128
+ return { status: 'failed', message: [error.message, ...errorDetailLines(error)].join('\n') };
129
+ }
130
+ }
131
+ export function logApplicationRegistration({ appId, registration, }) {
132
+ if (registration.status === 'failed') {
133
+ console.error(`${LOG} ✗ Application "${appId}" registration failed: ${registration.message}`);
134
+ return;
135
+ }
136
+ console.log(`${LOG} ✓ Application "${appId}" ${registration.created ? 'registered' : 'synced'}`);
137
+ for (const warning of registration.warnings) {
138
+ const section = warning.kind === 'collaborator' ? 'collaborators' : warning.kind === 'capability' ? 'capabilities' : 'roles';
139
+ console.warn(`${LOG} ! ${section}.${warning.role}: ${warning.detail}`);
140
+ }
141
+ }
142
+ /** Default registrar: authenticate against `env` the same way the primitive deployers do. */
143
+ export const registerApplicationWithAtlas = async ({ manifest, env }) => {
144
+ const context = await buildContext({ positional: [], flags: { env } });
145
+ return putApplication({ client: clientOptions(context), manifest });
146
+ };
@@ -5,6 +5,7 @@
5
5
  * orchestrates them. Injectable runners keep unit tests offline.
6
6
  */
7
7
  export { resolveContainedPrimitivePath } from './paths.js';
8
+ import { type ApplicationRegistration, type RegisterApplication } from './application-registration.js';
8
9
  export { createDefaultDeployers } from './adapters.js';
9
10
  import { type AppManifest, type PrimitiveEntry, type PrimitiveKind } from './manifest.js';
10
11
  export type DeployPrimitiveArgs = {
@@ -31,6 +32,8 @@ export type DeployAppOptions = {
31
32
  validatePrimitive?: (args: DeployPrimitiveArgs) => Promise<PrimitiveEntry | void>;
32
33
  approvedBy?: string;
33
34
  waitTimeout?: string;
35
+ /** Registers a schema_version 3 app with Atlas after its primitives deploy. */
36
+ registerApplication?: RegisterApplication;
34
37
  };
35
38
  export type DeployAppResult = {
36
39
  attempted: string[];
@@ -39,6 +42,11 @@ export type DeployAppResult = {
39
42
  skipped: string[];
40
43
  exitCode: number;
41
44
  reportPath?: string;
45
+ /** schema_version 3 only. */
46
+ application?: ApplicationRegistration | {
47
+ status: 'skipped';
48
+ reason: string;
49
+ };
42
50
  };
43
51
  /** Resolve ordered primitive entries for deploy, validating order / --only ids. */
44
52
  export declare function resolveDeployEntries({ manifest, only, }: {
@@ -11,15 +11,41 @@ import { join, resolve } from 'node:path';
11
11
  import { ensureAppOutputDirectory, resolveContainedPrimitivePath } from './paths.js';
12
12
  export { resolveContainedPrimitivePath } from './paths.js';
13
13
  import { executeDeployment } from './run-deployment.js';
14
+ import { buildApplicationDeployBody, logApplicationRegistration, registerApplicationWithAtlas, } from './application-registration.js';
14
15
  import { dependencyClosure, dependencyOrder } from './graph.js';
15
16
  import { createDefaultDeployers, validateAppPrimitive } from './adapters.js';
16
17
  import { prepareAppWorkspace } from './workspace.js';
17
18
  import { localGitMetadata } from '@sequenceholdings/artifact-studio/source-resolver';
18
19
  import { assertActiveDeployProvenance } from '@sequenceholdings/artifact-studio/active-deploy-policy';
19
20
  export { createDefaultDeployers } from './adapters.js';
20
- import { defaultDeployOrder, loadAppManifest, } from './manifest.js';
21
+ import { defaultDeployOrder, loadAppManifest, usesAppGraph, } from './manifest.js';
22
+ import { warnOnManifestRoles } from '../manifest-roles-notice.js';
21
23
  const LOG = '[seq-studio]';
22
24
  const APP_MANIFEST_HINT = 'sequence.app.yml';
25
+ /**
26
+ * The Application step of a v3 deploy. Runs only after every selected
27
+ * primitive succeeded (members must exist to resolve); a failed registration
28
+ * fails the deploy. Never throws: the primitives have already deployed, so
29
+ * even a network or auth failure must reach the deployment report.
30
+ */
31
+ async function registerApplicationStep({ manifest, options, result, }) {
32
+ if (manifest.schema_version !== 3)
33
+ return;
34
+ if (result.exitCode !== 0) {
35
+ result.application = { status: 'skipped', reason: 'a primitive failed to deploy' };
36
+ console.log(`${LOG} skip Application "${manifest.app.id}" registration (a primitive failed)`);
37
+ return;
38
+ }
39
+ const register = options.registerApplication ?? registerApplicationWithAtlas;
40
+ const registration = await register({ manifest, env: options.env }).catch((error) => ({
41
+ status: 'failed',
42
+ message: error instanceof Error ? error.message : String(error),
43
+ }));
44
+ logApplicationRegistration({ appId: manifest.app.id, registration });
45
+ result.application = registration;
46
+ if (registration.status === 'failed')
47
+ result.exitCode = 1;
48
+ }
23
49
  /** Resolve ordered primitive entries for deploy, validating order / --only ids. */
24
50
  export function resolveDeployEntries({ manifest, only, }) {
25
51
  const byId = new Map(manifest.primitives.map((entry) => [entry.id, entry]));
@@ -37,7 +63,7 @@ export function resolveDeployEntries({ manifest, only, }) {
37
63
  if (!orderedIds.includes(entry.id))
38
64
  orderedIds.push(entry.id);
39
65
  }
40
- const effectiveIds = manifest.schema_version === 2
66
+ const effectiveIds = usesAppGraph(manifest)
41
67
  ? dependencyOrder({ entries: manifest.primitives, priority: orderedIds })
42
68
  : orderedIds;
43
69
  if (only && only.length > 0) {
@@ -45,7 +71,7 @@ export function resolveDeployEntries({ manifest, only, }) {
45
71
  if (unknown.length > 0) {
46
72
  throw new Error(`Unknown primitive id(s) in --only: ${unknown.join(', ')}. Known: ${[...byId.keys()].join(', ')}`);
47
73
  }
48
- const onlySet = manifest.schema_version === 2
74
+ const onlySet = usesAppGraph(manifest)
49
75
  ? dependencyClosure({ entries: manifest.primitives, selected: only })
50
76
  : new Set(only);
51
77
  return effectiveIds
@@ -57,16 +83,17 @@ export function resolveDeployEntries({ manifest, only, }) {
57
83
  function assertAppDeploymentSource({ manifest, options, rootDir, entries }) {
58
84
  // Shared sources live outside the UI directory. Check the entire original
59
85
  // app before packaging so ignored staging cannot conceal a dirty package.
60
- if (manifest.schema_version === 2 && options.env !== 'local' && entries.some((entry) => entry.kind === 'artifact')) {
86
+ if (usesAppGraph(manifest) && options.env !== 'local' && entries.some((entry) => entry.kind === 'artifact')) {
61
87
  assertActiveDeployProvenance(localGitMetadata(rootDir));
62
88
  }
63
- if (manifest.schema_version === 2 && manifest.packages?.length && options.env !== 'local' && !options.dryRun && !existsSync(join(rootDir, 'pnpm-lock.yaml'))) {
89
+ if (usesAppGraph(manifest) && manifest.packages?.length && options.env !== 'local' && !options.dryRun && !existsSync(join(rootDir, 'pnpm-lock.yaml'))) {
64
90
  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.');
65
91
  }
66
92
  }
67
93
  export async function deployApp(options) {
68
94
  const rootDir = resolve(options.rootDir);
69
95
  const manifest = await loadAppManifest(rootDir);
96
+ await warnOnManifestRoles({ dir: rootDir, file: 'sequence.app.yml', kind: 'application' });
70
97
  const entries = resolveDeployEntries({ manifest, only: options.only });
71
98
  const onError = manifest.deploy.on_error;
72
99
  const deployers = options.deployers ?? (await createDefaultDeployers());
@@ -85,7 +112,7 @@ export async function deployApp(options) {
85
112
  }
86
113
  assertAppDeploymentSource({ manifest, options, rootDir, entries });
87
114
  const provenance = localGitMetadata(rootDir);
88
- const prepared = manifest.schema_version === 2
115
+ const prepared = usesAppGraph(manifest)
89
116
  ? await prepareAppWorkspace({ rootDir, manifest, entries, paths: resolvedPaths })
90
117
  : { paths: resolvedPaths, cleanup: async () => { } };
91
118
  try {
@@ -94,7 +121,7 @@ export async function deployApp(options) {
94
121
  entry: pinnedEntries.get(entry.id), path: prepared.paths.get(entry.id), rootDir, env: options.env,
95
122
  yes: options.yes === true, approvedBy: options.approvedBy, waitTimeout: options.waitTimeout,
96
123
  });
97
- if (manifest.schema_version === 2) {
124
+ if (usesAppGraph(manifest)) {
98
125
  const validate = options.validatePrimitive ?? validateAppPrimitive;
99
126
  for (const entry of entries) {
100
127
  const pinned = await validate(argsFor(entry));
@@ -103,6 +130,12 @@ export async function deployApp(options) {
103
130
  }
104
131
  }
105
132
  if (options.dryRun) {
133
+ if (manifest.schema_version === 3) {
134
+ const body = buildApplicationDeployBody(manifest);
135
+ console.log(`${LOG} dry-run: would register Application "${manifest.app.id}" ` +
136
+ `(${body.members.length} member(s), ${Object.keys(body.capabilities).length} capability(ies), ` +
137
+ `${Object.keys(body.roles).length} role(s) and ${Object.keys(body.collaborators).length} collaborator role(s) to seed)`);
138
+ }
106
139
  console.log(`${LOG} dry-run: no primitives deployed`);
107
140
  return {
108
141
  attempted: [],
@@ -112,9 +145,10 @@ export async function deployApp(options) {
112
145
  exitCode: 0,
113
146
  };
114
147
  }
115
- const reportDir = manifest.schema_version === 2
148
+ const reportDir = usesAppGraph(manifest)
116
149
  ? await ensureAppOutputDirectory({ rootDir, entryPath: '.sequence/deployments' }) : undefined;
117
150
  const result = await executeDeployment({ entries, onError, deployers, argsFor });
151
+ await registerApplicationStep({ manifest, options, result });
118
152
  if (reportDir) {
119
153
  result.reportPath = join(reportDir, `${encodeURIComponent(options.env)}.json`);
120
154
  const temporaryReport = join(reportDir, `${randomUUID()}.tmp`);
@@ -1,7 +1,7 @@
1
1
  import type { z } from 'zod';
2
2
  import type { PrimitiveEntry } from './manifest.js';
3
3
  type ManifestGraph = {
4
- schema_version: 1 | 2;
4
+ schema_version: 1 | 2 | 3;
5
5
  primitives: PrimitiveEntry[];
6
6
  packages?: {
7
7
  name: string;
@@ -11,6 +11,25 @@ type ManifestGraph = {
11
11
  order?: string[];
12
12
  on_error: 'stop' | 'continue';
13
13
  };
14
+ roles?: {
15
+ definitions: Record<string, {
16
+ inherits: string[];
17
+ includes: {
18
+ primitive: string;
19
+ role?: string;
20
+ capability?: string;
21
+ }[];
22
+ }>;
23
+ };
24
+ collaborators?: {
25
+ definitions: Record<string, {
26
+ inherits: string[];
27
+ includes: {
28
+ primitive: string;
29
+ tier: string;
30
+ }[];
31
+ }>;
32
+ };
14
33
  };
15
34
  export declare function validateManifestGraph(manifest: ManifestGraph, ctx: z.RefinementCtx): void;
16
35
  export {};