@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
@@ -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,69 @@ 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). DEPRECATED: create and edit roles in
54
+ * Atlas instead. Still accepted as a one-time seed — the first deploy that
55
+ * sees a key creates it; after that Atlas owns the role and a changed
56
+ * definition here is reported as drift, never applied.
57
+ */
58
+ export declare const applicationRolesSchema: z.ZodObject<{
59
+ definitions: z.ZodRecord<z.ZodString, z.ZodObject<{
60
+ description: z.ZodOptional<z.ZodString>;
61
+ inherits: z.ZodDefault<z.ZodArray<z.ZodString>>;
62
+ includes: z.ZodDefault<z.ZodArray<z.ZodObject<{
63
+ primitive: z.ZodString;
64
+ role: z.ZodOptional<z.ZodString>;
65
+ capability: z.ZodOptional<z.ZodString>;
66
+ }, z.core.$strict>>>;
67
+ }, z.core.$strict>>;
68
+ }, z.core.$strict>;
69
+ /**
70
+ * The Application's own capabilities (schema_version 3). Unlike roles these
71
+ * are code, like a primitive's capabilities: every deploy reconciles them
72
+ * (new keys published, removed keys deprecated). A member checks one by
73
+ * pinning `app/<app.id>/<key>` in its own `capabilities.uses`; roles, created
74
+ * in Atlas, grant them.
75
+ */
76
+ export declare const applicationCapabilitiesSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
77
+ description: z.ZodOptional<z.ZodString>;
78
+ }, z.core.$strict>>;
79
+ /**
80
+ * The member tiers a collaborator role can bundle. Which tier each primitive
81
+ * kind offers is checked in manifest-validation.ts; admin and owner never
82
+ * are — they stay direct grants.
83
+ */
84
+ export declare const COLLABORATOR_TIERS: readonly ["reader", "writer", "editor"];
85
+ export type CollaboratorTier = (typeof COLLABORATOR_TIERS)[number];
86
+ /**
87
+ * Application collaborator roles (schema_version 3): bundle the tiers that
88
+ * let someone change a member — never use-only access, never admin.
89
+ * DEPRECATED here the same way `roles` are: create them in Atlas.
90
+ */
91
+ export declare const applicationCollaboratorsSchema: z.ZodObject<{
92
+ definitions: z.ZodRecord<z.ZodString, z.ZodObject<{
93
+ description: z.ZodOptional<z.ZodString>;
94
+ inherits: z.ZodDefault<z.ZodArray<z.ZodString>>;
95
+ includes: z.ZodDefault<z.ZodArray<z.ZodObject<{
96
+ primitive: z.ZodString;
97
+ tier: z.ZodEnum<{
98
+ reader: "reader";
99
+ writer: "writer";
100
+ editor: "editor";
101
+ }>;
102
+ }, z.core.$strict>>>;
103
+ }, z.core.$strict>>;
104
+ }, z.core.$strict>;
35
105
  export declare const appManifestSchema: z.ZodObject<{
36
- schema_version: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>]>;
106
+ schema_version: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>, z.ZodLiteral<3>]>;
37
107
  app: z.ZodObject<{
38
108
  id: z.ZodString;
39
109
  title: z.ZodString;
@@ -50,12 +120,18 @@ export declare const appManifestSchema: z.ZodObject<{
50
120
  agent: "agent";
51
121
  process: "process";
52
122
  orm: "orm";
123
+ workspace: "workspace";
53
124
  pipeline: "pipeline";
54
125
  artifact: "artifact";
55
126
  }>;
56
127
  path: z.ZodString;
57
128
  depends_on: z.ZodDefault<z.ZodArray<z.ZodString>>;
129
+ uses: z.ZodDefault<z.ZodArray<z.ZodObject<{
130
+ primitive: z.ZodString;
131
+ as: z.ZodOptional<z.ZodString>;
132
+ }, z.core.$strict>>>;
58
133
  namespace: z.ZodOptional<z.ZodString>;
134
+ name: z.ZodOptional<z.ZodString>;
59
135
  slug: z.ZodOptional<z.ZodString>;
60
136
  project_id: z.ZodOptional<z.ZodString>;
61
137
  target: z.ZodOptional<z.ZodString>;
@@ -74,8 +150,40 @@ export declare const appManifestSchema: z.ZodObject<{
74
150
  stop: "stop";
75
151
  }>>;
76
152
  }, z.core.$strict>>;
