@sequenceholdings/studio-cli 0.7.1 → 0.9.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 (87) hide show
  1. package/README.md +390 -54
  2. package/dist/access/commands.d.ts +1 -1
  3. package/dist/access/commands.js +102 -55
  4. package/dist/access/custom-role-hosts.d.ts +3 -0
  5. package/dist/access/custom-role-hosts.js +88 -0
  6. package/dist/access/group-rosters.d.ts +6 -0
  7. package/dist/access/group-rosters.js +33 -0
  8. package/dist/access/host-contract.d.ts +55 -0
  9. package/dist/access/host-contract.js +33 -0
  10. package/dist/access/hosts.d.ts +4 -0
  11. package/dist/access/hosts.js +60 -0
  12. package/dist/access/principal.d.ts +16 -0
  13. package/dist/access/principal.js +36 -0
  14. package/dist/access/roles.d.ts +18 -0
  15. package/dist/access/roles.js +89 -0
  16. package/dist/access/tier-hosts.d.ts +12 -0
  17. package/dist/access/tier-hosts.js +206 -0
  18. package/dist/agents/commands.d.ts +1 -1
  19. package/dist/agents/commands.js +76 -16
  20. package/dist/agents/scaffold.js +8 -3
  21. package/dist/app/commands.d.ts +3 -1
  22. package/dist/app/commands.js +88 -12
  23. package/dist/app/manifest.d.ts +2 -2
  24. package/dist/app/official-source.d.ts +4 -2
  25. package/dist/app/official-source.js +6 -4
  26. package/dist/app/readme.js +2 -2
  27. package/dist/app/validate.d.ts +16 -0
  28. package/dist/app/validate.js +40 -0
  29. package/dist/app/workspace-model.js +4 -0
  30. package/dist/app/workspace-scaffold.js +5 -3
  31. package/dist/app/workspace.d.ts +2 -0
  32. package/dist/app/workspace.js +1 -1
  33. package/dist/artifact/delegate.js +26 -3
  34. package/dist/artifact/sandbox.js +2 -1
  35. package/dist/atlas-client.d.ts +17 -8
  36. package/dist/atlas-client.js +146 -62
  37. package/dist/bin.js +10 -1
  38. package/dist/cli-errors.js +12 -3
  39. package/dist/command-contract.d.ts +14 -2
  40. package/dist/command-contract.js +4 -2
  41. package/dist/command-help.d.ts +9 -7
  42. package/dist/command-help.js +56 -12
  43. package/dist/env-flags.d.ts +7 -0
  44. package/dist/env-flags.js +23 -0
  45. package/dist/functions/commands.d.ts +4 -0
  46. package/dist/functions/commands.js +127 -11
  47. package/dist/functions/manifest.d.ts +5 -0
  48. package/dist/functions/manifest.js +44 -23
  49. package/dist/functions/service-account-guidance.d.ts +21 -0
  50. package/dist/functions/service-account-guidance.js +62 -0
  51. package/dist/functions/workspace.d.ts +11 -0
  52. package/dist/functions/workspace.js +52 -0
  53. package/dist/main.d.ts +2 -1
  54. package/dist/main.js +17 -3
  55. package/dist/orm/delegate.d.ts +1 -0
  56. package/dist/orm/delegate.js +65 -12
  57. package/dist/orm/discover-schema.d.ts +26 -0
  58. package/dist/orm/discover-schema.js +5 -0
  59. package/dist/orm/execute.js +11 -5
  60. package/dist/orm/failures.d.ts +32 -0
  61. package/dist/orm/failures.js +75 -0
  62. package/dist/orm/operation-show.d.ts +2 -0
  63. package/dist/orm/operation-show.js +35 -0
  64. package/dist/orm/read.js +3 -3
  65. package/dist/orm/version-guard.d.ts +3 -0
  66. package/dist/orm/version-guard.js +63 -0
  67. package/dist/pipeline/commands.js +4 -1
  68. package/dist/principals/commands.d.ts +3 -0
  69. package/dist/principals/commands.js +124 -0
  70. package/dist/process/runs.d.ts +4 -3
  71. package/dist/process/runs.js +52 -10
  72. package/dist/release-age.d.ts +1 -1
  73. package/dist/release-age.js +1 -0
  74. package/dist/repos/commands.d.ts +44 -0
  75. package/dist/repos/commands.js +55 -15
  76. package/dist/repos/init-repo.d.ts +45 -0
  77. package/dist/repos/init-repo.js +257 -0
  78. package/dist/sandbox-unpushed-warning.d.ts +23 -0
  79. package/dist/sandbox-unpushed-warning.js +86 -0
  80. package/dist/service-accounts/commands.js +15 -3
  81. package/dist/templates/commands.d.ts +14 -2
  82. package/dist/templates/commands.js +70 -16
  83. package/dist/templates/process/pnpm-workspace.yaml +1 -0
  84. package/dist/transient-503.d.ts +4 -0
  85. package/dist/transient-503.js +25 -0
  86. package/package.json +14 -10
  87. package/templates/process/pnpm-workspace.yaml +1 -0
