@sequenceholdings/studio-cli 0.5.3 → 0.5.5

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 (63) hide show
  1. package/README.md +220 -12
  2. package/dist/agents/bundle.d.ts +8 -0
  3. package/dist/agents/bundle.js +38 -0
  4. package/dist/agents/commands.d.ts +6 -1
  5. package/dist/agents/commands.js +17 -20
  6. package/dist/agents/selection.d.ts +3 -0
  7. package/dist/agents/selection.js +17 -0
  8. package/dist/agents/source.js +2 -1
  9. package/dist/app/adapters.js +2 -1
  10. package/dist/app/application-registration.d.ts +1 -1
  11. package/dist/app/application-registration.js +6 -2
  12. package/dist/app/commands.d.ts +6 -0
  13. package/dist/app/commands.js +13 -4
  14. package/dist/app/primitive-scaffold.js +8 -1
  15. package/dist/app/readme.js +1 -1
  16. package/dist/app/scaffold.js +1 -1
  17. package/dist/artifact/delegate.js +16 -4
  18. package/dist/atlas-client.js +5 -1
  19. package/dist/auth-cmds/commands.d.ts +1 -1
  20. package/dist/auth-cmds/commands.js +3 -0
  21. package/dist/auth.d.ts +2 -1
  22. package/dist/auth.js +16 -0
  23. package/dist/command-contract.d.ts +9 -9
  24. package/dist/command-contract.js +7 -7
  25. package/dist/command-help.d.ts +3 -2
  26. package/dist/command-help.js +31 -3
  27. package/dist/command-input.js +2 -2
  28. package/dist/config.d.ts +5 -0
  29. package/dist/config.js +14 -1
  30. package/dist/env-flags.d.ts +6 -0
  31. package/dist/env-flags.js +9 -0
  32. package/dist/functions/commands.d.ts +5 -2
  33. package/dist/functions/commands.js +36 -10
  34. package/dist/functions/deploy-preflight.js +2 -2
  35. package/dist/functions/manifest.d.ts +43 -29
  36. package/dist/functions/manifest.js +37 -74
  37. package/dist/main.js +43 -3
  38. package/dist/orm/delegate.js +25 -4
  39. package/dist/orm/read.d.ts +54 -0
  40. package/dist/orm/read.js +308 -0
  41. package/dist/pipeline/commands.js +10 -0
  42. package/dist/pipeline/discovery.js +3 -16
  43. package/dist/pipeline/retirement.d.ts +3 -0
  44. package/dist/pipeline/retirement.js +34 -0
  45. package/dist/process/build.js +4 -0
  46. package/dist/process/codegen.js +2 -0
  47. package/dist/process/commands.js +66 -25
  48. package/dist/process/plan-diff.js +1 -0
  49. package/dist/process/runs.d.ts +14 -0
  50. package/dist/process/runs.js +238 -0
  51. package/dist/repos/ci-status.js +28 -0
  52. package/dist/repos/commands.d.ts +2 -2
  53. package/dist/repos/commands.js +11 -4
  54. package/dist/repos/git-credential.d.ts +3 -2
  55. package/dist/repos/git-credential.js +52 -3
  56. package/dist/repos/pulls.d.ts +7 -1
  57. package/dist/repos/pulls.js +162 -22
  58. package/dist/sandbox-auth.d.ts +52 -0
  59. package/dist/sandbox-auth.js +105 -0
  60. package/dist/storage/commands.js +6 -5
  61. package/dist/text-table.d.ts +7 -0
  62. package/dist/text-table.js +16 -0
  63. package/package.json +9 -9
@@ -173,6 +173,7 @@ const BEHAVIORAL_METADATA_FIELDS = {
173
173
  ],
