@sequenceholdings/studio-cli 0.2.2 → 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.
@@ -23,6 +23,15 @@ export declare function smartHttpCloneDepth({ ref, full, }: {
23
23
  ref?: string;
24
24
  full: boolean;
25
25
  }): number | undefined;
26
+ /**
27
+ * buildContext for repos commands: rejects a valueless -e/--env (which would
28
+ * silently fall back to the default environment — dangerous with `delete
29
+ * --yes`) and threads the Cloudflare preview WAF bypass header to
30
+ * artifact-studio's HTTP client, which resolveRepo/materializeRepo use
31
+ * (mirrors applyPreviewAccessHeader in ../artifact/delegate.ts — studio-cli's
32
+ * own atlas-client reads PREVIEW_ACCESS_HEADER directly).
33
+ */
34
+ export declare function reposContext(args: ParsedArgs): Promise<CommandContext>;
26
35
  /** Smart-HTTP clone base (aligned with PLA-83: `…/repos/<id>/git`). */
27
36
  export declare function cloneUrl(ctx: CommandContext, repoId: string): string;
28
37
  /**
@@ -106,6 +115,6 @@ export declare function reposCiRequireCommand(args: ParsedArgs): Promise<number>
106
115
  export declare function reposCiImportCommand(args: ParsedArgs): Promise<number>;
107
116
  export declare function reposCiCommand(args: ParsedArgs): Promise<number>;
108
117
  export declare function reposDeleteCommand(args: ParsedArgs): Promise<number>;
109
- export declare const REPOS_USAGE = "usage:\n seq-studio repos list -e <env> [--namespace <slug>] [--mine] repos visible on the environment\n seq-studio repos namespaces [create <slug>] -e <env> list or create namespaces\n seq-studio repos show <ns>/<name> -e <env> repo detail (branches, clone URL)\n seq-studio repos create <ns>/<name> -e <env> [--default-branch b] [--git-backend walgit]\n create a repo seeded with a README; --git-backend\n walgit creates it empty (for pushing existing\n history); needs namespace write\n seq-studio repos clone <ns>/<name> -e <env> [--ref r] [--output dir] [--force] [--full]\n seq-studio repos clone --url <https://\u2026/repos/<id>/git> -e <env> [--ref r] [--output dir] [--full]\n seq-studio repos clone --id <uuid> -e <env> [--ref r] [--output dir] [--full]\n smart-HTTP when ATLAS_GIT_PAT is set;\n otherwise JSON materialize (<ns>/<name>)\n seq-studio repos pull <ns>/<name> -e <env> [--ref r] [--out dir] [--force]\n materialize the tree at a ref (JSON API)\n seq-studio repos delete <ns>/<name> -e <env> [--yes] delete a repo (confirm prompt)\n seq-studio repos ci show <ns>/<name> -e <env> [--ref r] preview discovered CI checks\n seq-studio repos ci require <ns>/<name> --check <name> -e <env> reserved (refuses write until sandboxed runner)\n seq-studio repos ci import <ns>/<name> -e <env> [--ref r] reserved (refuses write until sandboxed runner)\n\n Flags: -e/--env <env> (required; see: seq-studio envs list)\n\n clone prefers real git clone (PAT via askpass \u2014 never written into the remote\n URL). Without ATLAS_GIT_PAT, <ns>/<name> falls back to the JSON API and prints\n how to get a PAT (seq-studio or Atlas UI /settings/tokens).\n PAT without Auth0 login: use --id from Repositories \u2192 Clone\n (or --url with the environment's canonical HTTPS origin).\n --ref accepts a branch, tag, or commit SHA (SHA \u2192 full clone, then checkout).\n Branch and tag clones are shallow (--depth 1). Pass --full for history.\n --output selects the clone directory (--out remains an alias).\n\n Authenticate JSON API calls with: seq-studio login\n Authenticate git clone/push with: ATLAS_GIT_PAT (from Atlas Settings \u2192 Tokens)\n";
118
+ export declare const REPOS_USAGE = "usage:\n seq-studio repos list -e <env> [--namespace <slug>] [--mine] repos visible on the environment\n seq-studio repos namespaces [create <slug>] -e <env> list or create namespaces\n seq-studio repos show <ns>/<name> -e <env> repo detail (branches, clone URL)\n seq-studio repos create <ns>/<name> -e <env> [--default-branch b] [--git-backend walgit]\n create a repo seeded with a README; --git-backend\n walgit creates it empty (for pushing existing\n history); needs namespace write\n seq-studio repos clone <ns>/<name> -e <env> [--ref r] [--output dir] [--force] [--full]\n seq-studio repos clone --url <https://\u2026/repos/<id>/git> -e <env> [--ref r] [--output dir] [--full]\n seq-studio repos clone --id <uuid> -e <env> [--ref r] [--output dir] [--full]\n smart-HTTP when ATLAS_GIT_PAT is set;\n otherwise JSON materialize (<ns>/<name>)\n seq-studio repos pull <ns>/<name> -e <env> [--ref r] [--out dir] [--force]\n materialize the tree at a ref (JSON API)\n seq-studio repos pulls <list|show|create|diff|merge> [args] review requests (see pulls --help)\n seq-studio repos delete <ns>/<name> -e <env> [--yes] delete a repo (confirm prompt)\n seq-studio repos ci show <ns>/<name> -e <env> [--ref r] preview discovered CI checks\n seq-studio repos ci require <ns>/<name> --check <name> -e <env> reserved (refuses write until sandboxed runner)\n seq-studio repos ci import <ns>/<name> -e <env> [--ref r] reserved (refuses write until sandboxed runner)\n\n Flags: -e/--env <env> (required; see: seq-studio envs list)\n\n clone prefers real git clone (PAT via askpass \u2014 never written into the remote\n URL). Without ATLAS_GIT_PAT, <ns>/<name> falls back to the JSON API and prints\n how to get a PAT (seq-studio or Atlas UI /settings/tokens).\n PAT without Auth0 login: use --id from Repositories \u2192 Clone\n (or --url with the environment's canonical HTTPS origin).\n --ref accepts a branch, tag, or commit SHA (SHA \u2192 full clone, then checkout).\n Branch and tag clones are shallow (--depth 1). Pass --full for history.\n --output selects the clone directory (--out remains an alias).\n\n Authenticate JSON API calls with: seq-studio login\n Authenticate git clone/push with: ATLAS_GIT_PAT (from Atlas Settings \u2192 Tokens)\n";
110
119
  export declare function runReposCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;
111
120
  export {};
@@ -73,7 +73,7 @@ export function smartHttpCloneDepth({ ref, full, }) {
73
73
  * (mirrors applyPreviewAccessHeader in ../artifact/delegate.ts — studio-cli's
74
74
  * own atlas-client reads PREVIEW_ACCESS_HEADER directly).
75
75
  */