@@ -1,3 +1,3 @@
1
1
  import type { ParsedArgs } from '../process/commands.js';
2
- export declare const ACCESS_USAGE = "usage:\n seq-studio access definitions <artifact|function|orm> <resource-id> -e <env>\n seq-studio access resolve <artifact|function|orm> <resource-id> -e <env>\n seq-studio access list <artifact|function|orm> <resource-id> -e <env> [--floor | --key <key>]\n seq-studio access grant <artifact|function|orm> <resource-id> -e <env>\n (--floor | --key <key>) --principal-type <user|group|organization> --principal-id <id>\n seq-studio access revoke <artifact|function|orm> <resource-id> -e <env>\n (--floor | --key <key>) --principal-type <user|group|organization> --principal-id <id>\n\n All results are JSON (--json is also accepted). Authenticate: seq-studio login --env <env>.\n Resource IDs are artifact project IDs, function IDs, or ORM namespace names.\n definitions lists declared roles/capabilities; resolve shows the CALLER's effective claims.\n list defaults to direct role/capability grants; --floor lists runtime entry access.\n --floor is end_user for artifacts/ORM and invoker for functions. A custom key can\n be granted with --key; it must be declared and grantable on that resource.\n User IDs are authenticated subjects (auth whoami); groups use directory IDs;\n organizations use tenant slugs. Service accounts use --principal-type user\n --principal-id 'service-account|<account-id>'. Never pass an email in place of an ID.\n Grant/list/revoke require existing grant-manager authority on the resource.\n Service-account grants also require authority to act as that account.\n These commands manage runtime access; deployment/collaborator permissions remain separate.\n";
2
+ export declare const ACCESS_USAGE: string;
3
3
  export declare function runAccessCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;
@@ -1,87 +1,134 @@
1
- import { deleteJson, getJson, postJson } from '../atlas-client.js';
1
+ import { changeGroupRosterAccess } from './group-rosters.js';
2
2
  import { printCliError } from '../cli-errors.js';
3
- import { requiredStringFlag, validateCommandInput, wantsHelp } from '../command-input.js';
3
+ import { validateCommandInput, wantsHelp } from '../command-input.js';
4
4
  import { buildContext, clientOptions } from '../functions/commands.js';
5
+ import { ACCESS_ROLES_USAGE, runAccessRolesCommand } from './roles.js';
6
+ import { ACCESS_HOSTS, findAccessHost, selectedTier } from './hosts.js';
7
+ import { parsePrincipal, PRINCIPAL_KINDS } from './principal.js';
8
+ const HOST_NAMES = ACCESS_HOSTS.map((host) => host.name).join('|');
9
+ const ACCESS_SUBCOMMANDS = ['definitions', 'resolve', 'list', 'grant', 'revoke'];
5
10
  export const ACCESS_USAGE = `usage:
6
- seq-studio access definitions <artifact|function|orm> <resource-id> -e <env>
11
+ seq-studio access definitions <type> <resource-id> -e <env>
7
12
  seq-studio access resolve <artifact|function|orm> <resource-id> -e <env>
8
- seq-studio access list <artifact|function|orm> <resource-id> -e <env> [--floor | --key <key>]
9
- seq-studio access grant <artifact|function|orm> <resource-id> -e <env>
10
- (--floor | --key <key>) --principal-type <user|group|organization> --principal-id <id>
11
- seq-studio access revoke <artifact|function|orm> <resource-id> -e <env>
12
- (--floor | --key <key>) --principal-type <user|group|organization> --principal-id <id>
13
+ seq-studio access list <type> <resource-id> -e <env> [--floor | --key <key>]
14
+ seq-studio access grant <type> <resource-id> -e <env> (--floor | --key <key>)
15
+ --principal-type <${PRINCIPAL_KINDS.join('|')}> --principal-id <id> [--replace]
16
+ seq-studio access revoke <type> <resource-id> -e <env> (--floor | --key <key>)
17
+ --principal-type <${PRINCIPAL_KINDS.join('|')}> --principal-id <id>
18
+
19
+ <type> is one of ${HOST_NAMES}:
20
+ ${ACCESS_HOSTS.map((host) => ` ${host.name.padEnd(16)}${host.summary}`).join('\n')}
21
+
22
+ seq-studio access grant|revoke group <group-id> -e <env>
23
+ --key roster-reader --principal-type user --principal-id 'service-account|<account-id>'
24
+
25
+ Group roster Reader requires a directly authenticated human platform operator
26
+ with actor authority on that account and a host supporting roster provisioning.
27
+ It grants roster reads without joining the group or inheriting member access.
28
+ Directory Reader and the function manifest's exact group allowlist remain required.
29
+ Group list/resolve/definitions and other group role keys are not supported here.
13
30
 
14
31
  All results are JSON (--json is also accepted). Authenticate: seq-studio login --env <env>.
15
- Resource IDs are artifact project IDs, function IDs, or ORM namespace names.
16
- definitions lists declared roles/capabilities; resolve shows the CALLER's effective claims.
17
- list defaults to direct role/capability grants; --floor lists runtime entry access.
18
- --floor is end_user for artifacts/ORM and invoker for functions. A custom key can
19
- be granted with --key; it must be declared and grantable on that resource.
20
- User IDs are authenticated subjects (auth whoami); groups use directory IDs;
21
- organizations use tenant slugs. Service accounts use --principal-type user
22
- --principal-id 'service-account|<account-id>'. Never pass an email in place of an ID.
23
- Grant/list/revoke require existing grant-manager authority on the resource.
24
- Service-account grants also require authority to act as that account.
25
- These commands manage runtime access; deployment/collaborator permissions remain separate.
32
+ --floor selects the resource's runtime entry tier (who may use it at all);
33
+ --key selects a declared role/capability (artifact, function, orm, application)
34
+ or a fixed tier (every other type; definitions lists them).
35
+ On single-tier types (process, agent, pipeline, service-account, secret, repo,
36
+ namespace, workspace) a principal holds one tier: grant refuses to change an
37
+ existing different tier unless you pass --replace.
38
+ Find principal ids with seq-studio principals search <query>. Users are
39
+ authenticated subjects, groups are directory group ids, organizations are
40
+ tenant slugs, and service accounts are <account-id> or service-account|<id>.
41
+ Never pass an email or display name in place of an id.
42
+ Atlas applies the same rules as the Permissions UI: you need grant authority
43
+ on the resource, service-account grants also need actor on the account, and
44
+ you can only grant groups you may assign. Application roles take
45
+ --kind runtime|collaborator (default runtime).
46
+
47
+ Roles are created and edited in Atlas, not in code: seq-studio access roles
48
+ lists, creates, updates, and deletes roles on artifact, function, and orm
49
+ resources. See: seq-studio access roles --help
26
50
  `;