153
+ roles: 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
+ role: z.ZodOptional<z.ZodString>;
160
+ capability: z.ZodOptional<z.ZodString>;
161
+ }, z.core.$strict>>>;
162
+ }, z.core.$strict>>;
163
+ }, z.core.$strict>>;
164
+ collaborators: z.ZodOptional<z.ZodObject<{
165
+ definitions: z.ZodRecord<z.ZodString, z.ZodObject<{
166
+ description: z.ZodOptional<z.ZodString>;
167
+ inherits: z.ZodDefault<z.ZodArray<z.ZodString>>;
168
+ includes: z.ZodDefault<z.ZodArray<z.ZodObject<{
169
+ primitive: z.ZodString;
170
+ tier: z.ZodEnum<{
171
+ reader: "reader";
172
+ writer: "writer";
173
+ editor: "editor";
174
+ }>;
175
+ }, z.core.$strict>>>;
176
+ }, z.core.$strict>>;
177
+ }, z.core.$strict>>;
178
+ capabilities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
179
+ description: z.ZodOptional<z.ZodString>;
180
+ }, z.core.$strict>>>;
77
181
  }, z.core.$strict>;
78
182
  export type AppManifest = z.infer<typeof appManifestSchema>;
183
+ export type ApplicationRoles = z.infer<typeof applicationRolesSchema>;
184
+ export type ApplicationCollaborators = z.infer<typeof applicationCollaboratorsSchema>;
185
+ /** Versions 2 and 3 share the deployment-graph semantics. */
186
+ export declare function usesAppGraph(manifest: Pick<AppManifest, 'schema_version'>): boolean;
79
187
  export type PrimitiveEntry = z.infer<typeof primitiveEntrySchema>;
80
188
  /**
81
189
  * Fail closed when the installed CLI is older than `studio.min_cli`, so an
@@ -6,6 +6,9 @@
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 { readFile, writeFile } from 'node:fs/promises';
11
14
  import { join, resolve } from 'node:path';
@@ -14,7 +17,8 @@ import { z } from 'zod';
14
17
  import { currentVersion, isNewerVersion } from '../update-check.js';
15
18
  import { validateManifestGraph } from './manifest-validation.js';
16
19
  export const APP_MANIFEST_FILENAME = 'sequence.app.yml';
17
- export const PRIMITIVE_KINDS = ['orm', 'function', 'agent', 'process', 'pipeline', 'artifact'];
20
+ // Order is the default deploy order: storage (ORM, workspaces) before the code that uses it.
21
+ export const PRIMITIVE_KINDS = ['orm', 'workspace', 'function', 'agent', 'process', 'pipeline', 'artifact'];
18
22
  export function isPrimitiveKind(value) {
19
23
  return PRIMITIVE_KINDS.includes(value);
20
24
  }
@@ -23,18 +27,33 @@ const appIdSchema = z
23
27
  .min(1)
24
28
  .max(64)
25
29
  .regex(/^[a-z][a-z0-9-]*$/, 'app id must be kebab-case (a-z, 0-9, -)');
30
+ /**
31
+ * A runtime dependency: this primitive uses another one while it runs (an
32
+ * artifact calls a function, a function stores files in a workspace). Unlike
33
+ * `depends_on` it doesn't order deploys — it feeds the Application's
34
+ * Dependencies graph in Atlas. `as` is a short label for the edge.
35
+ */
36
+ const primitiveUseSchema = z
37
+ .object({
38
+ primitive: z.string().min(1).max(128),
39
+ as: z.string().min(1).max(64).optional(),
40
+ })
41
+ .strict();
26
42
  const primitiveEntrySchema = z
