@sequenceholdings/studio-cli 0.5.4 → 0.6.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 (54) hide show
  1. package/README.md +226 -7
  2. package/dist/agents/source.js +2 -1
  3. package/dist/app/adapters.js +2 -1
  4. package/dist/app/commands.js +4 -4
  5. package/dist/artifact/delegate.js +32 -12
  6. package/dist/atlas-client.d.ts +2 -1
  7. package/dist/atlas-client.js +7 -3
  8. package/dist/auth-cmds/commands.d.ts +1 -1
  9. package/dist/auth-cmds/commands.js +3 -0
  10. package/dist/auth.d.ts +2 -1
  11. package/dist/auth.js +16 -0
  12. package/dist/command-contract.d.ts +8 -8
  13. package/dist/command-contract.js +6 -6
  14. package/dist/command-help.d.ts +5 -4
  15. package/dist/command-help.js +41 -4
  16. package/dist/command-input.js +2 -2
  17. package/dist/config.d.ts +5 -0
  18. package/dist/config.js +14 -1
  19. package/dist/env-flags.d.ts +6 -0
  20. package/dist/env-flags.js +9 -0
  21. package/dist/functions/commands.d.ts +4 -1
  22. package/dist/functions/commands.js +63 -5
  23. package/dist/functions/deploy-preflight.js +2 -2
  24. package/dist/functions/manifest.d.ts +43 -29
  25. package/dist/functions/manifest.js +37 -74
  26. package/dist/main.js +42 -2
  27. package/dist/orm/delegate.js +25 -4
  28. package/dist/orm/read.d.ts +54 -0
  29. package/dist/orm/read.js +308 -0
  30. package/dist/pipeline/commands.js +30 -5
  31. package/dist/pipeline/discovery.js +3 -16
  32. package/dist/pipeline/lifecycle.js +37 -6
  33. package/dist/pipeline/retirement.d.ts +3 -0
  34. package/dist/pipeline/retirement.js +34 -0
  35. package/dist/pipeline/source.d.ts +21 -0
  36. package/dist/pipeline/source.js +76 -0
  37. package/dist/process/build.js +4 -0
  38. package/dist/process/codegen.js +2 -0
  39. package/dist/process/commands.js +57 -18
  40. package/dist/process/plan-diff.js +1 -0
  41. package/dist/process/runs.d.ts +14 -0
  42. package/dist/process/runs.js +238 -0
  43. package/dist/repos/ci-status.js +28 -0
  44. package/dist/repos/commands.js +11 -1
  45. package/dist/repos/git-credential.d.ts +3 -2
  46. package/dist/repos/git-credential.js +52 -3
  47. package/dist/repos/pulls.d.ts +7 -1
  48. package/dist/repos/pulls.js +162 -22
  49. package/dist/sandbox-auth.d.ts +52 -0
  50. package/dist/sandbox-auth.js +105 -0
  51. package/dist/storage/commands.js +6 -5
  52. package/dist/text-table.d.ts +7 -0
  53. package/dist/text-table.js +16 -0
  54. package/package.json +9 -9
@@ -2,6 +2,7 @@ import { execFile } from 'node:child_process';
2
2
  import { promisify } from 'node:util';
3
3
  import { getAccessTokenWithMode } from '../auth.js';
4
4
  import { resolveConfiguredEnv } from '../config.js';
5
+ import { isSandboxOrigin, readSandboxToken, sandboxTarget } from '../sandbox-auth.js';
5
6
  const exec = promisify(execFile);