174
174
  agent: [
175
175
  'agent_version',
176
+ 'expected_identity',
176
177
  'allowed_tools',
177
178
  'output_mode',
178
179
  'input_mapper_source',
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `seq-studio process runs <start|list|show|cancel>` — start and observe
3
+ * Lattice runs through the programmatic run API, as the caller. Starting needs
4
+ * `invoker` on the process; reading a run needs `viewer` on it.
5
+ */
6
+ import type { ParsedArgs } from './commands.js';
7
+ type Sleep = (ms: number) => Promise<void>;
8
+ /** Validate every flag before authenticating so a typo never starts a run. */
9
+ export declare function startRunBody(args: ParsedArgs): Promise<Record<string, unknown>>;
10
+ export declare function listRunsQuery(args: ParsedArgs): URLSearchParams;
11
+ export declare function processRunsCommand(args: ParsedArgs, deps?: {
12
+ sleep?: Sleep;
13
+ }): Promise<number>;
14
+ export {};
@@ -0,0 +1,238 @@
1
+ /**
2
+ * `seq-studio process runs <start|list|show|cancel>` — start and observe
3
+ * Lattice runs through the programmatic run API, as the caller. Starting needs
4
+ * `invoker` on the process; reading a run needs `viewer` on it.
5
+ */
6
+ import { readFile } from 'node:fs/promises';
7
+ import { getJson, postJson } from '../atlas-client.js';
8
+ import { printCliError } from '../cli-errors.js';
9
+ import { PROCESS_RUNS_USAGE } from '../command-help.js';
10
+ import { validateCommandInput } from '../command-input.js';
11
+ import { buildContext, clientOptions } from '../functions/commands.js';
12
+ import { table } from '../text-table.js';
13
+ const RUN_STATUSES = ['pending', 'running', 'completed', 'failed', 'cancelled', 'timed_out'];
14
+ const TERMINAL_STATUSES = new Set(['completed', 'failed', 'cancelled', 'timed_out']);
15
+ const RUN_ID = /^[A-Za-z0-9._-]{2,128}$/;
16
+ const MAX_LIST_LIMIT = 500;
17
+ const DEFAULT_WAIT_SECONDS = 600;
18
+ const WAIT_POLL_MS = 2_000;
19
+ function stringFlag({ args, key }) {
20
+ const value = args.flags[key];
21
+ return typeof value === 'string' ? value : undefined;
22
+ }
23
+ function runIdArg({ args, label }) {
24
+ const value = args.positional[1];
25
+ if (!RUN_ID.test(value))
26
+ throw new Error(`Invalid ${label} '${value}': 2-128 letters, digits, '.', '_' or '-'.`);
27
+ return value;
28
+ }
29
+ function errorText(error) {
30
+ if (error === null || error === undefined)
31
+ return undefined;
32
+ if (typeof error === 'string')
33
+ return error;
34
+ if (typeof error === 'object' && typeof Reflect.get(error, 'message') === 'string')
35
+ return String(Reflect.get(error, 'message'));
36
+ return JSON.stringify(error);
37
+ }
38
+ async function metadataFromFile(path) {
39
+ let parsed;
40
+ try {
41
+ parsed = JSON.parse(await readFile(path, 'utf8'));
42
+ }
43
+ catch (error) {
44
+ throw new Error(`--metadata-file ${path}: ${error instanceof Error ? error.message : String(error)}`);
45
+ }
46
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
47
+ throw new Error(`--metadata-file ${path} must contain a JSON object.`);
48
+ }
49
+ return parsed;
50
+ }
51
+ /** Validate every flag before authenticating so a typo never starts a run. */
52
+ export async function startRunBody(args) {
53
+ validateCommandInput({
54
+ args,
55
+ flags: { version: 'string', 'run-id': 'string', 'metadata-file': 'string', title: 'string', entity: 'string' },
56
+ positional: 2,
57
+ });
58
+ const runId = stringFlag({ args, key: 'run-id' });
59
+ if (runId !== undefined && !RUN_ID.test(runId)) {
60
+ throw new Error(`Invalid --run-id '${runId}': 2-128 letters, digits, '.', '_' or '-'.`);
61
+ }
62
+ const entity = stringFlag({ args, key: 'entity' });
63
+ const separator = entity?.indexOf(':') ?? -1;
64
+ if (entity !== undefined && (separator < 1 || separator === entity.length - 1)) {
65
+ throw new Error(`Invalid --entity '${entity}': expected <type>:<id>.`);
66
+ }
67
+ const metadataFile = stringFlag({ args, key: 'metadata-file' });
68
+ const version = stringFlag({ args, key: 'version' });
69
+ const title = stringFlag({ args, key: 'title' });
70
+ return {
71
+ process_id: args.positional[1],
72
+ ...(version !== undefined ? { version } : {}),
73
+ ...(runId !== undefined ? { run_id: runId } : {}),
74
+ ...(title !== undefined ? { title } : {}),
75
+ ...(entity !== undefined ? { entity: { type: entity.slice(0, separator), id: entity.slice(separator + 1) } } : {}),
76
+ ...(metadataFile !== undefined ? { metadata: await metadataFromFile(metadataFile) } : {}),
77
+ };
78
+ }
79
+ export function listRunsQuery(args) {
80
+ validateCommandInput({
81
+ args,
82
+ flags: { process: 'string', status: 'string', 'entity-type': 'string', 'entity-id': 'string', archived: 'boolean', limit: 'string' },
83
+ positional: 1,
84
+ });
85
+ const params = new URLSearchParams();
86
+ const processId = stringFlag({ args, key: 'process' });
87
+ if (processId !== undefined)
88
+ params.set('process_id', processId);
89
+ const status = stringFlag({ args, key: 'status' });
90
+ if (status !== undefined) {
91
+ if (!RUN_STATUSES.includes(status)) {
92
+ throw new Error(`--status must be one of: ${RUN_STATUSES.join(', ')}.`);
93
+ }
94
+ params.set('status', status);
95
+ }
96
+ const entityType = stringFlag({ args, key: 'entity-type' });
97
+ const entityId = stringFlag({ args, key: 'entity-id' });
98
+ if (entityType !== undefined)
99
+ params.set('entity_type', entityType);
100
+ if (entityId !== undefined)
101
+ params.set('entity_id', entityId);
102
+ if (args.flags.archived === true)
103
+ params.set('archived', 'true');
104
+ const limit = stringFlag({ args, key: 'limit' });
105
+ if (limit !== undefined) {
106
+ const value = /^\d+$/.test(limit) ? Number(limit) : Number.NaN;
107
+ if (!Number.isSafeInteger(value) || value < 1 || value > MAX_LIST_LIMIT) {
108
+ throw new Error(`--limit must be an integer from 1 to ${MAX_LIST_LIMIT}.`);
109
+ }
110
+ params.set('limit', String(value));
111
+ }
112
+ return params;
113
+ }
114
+ function printRunsTable(runs) {
115
+ table({
116
+ headers: ['RUN', 'PROCESS', 'VERSION', 'STATUS', 'STARTED', 'COMPLETED', 'TITLE'],
117
+ rows: runs.map((run) => [run.id, run.processId, run.processVersion, run.status, run.startedAt, run.completedAt, run.title]),
118
+ });
119
+ }
120
+ function printRunDetail({ run, steps }) {
121
+ console.log(`Run: ${run.id} | Process: ${run.processId}@${run.processVersion ?? '—'} | Status: ${run.status}`);
122
+ console.log(`Started: ${run.startedAt ?? '—'} | Completed: ${run.completedAt ?? '—'}`);
123
+ const runError = errorText(run.error);
124
+ if (runError)
125
+ console.log(`Error: ${runError}`);
126
+ table({
127
+ headers: ['NODE', 'KIND', 'ATTEMPT', 'STATUS', 'STARTED', 'COMPLETED', 'ERROR'],
128
+ rows: steps.map((step) => [step.nodeId, step.kind, step.attempt, step.status, step.startedAt, step.completedAt, errorText(step.error)]),
129
+ });
130
+ }
131
+ async function waitForTerminal({ load, timeoutSeconds, sleep, }) {
132
+ const deadline = Date.now() + timeoutSeconds * 1000;
133
+ let detail = await load();
134
+ while (!TERMINAL_STATUSES.has(detail.run.status)) {
135
+ if (Date.now() >= deadline) {
136
+ throw new Error(`Run ${detail.run.id} is still ${detail.run.status} after ${timeoutSeconds}s; it keeps running. Check again with process runs show.`);
137
+ }
138
+ await sleep(WAIT_POLL_MS);
139
+ detail = await load();
140
+ }
141
+ return detail;
142
+ }
143
+ async function startRun({ args, json }) {
144
+ const body = await startRunBody(args);
145
+ const ctx = await buildContext(args);
146
+ const result = await postJson({ ...clientOptions(ctx), path: '/api/lattice/runs', body });
147
+ if (json) {
148
+ console.log(JSON.stringify(result, null, 2));
149
+ return 0;
150
+ }
151
+ const replay = result.idempotent_replay ? ' (existing run; --run-id already used)' : '';
152
+ console.log(`Run: ${result.run_id} | Process: ${result.process_id}@${result.process_version ?? '—'} | Status: ${result.status}${replay}`);
153
+ console.log(`Follow it with: seq-studio process runs show ${result.run_id} --wait`);
154
+ return 0;
155
+ }
156
+ async function listRuns({ args, json }) {
157
+ const params = listRunsQuery(args);
158
+ const ctx = await buildContext(args);
159
+ const query = params.toString();
160
+ const result = await getJson({ ...clientOptions(ctx), path: `/api/lattice/runs${query ? `?${query}` : ''}` });
161
+ if (json)
162
+ console.log(JSON.stringify(result, null, 2));
163
+ else {
164
+ printRunsTable(result.runs);
165
+ console.error(`${result.runs.length} run(s), newest first`);
166
+ }
167
+ const limit = Number(params.get('limit') ?? 50);
168
+ if (result.runs.length >= limit) {
169
+ console.error(`Showing the newest ${limit}. Narrow with --process/--status/--entity-type, or raise --limit (max ${MAX_LIST_LIMIT}).`);
170
+ }
171
+ return 0;
172
+ }
173
+ function waitTimeoutSeconds(args) {
174
+ const timeout = stringFlag({ args, key: 'timeout' });
175
+ if (timeout !== undefined && args.flags.wait !== true)
176
+ throw new Error('--timeout applies only with --wait.');
177
+ const seconds = timeout === undefined ? DEFAULT_WAIT_SECONDS : Number(timeout);
178
+ if (!Number.isSafeInteger(seconds) || seconds < 1)
179
+ throw new Error('--timeout must be a positive number of seconds.');
180
+ return seconds;
181
+ }
182
+ async function showRun({ args, json, sleep }) {
183
+ validateCommandInput({ args, flags: { wait: 'boolean', timeout: 'string' }, positional: 2 });
184
+ const runId = runIdArg({ args, label: 'run id' });
185
+ const timeoutSeconds = waitTimeoutSeconds(args);
186
+ const ctx = await buildContext(args);
187
+ const load = () => getJson({ ...clientOptions(ctx), path: `/api/lattice/runs/${encodeURIComponent(runId)}` });
188
+ const detail = args.flags.wait === true ? await waitForTerminal({ load, timeoutSeconds, sleep }) : await load();
189
+ if (json)
190
+ console.log(JSON.stringify(detail, null, 2));
191
+ else
192
+ printRunDetail(detail);
193
+ return 0;
194
+ }
195
+ async function cancelRun({ args, json }) {
196
+ validateCommandInput({ args, flags: {}, positional: 2 });
197
+ const runId = runIdArg({ args, label: 'run id' });
198
+ const ctx = await buildContext(args);
199
+ const result = await postJson({
200
+ ...clientOptions(ctx),
201
+ path: `/api/lattice/runs/${encodeURIComponent(runId)}/cancel`,
202
+ });
203
+ if (json)
204
+ console.log(JSON.stringify(result, null, 2));
205
+ else
206
+ console.log(`Run: ${runId} | Status: ${result.run?.status ?? 'unknown'}${result.idempotent_replay ? ' (already cancelled)' : ''}`);
207
+ return 0;
208
+ }
209
+ const RUN_ACTIONS = {
210
+ start: startRun,
211
+ list: listRuns,
212
+ show: showRun,
213
+ cancel: cancelRun,
214
+ };
215
+ export async function processRunsCommand(args, deps = {}) {
216
+ const action = args.positional[0];
217
+ if (!action || args.flags.help === true || action === 'help') {
218
+ console.log(PROCESS_RUNS_USAGE);
219
+ return action ? 0 : 1;
220
+ }
221
+ const handler = RUN_ACTIONS[action];
222
+ if (!handler) {
223
+ console.error(`unknown process runs command: ${action}`);
224
+ console.error(PROCESS_RUNS_USAGE);
225
+ return 1;
226
+ }
227
+ try {
228
+ return await handler({
229
+ args,
230
+ json: args.flags.json === true,
231
+ sleep: deps.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms))),
232
+ });
233
+ }
234
+ catch (error) {
235
+ printCliError(error);
236
+ return 1;
237
+ }
238
+ }
@@ -12,7 +12,16 @@ const statusSchema = z.object({
12
12
  }).nullable(),