27
43
  .object({
28
44
  id: z.string().min(1).max(128),
29
45
  kind: z.enum(PRIMITIVE_KINDS),
30
46
  path: z.string().min(1),
31
47
  depends_on: z.array(z.string().min(1)).default([]),
48
+ uses: z.array(primitiveUseSchema).default([]),
32
49
  namespace: z.string().min(1).optional(),
50
+ /** Workspaces V2 workspace name (matches `workspace.name` in the primitive's workspace.yml). */
51
+ name: z.string().regex(/^[a-z][a-z0-9-]{1,62}$/, 'workspace names are lowercase kebab-case, 2-63 characters').optional(),
33
52
  slug: z.string().min(1).optional(),
34
53
  project_id: z.string().min(1).optional(),
35
54
  target: z.string().min(1).optional(),
36
55
  only: z.array(z.string().min(1)).min(1).optional(),
37
- repo: z.string().regex(/^pipelines\/[a-z0-9][a-z0-9-]*$/).optional(),
56
+ repo: z.string().regex(/^(?:pipelines|apps)\/[a-z0-9][a-z0-9-]*$/).optional(),
38
57
  ref: z.string().min(1).refine((ref) => !ref.startsWith('-'), 'ref cannot start with -').optional(),
39
58
  })
40
59
  .strict()
@@ -42,6 +61,12 @@ const primitiveEntrySchema = z
42
61
  if (entry.kind === 'orm' && entry.namespace === undefined) {
43
62
  ctx.addIssue({ code: 'custom', message: `orm primitive "${entry.id}" requires namespace`, path: ['namespace'] });
44
63
  }
64
+ if (entry.kind === 'workspace' && entry.name === undefined) {
65
+ ctx.addIssue({ code: 'custom', message: `workspace primitive "${entry.id}" requires name`, path: ['name'] });
66
+ }
67
+ if (entry.name !== undefined && entry.kind !== 'workspace') {
68
+ ctx.addIssue({ code: 'custom', message: 'name is only used by workspace primitives', path: ['name'] });
69
+ }
45
70
  if (entry.kind === 'function' && entry.slug === undefined) {
46
71
  ctx.addIssue({ code: 'custom', message: `function primitive "${entry.id}" requires slug`, path: ['slug'] });
47
72
  }
@@ -53,11 +78,85 @@ const primitiveEntrySchema = z
53
78
  });
54
79
  }
55
80
  });