76
- async function reposContext(args) {
76
+ export async function reposContext(args) {
77
77
  if (args.flags.env === true || args.flags.e === true) {
78
78
  throw new Error('-e/--env requires a value — see: seq-studio envs list.');
79
79
  }
@@ -808,6 +808,7 @@ export const REPOS_USAGE = `usage:
808
808
  otherwise JSON materialize (<ns>/<name>)
809
809
  seq-studio repos pull <ns>/<name> -e <env> [--ref r] [--out dir] [--force]
810
810
  materialize the tree at a ref (JSON API)
811
+ seq-studio repos pulls <list|show|create|diff|merge> [args] review requests (see pulls --help)
811
812
  seq-studio repos delete <ns>/<name> -e <env> [--yes] delete a repo (confirm prompt)
812
813
  seq-studio repos ci show <ns>/<name> -e <env> [--ref r] preview discovered CI checks
813
814
  seq-studio repos ci require <ns>/<name> --check <name> -e <env> reserved (refuses write until sandboxed runner)
@@ -844,6 +845,10 @@ export async function runReposCommand(sub, args) {
844
845
  return await reposPullCommand(args);
845
846
  case 'delete':
846
847
  return await reposDeleteCommand(args);
848
+ case 'pulls': {
849
+ const { reposPullsCommand } = await import('./pulls.js');
850
+ return await reposPullsCommand(args);
851
+ }
847
852
  case 'ci':
848
853
  return await reposCiCommand(args);
849
854
  case 'help':
@@ -0,0 +1,3 @@
1
+ import type { ParsedArgs } from '../process/commands.js';
2
+ export declare const PULLS_USAGE = "usage:\n seq-studio repos pulls list <ns>/<name> -e <env> [--state open|closed|merged] [--limit N] [--cursor <cursor>]\n seq-studio repos pulls show <ns>/<name> <number> -e <env>\n seq-studio repos pulls create <ns>/<name> --head <branch> --base <branch> --title <title> -e <env> [--body-file <path>]\n seq-studio repos pulls diff <ns>/<name> <number> -e <env> [--max-files N]\n seq-studio repos pulls merge <ns>/<name> <number> -e <env> [--method squash|merge|ff] [--message <text>] [--yes]\n\n All results are JSON (--json is accepted). Authenticate: seq-studio login --env <env>.\n create needs repository write; merge needs merge/admin authority and passing server\n review/check policy. There is no policy bypass. Review show and diff before merging.\n Merge operates on the current branch head under server policy; a displayed SHA is\n informational and is not a compare-and-swap guard. Default merge method: squash.\n list returns one page with nextCursor; pass --cursor to continue.\n diff compares live base/head branches for open Pulls, recorded SHAs for terminal\n Pulls, and reports truncated when its file\n limit is reached (default 100, maximum 500).\n repos pull (singular) materializes files; repos pulls manages review requests.\n";
3
+ export declare function reposPullsCommand(input: ParsedArgs): Promise<number>;
@@ -0,0 +1,131 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { resolveRepo } from '@sequenceholdings/artifact-studio/git-service-client';
3
+ import { getJson, postJson } from '../atlas-client.js';
4
+ import { requiredStringFlag, validateCommandInput, wantsHelp } from '../command-input.js';
5
+ import { clientOptions } from '../functions/commands.js';
6
+ import { confirmYes } from '../prompt.js';
7
+ import { parseRepoPath, reposContext } from './commands.js';
8
+ export const PULLS_USAGE = `usage:
9
+ seq-studio repos pulls list <ns>/<name> -e <env> [--state open|closed|merged] [--limit N] [--cursor <cursor>]
10
+ seq-studio repos pulls show <ns>/<name> <number> -e <env>
11
+ seq-studio repos pulls create <ns>/<name> --head <branch> --base <branch> --title <title> -e <env> [--body-file <path>]
12
+ seq-studio repos pulls diff <ns>/<name> <number> -e <env> [--max-files N]
13
+ seq-studio repos pulls merge <ns>/<name> <number> -e <env> [--method squash|merge|ff] [--message <text>] [--yes]
14
+
15
+ All results are JSON (--json is accepted). Authenticate: seq-studio login --env <env>.
16
+ create needs repository write; merge needs merge/admin authority and passing server
17
+ review/check policy. There is no policy bypass. Review show and diff before merging.
18
+ Merge operates on the current branch head under server policy; a displayed SHA is
19
+ informational and is not a compare-and-swap guard. Default merge method: squash.
20
+ list returns one page with nextCursor; pass --cursor to continue.
21
+ diff compares live base/head branches for open Pulls, recorded SHAs for terminal
22
+ Pulls, and reports truncated when its file
23
+ limit is reached (default 100, maximum 500).
24
+ repos pull (singular) materializes files; repos pulls manages review requests.
25
+ `;
26
+ function integerFlag({ args, key, max }) {
27
+ const value = args.flags[key];
28
+ if (value === undefined)
29
+ return undefined;
30
+ if (typeof value !== 'string' || !/^\d+$/.test(value) || Number(value) < 1 || Number(value) > max) {
31
+ throw new Error(`--${key} must be an integer between 1 and ${max}.`);
32
+ }
33
+ return value;
34
+ }
35
+ function actionFlags(action) {
36
+ switch (action) {
37
+ case 'list': return { state: 'string', limit: 'string', cursor: 'string' };
38
+ case 'show': return {};
39
+ case 'create': return { head: 'string', base: 'string', title: 'string', 'body-file': 'string' };
40
+ case 'diff': return { 'max-files': 'string' };
41
+ case 'merge': return { method: 'string', message: 'string', yes: 'boolean' };
42
+ default: throw new Error(`Unknown pulls command: ${action}. See: seq-studio repos pulls --help`);
43
+ }
44
+ }
45
+ async function createBody(args) {
46
+ const headRef = requiredStringFlag({ args, key: 'head' });
47
+ const baseRef = requiredStringFlag({ args, key: 'base' });
48
+ const title = requiredStringFlag({ args, key: 'title' });
49
+ const bodyFile = args.flags['body-file'];
50
+ const body = typeof bodyFile === 'string' ? await readFile(bodyFile, 'utf8') : undefined;
51
+ if (body !== undefined && body.length > 65_536)
52
+ throw new Error('--body-file exceeds 65,536 characters.');
53
+ return { headRef, baseRef, title, ...(body === undefined ? {} : { body }) };
54
+ }
55
+ async function mergePull({ args, ctx, path, repoPath }) {
56
+ const detail = await getJson({ ...clientOptions(ctx), path });
57
+ if (!detail.viewerCanMerge)
58
+ throw new Error('The authenticated identity does not have merge authority on this repository.');
59
+ const preview = [
60
+ `Merge ${repoPath} Pull #${args.positional[1]} on ${ctx.env.name}: ${detail.pullRequest.title}`,
61
+ `${detail.pullRequest.headRef} → ${detail.pullRequest.baseRef}; recorded head: ${detail.pullRequest.headSha}`,
62
+ 'The server merges the current branch head, subject to its review and check policy.',
63
+ ];
64
+ for (const line of preview)
65
+ console.error(line);
66
+ const confirmed = await confirmYes({ confirmed: args.flags.yes === true, preview: [] });
67
+ if (!confirmed)
68
+ return 1;
69
+ const result = await postJson({ ...clientOptions(ctx), path: `${path}/merge`, body: {
70
+ method: args.flags.method ?? 'squash',
71
+ ...(args.flags.message === undefined ? {} : { message: args.flags.message }),
72
+ } });
73
+ console.log(JSON.stringify(result, null, 2));
74
+ return 0;
75
+ }
76
+ function parsePullOptions(args) {
77
+ if (args.positional[1] !== undefined && (!/^[1-9]\d*$/.test(args.positional[1]) || !Number.isSafeInteger(Number(args.positional[1])))) {
78
+ throw new Error('Pull number must be a positive integer.');
79
+ }
80
+ const state = args.flags.state;
81
+ if (state !== undefined && !['open', 'closed', 'merged'].includes(String(state)))
82
+ throw new Error('--state must be open, closed, or merged.');
83
+ const method = args.flags.method;
84
+ if (method !== undefined && !['squash', 'merge', 'ff'].includes(String(method)))
85
+ throw new Error('--method must be squash, merge, or ff.');
86
+ const limit = integerFlag({ args, key: 'limit', max: 200 });
87
+ const maxFiles = integerFlag({ args, key: 'max-files', max: 500 });
88
+ return { state: typeof state === 'string' ? state : undefined, limit, maxFiles };
89
+ }
90
+ export async function reposPullsCommand(input) {
91
+ const [action, ...positional] = input.positional;
92
+ if (!action || wantsHelp({ sub: action, args: input })) {
93
+ console.log(PULLS_USAGE);
94
+ return action || input.flags.help ? 0 : 1;
95
+ }
96
+ const args = { ...input, positional };
97
+ validateCommandInput({ args, flags: actionFlags(action), positional: ['list', 'create'].includes(action) ? 1 : 2 });
98
+ const repoPath = positional[0];
99
+ const repo = parseRepoPath(repoPath);
100
+ const { state, limit, maxFiles } = parsePullOptions(args);
101
+ const body = action === 'create' ? await createBody(args) : undefined;
102
+ const ctx = await reposContext(args);
103
+ const resolved = await resolveRepo({ ...clientOptions(ctx), ...repo });
104
+ const repoBase = `/api/git-service/repos/${encodeURIComponent(resolved.id)}`;
105
+ const path = `${repoBase}/pulls${positional[1] ? `/${positional[1]}` : ''}`;
106
+ if (action === 'merge')
107
+ return mergePull({ args, ctx, path, repoPath });
108
+ let result;
109
+ if (action === 'create') {
110
+ result = await postJson({ ...clientOptions(ctx), path, body });
111
+ }
112
+ else if (action === 'diff') {
113
+ const { pullRequest } = await getJson({ ...clientOptions(ctx), path: `${path}?include_mergeability=0` });
114
+ const base = pullRequest.state === 'open' ? pullRequest.baseRef : pullRequest.baseSha;
115
+ const head = pullRequest.state === 'open' ? pullRequest.headRef : pullRequest.headSha;
116
+ const range = `${encodeURIComponent(base)}...${encodeURIComponent(head)}`;
117
+ result = await getJson({ ...clientOptions(ctx), path: `${repoBase}/compare/${range}${maxFiles ? `?max_files=${maxFiles}` : ''}` });
118
+ }
119
+ else {
120
+ const query = new URLSearchParams();
121
+ if (typeof state === 'string')
122
+ query.set('state', state);
123
+ if (limit)
124
+ query.set('limit', limit);
125
+ if (typeof args.flags.cursor === 'string')
126
+ query.set('cursor', args.flags.cursor);
127
+ result = await getJson({ ...clientOptions(ctx), path: `${path}${query.size ? `?${query}` : ''}` });
128
+ }
129
+ console.log(JSON.stringify(result, null, 2));
130
+ return 0;
131
+ }
@@ -22,5 +22,5 @@ export declare function secretsSetDefaultCommand(args: ParsedArgs): Promise<numb
22
22
  * UI: pin + redeploy the function's active version / pin only / cancel.