13
13
  currentRunId: z.string().nullable(),
14
14
  runs: z.array(z.object({ id: z.string(), state: z.string(), error: z.string().nullable().optional() })),
15
+ intents: z.array(z.object({
16
+ id: z.string(), runId: z.string(), state: z.string(), mergeSha: z.string().nullable(),
17
+ error: z.string().nullable(), appUrl: z.string().nullable(),
18
+ targets: z.record(z.string(), z.object({ state: z.string(), reason: z.string().optional() }).passthrough()),
19
+ })).optional(),
15
20
  });
21
+ function oneLine(value) {
22
+ const normalized = value.replace(/\s+/g, ' ').trim();
23
+ return normalized.length > 240 ? `${normalized.slice(0, 237)}...` : normalized;
24
+ }
16
25
  function printPlan({ plan }) {
17
26
  console.log(` Head: ${plan.headSha}; plan: ${plan.planHash}`);
18
27
  for (const target of plan.targets) {
@@ -23,6 +32,24 @@ function printPlan({ plan }) {
23
32
  for (const finding of plan.findings)
24
33
  console.log(` ${finding.severity} ${finding.code}: ${finding.message}`);
25
34
  }
35
+ function printIntents({ intents }) {
36
+ if (intents.length === 0)
37
+ return;
38
+ console.log(` Deployment intents:${intents.length > 5 ? ` (showing 5 of ${intents.length}; use --json for all)` : ''}`);
39
+ for (const intent of intents.slice(0, 5)) {
40
+ console.log(` ${oneLine(intent.id)}: ${oneLine(intent.state)} (${intent.mergeSha ? `merge ${oneLine(intent.mergeSha)}` : 'merge pending'}, run ${oneLine(intent.runId)})`);
41
+ if (intent.error)
42
+ console.log(` Error: ${oneLine(intent.error)}`);
43
+ if (intent.appUrl)
44
+ console.log(` App: ${oneLine(intent.appUrl)}`);
45
+ const targets = Object.entries(intent.targets);
46
+ for (const [key, progress] of targets.slice(0, 10)) {
47
+ console.log(` ${oneLine(key)}: ${oneLine(progress.state)}${progress.reason ? ` — ${oneLine(progress.reason)}` : ''}`);
48
+ }
49
+ if (targets.length > 10)
50
+ console.log(` ... ${targets.length - 10} more targets (use --json)`);
51
+ }
52
+ }
26
53
  /** Read the authoritative server plan; the CLI never infers execution or deployment authority. */
27
54
  export async function showRepositoryPrCi({ ctx, repoId, repoPath, number, json }) {
28
55
  const response = await getJson({ ...clientOptions(ctx), path: `/api/git-service/repos/${repoId}/pulls/${number}/ci` });
@@ -45,5 +72,6 @@ export async function showRepositoryPrCi({ ctx, repoId, repoPath, number, json }
45
72
  }
46
73
  for (const run of status.runs.slice(0, 5))
47
74
  console.log(` ${run.id === status.currentRunId ? 'Current' : 'Previous'} run ${run.id}: ${run.state}${run.error ? ` — ${run.error}` : ''}`);
75
+ printIntents({ intents: status.intents ?? [] });
48
76
  return blocked ? 1 : 0;
49
77
  }
@@ -91,8 +91,8 @@ export declare function loadRemoteCiSources({ ctx, repoId, ref, }: {
91
91
  error: string;
92
92
  }>;
93
93
  /**
94
- * Discover CI checks from a remote repo tip (pure preview — no Settings write).
95
- * Uses the same autodiscovery rules as the platform runner (PLA-378).
94
+ * Preview legacy CI checks from a remote repo tip (no Settings write).
95
+ * Native repository plans are authoritative only through the PR status path.
96
96
  */
97
97
  export declare function reposCiShowCommand(args: ParsedArgs): Promise<number>;
98
98
  /** Add a check-run name to Settings `requiredChecks` (merge-blocking). */
@@ -628,8 +628,8 @@ export async function loadRemoteCiSources({ ctx, repoId, ref, }) {
628
628
  return { ok: true, packageScripts };
629
629
  }
630
630
  /**
631
- * Discover CI checks from a remote repo tip (pure preview — no Settings write).
632
- * Uses the same autodiscovery rules as the platform runner (PLA-378).
631
+ * Preview legacy CI checks from a remote repo tip (no Settings write).
632
+ * Native repository plans are authoritative only through the PR status path.
633
633
  */
634
634
  export async function reposCiShowCommand(args) {
635
635
  const { namespace, name } = parseRepoPath(args.positional[0]);
@@ -667,7 +667,8 @@ export async function reposCiShowCommand(args) {
667
667
  return 0;
668
668
  }
669
669
  if (discovered.checks.length === 0) {
670
- console.log(' (no checks discovered)');
670
+ console.log(' No legacy checks discovered at this ref; this preview does not show the server repository plan, including its targets, checks, or findings.');
671
+ console.log(` Open or update a pull request, then inspect the authoritative plan with: seq-studio repos ci show ${namespace}/${name} -e ${ctx.env.name} --pr <number>`);
671
672
  return 0;
672
673
  }
673
674
  for (const check of discovered.checks) {
@@ -706,6 +707,12 @@ export async function reposCiImportCommand(args) {
706
707
  }
707
708
  export async function reposCiCommand(args) {
708
709
  const [requestedAction] = args.positional;
710
+ if (requestedAction && requestedAction !== 'help' &&
711
+ !['init', 'show', 'require', 'import'].includes(requestedAction) &&
712
+ (flagBool(args.flags, 'help') || flagBool(args.flags, 'h'))) {
713
+ console.error(`unknown repos ci command: ${requestedAction}`);
714
+ return 1;
715
+ }
709
716
  const action = flagBool(args.flags, 'help') || flagBool(args.flags, 'h') ? 'help' : requestedAction;
710
717
  const rest = {
711
718
  ...args,
@@ -731,7 +738,7 @@ export async function reposCiCommand(args) {
731
738
  console.log(`usage:
732
739
  seq-studio repos ci init [--dir <repository>] create .seq/pipeline.yml; no login needed
733
740
  seq-studio repos ci show <ns>/<name> -e <env> --pr <number> [--json] inspect the server CI plan and runs
734
- seq-studio repos ci show <ns>/<name> -e <env> [--ref r] preview pipeline discovery or legacy checks
741
+ seq-studio repos ci show <ns>/<name> -e <env> [--ref r] preview legacy discovery; use --pr for the server plan
735
742
  seq-studio repos ci require <ns>/<name> --check <name> -e <env> disabled legacy control; use native pipeline discovery
736
743
  seq-studio repos ci import <ns>/<name> -e <env> [--ref r] disabled legacy control; use native pipeline discovery
737
744
 
@@ -1,10 +1,11 @@
1
1
  import type { ParsedArgs } from '../process/commands.js';
2
+ export declare const GIT_CREDENTIAL_USAGE: string;
2
3
  /** Only send a login credential to the exact repository pinned at clone time. */
3
4
  export declare function gitCredentialResponse({ input, operation, envName, cloneUrl, }: {
4
5
  input: string;
5
6
  operation: string;
6
- envName: string;
7
- cloneUrl: string;
7
+ envName?: string;
8
+ cloneUrl?: string;
8
9
  }): Promise<string>;
9
10
  /** Store only a helper command, bound to this environment and repository URL. */
10
11
  export declare function configureGitLogin({ destDir, envName, cloneUrl, }: {
@@ -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 {};