81
+ /** Custom-role key grammar, mirroring the Atlas registry. */
82
+ const ROLE_KEY_RE = /^[a-z0-9-]{1,64}$/;
83
+ const roleKeySchema = z.string().regex(ROLE_KEY_RE, 'role/capability keys are kebab-case (a-z, 0-9, -), at most 64 characters');
84
+ /**
85
+ * How YAML names a member's floor (the right to use it at all). `end_user` works
86
+ * on every member; `invoker` is accepted on functions and processes, where it's
87
+ * the native term.
88
+ */
89
+ export const FLOOR_ROLE_ALIASES = ['end_user', 'invoker'];
90
+ export function isFloorRoleAlias(value) {
91
+ return FLOOR_ROLE_ALIASES.includes(value);
92
+ }
93
+ const applicationRoleIncludeSchema = z
94
+ .object({
95
+ primitive: z.string().min(1),
96
+ role: z.string().min(1).max(64).optional(),
97
+ capability: roleKeySchema.optional(),
98
+ })
99
+ .strict()
100
+ .superRefine((include, ctx) => {
101
+ if ((include.role === undefined) === (include.capability === undefined)) {
102
+ ctx.addIssue({ code: 'custom', message: 'set exactly one of role or capability' });
103
+ }
104
+ if (include.role !== undefined && !isFloorRoleAlias(include.role) && !ROLE_KEY_RE.test(include.role)) {
105
+ ctx.addIssue({ code: 'custom', message: `invalid role "${include.role}"`, path: ['role'] });
106
+ }
107
+ });
108
+ const applicationRoleDefinitionSchema = z
109
+ .object({
110
+ description: z.string().max(1024).optional(),
111
+ inherits: z.array(roleKeySchema).default([]),
112
+ includes: z.array(applicationRoleIncludeSchema).default([]),
113
+ })
114
+ .strict();
115
+ /**
116
+ * Application roles (schema_version 3). DEPRECATED: create and edit roles in
117
+ * Atlas instead. Still accepted as a one-time seed — the first deploy that
118
+ * sees a key creates it; after that Atlas owns the role and a changed
119
+ * definition here is reported as drift, never applied.
120
+ */
121
+ export const applicationRolesSchema = z
122
+ .object({ definitions: z.record(roleKeySchema, applicationRoleDefinitionSchema) })
123
+ .strict();
124
+ /**
125
+ * The Application's own capabilities (schema_version 3). Unlike roles these
126
+ * are code, like a primitive's capabilities: every deploy reconciles them
127
+ * (new keys published, removed keys deprecated). A member checks one by
128
+ * pinning `app/<app.id>/<key>` in its own `capabilities.uses`; roles, created
129
+ * in Atlas, grant them.
130
+ */
131
+ export const applicationCapabilitiesSchema = z.record(roleKeySchema, z.object({ description: z.string().max(1024).optional() }).strict());
132
+ /**
133
+ * The member tiers a collaborator role can bundle. Which tier each primitive
134
+ * kind offers is checked in manifest-validation.ts; admin and owner never
135
+ * are — they stay direct grants.
136
+ */
137
+ export const COLLABORATOR_TIERS = ['reader', 'writer', 'editor'];
138
+ const applicationCollaboratorDefinitionSchema = z
139
+ .object({
140
+ description: z.string().max(1024).optional(),
141
+ inherits: z.array(roleKeySchema).default([]),
142
+ includes: z
143
+ .array(z.object({ primitive: z.string().min(1), tier: z.enum(COLLABORATOR_TIERS) }).strict())
144
+ .default([]),
145
+ })
146
+ .strict();
147
+ /**
148
+ * Application collaborator roles (schema_version 3): bundle the tiers that
149
+ * let someone change a member — never use-only access, never admin.
150
+ * DEPRECATED here the same way `roles` are: create them in Atlas.
151
+ */
152
+ export const applicationCollaboratorsSchema = z
153
+ .object({ definitions: z.record(roleKeySchema, applicationCollaboratorDefinitionSchema) })
154
+ .strict();
56
155
  const relativeDirectorySchema = z.string().min(1).refine((path) => path.trim() === path && !path.includes('\\') && !/^[A-Za-z]:/.test(path) &&
57
156
  !/[\x00-\x1f]/.test(path) && path.split('/').every((part) => part !== '' && part !== '.' && part !== '..'), 'path must be a relative directory within the app root');
58
157
  export const appManifestSchema = z
59
158
  .object({
60
- schema_version: z.union([z.literal(1), z.literal(2)]),
159
+ schema_version: z.union([z.literal(1), z.literal(2), z.literal(3)]),
61
160
  app: z.object({
62
161
  id: appIdSchema,
63
162
  title: z.string().min(1),
@@ -78,6 +177,9 @@ export const appManifestSchema = z
78
177
  on_error: z.enum(['stop', 'continue']).default('stop'),
79
178
  }).strict()
80
179
  .default({ on_error: 'stop' }),
180
+ roles: applicationRolesSchema.optional(),
181
+ collaborators: applicationCollaboratorsSchema.optional(),
182
+ capabilities: applicationCapabilitiesSchema.optional(),
81
183
  }).strict()
82
184
  .superRefine(validateManifestGraph);
83
185
  /** Local helper so schema refinement does not depend on later exports. */
@@ -87,6 +189,10 @@ function defaultDeployOrderForValidation(primitives) {
87
189
  .sort((a, b) => rank(a.kind) - rank(b.kind) || a.id.localeCompare(b.id))
88
190
  .map((entry) => entry.id);
89
191
  }