23
23
  */
24
24
  export declare function secretsPinCommand(args: ParsedArgs): Promise<number>;
25
- export declare const SECRETS_USAGE = "usage:\n seq-studio secrets create <NAME> -e <env> [--org <slug>] [--description text]\n register an org-owned secret\n seq-studio secrets set <NAME> -e <env> [--org <slug>] [--from-file <path>]\n set the shared default value (write-only)\n seq-studio secrets list -e <env> secrets you can see (never values)\n seq-studio secrets attach <NAME> --fn <slug> -e <env> [--org <slug>]\n mount default on a function env var\n seq-studio secrets detach <NAME> --fn <slug> -e <env> [--org <slug>]\n remove attachment\n seq-studio secrets attach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>]\n attach to a pipeline stage's credential for one deploy target\n seq-studio secrets detach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>]\n remove it (the stage's copy is deleted now)\n seq-studio secrets apply --from-env-file .env -e <env> push defaults + attach (keys default from manifest)\n seq-studio secrets versions <NAME> -e <env> [--org <slug>] value version history (never values)\n seq-studio secrets set-default <NAME> [version] -e <env> [--org <slug>]\n point the default at a prior version (editor)\n seq-studio secrets pin <NAME> --fn <slug> [version] -e <env> [--org <slug>]\n pin one function to a version (sticky; --unpin clears)\n\n Note: for the common deploy loop, secrets declared in managed-function.yml are\n reconciled automatically by `seq-studio functions deploy` using a local .env.\n Use `secrets` commands for CI (no .env), bulk/multi-function ops, or write-only\n value changes without a redeploy.\n\n Pipelines: managed secrets are the preferred way to give a stage a credential.\n Declare source.credential in the stage spec and read it in code with\n pipeline_runtime.get_credential(\"<name>\"). `seq-studio pipeline plan|deploy`\n attaches the secret named by convention (abrigo_oauth -> ABRIGO_OAUTH) when\n you can edit it (stages already deployed the legacy way are left alone); use\n `secrets attach --stage` for any other name.\n\n Flags: -e/--env <env> (required; see: seq-studio envs list)\n --org <slug> (target/select managed-scope org; required when a name exists in multiple orgs)\n set: --from-file <path> (non-interactive; file is not echoed)\n --fn <slug> \u00B7 --env-var <NAME> \u00B7 --yes\n --stage <slug> \u00B7 --target <id> (deploy target; default from -e) \u00B7 --credential <name>\n (the spec's source.credential; default: NAME lowercased) \u00B7 --repo <ns>/<name> (disambiguate)\n --functions <f1,f2> \u00B7 --keys <K1,K2> \u00B7 --all (override key selection)\n set-default: [version|version-row-id] (defaults to the most recent non-default) \u00B7 --yes\n pin: [version|version-row-id] (defaults to the current default) \u00B7 --unpin \u00B7 --yes (redeploy) \u00B7 --yes --no-redeploy\n";
25
+ export declare const SECRETS_USAGE = "usage:\n seq-studio secrets create <NAME> -e <env> [--type key-value|single] [--org <slug>] [--description text]\n register an org-owned secret\n seq-studio secrets set <NAME> -e <env> [--org <slug>] [--from-file <path>|--from-json <path>] [--merge]\n set the shared default value (write-only)\n seq-studio secrets list -e <env> secrets you can see (never values)\n seq-studio secrets attach <NAME> --fn <slug> -e <env> [--org <slug>] [--map KEY=ENV,KEY=ENV]\n mount default on a function env var\n seq-studio secrets detach <NAME> --fn <slug> -e <env> [--org <slug>]\n remove attachment\n seq-studio secrets attach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>] [--entry KEY]\n attach to a pipeline stage's credential for one deploy target\n seq-studio secrets detach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>]\n remove it (the stage's copy is deleted now)\n seq-studio secrets apply --from-env-file .env -e <env> push defaults + attach (keys default from manifest)\n seq-studio secrets versions <NAME> -e <env> [--org <slug>] value version history (never values)\n seq-studio secrets set-default <NAME> [version] -e <env> [--org <slug>]\n point the default at a prior version (editor)\n seq-studio secrets pin <NAME> --fn <slug> [version] -e <env> [--org <slug>]\n pin one function to a version (sticky; --unpin clears)\n\n Note: for the common deploy loop, secrets declared in managed-function.yml are\n reconciled automatically by `seq-studio functions deploy` using a local .env.\n Explicit function attachments require the same secret source and mapping in the active manifest.\n Use `secrets` commands for CI (no .env), bulk/multi-function ops, or write-only\n value changes without a redeploy.\n\n Pipelines: managed secrets are the preferred way to give a stage a credential.\n Declare source.credential in the stage spec and read it in code with\n pipeline_runtime.get_credential(\"<name>\"). `seq-studio pipeline plan|deploy`\n attaches the secret named by convention (abrigo_oauth -> ABRIGO_OAUTH) when\n you can edit it (stages already deployed the legacy way are left alone); use\n `secrets attach --stage` for any other name.\n\n Flags: -e/--env <env> (required; see: seq-studio envs list)\n --org <slug> (target/select managed-scope org; required when a name exists in multiple orgs)\n set: --from-file <path> for single values; --from-json <path> for key/value sets; --merge changes only listed entries (null removes one)\n --fn <slug> \u00B7 --env-var <NAME> \u00B7 --yes\n --stage <slug> \u00B7 --target <id> (deploy target; default from -e) \u00B7 --credential <name> \u00B7 --entry <KEY> (key/value sets)\n (the spec's source.credential; default: NAME lowercased) \u00B7 --repo <ns>/<name> (disambiguate)\n --functions <f1,f2> \u00B7 --keys <K1,K2> \u00B7 --all (override key selection)\n set-default: [version|version-row-id] (defaults to the most recent non-default) \u00B7 --yes\n pin: [version|version-row-id] (defaults to the current default) \u00B7 --unpin \u00B7 --yes (redeploy) \u00B7 --yes --no-redeploy\n";
26
26
  export declare function runSecretsCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;