6
7
  function matchesGitDestination(input, url) {
7
8
  const fields = new Map();
@@ -28,6 +29,42 @@ function matchesGitDestination(input, url) {
28
29
  return false;
29
30
  return true;
30
31
  }
32
+ /** The destination Git asked about, when it names one complete https/http URL. */
33
+ function credentialRequestUrl(input) {
34
+ const fields = new Map();
35
+ for (const line of input.split('\n')) {
36
+ if (!line)
37
+ break;
38
+ const index = line.indexOf('=');
39
+ if (index > 0)
40
+ fields.set(line.slice(0, index), line.slice(index + 1));
41
+ }
42
+ const protocol = fields.get('protocol');
43
+ const host = fields.get('host');
44
+ const path = fields.get('path');
45
+ if ((protocol !== 'https' && protocol !== 'http') || !host || !path)
46
+ return null;
47
+ try {
48
+ return new URL(`${protocol}://${host}/${path}`);
49
+ }
50
+ catch {
51
+ return null;
52
+ }
53
+ }
54
+ /**
55
+ * Sandbox token mode: answer with the sandbox bearer for git-service
56
+ * repositories on the sandbox origin only. Without a pinned clone URL (a
57
+ * helper configured by hand for the whole host) any repository path on that
58
+ * origin qualifies; Atlas still authorizes the repository itself.
59
+ */
60
+ async function sandboxCredentialResponse({ input, target, cloneUrl, }) {
61
+ const url = cloneUrl ? new URL(cloneUrl) : credentialRequestUrl(input);
62
+ if (!url || !isSandboxOrigin({ target, url: url.href }) || !matchesGitDestination(input, url))
63
+ return '';
64
+ return `username=git\npassword=${await readSandboxToken(target)}\n\n`;
65
+ }
66
+ export const GIT_CREDENTIAL_USAGE = 'usage: seq-studio auth git-credential --env <env> --url <clone-url> <get|store|erase>\n' +
67
+ ' seq-studio auth git-credential [--url <clone-url>] <get|store|erase> (sandbox token mode)';
31
68
  /** Only send a login credential to the exact repository pinned at clone time. */
32
69
  export async function gitCredentialResponse({ input, operation, envName, cloneUrl, }) {
33
70
  // Git asks helpers to store/erase credentials after success/failure. Our source
@@ -36,6 +73,11 @@ export async function gitCredentialResponse({ input, operation, envName, cloneUr
36
73
  return '';
37
74
  if (operation !== 'get')
38
75
  throw new Error('Expected Git credential operation: get, store, or erase.');
76
+ const sandbox = sandboxTarget();
77
+ if (sandbox)
78
+ return sandboxCredentialResponse({ input, target: sandbox, ...(cloneUrl ? { cloneUrl } : {}) });
79
+ if (!envName || !cloneUrl)
80
+ throw new Error(GIT_CREDENTIAL_USAGE);
39
81
  const url = new URL(cloneUrl);
40
82
  if (!matchesGitDestination(input, url))
41
83
  return '';
@@ -75,8 +117,10 @@ export async function gitCredentialCommand(args) {
75
117
  const envName = args.flags.env ?? args.flags.e;
76
118
  const cloneUrl = args.flags.url;
77
119
  const operation = args.positional[0];
78
- if (typeof envName !== 'string' || typeof cloneUrl !== 'string' || !operation || args.positional.length !== 1) {
79
- throw new Error('usage: seq-studio auth git-credential --env <env> --url <clone-url> <get|store|erase>');
120
+ const pinned = typeof envName === 'string' && typeof cloneUrl === 'string';
121
+ const sandboxed = sandboxTarget() !== null && (cloneUrl === undefined || typeof cloneUrl === 'string');
122
+ if ((!pinned && !sandboxed) || !operation || args.positional.length !== 1) {
123
+ throw new Error(GIT_CREDENTIAL_USAGE);
80
124
  }
81
125
  let input = '';
82
126
  for await (const chunk of process.stdin) {
@@ -86,6 +130,11 @@ export async function gitCredentialCommand(args) {
86
130
  if (input.includes('\n\n'))
87
131
  break;
88
132
  }
89
- process.stdout.write(await gitCredentialResponse({ input, operation, envName, cloneUrl }));
133
+ process.stdout.write(await gitCredentialResponse({
134
+ input,
135
+ operation,
136
+ ...(typeof envName === 'string' ? { envName } : {}),
137
+ ...(typeof cloneUrl === 'string' ? { cloneUrl } : {}),
138
+ }));
90
139
  return 0;
91
140
  }
@@ -1,5 +1,5 @@
1
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. When repository CI\n checks the branch, merge sends the checked head and base revisions; a newer push\n makes the server refuse until checks rerun. 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";
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 seq-studio repos pulls close <ns>/<name> <number> -e <env>\n seq-studio repos pulls comment <ns>/<name> <number> -e <env> (--body <text> | --body-file <path>)\n [--path <file> --line N [--side LEFT|RIGHT] [--commit <sha>]] [--reply-to <comment-id>]\n seq-studio repos pulls comments <ns>/<name> <number> -e <env> [--limit N] [--cursor <cursor>]\n seq-studio repos pulls review <ns>/<name> <number> -e <env> (--approve | --request-changes | --comment)\n [--body <text> | --body-file <path>] [--commit <sha>]\n seq-studio repos pulls reviews <ns>/<name> <number> -e <env> [--limit N] [--cursor <cursor>]\n seq-studio repos pulls checks <ns>/<name> <number> -e <env> [--head <sha>]\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. When repository CI\n checks the branch, merge sends the checked head and base revisions; a newer push\n makes the server refuse until checks rerun. 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 close needs to be the Pull's author or have repository write; it is idempotent.\n comment adds a Pull comment; --path and --line anchor it to a diff line (side RIGHT\n and the branch's current commit unless --side/--commit say otherwise), and\n --reply-to answers an existing thread. review records approve, request-changes, or\n comment against the commit the Pull's branch points at now (or --commit). checks prints the check runs,\n CI plan and runs, and merge gates (mergeability, reviews, code owners) in one object.\n repos pull (singular) materializes files; repos pulls manages review requests.\n";
3
3
  /** Only the revisions this command needs from GET .../pulls/<n>/ci. */
4
4
  interface PullCiStatus {
5
5
  plan?: {
@@ -17,5 +17,11 @@ export declare function checkedMergeRevision({ fetchStatus }: {
17
17
  expectedHeadSha: string;
18
18
  expectedBaseSha: string;
19
19
  } | Record<string, never>>;
20
+ export declare function commentBody(args: ParsedArgs): Promise<object>;
21
+ export declare function reviewInput(args: ParsedArgs): Promise<{
22
+ state: string;
23
+ body?: string;
24
+ commitSha?: string;
25
+ }>;
20
26
  export declare function reposPullsCommand(input: ParsedArgs): Promise<number>;
21
27
  export {};
@@ -1,5 +1,5 @@
1
1
  import { readFile } from 'node:fs/promises';
2
- import { resolveRepo } from '@sequenceholdings/artifact-studio/git-service-client';
2
+ import { resolveCommitSha, resolveRepo } from '@sequenceholdings/artifact-studio/git-service-client';
3
3
  import { getJson, postJson } from '../atlas-client.js';
4
4
  import { requiredStringFlag, validateCommandInput, wantsHelp } from '../command-input.js';
5
5
  import { clientOptions } from '../functions/commands.js';
@@ -11,6 +11,14 @@ export const PULLS_USAGE = `usage:
11
11
  seq-studio repos pulls create <ns>/<name> --head <branch> --base <branch> --title <title> -e <env> [--body-file <path>]
12
12
  seq-studio repos pulls diff <ns>/<name> <number> -e <env> [--max-files N]
13
13
  seq-studio repos pulls merge <ns>/<name> <number> -e <env> [--method squash|merge|ff] [--message <text>] [--yes]
14
+ seq-studio repos pulls close <ns>/<name> <number> -e <env>
15
+ seq-studio repos pulls comment <ns>/<name> <number> -e <env> (--body <text> | --body-file <path>)
16
+ [--path <file> --line N [--side LEFT|RIGHT] [--commit <sha>]] [--reply-to <comment-id>]
17
+ seq-studio repos pulls comments <ns>/<name> <number> -e <env> [--limit N] [--cursor <cursor>]
18
+ seq-studio repos pulls review <ns>/<name> <number> -e <env> (--approve | --request-changes | --comment)
19
+ [--body <text> | --body-file <path>] [--commit <sha>]
20
+ seq-studio repos pulls reviews <ns>/<name> <number> -e <env> [--limit N] [--cursor <cursor>]
21
+ seq-studio repos pulls checks <ns>/<name> <number> -e <env> [--head <sha>]
14
22
 
15
23
  All results are JSON (--json is accepted). Authenticate: seq-studio login --env <env>.
16
24
  create needs repository write; merge needs merge/admin authority and passing server
@@ -22,6 +30,12 @@ export const PULLS_USAGE = `usage:
22
30
  diff compares live base/head branches for open Pulls, recorded SHAs for terminal
23
31
  Pulls, and reports truncated when its file
24
32
  limit is reached (default 100, maximum 500).
33
+ close needs to be the Pull's author or have repository write; it is idempotent.
34
+ comment adds a Pull comment; --path and --line anchor it to a diff line (side RIGHT
35
+ and the branch's current commit unless --side/--commit say otherwise), and
36
+ --reply-to answers an existing thread. review records approve, request-changes, or
37
+ comment against the commit the Pull's branch points at now (or --commit). checks prints the check runs,
38
+ CI plan and runs, and merge gates (mergeability, reviews, code owners) in one object.
25
39
  repos pull (singular) materializes files; repos pulls manages review requests.
26
40
  `;
27
41
  /**
@@ -50,6 +64,12 @@ function actionFlags(action) {
50
64
  case 'create': return { head: 'string', base: 'string', title: 'string', 'body-file': 'string' };
51
65
  case 'diff': return { 'max-files': 'string' };
52
66
  case 'merge': return { method: 'string', message: 'string', yes: 'boolean' };
67
+ case 'close': return {};
68
+ case 'comment': return { body: 'string', 'body-file': 'string', path: 'string', line: 'string', side: 'string', commit: 'string', 'reply-to': 'string' };
69
+ case 'comments':
70
+ case 'reviews': return { limit: 'string', cursor: 'string' };
71
+ case 'review': return { approve: 'boolean', 'request-changes': 'boolean', comment: 'boolean', body: 'string', 'body-file': 'string', commit: 'string' };
72
+ case 'checks': return { head: 'string' };
53
73
  default: throw new Error(`Unknown pulls command: ${action}. See: seq-studio repos pulls --help`);
54
74
  }
55
75
  }
@@ -63,6 +83,77 @@ async function createBody(args) {
63
83
  throw new Error('--body-file exceeds 65,536 characters.');
64
84
  return { headRef, baseRef, title, ...(body === undefined ? {} : { body }) };
65
85
  }
86
+ const MAX_BODY_LENGTH = 65_536;
87
+ const COMMIT_SHA = /^[0-9a-f]{40}$/i;
88
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
89
+ const REVIEW_STATES = { approve: 'approved', 'request-changes': 'changes_requested', comment: 'commented' };
90
+ function shaFlag({ args, key }) {
91
+ const value = args.flags[key];
92
+ if (value === undefined)
93
+ return undefined;
94
+ if (typeof value !== 'string' || !COMMIT_SHA.test(value))
95
+ throw new Error(`--${key} must be a full 40-character commit SHA.`);
96
+ return value;
97
+ }
98
+ /** Text from --body or --body-file; at most one, bounded like the server. */
99
+ async function bodyText(args) {
100
+ const inline = args.flags.body;
101
+ const file = args.flags['body-file'];
102
+ if (inline !== undefined && file !== undefined)
103
+ throw new Error('Pass only one of --body or --body-file.');
104
+ const body = typeof file === 'string' ? await readFile(file, 'utf8') : typeof inline === 'string' ? inline : undefined;
105
+ if (body !== undefined && body.length > MAX_BODY_LENGTH)
106
+ throw new Error('The body exceeds 65,536 characters.');
107
+ return body;
108
+ }
109
+ export async function commentBody(args) {
110
+ const body = await bodyText(args);
111
+ if (!body?.trim())
112
+ throw new Error('comment requires --body <text> or --body-file <path>.');
113
+ const path = args.flags.path;
114
+ const line = args.flags.line;
115
+ const side = args.flags.side;
116
+ if ((path === undefined) !== (line === undefined))
117
+ throw new Error('--path and --line anchor a comment together; pass both or neither.');
118
+ if (line !== undefined && (typeof line !== 'string' || !/^[1-9]\d*$/.test(line)))
119
+ throw new Error('--line must be a positive integer.');
120
+ if (side !== undefined && side !== 'LEFT' && side !== 'RIGHT')
121
+ throw new Error('--side must be LEFT or RIGHT.');
122
+ if (path === undefined && (side !== undefined || args.flags.commit !== undefined)) {
123
+ throw new Error('--side and --commit apply only to a line comment (--path and --line).');
124
+ }
125
+ // The server needs path, line, side, and commit together; side defaults to the
126
+ // new version of the file, and a missing commit resolves to the live head later.
127
+ const replyTo = args.flags['reply-to'];
128
+ if (replyTo !== undefined && (typeof replyTo !== 'string' || !UUID.test(replyTo)))
129
+ throw new Error('--reply-to must be a comment id (UUID).');
130
+ const commitSha = shaFlag({ args, key: 'commit' });
131
+ return {
132
+ body,
133
+ ...(typeof path === 'string' ? { path, line: Number(line), side: typeof side === 'string' ? side : 'RIGHT' } : {}),
134
+ ...(commitSha ? { commitSha } : {}),
135
+ ...(typeof replyTo === 'string' ? { parentId: replyTo } : {}),
136
+ };
137
+ }
138
+ export async function reviewInput(args) {
139
+ const chosen = Object.keys(REVIEW_STATES).filter((flag) => args.flags[flag] === true);
140
+ if (chosen.length !== 1)
141
+ throw new Error('review requires exactly one of --approve, --request-changes, or --comment.');
142
+ const body = await bodyText(args);
143
+ const commitSha = shaFlag({ args, key: 'commit' });
144
+ return { state: REVIEW_STATES[chosen[0]], ...(body !== undefined ? { body } : {}), ...(commitSha ? { commitSha } : {}) };
145
+ }
146
+ /** Check runs, CI plan/runs, and merge gates for one Pull, as a single object. */
147
+ async function pullChecks({ ctx, path, head }) {
148
+ const options = clientOptions(ctx);
149
+ const checkQuery = new URLSearchParams({ limit: '200', ...(head ? { headSha: head } : {}) });
150
+ const [checkRuns, ci, mergeability] = await Promise.all([
151
+ getJson({ ...options, path: `${path}/check-runs?${checkQuery}` }),
152
+ getJson({ ...options, path: `${path}/ci` }),
153
+ getJson({ ...options, path: `${path}/mergeability` }),
154
+ ]);
155
+ return { checkRuns, ci, mergeability };
156
+ }
66
157
  async function mergePull({ args, ctx, path, repoPath }) {
67
158
  const detail = await getJson({ ...clientOptions(ctx), path });
68
159
  if (!detail.viewerCanMerge)
@@ -100,6 +191,67 @@ function parsePullOptions(args) {
100
191
  const maxFiles = integerFlag({ args, key: 'max-files', max: 500 });
101
192
  return { state: typeof state === 'string' ? state : undefined, limit, maxFiles };
102
193
  }
194
+ /** Validate an action's flags and read its files before authenticating. */
195
+ async function pullInput({ action, args }) {
196
+ if (action === 'create')
197
+ return { body: await createBody(args) };
198
+ if (action === 'comment')
199
+ return { body: await commentBody(args) };
200
+ if (action === 'review')
201
+ return { review: await reviewInput(args) };
202
+ if (action === 'checks')
203
+ return { head: shaFlag({ args, key: 'head' }) };
204
+ return {};
205
+ }
206
+ /**
207
+ * The commit an open Pull's branch points at now. The Pull row's `headSha` is
208
+ * refreshed asynchronously after a push, so it can name an older commit; the
209
+ * server's review gate counts only reviews of the live head.
210
+ */
211
+ async function liveHeadSha({ ctx, path, repoId }) {
212
+ const { pullRequest } = await getJson({ ...clientOptions(ctx), path: `${path}?include_mergeability=0` });
213
+ if (pullRequest.state !== 'open')
214
+ return pullRequest.headSha;
215
+ return resolveCommitSha({ ...clientOptions(ctx), repoId, ref: pullRequest.headRef });
216
+ }
217
+ /** close, comment, review, and checks: the review-request actions. */
218
+ async function reviewActionResult({ action, ctx, path, repoId, input }) {
219
+ const options = clientOptions(ctx);
220
+ if (action === 'close')
221
+ return postJson({ ...options, path: `${path}/close` });
222
+ if (action === 'checks')
223
+ return pullChecks({ ctx, path, head: input.head });
224
+ if (action === 'comment') {
225
+ const body = input.body;
226
+ const anchored = body.path !== undefined && body.commitSha === undefined
227
+ ? { ...body, commitSha: await liveHeadSha({ ctx, path, repoId }) }
228
+ : body;
229
+ return postJson({ ...options, path: `${path}/comments`, body: anchored });
230
+ }
231
+ // The server records a review against an exact commit; default to the live head.
232
+ const commitSha = input.review.commitSha ?? await liveHeadSha({ ctx, path, repoId });
233
+ return postJson({ ...options, path: `${path}/reviews`, body: { ...input.review, commitSha } });
234
+ }
235
+ async function pullDiff({ ctx, path, repoBase, maxFiles }) {
236
+ const { pullRequest } = await getJson({ ...clientOptions(ctx), path: `${path}?include_mergeability=0` });
237
+ const base = pullRequest.state === 'open' ? pullRequest.baseRef : pullRequest.baseSha;
238
+ const head = pullRequest.state === 'open' ? pullRequest.headRef : pullRequest.headSha;
239
+ const range = `${encodeURIComponent(base)}...${encodeURIComponent(head)}`;
240
+ return getJson({ ...clientOptions(ctx), path: `${repoBase}/compare/${range}${maxFiles ? `?max_files=${maxFiles}` : ''}` });
241
+ }
242
+ /** list, show, comments, and reviews: paginated or single reads. */
243
+ async function pullRead({ action, args, ctx, path, state, limit }) {
244
+ const query = new URLSearchParams();
245
+ if (typeof state === 'string')
246
+ query.set('state', state);
247
+ if (limit)
248
+ query.set('limit', limit);
249
+ if (typeof args.flags.cursor === 'string')
250
+ query.set('cursor', args.flags.cursor);
251
+ const listPath = action === 'comments' || action === 'reviews' ? `${path}/${action}` : path;
252
+ return getJson({ ...clientOptions(ctx), path: `${listPath}${query.size ? `?${query}` : ''}` });
253
+ }
254
+ const REVIEW_ACTIONS = new Set(['close', 'comment', 'review', 'checks']);
103
255
  export async function reposPullsCommand(input) {
104
256
  const [action, ...positional] = input.positional;
105
257
  if (!action || wantsHelp({ sub: action, args: input })) {
@@ -111,7 +263,7 @@ export async function reposPullsCommand(input) {
111
263
  const repoPath = positional[0];
112
264
  const repo = parseRepoPath(repoPath);
113
265
  const { state, limit, maxFiles } = parsePullOptions(args);
114
- const body = action === 'create' ? await createBody(args) : undefined;
266
+ const actionInput = await pullInput({ action, args });
115
267
  const ctx = await reposContext(args);
116
268
  const resolved = await resolveRepo({ ...clientOptions(ctx), ...repo });
117
269
  const repoBase = `/api/git-service/repos/${encodeURIComponent(resolved.id)}`;
@@ -119,26 +271,14 @@ export async function reposPullsCommand(input) {
119
271
  if (action === 'merge')
120
272
  return mergePull({ args, ctx, path, repoPath });
121
273
  let result;
122
- if (action === 'create') {
123
- result = await postJson({ ...clientOptions(ctx), path, body });
124
- }
125
- else if (action === 'diff') {
126
- const { pullRequest } = await getJson({ ...clientOptions(ctx), path: `${path}?include_mergeability=0` });
127
- const base = pullRequest.state === 'open' ? pullRequest.baseRef : pullRequest.baseSha;
128
- const head = pullRequest.state === 'open' ? pullRequest.headRef : pullRequest.headSha;
129
- const range = `${encodeURIComponent(base)}...${encodeURIComponent(head)}`;
130
- result = await getJson({ ...clientOptions(ctx), path: `${repoBase}/compare/${range}${maxFiles ? `?max_files=${maxFiles}` : ''}` });
131
- }
132
- else {
133
- const query = new URLSearchParams();
134
- if (typeof state === 'string')
135
- query.set('state', state);
136
- if (limit)
137
- query.set('limit', limit);
138
- if (typeof args.flags.cursor === 'string')
139
- query.set('cursor', args.flags.cursor);
140
- result = await getJson({ ...clientOptions(ctx), path: `${path}${query.size ? `?${query}` : ''}` });
141
- }
274
+ if (action === 'create')
275
+ result = await postJson({ ...clientOptions(ctx), path, body: actionInput.body });
276
+ else if (REVIEW_ACTIONS.has(action))
277
+ result = await reviewActionResult({ action, ctx, path, repoId: resolved.id, input: actionInput });
278
+ else if (action === 'diff')
279
+ result = await pullDiff({ ctx, path, repoBase, maxFiles });
280
+ else
281
+ result = await pullRead({ action, args, ctx, path, state, limit });
142
282
  console.log(JSON.stringify(result, null, 2));
143
283
  return 0;
144
284
  }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Sandbox token mode.
3
+ *
4
+ * An agent sandbox has no browser, no `~/.config` login, and network egress to
5
+ * one Atlas origin only. Atlas writes a short-lived bearer scoped to the
6
+ * calling user into a file, rotates it roughly once per tool call, and exports
7
+ * two variables:
8
+ *
9
+ * SEQ_STUDIO_BASE_URL the deployment's Atlas origin
10
+ * SEQ_STUDIO_TOKEN_FILE the file holding the current bearer
11
+ *
12
+ * With both set, every command targets that origin with that bearer: no login,
13
+ * token cache, environment registry, or `-e`. The file is read again for each
14
+ * request so a token rotated mid-command is picked up. The CLI carries no
15
+ * knowledge of which deployments exist; the variables are the whole contract.
16
+ */
17
+ export declare const SANDBOX_BASE_URL_ENV = "SEQ_STUDIO_BASE_URL";
18
+ export declare const SANDBOX_TOKEN_FILE_ENV = "SEQ_STUDIO_TOKEN_FILE";
19
+ /** The environment name commands report while sandbox token mode is active. */
20
+ export declare const SANDBOX_ENV_NAME = "sandbox";
21
+ export interface SandboxTarget {
22
+ /** Canonical origin, e.g. `https://atlas.example.seqholdings.com`. */
23
+ baseUrl: string;
24
+ tokenFile: string;
25
+ }
26
+ /**
27
+ * How git-service sources are fetched for a caller. A sandbox has no
28
+ * interactive login and no egress beyond Atlas, so it resolves sources like a
29
+ * headless M2M caller: JSON materialize, platform repositories only.
30
+ */
31
+ export declare function sourceAuthMode(mode: 'm2m' | 'user' | 'sandbox'): 'm2m' | 'user';
32
+ export declare class SandboxAuthError extends Error {
33
+ readonly name = "SandboxAuthError";
34
+ }
35
+ /**
36
+ * The sandbox target, or null when neither variable is set. Exactly one set is
37
+ * a misconfigured sandbox, never a reason to fall back to a cached login.
38
+ */
39
+ export declare function sandboxTarget(env?: NodeJS.ProcessEnv): SandboxTarget | null;
40
+ export declare function isSandboxTokenMode(env?: NodeJS.ProcessEnv): boolean;
41
+ /** Read the current bearer. Never cached: Atlas rotates the file between requests. */
42
+ export declare function readSandboxToken(target: SandboxTarget): Promise<string>;
43
+ export declare function isSandboxOrigin({ target, url }: {
44
+ target: SandboxTarget;
45
+ url: string;
46
+ }): boolean;
47
+ /**
48
+ * A freshly read bearer for a request to `baseUrl`, or null outside sandbox
49
+ * mode. A request to any other origin is refused rather than sent with the
50
+ * caller's credential.
51
+ */
52
+ export declare function sandboxBearerFor(baseUrl: string): Promise<string | null>;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Sandbox token mode.
3
+ *
4
+ * An agent sandbox has no browser, no `~/.config` login, and network egress to
5
+ * one Atlas origin only. Atlas writes a short-lived bearer scoped to the
6
+ * calling user into a file, rotates it roughly once per tool call, and exports
7
+ * two variables:
8
+ *
9
+ * SEQ_STUDIO_BASE_URL the deployment's Atlas origin
10
+ * SEQ_STUDIO_TOKEN_FILE the file holding the current bearer
11
+ *
12
+ * With both set, every command targets that origin with that bearer: no login,
13
+ * token cache, environment registry, or `-e`. The file is read again for each
14
+ * request so a token rotated mid-command is picked up. The CLI carries no
15
+ * knowledge of which deployments exist; the variables are the whole contract.
16
+ */
17
+ import { readFile } from 'node:fs/promises';
18
+ import { validateDeploymentBaseUrl } from '@sequenceholdings/artifact-studio/deployment-validation';
19
+ export const SANDBOX_BASE_URL_ENV = 'SEQ_STUDIO_BASE_URL';
20
+ export const SANDBOX_TOKEN_FILE_ENV = 'SEQ_STUDIO_TOKEN_FILE';
21
+ /** The environment name commands report while sandbox token mode is active. */
22
+ export const SANDBOX_ENV_NAME = 'sandbox';
23
+ /**
24
+ * How git-service sources are fetched for a caller. A sandbox has no
25
+ * interactive login and no egress beyond Atlas, so it resolves sources like a
26
+ * headless M2M caller: JSON materialize, platform repositories only.
27
+ */
28
+ export function sourceAuthMode(mode) {
29
+ return mode === 'sandbox' ? 'm2m' : mode;
30
+ }
31
+ export class SandboxAuthError extends Error {
32
+ name = 'SandboxAuthError';
33
+ }
34
+ /**
35
+ * The sandbox target, or null when neither variable is set. Exactly one set is
36
+ * a misconfigured sandbox, never a reason to fall back to a cached login.
37
+ */
38
+ export function sandboxTarget(env = process.env) {
39
+ const rawBaseUrl = env[SANDBOX_BASE_URL_ENV]?.trim();
40
+ const tokenFile = env[SANDBOX_TOKEN_FILE_ENV]?.trim();
41
+ if (!rawBaseUrl && !tokenFile)
42
+ return null;
43
+ if (!rawBaseUrl || !tokenFile) {
44
+ const [present, missing] = rawBaseUrl
45
+ ? [SANDBOX_BASE_URL_ENV, SANDBOX_TOKEN_FILE_ENV]
46
+ : [SANDBOX_TOKEN_FILE_ENV, SANDBOX_BASE_URL_ENV];
47
+ throw new SandboxAuthError(`${present} is set but ${missing} is not. Sandbox token mode needs both; ` +
48
+ `unset ${present} to use seq-studio login instead.`);
49
+ }
50
+ let baseUrl;
51
+ try {
52
+ baseUrl = validateDeploymentBaseUrl(rawBaseUrl.replace(/\/+$/, ''));
53
+ }
54
+ catch (error) {
55
+ throw new SandboxAuthError(`${SANDBOX_BASE_URL_ENV}: ${error instanceof Error ? error.message : String(error)}`);
56
+ }
57
+ return { baseUrl, tokenFile };
58
+ }
59
+ export function isSandboxTokenMode(env = process.env) {
60
+ return sandboxTarget(env) !== null;
61
+ }
62
+ /** Read the current bearer. Never cached: Atlas rotates the file between requests. */
63
+ export async function readSandboxToken(target) {
64
+ let text;
65
+ try {
66
+ text = await readFile(target.tokenFile, 'utf8');
67
+ }
68
+ catch (error) {
69
+ const code = error instanceof Error ? Reflect.get(error, 'code') : undefined;
70
+ throw new SandboxAuthError(`Cannot read the sandbox token at ${target.tokenFile} (${SANDBOX_TOKEN_FILE_ENV})` +
71
+ `${typeof code === 'string' ? `: ${code}` : ''}.`);
72
+ }
73
+ const token = text.trim();
74
+ if (!token)
75
+ throw new SandboxAuthError(`The sandbox token file ${target.tokenFile} is empty.`);
76
+ if (/[\s\0]/.test(token)) {
77
+ throw new SandboxAuthError(`The sandbox token file ${target.tokenFile} must hold a single bearer token.`);
78
+ }
79
+ return token;
80
+ }
81
+ function originOf(url) {
82
+ try {
83
+ return new URL(url).origin.toLowerCase();
84
+ }
85
+ catch {
86
+ return null;
87
+ }
88
+ }
89
+ export function isSandboxOrigin({ target, url }) {
90
+ return originOf(url) === originOf(target.baseUrl);
91
+ }
92
+ /**
93
+ * A freshly read bearer for a request to `baseUrl`, or null outside sandbox
94
+ * mode. A request to any other origin is refused rather than sent with the
95
+ * caller's credential.
96
+ */
97
+ export async function sandboxBearerFor(baseUrl) {
98
+ const target = sandboxTarget();
99
+ if (!target)
100
+ return null;
101
+ if (!isSandboxOrigin({ target, url: baseUrl })) {
102
+ throw new SandboxAuthError(`Refusing to send the sandbox token to ${baseUrl}: sandbox token mode only targets ${target.baseUrl}.`);
103
+ }
104
+ return readSandboxToken(target);
105
+ }
@@ -11,7 +11,7 @@ import { resolveConfiguredEnv } from '../config.js';
11
11
  import { getJson, postJson, putJson, patchJson, deleteJson, } from '../atlas-client.js';
12
12
  import { printCliError } from '../cli-errors.js';
13
13
  import { runStorageImport } from './import-run.js';
14
- import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
14
+ import { REQUIRE_EXPLICIT_ENV_MESSAGE, explicitOrSandboxEnv } from '../env-flags.js';
15
15
  import { writeScaffoldGuidance } from '../scaffold-guidance.js';
16
16
  const usage = `usage:
17
17
  seq-studio storage init <workspace-name> [--out workspace.yml]
@@ -33,9 +33,9 @@ const usage = `usage:
33
33
 
34
34
  Workspaces are provisioned from YAML; paths create folders at upload time.
35
35
  Uploads print their session ID to stderr for retry. Resume uses the same original file.
36
- Use -e local or -e local:<worktree> for the standard local Atlas target.`;
36
+ Use -e <env> with a registered environment; run seq-studio envs list to see them.`;
37
37
  export async function runStorageCommand(sub, args) {
38
- if (!sub || sub === 'help' || args.flags.help) {
38
+ if (!sub || sub === 'help' || sub === '--help' || sub === '-h' || args.flags.help) {
39
39
  console.log(usage);
40
40
  return sub ? 0 : 1;
41
41
  }
@@ -64,9 +64,10 @@ export async function runStorageCommand(sub, args) {
64
64
  console.log('Workspace manifest is valid');
65
65
  return 0;
66
66
  }
67
- if (!flag('env'))
67
+ const requested = explicitOrSandboxEnv(flag('env'));
68
+ if (!requested)
68
69
  throw new Error(REQUIRE_EXPLICIT_ENV_MESSAGE);
69
- const env = await resolveConfiguredEnv({ requested: flag('env') });
70
+ const env = await resolveConfiguredEnv({ requested });
70
71
  const { token } = await getAccessTokenWithMode({
71
72
  env: env.name,
72
73
  targetUrl: env.url,
@@ -0,0 +1,7 @@
1
+ /** Render one value for a human-readable table cell. */
2
+ export declare function cell(value: unknown): string;
3
+ /** Print an aligned, space-separated table to stdout. */
4
+ export declare function table({ headers, rows }: {
5
+ headers: string[];
6
+ rows: unknown[][];
7
+ }): void;
@@ -0,0 +1,16 @@
1
+ /** Render one value for a human-readable table cell. */
2
+ export function cell(value) {
3
+ if (value === undefined)
4
+ return '—';
5
+ if (typeof value !== 'string')
6
+ return JSON.stringify(value) ?? '—';
7
+ // Preserve readable text while escaping control characters from source data.
8
+ return value.replace(/\p{Cc}/gu, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`);
9
+ }
10
+ /** Print an aligned, space-separated table to stdout. */
11
+ export function table({ headers, rows }) {
12
+ const lines = [headers, ...rows].map((row) => row.map(cell));
13
+ const widths = headers.map((_, index) => Math.max(...lines.map((line) => line[index]?.length ?? 0)));
14
+ for (const line of lines)
15
+ console.log(line.map((value, index) => value.padEnd(widths[index] ?? 0)).join(' ').trimEnd());
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequenceholdings/studio-cli",
3
- "version": "0.5.4",
3
+ "version": "0.6.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 whoami`. Includes Auth0 browser login shared with seqapi.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -42,15 +42,15 @@
42
42
  "tsx": "^4.20.3",
43
43
  "zod": "^4.1.13",
44
44
  "yaml": "^2.8.4",
45
- "@sequenceholdings/artifact-studio": "0.8.0",
46
- "@sequenceholdings/agent-spec": "0.1.3",
47
- "@sequenceholdings/lattice": "0.1.5",
48
- "@sequenceholdings/managed-functions": "0.4.1",
45
+ "@sequenceholdings/agent-spec": "0.1.4",
46
+ "@sequenceholdings/artifact-studio": "0.9.0",
47
+ "@sequenceholdings/lattice": "0.1.6",
48
+ "@sequenceholdings/managed-functions": "0.4.2",
49
49
  "@sequenceholdings/storage": "0.1.1"
50
50
  },
51
51
  "peerDependencies": {
52
- "@sequenceholdings/orm": "2.6.1",
53
- "@sequenceholdings/pipeline-spec": "0.2.5"
52
+ "@sequenceholdings/pipeline-spec": "0.2.6",
53
+ "@sequenceholdings/orm": "2.6.2"
54
54
  },
55
55
  "peerDependenciesMeta": {
56
56
  "@sequenceholdings/orm": {
@@ -65,8 +65,8 @@
65
65
  "@types/node": "^22.0.0",
66
66
  "typescript": "^5.6.0",
67
67
  "vitest": "^4.1.11",
68
- "@sequenceholdings/orm": "2.6.1",
69
- "@sequenceholdings/pipeline-spec": "0.2.5"
68
+ "@sequenceholdings/orm": "2.6.2",
69
+ "@sequenceholdings/pipeline-spec": "0.2.6"
70
70
  },
71
71
  "engines": {
72
72
  "node": ">=20"