@sequenceholdings/studio-cli 0.2.1 → 0.2.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.
@@ -0,0 +1,145 @@
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
+ };
83
+ }
84
+ function asRecord(value) {
85
+ return value && typeof value === 'object' ? Object.fromEntries(Object.entries(value)) : {};
86
+ }
87
+ const isString = (value) => typeof value === 'string';
88
+ /** Server-side detail worth printing beyond the error message. */
89
+ function errorDetailLines(error) {
90
+ const record = asRecord(error.body);
91
+ const lines = [];
92
+ if (Array.isArray(record.issues)) {
93
+ for (const issue of record.issues.filter(isString))
94
+ lines.push(` - ${issue}`);
95
+ }
96
+ if (Array.isArray(record.members)) {
97
+ const members = record.members.filter(isString);
98
+ if (members.length > 0)
99
+ lines.push(` members lacking your consent: ${members.join(', ')}`);
100
+ }
101
+ return lines;
102
+ }
103
+ export async function putApplication({ client, manifest, }) {
104
+ const path = `/api/custom-roles/applications/${encodeURIComponent(manifest.app.id)}`;
105
+ try {
106
+ const response = await putJson({
107
+ ...client,
108
+ path,
109
+ body: buildApplicationDeployBody(manifest),
110
+ });
111
+ const warnings = (Array.isArray(response.warnings) ? response.warnings : []).flatMap((warning) => {
112
+ const { type, role, kind, detail } = asRecord(warning);
113
+ return isString(detail)
114
+ ? [{
115
+ type: isString(type) ? type : 'warning',
116
+ role: isString(role) ? role : '',
117
+ ...(isString(kind) ? { kind } : {}),
118
+ detail,
119
+ }]
120
+ : [];
121
+ });
122
+ return { status: 'registered', created: response.created === true, warnings };
123
+ }
124
+ catch (error) {
125
+ if (!(error instanceof AtlasApiError))
126
+ throw error;
127
+ return { status: 'failed', message: [error.message, ...errorDetailLines(error)].join('\n') };
128
+ }
129
+ }
130
+ export function logApplicationRegistration({ appId, registration, }) {
131
+ if (registration.status === 'failed') {
132
+ console.error(`${LOG} ✗ Application "${appId}" registration failed: ${registration.message}`);
133
+ return;
134
+ }
135
+ console.log(`${LOG} ✓ Application "${appId}" ${registration.created ? 'registered' : 'synced'}`);
136
+ for (const warning of registration.warnings) {
137
+ const section = warning.kind === 'collaborator' ? 'collaborators' : 'roles';
138
+ console.warn(`${LOG} ! ${section}.${warning.role}: ${warning.detail}`);
139
+ }
140
+ }
141
+ /** Default registrar: authenticate against `env` the same way the primitive deployers do. */
142
+ export const registerApplicationWithAtlas = async ({ manifest, env }) => {
143
+ const context = await buildContext({ positional: [], flags: { env } });
144
+ return putApplication({ client: clientOptions(context), manifest });
145
+ };
@@ -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,40 @@ 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';
21
22
  const LOG = '[seq-studio]';
22
23
  const APP_MANIFEST_HINT = 'sequence.app.yml';
24
+ /**
25
+ * The Application step of a v3 deploy. Runs only after every selected
26
+ * primitive succeeded (members must exist to resolve); a failed registration
27
+ * fails the deploy. Never throws: the primitives have already deployed, so
28
+ * even a network or auth failure must reach the deployment report.
29
+ */
30
+ async function registerApplicationStep({ manifest, options, result, }) {
31
+ if (manifest.schema_version !== 3)
32
+ return;
33
+ if (result.exitCode !== 0) {
34
+ result.application = { status: 'skipped', reason: 'a primitive failed to deploy' };
35
+ console.log(`${LOG} skip Application "${manifest.app.id}" registration (a primitive failed)`);
36
+ return;
37
+ }
38
+ const register = options.registerApplication ?? registerApplicationWithAtlas;
39
+ const registration = await register({ manifest, env: options.env }).catch((error) => ({
40
+ status: 'failed',
41
+ message: error instanceof Error ? error.message : String(error),
42
+ }));
43
+ logApplicationRegistration({ appId: manifest.app.id, registration });
44
+ result.application = registration;
45
+ if (registration.status === 'failed')
46
+ result.exitCode = 1;
47
+ }
23
48
  /** Resolve ordered primitive entries for deploy, validating order / --only ids. */