@@ -162,12 +162,17 @@ async function functionExistsBySlugEventually({ ctx, slug, attempts = 3, retryDe
162
162
  export async function secretsCreateCommand(args) {
163
163
  const name = args.positional[0];
164
164
  if (!name) {
165
- console.error('usage: seq-studio secrets create <NAME> -e <env> [--org <slug>] [--description text]');
165
+ console.error('usage: seq-studio secrets create <NAME> -e <env> [--type key-value|single] [--org <slug>] [--description text]');
166
166
  return 1;
167
167
  }
168
168
  const ctx = await buildContext(args);
169
169
  const description = typeof args.flags.description === 'string' ? args.flags.description : undefined;
170
170
  const org = orgFlag(args);
171
+ const typeFlag = args.flags.type;
172
+ if (typeFlag !== undefined && typeFlag !== 'single' && typeFlag !== 'key-value') {
173
+ console.error(`${LOG} --type must be key-value or single`);
174
+ return 1;
175
+ }
171
176
  if (org) {
172
177
  const mismatch = orgDeploymentError(org, ctx.env.name);
173
178
  if (mismatch) {
@@ -180,6 +185,7 @@ export async function secretsCreateCommand(args) {
180
185
  path: '/api/managed-secrets',
181
186
  body: {
182
187
  name,
188
+ ...(typeFlag === 'key-value' ? { valueType: 'key_value' } : {}),
183
189
  description: description ?? null,
184
190
  ...(org ? { orgId: org } : {}),
185
191
  },
@@ -193,12 +199,55 @@ export async function secretsCreateCommand(args) {
193
199
  export async function secretsSetCommand(args) {
194
200
  const name = args.positional[0];
195
201
  if (!name) {
196
- console.error('usage: seq-studio secrets set <NAME> -e <env> [--org <slug>] [--from-file <path>]');
202
+ console.error('usage: seq-studio secrets set <NAME> -e <env> [--org <slug>] [--from-file <path>] [--from-json <path>]');
197
203
  return 1;
198
204
  }
199
205
  const ctx = await buildContext(args);
200
206
  const secret = await resolveSecretByName({ ctx, name, org: orgFlag(args) });
201
207
  const fromFile = typeof args.flags['from-file'] === 'string' ? args.flags['from-file'] : undefined;
208
+ const fromJson = typeof args.flags['from-json'] === 'string' ? args.flags['from-json'] : undefined;
209
+ if (secret.valueType === 'key_value') {
210
+ if (!fromJson || fromFile) {
211
+ console.error(`${LOG} key/value sets require --from-json <path> containing an object of entry names and string values`);
212
+ return 1;
213
+ }
214
+ const filePath = isAbsolute(fromJson) ? fromJson : resolve(workDir(args), fromJson);
215
+ if (!existsSync(filePath)) {
216
+ console.error(`${LOG} --from-json not found: ${filePath}`);
217
+ return 1;
218
+ }
219
+ let entries;
220
+ try {
221
+ entries = JSON.parse(await readFile(filePath, 'utf8'));
222
+ }
223
+ catch {
224
+ console.error(`${LOG} --from-json must contain valid JSON`);
225
+ return 1;
226
+ }
227
+ const merge = flagBool(args.flags, 'merge');
228
+ if (!entries || typeof entries !== 'object' || Array.isArray(entries) || Object.keys(entries).length === 0 || Object.values(entries).some((value) => merge ? value !== null && (typeof value !== 'string' || !value) : typeof value !== 'string' || !value)) {
229
+ console.error(`${LOG} --from-json must contain a nonempty object of ${merge ? 'nonempty string values or null removals' : 'nonempty string values'}`);
230
+ return 1;
231
+ }
232
+ if (merge) {
233
+ const detail = await getJson({ ...clientOptions(ctx), path: `/api/managed-secrets/${secret.id}` });
234
+ if (!detail.currentGcpVersion) {
235
+ console.error(`${LOG} the set has no active version; use secrets set --from-json without --merge first`);
236
+ return 1;
237
+ }
238
+ await patchJson({ ...clientOptions(ctx), path: `/api/managed-secrets/${secret.id}/value`, body: { expectedVersion: detail.currentGcpVersion, changes: entries } });
239
+ }
240
+ else {
241
+ await putJson({ ...clientOptions(ctx), path: `/api/managed-secrets/${secret.id}/value`, body: { entries } });
242
+ }
243
+ console.log(`${LOG} ${merge ? 'updated' : 'set'} default key/value version for "${name}" (${Object.keys(entries).length} ${merge ? 'changes' : 'entries'})`);
244
+ console.log(`${LOG} functions tracking this secret need a redeploy to pick up the new version`);
245
+ return 0;
246
+ }
247
+ if (fromJson) {
248
+ console.error(`${LOG} --from-json is only for key/value sets`);
249
+ return 1;
250
+ }
202
251
  let value;
203
252
  if (fromFile) {
204
253
  const filePath = isAbsolute(fromFile) ? fromFile : resolve(workDir(args), fromFile);
@@ -238,7 +287,7 @@ export async function secretsListCommand(args) {
238
287
  for (const secret of secrets) {
239
288
  const defaultState = secret.hasDefaultValue ? 'default set' : 'no default';
240
289
  const access = secret.currentUserAccess ?? 'none';
241
- console.log(` ${secret.name} org=${secret.orgId} [${defaultState}] access=${access} attachments=${secret.attachmentCount}`);
290
+ console.log(` ${secret.name} type=${secret.valueType ?? 'single'} org=${secret.orgId} [${defaultState}] access=${access} attachments=${secret.attachmentCount}`);
242
291
  }
243
292
  return 0;
244
293
  }
@@ -259,10 +308,20 @@ async function resolveStageAttachment({ args, ctx, name }) {
259
308
  async function secretsAttachToStage(args, name) {
260
309
  const ctx = await buildContext(args);
261
310
  const secret = await resolveSecretByName({ ctx, name, org: orgFlag(args) });
311
+ const entryKey = typeof args.flags.entry === 'string' ? args.flags.entry : undefined;
312
+ if (secret.valueType === 'key_value' && !entryKey) {
313
+ console.error(`${LOG} key/value set ${name} requires --entry KEY for a pipeline credential`);
314
+ return 1;
315
+ }
316
+ if (secret.valueType !== 'key_value' && entryKey) {
317
+ console.error(`${LOG} --entry is only for key/value sets`);
318
+ return 1;
319
+ }
262
320
  const { stage, symbolic, deployTarget } = await resolveStageAttachment({ args, ctx, name });
263
321
  const preview = [
264
322
  `${LOG} attach preview:`,
265
323
  `${LOG} secret: ${name}`,
324
+ ...(entryKey ? [`${LOG} entry: ${entryKey}`] : []),
266
325
  `${LOG} stage: ${stage.slug} (${stage.repo})`,
267
326
  `${LOG} credential: ${symbolic}`,
268
327
  `${LOG} target: ${deployTarget}`,
@@ -270,7 +329,7 @@ async function secretsAttachToStage(args, name) {
270
329
  ];
271
330
  if (!(await confirmYes({ preview, confirmed: flagBool(args.flags, 'yes') })))
272
331
  return 1;
273
- await attachSecretToStage({ client: clientOptions(ctx), stageId: stage.id, deployTarget, symbolic, secretId: secret.id });
332
+ await attachSecretToStage({ client: clientOptions(ctx), stageId: stage.id, deployTarget, symbolic, secretId: secret.id, entryKey });
274
333
  console.log(`${LOG} attached "${name}" to ${stage.slug} as ${symbolic} for ${deployTarget}`);
275
334
  console.log(`${LOG} plan and deploy the stage to copy it; read it with pipeline_runtime.get_credential("${symbolic}")`);
276
335
  return 0;
@@ -300,20 +359,38 @@ export async function secretsAttachCommand(args) {
300
359
  return secretsAttachToStage(args, name);
301
360
  const fnSlug = typeof args.flags.fn === 'string' ? args.flags.fn : args.positional[1];
302
361
  if (!name || !fnSlug) {
303
- console.error('usage: seq-studio secrets attach <NAME> --fn <slug> -e <env> [--org <slug>] [--env-var NAME]\n' +
304
- ' seq-studio secrets attach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>] [--repo <ns>/<name>] [--org <slug>]');
362
+ console.error('usage: seq-studio secrets attach <NAME> --fn <slug> -e <env> [--org <slug>] [--env-var NAME] [--map KEY=ENV,KEY=ENV]\n' +
363
+ ' seq-studio secrets attach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>] [--entry KEY] [--repo <ns>/<name>] [--org <slug>]');
305
364
  return 1;
306
365
  }
307
366
  const ctx = await buildContext(args);
308
367
  const secret = await resolveSecretByName({ ctx, name, org: orgFlag(args) });
309
368
  const fn = await resolveFunctionBySlug({ ctx, slug: fnSlug });
310
369
  const envVarName = (typeof args.flags['env-var'] === 'string' ? args.flags['env-var'] : undefined) ?? name;
370
+ let entryMappings;
371
+ if (secret.valueType === 'key_value') {
372
+ const mapFlag = args.flags.map;
373
+ if (typeof mapFlag !== 'string' || !mapFlag.trim()) {
374
+ console.error(`${LOG} key/value sets require --map KEY=ENV,KEY=ENV matching the function manifest's secret and entry mappings`);
375
+ return 1;
376
+ }
377
+ const pairs = mapFlag.split(',').map((part) => part.trim().split('='));
378
+ if (pairs.some((parts) => parts.length !== 2 || !parts[0] || !parts[1]) || new Set(pairs.map((parts) => parts[0])).size !== pairs.length) {
379
+ console.error(`${LOG} --map must contain distinct KEY=ENV pairs`);
380
+ return 1;
381
+ }
382
+ entryMappings = Object.fromEntries(pairs.map(([key, env]) => [key, env]));
383
+ }
384
+ else if (args.flags.map !== undefined) {
385
+ console.error(`${LOG} --map is only for key/value sets`);
386
+ return 1;
387
+ }
311
388
  if (secret.hasDefaultValue) {
312
389
  const preview = [
313
390
  `${LOG} attach preview:`,
314
391
  `${LOG} secret: ${name}`,
315
392
  `${LOG} function: ${fnSlug}`,
316
- `${LOG} env var: ${envVarName}`,
393
+ ...(entryMappings ? Object.entries(entryMappings).map(([key, env]) => `${LOG} ${key} → ${env}`) : [`${LOG} env var: ${envVarName}`]),
317
394
  `${LOG} note: shared default — anyone who can invoke "${fnSlug}" receives it at runtime`,
318
395
  ];
319
396
  const ok = await confirmYes({ preview, confirmed: flagBool(args.flags, 'yes') });
@@ -326,10 +403,11 @@ export async function secretsAttachCommand(args) {
326
403
  body: {
327
404
  functionId: fn.id,
328
405
  envVarName,
406
+ ...(entryMappings ? { entryMappings } : {}),
329
407
  },
330
408
  });
331
- console.log(`${LOG} attached "${name}" to ${fnSlug} as env var ${envVarName}`);
332
- console.log(`${LOG} redeploy ${fnSlug} to mount the secret`);
409
+ console.log(`${LOG} attached "${name}" to ${fnSlug}${entryMappings ? ` with ${Object.keys(entryMappings).length} entry mappings` : ` as env var ${envVarName}`}`);
410
+ console.log(`${LOG} the function manifest must bind ${name} with this exact mapping; redeploy ${fnSlug} to mount the secret`);
333
411
  return 0;
334
412
  }
335
413
  export async function secretsDetachCommand(args) {
@@ -383,7 +461,9 @@ function resolveApplyKeys({ parsed, manifest, explicitKeys, applyAll, }) {
383
461
  };
384
462
  }
385
463
  if (manifest) {
386
- const keys = manifest.secrets.filter((key) => parsed[key] && parsed[key].length > 0);
464
+ const keys = manifest.secrets
465
+ .filter((entry) => typeof entry === 'string')
466
+ .filter((key) => parsed[key] && parsed[key].length > 0);
387
467
  return {
388
468
  keys,
389
469
  mode: manifest.secrets.length > 0 ? 'manifest secrets ∩ .env' : 'manifest secrets (none declared)',
@@ -753,16 +833,16 @@ export async function secretsPinCommand(args) {
753
833
  // dispatcher
754
834
  // ---------------------------------------------------------------------------
755
835
  export const SECRETS_USAGE = `usage:
756
- seq-studio secrets create <NAME> -e <env> [--org <slug>] [--description text]
836
+ seq-studio secrets create <NAME> -e <env> [--type key-value|single] [--org <slug>] [--description text]
757
837
  register an org-owned secret
758
- seq-studio secrets set <NAME> -e <env> [--org <slug>] [--from-file <path>]
838
+ seq-studio secrets set <NAME> -e <env> [--org <slug>] [--from-file <path>|--from-json <path>] [--merge]
759
839
  set the shared default value (write-only)
760
840
  seq-studio secrets list -e <env> secrets you can see (never values)
761
- seq-studio secrets attach <NAME> --fn <slug> -e <env> [--org <slug>]
841
+ seq-studio secrets attach <NAME> --fn <slug> -e <env> [--org <slug>] [--map KEY=ENV,KEY=ENV]
762
842
  mount default on a function env var
763
843
  seq-studio secrets detach <NAME> --fn <slug> -e <env> [--org <slug>]
764
844
  remove attachment
765
- seq-studio secrets attach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>]
845
+ seq-studio secrets attach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>] [--entry KEY]
766
846
  attach to a pipeline stage's credential for one deploy target
767
847
  seq-studio secrets detach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>]
768
848
  remove it (the stage's copy is deleted now)
@@ -775,6 +855,7 @@ export const SECRETS_USAGE = `usage:
775
855
 
776
856
  Note: for the common deploy loop, secrets declared in managed-function.yml are
777
857
  reconciled automatically by \`seq-studio functions deploy\` using a local .env.
858
+ Explicit function attachments require the same secret source and mapping in the active manifest.
778
859
  Use \`secrets\` commands for CI (no .env), bulk/multi-function ops, or write-only
779
860
  value changes without a redeploy.
780
861
 
@@ -787,9 +868,9 @@ export const SECRETS_USAGE = `usage:
787
868
 
788
869
  Flags: -e/--env <env> (required; see: seq-studio envs list)
789
870
  --org <slug> (target/select managed-scope org; required when a name exists in multiple orgs)
790
- set: --from-file <path> (non-interactive; file is not echoed)
871
+ set: --from-file <path> for single values; --from-json <path> for key/value sets; --merge changes only listed entries (null removes one)
791
872
  --fn <slug> · --env-var <NAME> · --yes
792
- --stage <slug> · --target <id> (deploy target; default from -e) · --credential <name>
873
+ --stage <slug> · --target <id> (deploy target; default from -e) · --credential <name> · --entry <KEY> (key/value sets)
793
874
  (the spec's source.credential; default: NAME lowercased) · --repo <ns>/<name> (disambiguate)
794
875
  --functions <f1,f2> · --keys <K1,K2> · --all (override key selection)
795
876
  set-default: [version|version-row-id] (defaults to the most recent non-default) · --yes
@@ -0,0 +1,3 @@
1
+ import type { ParsedArgs } from '../process/commands.js';
2
+ export declare const SERVICE_ACCOUNTS_USAGE = "usage:\n seq-studio service-accounts list -e <env> [--json]\n seq-studio service-accounts show <account-id> -e <env> [--json]\n seq-studio service-accounts create <slug> --display-name <name> -e <env> [--description <text>] [--json]\n\n All results are JSON. Authenticate: seq-studio login --env <env>.\n Administrator provisioning: listing needs Service Accounts surface access;\n create needs its editor grant; show needs admin on that account.\n A normal builder should use the account ID/slug supplied by their administrator.\n Creation does not grant the account access to data or functions. Grant required\n runtime access with seq-studio access using principal user: service-account|<id>.\n The server checks creator, actor, and resource authority on every operation.\n No credential is issued or printed by these commands.\n";
3
+ export declare function runServiceAccountsCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;
@@ -0,0 +1,50 @@
1
+ import { getJson, postJson } from '../atlas-client.js';
2
+ import { printCliError } from '../cli-errors.js';
3
+ import { requiredStringFlag, validateCommandInput, wantsHelp } from '../command-input.js';
4
+ import { buildContext, clientOptions } from '../functions/commands.js';
5
+ export const SERVICE_ACCOUNTS_USAGE = `usage:
6
+ seq-studio service-accounts list -e <env> [--json]
7
+ seq-studio service-accounts show <account-id> -e <env> [--json]
8
+ seq-studio service-accounts create <slug> --display-name <name> -e <env> [--description <text>] [--json]
9
+
10
+ All results are JSON. Authenticate: seq-studio login --env <env>.
11
+ Administrator provisioning: listing needs Service Accounts surface access;
12
+ create needs its editor grant; show needs admin on that account.
13
+ A normal builder should use the account ID/slug supplied by their administrator.
14
+ Creation does not grant the account access to data or functions. Grant required
15
+ runtime access with seq-studio access using principal user: service-account|<id>.
16
+ The server checks creator, actor, and resource authority on every operation.
17
+ No credential is issued or printed by these commands.
18
+ `;
19
+ export async function runServiceAccountsCommand(sub, args) {
20
+ if (!sub || wantsHelp({ sub, args })) {
21
+ console.log(SERVICE_ACCOUNTS_USAGE);
22
+ return sub ? 0 : 1;
23
+ }
24
+ try {
25
+ if (!['list', 'show', 'create'].includes(sub)) {
26
+ throw new Error(`Unknown service-accounts command: ${sub}. See --help.`);
27
+ }
28
+ validateCommandInput({ args,
29
+ flags: sub === 'create' ? { 'display-name': 'string', description: 'string' } : {},
30
+ positional: sub === 'list' ? 0 : 1,
31
+ });
32
+ const target = args.positional[0];
33
+ const body = sub === 'create' ? {
34
+ slug: target,
35
+ displayName: requiredStringFlag({ args, key: 'display-name' }),
36
+ ...(typeof args.flags.description === 'string' ? { description: args.flags.description } : {}),
37
+ } : undefined;
38
+ if (target !== undefined && !target.trim())
39
+ throw new Error('An account ID or slug is required.');
40
+ const ctx = await buildContext(args);
41
+ const request = { ...clientOptions(ctx), path: `/api/service-accounts${sub === 'show' ? `/${encodeURIComponent(target)}` : ''}` };
42
+ const result = sub === 'create' ? await postJson({ ...request, body }) : await getJson(request);
43
+ console.log(JSON.stringify(result, null, 2));
44
+ return 0;
45
+ }
46
+ catch (error) {
47
+ printCliError(error);
48
+ return 1;
49
+ }
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequenceholdings/studio-cli",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Unified Sequence Studio CLI — `seq-studio init` / `add` / `deploy` (app monorepos), `seq-studio agents`, `seq-studio process` (Lattice), `seq-studio artifact`, `seq-studio functions` / `secrets`, `seq-studio repos`, and `seq-studio auth pat`. Includes Auth0 browser login shared with seqapi.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -42,13 +42,13 @@
42
42
  "tsx": "^4.20.3",
43
43
  "zod": "^4.1.13",
44
44
  "@sequenceholdings/agent-spec": "0.1.2",
45
- "@sequenceholdings/artifact-studio": "0.3.1",
45
+ "@sequenceholdings/artifact-studio": "0.4.0",
46
46
  "@sequenceholdings/lattice": "0.1.4",
47
- "@sequenceholdings/managed-functions": "0.1.1",
47
+ "@sequenceholdings/managed-functions": "0.2.0",
48
48
  "@sequenceholdings/storage": "0.1.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "@sequenceholdings/orm": "2.1.0",
51
+ "@sequenceholdings/orm": "2.1.1",
52
52
  "@sequenceholdings/pipeline-spec": "0.1.0"
53
53
  },
54
54
  "peerDependenciesMeta": {
@@ -64,7 +64,7 @@
64
64
  "@types/node": "^22.0.0",
65
65
  "typescript": "^5.6.0",
66
66
  "vitest": "^4.1.11",
67
- "@sequenceholdings/orm": "2.1.0",
67
+ "@sequenceholdings/orm": "2.1.1",
68
68
  "@sequenceholdings/pipeline-spec": "0.1.0"
69
69
  },
70
70
  "engines": {