192
+ /** Versions 2 and 3 share the deployment-graph semantics. */
193
+ export function usesAppGraph(manifest) {
194
+ return manifest.schema_version >= 2;
195
+ }
90
196
  /**
91
197
  * Fail closed when the installed CLI is older than `studio.min_cli`, so an
92
198
  * older binary cannot load / rewrite a manifest that requires newer semantics.
@@ -18,6 +18,7 @@ export function primitiveIdFor({ kind, name }) {
18
18
  case 'agent':
19
19
  case 'process':
20
20
  case 'pipeline':
21
+ case 'workspace':
21
22
  return `${name}-${kind}`;
22
23
  }
23
24
  }
@@ -35,12 +36,14 @@ export function relativePathFor({ kind, appId, name, }) {
35
36
  return join('processes', name);
36
37
  case 'pipeline':
37
38
  return join('pipelines', name);
39
+ case 'workspace':
40
+ return join('workspaces', name);
38
41
  }
39
42
  }
40
43
  function buildPrimitiveEntry({ kind, appId, name, dependsOn, }) {
41
44
  const path = relativePathFor({ kind, appId, name }).replace(/\\/g, '/');
42
45
  const id = primitiveIdFor({ kind, name });
43
- const base = { id, kind, path, depends_on: dependsOn };
46
+ const base = { id, kind, path, depends_on: dependsOn, uses: [] };
44
47
  switch (kind) {
45
48
  case 'orm':
46
49
  return { ...base, namespace: ormNamespaceFromAppId(name) };
@@ -48,6 +51,8 @@ function buildPrimitiveEntry({ kind, appId, name, dependsOn, }) {
48
51
  return { ...base, slug: name };
49
52
  case 'artifact':
50
53
  return { ...base, project_id: name };
54
+ case 'workspace':
55
+ return { ...base, name };
51
56
  case 'agent':
52
57
  case 'process':
53
58
  case 'pipeline':
@@ -131,6 +136,11 @@ export async function scaffoldKind({ kind, appRoot, appId, name, pipelineType =
131
136
  throw new Error(`pipeline init failed for ${absPath}`);
132
137
  }
133
138
  break;
139
+ case 'workspace':
140
+ await mkdir(absPath, { recursive: true });
141
+ // Same file `seq-studio storage init` writes.
142
+ await writeFile(join(absPath, 'workspace.yml'), `workspace:\n name: ${name}\n description: ""\n`, { flag: 'wx' });
143
+ break;
134
144
  }
135
145
  return entry;
136
146
  }
@@ -18,11 +18,13 @@ function primitivePath({ kind, appId, functionName }) {
18
18
  case 'process': return `processes/${appId}`;
19
19
  case 'pipeline': return `pipelines/${appId}`;
20
20
  case 'artifact': return 'artifact';
21
+ case 'workspace': return `workspaces/${appId}`;
21
22
  }
22
23
  }
23
24
  const PRIMITIVE_LABELS = {
24
25
  orm: 'ORM namespace', function: 'Managed Function', agent: 'Typed agent',
25
26
  process: 'Lattice process', pipeline: 'Data Pipeline', artifact: 'Artifact Studio UI',
27
+ workspace: 'Workspaces V2 workspace',
26
28
  };
27
29
  export function renderAppReadme(input) {
28
30
  const title = input.title?.trim() || titleizeSlug(input.appId);
@@ -33,7 +33,7 @@ function applyDefaultDependsOn(primitives) {
33
33
  }
34
34
  export async function initAppMonorepo({ rootDir, appId, kinds, names = defaultScaffoldNames(appId), description, pipelineType, }) {
35
35
  if (kinds.length === 0) {
36
- throw new Error('select at least one primitive via --with orm,function,agent,process,pipeline,artifact (or --orm --function …)');
36
+ throw new Error('select at least one primitive via --with orm,workspace,function,agent,process,pipeline,artifact (or --orm --function …)');
37
37
  }
38
38
  assertScaffoldName(appId);
39
39
  assertScaffoldName(names.functionName);
@@ -124,7 +124,8 @@ export async function addPrimitiveToApp({ rootDir, kind, name, pipelineType, dep
124
124
  entry = { ...entry, depends_on: [orm.id] };
125
125
  }
126
126
  const primitives = [...manifest.primitives, entry];
127
- const upgrade = manifest.schema_version === 1 && ['agent', 'process', 'pipeline'].includes(kind);
127
+ // Kinds version 1 doesn't know upgrade the app to version 2 on add.
128
+ const upgrade = manifest.schema_version === 1 && ['agent', 'process', 'pipeline', 'workspace'].includes(kind);
128
129
  const version = currentVersion();
129
130
  const next = {
130
131
  ...manifest,
@@ -3,7 +3,7 @@ import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
3
3
  import { join } from 'node:path';
4
4
  import { dump as yamlDump, load as yamlLoad } from 'js-yaml';
5
5
  import { z } from 'zod';
6
- import { loadAppManifest, writeAppManifest } from './manifest.js';
6
+ import { loadAppManifest, usesAppGraph, writeAppManifest } from './manifest.js';
7
7
  import { currentVersion } from '../update-check.js';
8
8
  const packageSchema = z.looseObject({
9
9
  dependencies: z.record(z.string(), z.string()).optional(),
@@ -43,7 +43,7 @@ export async function scaffoldSharedPackage({ rootDir, appId, name, }) {
43
43
  /** Convert only freshly generated primitive files into members of the app workspace. */