27
- function parsePrincipal(args) {
28
- const type = requiredStringFlag({ args, key: 'principal-type' });
29
- const id = requiredStringFlag({ args, key: 'principal-id' });
30
- if (!['user', 'group', 'organization'].includes(type)) {
31
- throw new Error('--principal-type must be user, group, or organization.');
32
- }
33
- if (type === 'user' && (/[#*\s]/.test(id) || (!id.includes('|') && !id.endsWith('@clients')))) {
34
- throw new Error('User principal IDs must be authenticated subjects, not emails or display names. Use auth whoami; service accounts use service-account|<id>.');
35
- }
36
- return { type, id };
37
- }
38
- function parseGrantSelection({ args, mutation }) {
51
+ function parseSelection({ args, mutation }) {
39
52
  const floor = args.flags.floor === true;
40
- const key = args.flags.key;
53
+ const key = typeof args.flags.key === 'string' ? args.flags.key : undefined;
41
54
  if ((floor && key !== undefined) || (mutation && !floor && key === undefined)) {
42
55
  throw new Error('Choose exactly one of --floor or --key <key>.');
43
56
  }
44
57
  return { floor, key };
45
58
  }
46
- function parseAccessTarget({ sub, args }) {
47
- if (!['definitions', 'resolve', 'list', 'grant', 'revoke'].includes(sub)) {
59
+ function parseTarget({ sub, args }) {
60
+ if (!ACCESS_SUBCOMMANDS.includes(sub)) {
48
61
  throw new Error(`Unknown access command: ${sub}. See: seq-studio access --help`);
49
62
  }
63
+ const host = findAccessHost(args.positional[0] ?? '');
64
+ if (!host)
65
+ throw new Error(`Resource type must be one of ${HOST_NAMES}.`);
50
66
  const mutation = sub === 'grant' || sub === 'revoke';
51
- const flags = {};
67
+ const flags = { ...host.flags };
52
68
  if (sub === 'list' || mutation)
53
69
  Object.assign(flags, { floor: 'boolean', key: 'string' });
54
70
  if (mutation)
55
71
  Object.assign(flags, { 'principal-type': 'string', 'principal-id': 'string' });
72
+ if (sub === 'grant')
73
+ Object.assign(flags, { replace: 'boolean' });
56
74
  validateCommandInput({ args, flags, positional: 2 });
57
- const [hostType, hostId] = args.positional;
58
- if (!hostType || !['artifact', 'function', 'orm'].includes(hostType)) {
59
- throw new Error('Resource type must be artifact, function, or orm.');
60
- }
61
- if (!hostId?.trim())
75
+ const id = args.positional[1]?.trim();
76
+ if (!id)
62
77
  throw new Error('A resource ID is required.');
63
- const { floor, key } = parseGrantSelection({ args, mutation });
64
- const principal = mutation ? parsePrincipal(args) : undefined;
65
- const suffix = sub === 'definitions' || sub === 'resolve' ? sub : floor ? 'end-users' : 'grants';
66
- const query = sub === 'list' && typeof key === 'string' ? `?key=${encodeURIComponent(key)}` : '';
67
- return {
68
- path: `/api/custom-roles/${hostType}/${encodeURIComponent(hostId)}/${suffix}${query}`,
69
- body: principal ? (floor ? { principal } : { key, principal }) : undefined,
70
- };
78
+ if (sub === 'resolve' && !host.resolve) {
79
+ throw new Error('resolve is available for artifact, function, and orm resources (declared capabilities).');
80
+ }
81
+ return { host, id };
82
+ }
83
+ async function runAccess({ sub, args }) {
84
+ const { host, id } = parseTarget({ sub, args });
85
+ const mutation = sub === 'grant' || sub === 'revoke';
86
+ const selection = sub === 'list' || mutation ? parseSelection({ args, mutation }) : { floor: false, key: undefined };
87
+ // Validate everything that needs no network before authenticating.
88
+ if (sub === 'list' || mutation)
89
+ selectedTier(host, selection);
90
+ const change = mutation
91
+ ? { ...selection, principal: parsePrincipal(args), replace: args.flags.replace === true }
92
+ : undefined;
93
+ if (change && !host.principals.includes(change.principal.kind)) {
94
+ throw new Error(`${host.name} grants accept ${host.principals.join(', ')} principals, not ${change.principal.kind}.`);
95
+ }
96
+ const ctx = await buildContext(args);
97
+ const call = { request: clientOptions(ctx), id, flags: args.flags };
98
+ switch (sub) {
99
+ case 'definitions': return host.definitions(call);
100
+ case 'resolve': return host.resolve(call);
101
+ case 'list': return host.list({ ...call, selection });
102
+ case 'grant': return host.grant({ ...call, change: change });
103
+ default: return host.revoke({ ...call, change: change });
104
+ }
71
105
  }
72
106
  export async function runAccessCommand(sub, args) {
107
+ // Before the group-level help check, so `access roles --help` shows the roles verbs.
108
+ if (sub === 'roles') {
109
+ const help = wantsHelp({ sub: args.positional[0], args });
110
+ if (help || args.positional.length === 0) {
111
+ console.log(ACCESS_ROLES_USAGE);
112
+ return help ? 0 : 1;
113
+ }
114
+ try {
115
+ return await runAccessRolesCommand(args);
116
+ }
117
+ catch (error) {
118
+ printCliError(error);
119
+ return 1;
120
+ }
121
+ }
73
122
  if (!sub || wantsHelp({ sub, args })) {
74
123
  console.log(ACCESS_USAGE);
75
124
  return sub ? 0 : 1;
76
125
  }
77
126
  try {
78
- const { path, body } = parseAccessTarget({ sub, args });
79
- const ctx = await buildContext(args);
80
- const request = { ...clientOptions(ctx), path };
81
- const result = sub === 'grant' ? await postJson({ ...request, body })
82
- : sub === 'revoke' ? await deleteJson({ ...request, body })
83
- : await getJson(request);
84
- console.log(JSON.stringify(result, null, 2));
127
+ if (args.positional[0] === 'group') {
128
+ console.log(JSON.stringify(await changeGroupRosterAccess({ sub, args }), null, 2));
129
+ return 0;
130
+ }
131
+ console.log(JSON.stringify(await runAccess({ sub, args }), null, 2));
85
132
  return 0;
86
133
  }
87
134
  catch (error) {
@@ -0,0 +1,3 @@
1
+ import { type AccessHost } from './host-contract.js';
2
+ export declare function customRolesHost(hostType: 'artifact' | 'function' | 'orm', summary: string): AccessHost;
3
+ export declare const applicationHost: AccessHost;
@@ -0,0 +1,88 @@
1
+ /** Hosts whose keys are declared per resource: Custom Roles hosts and Applications. */
2
+ import { deleteJson, getJson, postJson } from '../atlas-client.js';
3
+ import { unsupportedPrincipal } from './host-contract.js';
4
+ import { serviceAccountSubject } from './principal.js';
5
+ // ---------------------------------------------------------------------------
6
+ // Custom Roles hosts: artifact, function, orm
7
+ // ---------------------------------------------------------------------------
8
+ const CUSTOM_ROLE_FLOOR = { artifact: 'end_user', function: 'invoker', orm: 'end_user' };
9
+ function customRolePrincipal(principal) {
10
+ return principal.kind === 'service-account'
11
+ ? { type: 'user', id: serviceAccountSubject(principal.id) }
12
+ : { type: principal.kind, id: principal.id };
13
+ }
14
+ export function customRolesHost(hostType, summary) {
15
+ const base = ({ id }) => `/api/custom-roles/${hostType}/${encodeURIComponent(id)}`;
16
+ const host = {
17
+ name: hostType,
18
+ summary,
19
+ floor: CUSTOM_ROLE_FLOOR[hostType],
20
+ singleTier: false,
21
+ // Function floors refuse organizations server-side, with a clear message.
22
+ principals: ['user', 'group', 'organization', 'service-account'],
23
+ definitions: (call) => getJson({ ...call.request, path: `${base(call)}/definitions` }),
24
+ resolve: (call) => getJson({ ...call.request, path: `${base(call)}/resolve` }),
25
+ list: (call) => {
26
+ const { floor, key } = call.selection;
27
+ const query = !floor && key ? `?key=${encodeURIComponent(key)}` : '';
28
+ return getJson({ ...call.request, path: `${base(call)}/${floor ? 'end-users' : 'grants'}${query}` });
29
+ },
30
+ grant: (call) => customRoleMutation({ host, call, method: 'grant', base: base(call) }),
31
+ revoke: (call) => customRoleMutation({ host, call, method: 'revoke', base: base(call) }),
32
+ };
33
+ return host;
34
+ }
35
+ function customRoleMutation({ host, call, method, base }) {
36
+ const { change } = call;
37
+ if (!host.principals.includes(change.principal.kind))
38
+ throw unsupportedPrincipal(host, change.principal.kind);
39
+ if (!change.floor && !change.key)
40
+ throw new Error('Choose exactly one of --floor or --key <key>.');
41
+ const principal = customRolePrincipal(change.principal);
42
+ const path = `${base}/${change.floor ? 'end-users' : 'grants'}`;
43
+ const body = change.floor ? { principal } : { key: change.key, principal };
44
+ return method === 'grant'
45
+ ? postJson({ ...call.request, path, body })
46
+ : deleteJson({ ...call.request, path, body });
47
+ }
48
+ // ---------------------------------------------------------------------------
49
+ // Application roles
50
+ // ---------------------------------------------------------------------------
51
+ function applicationKind(flags) {
52
+ const kind = flags.kind ?? 'runtime';
53
+ if (kind !== 'runtime' && kind !== 'collaborator')
54
+ throw new Error('--kind must be runtime or collaborator.');
55
+ return kind;
56
+ }
57
+ export const applicationHost = {
58
+ name: 'application',
59
+ summary: 'Application roles (sequence.app.yml schema 3); --kind runtime|collaborator',
60
+ singleTier: false,
61
+ principals: ['user', 'group', 'organization'],
62
+ flags: { kind: 'string' },
63
+ definitions: (call) => getJson({
64
+ ...call.request,
65
+ path: `/api/custom-roles/applications/${encodeURIComponent(call.id)}/roles?kind=${applicationKind(call.flags)}`,
66
+ }),
67
+ list: (call) => {
68
+ if (call.selection.floor)
69
+ throw new Error('Applications have no floor; list roles with --key or no selector.');
70
+ const key = call.selection.key ? `&key=${encodeURIComponent(call.selection.key)}` : '';
71
+ return getJson({
72
+ ...call.request,
73
+ path: `/api/custom-roles/applications/${encodeURIComponent(call.id)}/grants?kind=${applicationKind(call.flags)}${key}`,
74
+ });
75
+ },
76
+ grant: (call) => applicationMutation(call, 'grant'),
77
+ revoke: (call) => applicationMutation(call, 'revoke'),
78
+ };
79
+ function applicationMutation(call, method) {
80
+ const { change } = call;
81
+ if (change.floor || !change.key)
82
+ throw new Error('Applications have no floor; choose a role with --key <role>.');
83
+ if (!applicationHost.principals.includes(change.principal.kind))
84
+ throw unsupportedPrincipal(applicationHost, change.principal.kind);
85
+ const path = `/api/custom-roles/applications/${encodeURIComponent(call.id)}/grants?kind=${applicationKind(call.flags)}`;
86
+ const body = { key: change.key, principal: { type: change.principal.kind, id: change.principal.id } };
87
+ return method === 'grant' ? postJson({ ...call.request, path, body }) : deleteJson({ ...call.request, path, body });
88
+ }
@@ -0,0 +1,6 @@
1
+ import type { ParsedArgs } from "../process/commands.js";
2
+ /** Group roster provisioning is control-plane access, not a custom runtime role. */
3
+ export declare function changeGroupRosterAccess({ sub, args, }: {
4
+ sub: string;
5
+ args: ParsedArgs;
6
+ }): Promise<unknown>;
@@ -0,0 +1,33 @@
1
+ import { groupRosterAccessTargetSchema } from "@sequenceholdings/platform/contracts";
2
+ import { operatorPlatformClient } from "../atlas-client.js";
3
+ import { requiredStringFlag, validateCommandInput } from "../command-input.js";
4
+ import { buildContext, clientOptions } from "../functions/commands.js";
5
+ /** Group roster provisioning is control-plane access, not a custom runtime role. */
6
+ export async function changeGroupRosterAccess({ sub, args, }) {
7
+ if (sub !== "grant" && sub !== "revoke")
8
+ throw new Error("Group roster access supports grant and revoke only.");
9
+ validateCommandInput({
10
+ args,
11
+ positional: 2,
12
+ flags: {
13
+ key: "string",
14
+ "principal-type": "string",
15
+ "principal-id": "string",
16
+ },
17
+ });
18
+ if (requiredStringFlag({ args, key: "key" }) !== "roster-reader" ||
19
+ requiredStringFlag({ args, key: "principal-type" }) !== "user") {
20
+ throw new Error("Group access requires --key roster-reader --principal-type user and an explicit service-account subject.");
21
+ }
22
+ const subject = requiredStringFlag({ args, key: "principal-id" });
23
+ const prefix = "service-account|";
24
+ if (!subject.startsWith(prefix))
25
+ throw new Error("Roster Reader can be provisioned only for service-account|<account-id>.");
26
+ const target = groupRosterAccessTargetSchema.parse({
27
+ groupId: args.positional[1],
28
+ accountId: subject.slice(prefix.length),
29
+ });
30
+ const ctx = await buildContext(args);
31
+ const client = operatorPlatformClient(clientOptions(ctx)).groups.rosterAccess;
32
+ return sub === "grant" ? client.grant(target) : client.revoke(target);
33
+ }
@@ -0,0 +1,55 @@
1
+ /** The adapter contract every `seq-studio access` host implements, plus shared guards. */
2
+ import type { Principal, PrincipalKind } from './principal.js';
3
+ export interface HostRequest {
4
+ baseUrl: string;
5
+ token: string;
6
+ }
7
+ export interface Selection {
8
+ floor: boolean;
9
+ key: string | undefined;
10
+ }
11
+ export interface GrantChange extends Selection {
12
+ principal: Principal;
13
+ /** Single-tier hosts: allow replacing a principal's existing different tier. */
14
+ replace: boolean;
15
+ }
16
+ export interface AccessHost {
17
+ /** The CLI name (`process`, `repo`, …). */
18
+ name: string;
19
+ summary: string;
20
+ /** Runtime entry tier, when the host has one; `--floor` selects it. */
21
+ floor?: string;
22
+ /** Fixed tiers. Undefined when keys are declared per resource (custom roles). */
23
+ keys?: readonly string[];
24
+ /** Hosts where a principal holds exactly one tier (grant replaces with --replace). */
25
+ singleTier: boolean;
26
+ principals: readonly PrincipalKind[];
27
+ /** Extra flags this host accepts, beyond the shared ones. */
28
+ flags?: Record<string, 'string' | 'boolean'>;
29
+ definitions(input: HostCall): Promise<unknown>;
30
+ resolve?(input: HostCall): Promise<unknown>;
31
+ list(input: HostCall & {
32
+ selection: Selection;
33
+ }): Promise<unknown>;
34
+ grant(input: HostCall & {
35
+ change: GrantChange;
36
+ }): Promise<unknown>;
37
+ revoke(input: HostCall & {
38
+ change: GrantChange;
39
+ }): Promise<unknown>;
40
+ }
41
+ export interface HostCall {
42
+ request: HostRequest;
43
+ id: string;
44
+ flags: Record<string, string | boolean | undefined>;
45
+ }
46
+ export declare function staticDefinitions(host: AccessHost): Record<string, unknown>;
47
+ /** `--floor` or `--key` → the tier name this host uses. */
48
+ export declare function selectedTier(host: AccessHost, selection: Selection): string | undefined;
49
+ export declare function requireTier(host: AccessHost, change: GrantChange): string;
50
+ export declare function unsupportedPrincipal(host: AccessHost, kind: PrincipalKind): Error;
51
+ export declare function heldTierConflict({ host, current, tier }: {
52
+ host: AccessHost;
53
+ current: string;
54
+ tier: string;
55
+ }): Error;
@@ -0,0 +1,33 @@
1
+ export function staticDefinitions(host) {
2
+ return {
3
+ hostType: host.name,
4
+ floor: host.floor ?? null,
5
+ keys: host.keys ?? null,
6
+ singleTier: host.singleTier,
7
+ principalTypes: host.principals,
8
+ };
9
+ }
10
+ /** `--floor` or `--key` → the tier name this host uses. */
11
+ export function selectedTier(host, selection) {
12
+ if (selection.floor) {
13
+ if (!host.floor)
14
+ throw new Error(`${host.name} has no runtime floor; choose a tier with --key (${(host.keys ?? []).join(', ')}).`);
15
+ return host.floor;
16
+ }
17
+ if (selection.key !== undefined && host.keys && !host.keys.includes(selection.key)) {
18
+ throw new Error(`--key for ${host.name} must be one of ${host.keys.join(', ')}.`);
19
+ }
20
+ return selection.key;
21
+ }
22
+ export function requireTier(host, change) {
23
+ const tier = selectedTier(host, change);
24
+ if (!tier)
25
+ throw new Error('Choose exactly one of --floor or --key <key>.');
26
+ return tier;
27
+ }
28
+ export function unsupportedPrincipal(host, kind) {
29
+ return new Error(`${host.name} grants accept ${host.principals.join(', ')} principals, not ${kind}.`);
30
+ }
31
+ export function heldTierConflict({ host, current, tier }) {
32
+ return new Error(`This principal already holds ${current} on this ${host.name}. Pass --replace to change it to ${tier}, or revoke --key ${current} first.`);
33
+ }
@@ -0,0 +1,4 @@
1
+ import type { AccessHost } from './host-contract.js';
2
+ export { selectedTier, type AccessHost, type GrantChange, type Selection } from './host-contract.js';
3
+ export declare const ACCESS_HOSTS: readonly AccessHost[];
4
+ export declare function findAccessHost(name: string): AccessHost | undefined;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * One adapter per Atlas access plane, so `seq-studio access` offers the same
3
+ * verbs on every primitive while each request goes to the route (and the
4
+ * authority rules) the Atlas UI already uses:
5
+ *
6
+ * artifact | function | orm /api/custom-roles/<host>/<id>/… declared roles/capabilities + floor
7
+ * application /api/custom-roles/applications/<id>/… Application roles
8
+ * process | agent | pipeline | service-account
9
+ * /api/authz/permissions/<type>/<id> fixed tiers (Permissions panel)
10
+ * secret /api/managed-secrets/<id>/principals
11
+ * repo | namespace /api/git-service/{repos,namespaces}/<id>/principals
12
+ * workspace /api/storage/workspaces/<id>/access
13
+ *
14
+ * The server decides every grant: these adapters only shape requests and
15
+ * refuse ambiguous ones (unsupported principal types, accidental tier
16
+ * replacement) before they leave the machine.
17
+ */
18
+ import { applicationHost, customRolesHost } from './custom-role-hosts.js';
19
+ import { gitHost, permissionsHost, secretHost, workspaceHost } from './tier-hosts.js';
20
+ export { selectedTier } from './host-contract.js';
21
+ export const ACCESS_HOSTS = [
22
+ customRolesHost('artifact', 'Artifact Studio project (id); floor end_user, plus declared roles/capabilities'),
23
+ customRolesHost('function', 'Managed Function (id); floor invoker, plus declared roles/capabilities'),
24
+ customRolesHost('orm', 'ORM namespace (name); floor end_user, plus declared roles/capabilities'),
25
+ applicationHost,
26
+ permissionsHost({
27
+ name: 'process',
28
+ resourceType: 'lattice_process',
29
+ summary: 'Lattice process (id); floor invoker (start runs); viewer reads runs and context',
30
+ keys: ['owner', 'editor', 'invoker', 'viewer'],
31
+ floor: 'invoker',
32
+ }),
33
+ permissionsHost({
34
+ name: 'agent',
35
+ resourceType: 'agent',
36
+ summary: 'Agent Builder agent (id); floor invoker (chat and runs)',
37
+ keys: ['owner', 'editor', 'invoker', 'outputs_viewer'],
38
+ floor: 'invoker',
39
+ }),
40
+ permissionsHost({
41
+ name: 'pipeline',
42
+ resourceType: 'managed_pipeline',
43
+ summary: 'Managed Pipeline release unit (<namespace>/<name>); collaborators only, no floor',
44
+ keys: ['admin', 'editor', 'operator', 'viewer'],
45
+ routeId: (id) => id.replaceAll('/', ':'),
46
+ }),
47
+ permissionsHost({
48
+ name: 'service-account',
49
+ resourceType: 'service_account',
50
+ summary: 'Service account (id); actor may attach it to workloads (granting is Sequence-operator only)',
51
+ keys: ['admin', 'actor'],
52
+ }),
53
+ secretHost,
54
+ gitHost('repo'),
55
+ gitHost('namespace'),
56
+ workspaceHost,
57
+ ];
58
+ export function findAccessHost(name) {
59
+ return ACCESS_HOSTS.find((host) => host.name === name);
60
+ }
@@ -0,0 +1,16 @@
1
+ import type { ParsedArgs } from '../process/commands.js';
2
+ export declare const PRINCIPAL_KINDS: readonly ["user", "group", "organization", "service-account"];
3
+ export type PrincipalKind = (typeof PRINCIPAL_KINDS)[number];
4
+ /** A grant target as the caller named it; `id` is a bare account id for service accounts. */
5
+ export interface Principal {
6
+ kind: PrincipalKind;
7
+ id: string;
8
+ }
9
+ export declare function serviceAccountSubject(accountId: string): string;
10
+ /**
11
+ * Parse `--principal-type` / `--principal-id`. Accepts the legacy spelling for
12
+ * service accounts (`--principal-type user --principal-id service-account|<id>`)
13
+ * and `service_account` as an alias, so ids copied from `principals search`
14
+ * work unchanged.
15
+ */
16
+ export declare function parsePrincipal(args: ParsedArgs): Principal;
@@ -0,0 +1,36 @@
1
+ import { requiredStringFlag } from '../command-input.js';
2
+ export const PRINCIPAL_KINDS = ['user', 'group', 'organization', 'service-account'];
3
+ const SERVICE_ACCOUNT_PREFIX = 'service-account|';
4
+ export function serviceAccountSubject(accountId) {
5
+ return `${SERVICE_ACCOUNT_PREFIX}${accountId}`;
6
+ }
7
+ /**
8
+ * Parse `--principal-type` / `--principal-id`. Accepts the legacy spelling for
9
+ * service accounts (`--principal-type user --principal-id service-account|<id>`)
10
+ * and `service_account` as an alias, so ids copied from `principals search`
11
+ * work unchanged.
12
+ */
13
+ export function parsePrincipal(args) {
14
+ const rawType = requiredStringFlag({ args, key: 'principal-type' });
15
+ const rawId = requiredStringFlag({ args, key: 'principal-id' }).trim();
16
+ const type = rawType === 'service_account' ? 'service-account' : rawType;
17
+ if (!PRINCIPAL_KINDS.includes(type)) {
18
+ throw new Error(`--principal-type must be one of ${PRINCIPAL_KINDS.join(', ')}.`);
19
+ }
20
+ if (!rawId || /[#*\s]/.test(rawId)) {
21
+ throw new Error('--principal-id must be an exact id (no spaces, wildcards, or #). Find ids with seq-studio principals search.');
22
+ }
23
+ if (type === 'service-account' || rawId.startsWith(SERVICE_ACCOUNT_PREFIX)) {
24
+ if (type !== 'service-account' && type !== 'user') {
25
+ throw new Error(`A service-account id cannot be granted as a ${type}.`);
26
+ }
27
+ const accountId = rawId.startsWith(SERVICE_ACCOUNT_PREFIX) ? rawId.slice(SERVICE_ACCOUNT_PREFIX.length) : rawId;
28
+ if (!accountId || accountId.includes('|'))
29
+ throw new Error('Service-account ids look like <account-id> or service-account|<account-id>.');
30
+ return { kind: 'service-account', id: accountId };
31
+ }
32
+ if (type === 'user' && !rawId.includes('|') && !rawId.endsWith('@clients')) {
33
+ throw new Error('User principal ids are authenticated subjects (e.g. auth0|abc), not emails or names. Find them with seq-studio principals users search <query>.');
34
+ }
35
+ return { kind: type, id: rawId };
36
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `seq-studio access roles` — create and edit a resource's roles in Atlas.
3
+ *
4
+ * Capabilities are code (declared in the resource's source and published by
5
+ * its deploy); roles are data: they bundle capabilities, live in the Atlas
6
+ * role registry, and are edited here or on the Permissions page. This wraps
7
+ * the registry routes the Permissions page uses, so registry write authority
8
+ * (the resource's capability admins) and DAG validation stay server-side.
9
+ */
10
+ import type { ParsedArgs } from '../process/commands.js';
11
+ export declare const ACCESS_ROLES_USAGE = "usage:\n seq-studio access roles list <artifact|function|orm> <resource-id> -e <env>\n seq-studio access roles create <artifact|function|orm> <resource-id> <role-key> -e <env>\n [--grants <capability,...>] [--inherits <role,...>] [--description <text>] [--default]\n seq-studio access roles update <artifact|function|orm> <resource-id> <role-key> -e <env>\n [--grants <capability,...>] [--inherits <role,...>] [--description <text>] [--default | --no-default]\n seq-studio access roles delete <artifact|function|orm> <resource-id> <role-key> -e <env>\n\n Roles bundle the capabilities a resource declares in its source; create and edit\n them here, then assign them with seq-studio access grant ... --key <role-key>.\n --grants and --inherits replace the role's whole list on update.\n Editing roles requires capability-admin authority on the resource.\n";
12
+ /** The request one `access roles` invocation makes. */
13
+ export declare function rolesRequest(args: ParsedArgs): {
14
+ method: 'GET' | 'POST' | 'PATCH' | 'DELETE';
15
+ path: string;
16
+ body?: Record<string, unknown>;
17
+ };
18
+ export declare function runAccessRolesCommand(args: ParsedArgs): Promise<number>;