24
49
  export function resolveDeployEntries({ manifest, only, }) {
25
50
  const byId = new Map(manifest.primitives.map((entry) => [entry.id, entry]));
@@ -37,7 +62,7 @@ export function resolveDeployEntries({ manifest, only, }) {
37
62
  if (!orderedIds.includes(entry.id))
38
63
  orderedIds.push(entry.id);
39
64
  }
40
- const effectiveIds = manifest.schema_version === 2
65
+ const effectiveIds = usesAppGraph(manifest)
41
66
  ? dependencyOrder({ entries: manifest.primitives, priority: orderedIds })
42
67
  : orderedIds;
43
68
  if (only && only.length > 0) {
@@ -45,7 +70,7 @@ export function resolveDeployEntries({ manifest, only, }) {
45
70
  if (unknown.length > 0) {
46
71
  throw new Error(`Unknown primitive id(s) in --only: ${unknown.join(', ')}. Known: ${[...byId.keys()].join(', ')}`);
47
72
  }
48
- const onlySet = manifest.schema_version === 2
73
+ const onlySet = usesAppGraph(manifest)
49
74
  ? dependencyClosure({ entries: manifest.primitives, selected: only })
50
75
  : new Set(only);
51
76
  return effectiveIds
@@ -57,10 +82,10 @@ export function resolveDeployEntries({ manifest, only, }) {
57
82
  function assertAppDeploymentSource({ manifest, options, rootDir, entries }) {
58
83
  // Shared sources live outside the UI directory. Check the entire original
59
84
  // 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')) {
85
+ if (usesAppGraph(manifest) && options.env !== 'local' && entries.some((entry) => entry.kind === 'artifact')) {
61
86
  assertActiveDeployProvenance(localGitMetadata(rootDir));
62
87
  }
63
- if (manifest.schema_version === 2 && manifest.packages?.length && options.env !== 'local' && !options.dryRun && !existsSync(join(rootDir, 'pnpm-lock.yaml'))) {
88
+ if (usesAppGraph(manifest) && manifest.packages?.length && options.env !== 'local' && !options.dryRun && !existsSync(join(rootDir, 'pnpm-lock.yaml'))) {
64
89
  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
90
  }
66
91
  }
@@ -85,7 +110,7 @@ export async function deployApp(options) {
85
110
  }
86
111
  assertAppDeploymentSource({ manifest, options, rootDir, entries });
87
112
  const provenance = localGitMetadata(rootDir);
88
- const prepared = manifest.schema_version === 2
113
+ const prepared = usesAppGraph(manifest)
89
114
  ? await prepareAppWorkspace({ rootDir, manifest, entries, paths: resolvedPaths })
90
115
  : { paths: resolvedPaths, cleanup: async () => { } };
91
116
  try {
@@ -94,7 +119,7 @@ export async function deployApp(options) {
94
119
  entry: pinnedEntries.get(entry.id), path: prepared.paths.get(entry.id), rootDir, env: options.env,
95
120
  yes: options.yes === true, approvedBy: options.approvedBy, waitTimeout: options.waitTimeout,
96
121
  });
97
- if (manifest.schema_version === 2) {
122
+ if (usesAppGraph(manifest)) {
98
123
  const validate = options.validatePrimitive ?? validateAppPrimitive;
99
124
  for (const entry of entries) {
100
125
  const pinned = await validate(argsFor(entry));
@@ -103,6 +128,12 @@ export async function deployApp(options) {
103
128
  }
104
129
  }
105
130
  if (options.dryRun) {
131
+ if (manifest.schema_version === 3) {
132
+ const body = buildApplicationDeployBody(manifest);
133
+ console.log(`${LOG} dry-run: would register Application "${manifest.app.id}" ` +
134
+ `(${body.members.length} member(s), ${Object.keys(body.roles).length} role(s) and ` +
135
+ `${Object.keys(body.collaborators).length} collaborator role(s) to seed)`);
136
+ }
106
137
  console.log(`${LOG} dry-run: no primitives deployed`);
107
138
  return {
108
139
  attempted: [],
@@ -112,9 +143,10 @@ export async function deployApp(options) {
112
143
  exitCode: 0,
113
144
  };
114
145
  }
115
- const reportDir = manifest.schema_version === 2
146
+ const reportDir = usesAppGraph(manifest)
116
147
  ? await ensureAppOutputDirectory({ rootDir, entryPath: '.sequence/deployments' }) : undefined;
117
148
  const result = await executeDeployment({ entries, onError, deployers, argsFor });
149
+ await registerApplicationStep({ manifest, options, result });
118
150
  if (reportDir) {
119
151
  result.reportPath = join(reportDir, `${encodeURIComponent(options.env)}.json`);
120
152
  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 {};
@@ -1,4 +1,108 @@
1
1
  import { dependencyOrder } from './graph.js';
2
+ /** Primitive kinds an Application role can reach into. */
3
+ const ROLE_MEMBER_KINDS = new Set(['artifact', 'function', 'orm', 'process']);
4
+ /** Kinds whose floor YAML may also spell `invoker` (their native term). */
5
+ const INVOKER_FLOOR_KINDS = new Set(['function', 'process']);
6
+ /** The member tiers each kind lets a collaborator role bundle (mirrors Atlas). */
7
+ const COLLABORATOR_TIERS_BY_KIND = {
8
+ artifact: ['reader', 'writer'],
9
+ function: ['reader', 'editor'],
10
+ orm: ['reader', 'writer'],
11
+ process: ['editor'],
12
+ };
13
+ /** v2 and v3 share the deployment graph (manifest.ts `usesAppGraph`; inlined to avoid an import cycle). */
14
+ const usesGraph = (manifest) => manifest.schema_version >= 2;
15
+ /**
16
+ * Local checks that catch typos before a deploy round-trip. Atlas re-validates
17
+ * everything (member registry keys, inheritance cycles) when it registers.
18
+ */
19
+ function validateRoles({ manifest, ctx }) {
20
+ if (!manifest.roles)
21
+ return;
22
+ if (manifest.schema_version !== 3) {
23
+ ctx.addIssue({ code: 'custom', message: 'roles require schema_version: 3', path: ['roles'] });
24
+ return;
25
+ }
26
+ const kindById = new Map(manifest.primitives.map((entry) => [entry.id, entry.kind]));
27
+ const entryById = new Map(manifest.primitives.map((entry) => [entry.id, entry]));
28
+ const definitions = manifest.roles.definitions;
29
+ for (const [key, definition] of Object.entries(definitions)) {
30
+ const at = (...path) => ['roles', 'definitions', key, ...path];
31
+ for (const [index, junior] of definition.inherits.entries()) {
32
+ if (!(junior in definitions)) {
33
+ ctx.addIssue({ code: 'custom', message: `inherits unknown role "${junior}"`, path: at('inherits', index) });
34
+ }
35
+ }
36
+ for (const [index, include] of definition.includes.entries()) {
37
+ const kind = kindById.get(include.primitive);
38
+ if (!kind) {
39
+ ctx.addIssue({ code: 'custom', message: `unknown primitive "${include.primitive}"`, path: at('includes', index, 'primitive') });
40
+ }
41
+ else if (kind === 'workspace') {
42
+ // Workspace access is data-driven (folders, files, sharing); a bundle's
43
+ // static grant can't express it. Apps reach storage as their own identity.
44
+ ctx.addIssue({ code: 'custom', message: "Application roles can't include workspace primitives — grant workspace access in Workspaces V2", path: at('includes', index, 'primitive') });
45
+ }
46
+ else if (!ROLE_MEMBER_KINDS.has(kind)) {
47
+ ctx.addIssue({ code: 'custom', message: `Application roles can't include ${kind} primitives yet`, path: at('includes', index, 'primitive') });
48
+ }
49
+ else if (include.role === 'invoker' && !INVOKER_FLOOR_KINDS.has(kind)) {
50
+ ctx.addIssue({ code: 'custom', message: `invoker is the function and process floor; use end_user for ${kind} primitives`, path: at('includes', index, 'role') });
51
+ }
52
+ else if (kind === 'process') {
53
+ processIncludeIssue({ entry: entryById.get(include.primitive), include, path: at('includes', index), ctx });
54
+ }
55
+ }
56
+ }
57
+ }
58
+ /** Local checks for `collaborators`; Atlas re-validates on register. */
59
+ function validateCollaborators({ manifest, ctx }) {
60
+ if (!manifest.collaborators)
61
+ return;
62
+ if (manifest.schema_version !== 3) {
63
+ ctx.addIssue({ code: 'custom', message: 'collaborators require schema_version: 3', path: ['collaborators'] });
64
+ return;
65
+ }
66
+ const entryById = new Map(manifest.primitives.map((entry) => [entry.id, entry]));
67
+ const definitions = manifest.collaborators.definitions;
68
+ for (const [key, definition] of Object.entries(definitions)) {
69
+ const at = (...path) => ['collaborators', 'definitions', key, ...path];
70
+ for (const [index, junior] of definition.inherits.entries()) {
71
+ if (!(junior in definitions)) {
72
+ ctx.addIssue({ code: 'custom', message: `inherits unknown collaborator role "${junior}"`, path: at('inherits', index) });
73
+ }
74
+ }
75
+ for (const [index, include] of definition.includes.entries()) {
76
+ const entry = entryById.get(include.primitive);
77
+ const allowed = entry ? COLLABORATOR_TIERS_BY_KIND[entry.kind] : undefined;
78
+ if (!entry) {
79
+ ctx.addIssue({ code: 'custom', message: `unknown primitive "${include.primitive}"`, path: at('includes', index, 'primitive') });
80
+ }
81
+ else if (!allowed) {
82
+ ctx.addIssue({ code: 'custom', message: `collaborator roles can't include ${entry.kind} primitives`, path: at('includes', index, 'primitive') });
83
+ }
84
+ else if (!allowed.includes(include.tier)) {
85
+ ctx.addIssue({ code: 'custom', message: `${entry.kind} primitives offer ${allowed.join(', ')} — admin and owner stay direct grants`, path: at('includes', index, 'tier') });
86
+ }
87
+ else if (entry.kind === 'process' && entry.only?.length !== 1) {
88
+ ctx.addIssue({ code: 'custom', message: `set only: [<process-id>] on "${entry.id}" so the role reaches exactly one process`, path: at('includes', index) });
89
+ }
90
+ }
91
+ }
92
+ }
93
+ /**
94
+ * A process member is floor-only (a Lattice process has no roles or
95
+ * capabilities), and the entry must deploy exactly one process so Atlas
96
+ * knows which one the role reaches.
97
+ */
98
+ function processIncludeIssue({ entry, include, path, ctx, }) {
99
+ if (include.capability !== undefined || (include.role !== 'end_user' && include.role !== 'invoker')) {
100
+ ctx.addIssue({ code: 'custom', message: 'process primitives offer only end_user (or invoker) — not roles or capabilities', path });
101
+ }
102
+ else if (entry?.only?.length !== 1) {
103
+ ctx.addIssue({ code: 'custom', message: `set only: [<process-id>] on "${entry?.id ?? ''}" so the role reaches exactly one process`, path });
104
+ }
105
+ }
2
106
  function validateV2Entry({ entry, index, ctx }) {
3
107
  const issue = (message, field) => ctx.addIssue({
4
108
  code: 'custom', message, path: ['primitives', index, ...(field ? [field] : [])],
@@ -29,7 +133,7 @@ function validateInventory({ manifest, ctx }) {
29
133
  ctx.addIssue({ code: 'custom', message: `duplicate primitive path "${entry.path}"`, path: ['primitives', index, 'path'] });
30
134
  ids.add(entry.id);
31
135
  paths.add(entry.path);
32
- if (manifest.schema_version === 2)
136
+ if (usesGraph(manifest))
33
137
  validateV2Entry({ entry, index, ctx });
34
138
  }
35
139
  for (const [index, entry] of manifest.primitives.entries()) {
@@ -37,6 +141,7 @@ function validateInventory({ manifest, ctx }) {
37
141
  if (!ids.has(dep))
38
142
  ctx.addIssue({ code: 'custom', message: `depends_on references unknown primitive id "${dep}"`, path: ['primitives', index, 'depends_on', depIndex] });
39
143
  }
144
+ validateUses({ entry, index, ids, ctx });
40
145
  }
41
146
  const names = new Set();
42
147
  for (const [index, pkg] of (manifest.packages ?? []).entries()) {
@@ -45,7 +150,7 @@ function validateInventory({ manifest, ctx }) {
45
150
  names.add(pkg.name);
46
151
  paths.add(pkg.path);
47
152
  }
48
- if (manifest.schema_version !== 2)
153
+ if (!usesGraph(manifest))
49
154
  return;
50
155
  const sortedPaths = [...paths].sort();
51
156
  for (const [index, path] of sortedPaths.entries()) {
@@ -54,6 +159,23 @@ function validateInventory({ manifest, ctx }) {
54
159
  }
55
160
  }
56
161
  }
162
+ /** `uses` edges (runtime dependencies) must point at other primitives in this app, once each. */
163
+ function validateUses({ entry, index, ids, ctx, }) {
164
+ const seen = new Set();
165
+ for (const [useIndex, use] of entry.uses.entries()) {
166
+ const path = ['primitives', index, 'uses', useIndex, 'primitive'];
167
+ if (!ids.has(use.primitive)) {
168
+ ctx.addIssue({ code: 'custom', message: `uses references unknown primitive id "${use.primitive}"`, path });
169
+ }
170
+ else if (use.primitive === entry.id) {
171
+ ctx.addIssue({ code: 'custom', message: `primitive "${entry.id}" cannot use itself`, path });
172
+ }
173
+ else if (seen.has(use.primitive)) {
174
+ ctx.addIssue({ code: 'custom', message: `duplicate uses entry "${use.primitive}"`, path });
175
+ }
176
+ seen.add(use.primitive);
177
+ }
178
+ }
57
179
  function orderPriority({ manifest, ctx }) {
58
180
  const known = new Set(manifest.primitives.map((entry) => entry.id));
59
181
  const order = manifest.deploy.order ?? [];
@@ -68,18 +190,20 @@ function orderPriority({ manifest, ctx }) {
68
190
  if (order.length > 0)
69
191
  return [...order, ...manifest.primitives.map((entry) => entry.id).filter((id) => !seen.has(id))];
70
192
  // V1's kind ordering is contractual; V2 treats declaration order as a tie breaker here.
71
- if (manifest.schema_version === 2)
193
+ if (usesGraph(manifest))
72
194
  return manifest.primitives.map((entry) => entry.id);
73
195
  const ranks = ['orm', 'function', 'artifact'];
74
196
  return [...manifest.primitives].sort((a, b) => ranks.indexOf(a.kind) - ranks.indexOf(b.kind) || a.id.localeCompare(b.id)).map((entry) => entry.id);
75
197
  }
76
198
  export function validateManifestGraph(manifest, ctx) {
77
- if (manifest.schema_version === 1 && (manifest.packages !== undefined || manifest.primitives.some((entry) => !['orm', 'function', 'artifact'].includes(entry.kind)))) {
78
- ctx.addIssue({ code: 'custom', message: 'Agents, processes, pipelines and shared packages require schema_version: 2', path: ['schema_version'] });
199
+ if (manifest.schema_version === 1 && (manifest.packages !== undefined || manifest.primitives.some((entry) => !['orm', 'function', 'artifact'].includes(entry.kind) || entry.uses.length > 0))) {
200
+ ctx.addIssue({ code: 'custom', message: 'Agents, processes, pipelines, workspaces, uses and shared packages require schema_version: 2', path: ['schema_version'] });
79
201
  }
80
202
  validateInventory({ manifest, ctx });
203
+ validateRoles({ manifest, ctx });
204
+ validateCollaborators({ manifest, ctx });
81
205
  const priority = orderPriority({ manifest, ctx });
82
- if (manifest.schema_version === 2) {
206
+ if (usesGraph(manifest)) {
83
207
  try {
84
208
  dependencyOrder({ entries: manifest.primitives, priority });
85
209
  }
@@ -6,10 +6,13 @@
6
6
  * intentionally not supported — `seq-studio init` / `add` own this file.
7
7
  *
8
8
  * Version 2 is the app deployment graph; version 1 keeps its legacy ordering.
9
+ * Version 3 is version 2 plus Application `roles` (runtime access) and
10
+ * `collaborators` (edit access): the deploy also registers the bundle with
11
+ * Atlas so one role grant covers every member.
9
12
  */
10
13
  import { z } from 'zod';
11
14
  export declare const APP_MANIFEST_FILENAME = "sequence.app.yml";
12
- export declare const PRIMITIVE_KINDS: readonly ["orm", "function", "agent", "process", "pipeline", "artifact"];
15
+ export declare const PRIMITIVE_KINDS: readonly ["orm", "workspace", "function", "agent", "process", "pipeline", "artifact"];
13
16
  export type PrimitiveKind = (typeof PRIMITIVE_KINDS)[number];
14
17
  export declare function isPrimitiveKind(value: string): value is PrimitiveKind;
15
18
  declare const primitiveEntrySchema: z.ZodObject<{
@@ -19,12 +22,18 @@ declare const primitiveEntrySchema: z.ZodObject<{
19
22
  agent: "agent";
20
23
  process: "process";
21
24
  orm: "orm";
25
+ workspace: "workspace";
22
26
  pipeline: "pipeline";
23
27
  artifact: "artifact";
24
28
  }>;
25
29
  path: z.ZodString;
26
30
  depends_on: z.ZodDefault<z.ZodArray<z.ZodString>>;
31
+ uses: z.ZodDefault<z.ZodArray<z.ZodObject<{
32
+ primitive: z.ZodString;
33
+ as: z.ZodOptional<z.ZodString>;
34
+ }, z.core.$strict>>>;
27
35
  namespace: z.ZodOptional<z.ZodString>;
36
+ name: z.ZodOptional<z.ZodString>;
28
37
  slug: z.ZodOptional<z.ZodString>;
29
38
  project_id: z.ZodOptional<z.ZodString>;
30
39
  target: z.ZodOptional<z.ZodString>;
@@ -32,8 +41,58 @@ declare const primitiveEntrySchema: z.ZodObject<{
32
41
  repo: z.ZodOptional<z.ZodString>;
33
42
  ref: z.ZodOptional<z.ZodString>;
34
43
  }, z.core.$strict>;
44
+ /**
45
+ * How YAML names a member's floor (the right to use it at all). `end_user` works
46
+ * on every member; `invoker` is accepted on functions and processes, where it's
47
+ * the native term.
48
+ */
49
+ export declare const FLOOR_ROLE_ALIASES: readonly ["end_user", "invoker"];
50
+ export type FloorRoleAlias = (typeof FLOOR_ROLE_ALIASES)[number];
51
+ export declare function isFloorRoleAlias(value: string): value is FloorRoleAlias;
52
+ /**
53
+ * Application roles (schema_version 3). Seeded on the first deploy that sees
54
+ * each key; after that Atlas owns the role and a changed definition here is
55
+ * reported as drift rather than applied.
56
+ */
57
+ export declare const applicationRolesSchema: z.ZodObject<{
58
+ definitions: z.ZodRecord<z.ZodString, z.ZodObject<{
59
+ description: z.ZodOptional<z.ZodString>;
60
+ inherits: z.ZodDefault<z.ZodArray<z.ZodString>>;
61
+ includes: z.ZodDefault<z.ZodArray<z.ZodObject<{
62
+ primitive: z.ZodString;
63
+ role: z.ZodOptional<z.ZodString>;
64
+ capability: z.ZodOptional<z.ZodString>;
65
+ }, z.core.$strict>>>;
66
+ }, z.core.$strict>>;
67
+ }, z.core.$strict>;
68
+ /**
69
+ * The member tiers a collaborator role can bundle. Which tier each primitive
70
+ * kind offers is checked in manifest-validation.ts; admin and owner never
71
+ * are — they stay direct grants.
72
+ */
73
+ export declare const COLLABORATOR_TIERS: readonly ["reader", "writer", "editor"];
74
+ export type CollaboratorTier = (typeof COLLABORATOR_TIERS)[number];
75
+ /**
76
+ * Application collaborator roles (schema_version 3): bundle the tiers that
77
+ * let someone change a member — never use-only access, never admin. Seeded
78
+ * and owned by Atlas the same way `roles` are.
79
+ */
80
+ export declare const applicationCollaboratorsSchema: z.ZodObject<{
81
+ definitions: z.ZodRecord<z.ZodString, z.ZodObject<{
82
+ description: z.ZodOptional<z.ZodString>;
83
+ inherits: z.ZodDefault<z.ZodArray<z.ZodString>>;
84
+ includes: z.ZodDefault<z.ZodArray<z.ZodObject<{
85
+ primitive: z.ZodString;
86
+ tier: z.ZodEnum<{
87
+ reader: "reader";
88
+ writer: "writer";
89
+ editor: "editor";
90
+ }>;
91
+ }, z.core.$strict>>>;
92
+ }, z.core.$strict>>;
93
+ }, z.core.$strict>;
35
94
  export declare const appManifestSchema: z.ZodObject<{
36
- schema_version: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>]>;
95
+ schema_version: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>, z.ZodLiteral<3>]>;
37
96
  app: z.ZodObject<{
38
97
  id: z.ZodString;
39
98
  title: z.ZodString;
@@ -50,12 +109,18 @@ export declare const appManifestSchema: z.ZodObject<{
50
109
  agent: "agent";
51
110
  process: "process";
52
111
  orm: "orm";
112
+ workspace: "workspace";
53
113
  pipeline: "pipeline";
54
114
  artifact: "artifact";
55
115
  }>;
56
116
  path: z.ZodString;
57
117
  depends_on: z.ZodDefault<z.ZodArray<z.ZodString>>;
118
+ uses: z.ZodDefault<z.ZodArray<z.ZodObject<{
119
+ primitive: z.ZodString;
120
+ as: z.ZodOptional<z.ZodString>;
121
+ }, z.core.$strict>>>;
58
122
  namespace: z.ZodOptional<z.ZodString>;
123
+ name: z.ZodOptional<z.ZodString>;
59
124
  slug: z.ZodOptional<z.ZodString>;
60
125
  project_id: z.ZodOptional<z.ZodString>;
61
126
  target: z.ZodOptional<z.ZodString>;
@@ -74,8 +139,37 @@ export declare const appManifestSchema: z.ZodObject<{
74
139
  stop: "stop";
75
140
  }>>;
76
141
  }, z.core.$strict>>;
142
+ roles: z.ZodOptional<z.ZodObject<{
143
+ definitions: z.ZodRecord<z.ZodString, z.ZodObject<{
144
+ description: z.ZodOptional<z.ZodString>;
145
+ inherits: z.ZodDefault<z.ZodArray<z.ZodString>>;
146
+ includes: z.ZodDefault<z.ZodArray<z.ZodObject<{
147
+ primitive: z.ZodString;
148
+ role: z.ZodOptional<z.ZodString>;
149
+ capability: z.ZodOptional<z.ZodString>;
150
+ }, z.core.$strict>>>;
151
+ }, z.core.$strict>>;
152
+ }, z.core.$strict>>;
153
+ collaborators: z.ZodOptional<z.ZodObject<{
154
+ definitions: z.ZodRecord<z.ZodString, z.ZodObject<{
155
+ description: z.ZodOptional<z.ZodString>;
156
+ inherits: z.ZodDefault<z.ZodArray<z.ZodString>>;
157
+ includes: z.ZodDefault<z.ZodArray<z.ZodObject<{
158
+ primitive: z.ZodString;
159
+ tier: z.ZodEnum<{
160
+ reader: "reader";
161
+ writer: "writer";
162
+ editor: "editor";
163
+ }>;
164
+ }, z.core.$strict>>>;
165
+ }, z.core.$strict>>;
166
+ }, z.core.$strict>>;
77
167
  }, z.core.$strict>;
78
168
  export type AppManifest = z.infer<typeof appManifestSchema>;
169
+ export type ApplicationRoles = z.infer<typeof applicationRolesSchema>;
170
+ export type ApplicationCollaborators = z.infer<typeof applicationCollaboratorsSchema>;
171
+ /** Versions 2 and 3 share the deployment-graph semantics. */
172
+ export declare function usesAppGraph(manifest: Pick<AppManifest, 'schema_version'>): boolean;
79
173
  export type PrimitiveEntry = z.infer<typeof primitiveEntrySchema>;
80
174
  /**
81
175
  * Fail closed when the installed CLI is older than `studio.min_cli`, so an