44
44
  export async function joinAppWorkspace({ rootDir, manifest, entries, }) {
45
45
  const workspacePath = join(rootDir, 'pnpm-workspace.yaml');
46
- if (manifest.schema_version !== 2 || !existsSync(workspacePath))
46
+ if (!usesAppGraph(manifest) || !existsSync(workspacePath))
47
47
  return;
48
48
  const config = workspaceSchema.parse(yamlLoad(await readFile(workspacePath, 'utf8')));
49
49
  const paths = new Set(config.packages ?? []);
@@ -103,7 +103,7 @@ export async function scaffoldAppWorkspace({ rootDir, manifest, }) {
103
103
  export async function addSharedPackageToApp({ rootDir, name, }) {
104
104
  const manifest = await loadAppManifest(rootDir);
105
105
  const workspacePath = join(rootDir, 'pnpm-workspace.yaml');
106
- if (manifest.schema_version !== 2 || !existsSync(workspacePath)) {
106
+ if (!usesAppGraph(manifest) || !existsSync(workspacePath)) {
107
107
  throw new Error('adding a shared package requires a version 2 app with a root pnpm-workspace.yaml');
108
108
  }
109
109
  const packageName = `@${manifest.app.id}/${name}`;
@@ -32,6 +32,8 @@ const ARTIFACT_USAGE = `usage:
32
32
  seq-studio artifact whoami -e <env>
33
33
  seq-studio artifact env list
34
34
 
35
+ Add --help or -h to any artifact command to print this usage without running it.
36
+
35
37
  Environments: see \`seq-studio envs list\` (built-in: local; more are
36
38
  discovered after you authenticate).
37
39
 
@@ -70,6 +72,12 @@ export async function runArtifactCommand(sub, rest) {
70
72
  'AUTH0_M2M_CLIENT_SECRET for headless automation.');
71
73
  return 1;
72
74
  }
75
+ // Help must not resolve environments, authenticate, or dispatch a command.
76
+ if (!sub || sub === 'help' || sub === '--help' || sub === '-h' ||
77
+ rest.some((arg) => arg === '--help' || arg === '-h')) {
78
+ console.log(ARTIFACT_USAGE);
79
+ return sub ? 0 : 1;
80
+ }
73
81
  // Never pass a legacy bearer environment variable into the embedded package.
74
82
  delete process.env['ARTIFACT_STUDIO_TOKEN'];
75
83
  // Older artifact-studio versions exposed nested login/logout commands backed
@@ -84,10 +92,6 @@ export async function runArtifactCommand(sub, rest) {
84
92
  await auth[sub]();
85
93
  return 0;
86
94
  }
87
- if (!sub || sub === 'help' || sub === '--help' || sub === '-h') {
88
- console.log(ARTIFACT_USAGE);
89
- return sub ? 0 : 1;
90
- }
91
95
  // `artifact env list` renders the tier-aware discovered catalog instead of
92
96
  // artifact-studio's built-in (local-only) list.
93
97
  if (sub === 'env' && rest[0] === 'list') {