@sequenceholdings/studio-cli 0.6.3 → 0.6.4

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.
@@ -181,8 +181,9 @@ export async function runAppInitCommand(args) {
181
181
  try {
182
182
  if (args.flags.template === true)
183
183
  throw new Error('--template requires <name>@<version>.');
184
- const env = args.flags.env ?? args.flags.e;
185
- if (typeof env !== 'string')
184
+ const requested = args.flags.env ?? args.flags.e;
185
+ const env = explicitOrSandboxEnv(typeof requested === 'string' ? requested : undefined);
186
+ if (!env)
186
187
  throw new Error('--template requires -e <deployment>.');
187
188
  if (kinds.length > 0)
188
189
  throw new Error('Use either --template or --with/primitive flags.');
@@ -2,6 +2,7 @@ import { validateCommandInput, wantsHelp } from '../command-input.js';
2
2
  import { getJson } from '../atlas-client.js';
3
3
  import { printCliError } from '../cli-errors.js';
4
4
  import { buildContext, clientOptions } from '../functions/commands.js';
5
+ import { describeSandboxTarget, sandboxTarget } from '../sandbox-auth.js';
5
6
  export const AUTH_USAGE = `usage:
6
7
  seq-studio auth whoami -e <env> [--json]
7
8
  seq-studio auth git-credential --env <env> --url <clone-url> <get|store|erase>
@@ -25,8 +26,10 @@ export async function runAuthCommand(sub, args) {
25
26
  validateCommandInput({ args, flags: {}, positional: 0 });
26
27
  const ctx = await buildContext(args);
27
28
  const { sub: subject, email, name, tenantSlug, roles, permissions } = await getJson({ ...clientOptions(ctx), path: '/api/me' });
29
+ const sandbox = ctx.authMode === 'sandbox' ? sandboxTarget() : null;
28
30
  console.log(JSON.stringify({
29
31
  environment: ctx.env.name, url: ctx.env.url, authMode: ctx.authMode,
32
+ ...(sandbox ? { host: new URL(sandbox.baseUrl).host, note: describeSandboxTarget(sandbox) } : {}),
30
33
  identity: { sub: subject, email, name, tenantSlug, roles, permissions },
31
34
  }, null, 2));
32
35
  return 0;
@@ -14,3 +14,9 @@ export declare function readEnvFromArgv(rest: readonly string[]): string | undef
14
14
  * deployment and `-e` is optional (and ignored).
15
15
  */
16
16
  export declare function explicitOrSandboxEnv(requested: string | undefined): string | undefined;
17
+ /**
18
+ * In sandbox token mode, a notice that the `-e` value in `argv` is ignored and
19
+ * where the command goes instead; null when nothing is ignored. An agent that
20
+ * passed `-e production` otherwise has no sign its request went elsewhere.
21
+ */
22
+ export declare function ignoredSandboxEnvNotice(argv: readonly string[]): string | null;
package/dist/env-flags.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * CLIs only recognize the two-token `--env <value>` form, so every `-e value`
4
4
  * / `-e=value` / `--env=value` spelling is rewritten before forwarding.
5
5
  */
6
- import { SANDBOX_ENV_NAME, isSandboxTokenMode } from './sandbox-auth.js';
6
+ import { SANDBOX_BASE_URL_ENV, SANDBOX_ENV_NAME, isSandboxTokenMode, sandboxTarget } from './sandbox-auth.js';
7
7
  /** Shared copy for network commands that must not silently fall back to `local`. */
8
8
  export const REQUIRE_EXPLICIT_ENV_MESSAGE = 'You must specify an environment you have access to with `-e <env>`. Run `seq-studio envs list` to see available environments.';
9
9
  export function normalizeShortEnvFlag(argv) {
@@ -56,3 +56,25 @@ export function readEnvFromArgv(rest) {
56
56
  export function explicitOrSandboxEnv(requested) {
57
57
  return isSandboxTokenMode() ? SANDBOX_ENV_NAME : requested;
58
58
  }
59
+ /**
60
+ * In sandbox token mode, a notice that the `-e` value in `argv` is ignored and
61
+ * where the command goes instead; null when nothing is ignored. An agent that
62
+ * passed `-e production` otherwise has no sign its request went elsewhere.
63
+ */
64
+ export function ignoredSandboxEnvNotice(argv) {
65
+ let target;
66
+ try {
67
+ target = sandboxTarget();
68
+ }
69
+ catch {
70
+ // A half-configured sandbox: the command itself fails with that error.
71
+ return null;
72
+ }
73
+ if (!target)
74
+ return null;
75
+ const requested = readEnvFromArgv(normalizeShortEnvFlag(argv));
76
+ if (!requested || requested === SANDBOX_ENV_NAME)
77
+ return null;
78
+ return (`[seq-studio] Sandbox token mode ignores -e ${requested}: this command targets ` +
79
+ `${target.baseUrl} (${SANDBOX_BASE_URL_ENV}).`);
80
+ }
@@ -1,6 +1,7 @@
1
1
  import { addSharedLoginEnvironment, readConfig, configPath, manualEnvConfigHint } from '../config.js';
2
2
  import { isSharedLoginDeploymentName } from '../auth.js';
3
3
  import { readRegisteredEnvironmentUrls, registerEnvironment, } from '../env-registry.js';
4
+ import { describeSandboxTarget, SANDBOX_ENV_NAME, sandboxTarget, sandboxUsageFooter, } from '../sandbox-auth.js';
4
5
  const ENVS_USAGE = `usage:
5
6
  seq-studio envs list show the configured environments
6
7
  seq-studio envs add <name> <url>
@@ -21,14 +22,24 @@ const ENVS_USAGE = `usage:
21
22
  export async function runEnvsCommand(sub, rest) {
22
23
  switch (sub) {
23
24
  case 'add':
24
- return addCommand(rest);
25
- case 'list':
26
- return listCommand();
25
+ case 'list': {
26
+ let sandbox;
27
+ try {
28
+ sandbox = sandboxTarget();
29
+ }
30
+ catch (error) {
31
+ console.error(`envs ${sub}: FAIL — ${error instanceof Error ? error.message : String(error)}`);
32
+ return 1;
33
+ }
34
+ if (sandbox)
35
+ return sub === 'add' ? refuseSandboxAdd(sandbox) : listSandbox(sandbox);
36
+ return sub === 'add' ? addCommand(rest) : listCommand();
37
+ }
27
38
  case undefined:
28
39
  case 'help':
29
40
  case '--help':
30
41
  case '-h':
31
- console.log(ENVS_USAGE);
42
+ console.log(`${ENVS_USAGE}${sandboxUsageFooter()}`);
32
43
  return sub ? 0 : 1;
33
44
  default:
34
45
  console.error(`unknown envs command: ${sub}`);
@@ -36,6 +47,21 @@ export async function runEnvsCommand(sub, rest) {
36
47
  return 1;
37
48
  }
38
49
  }
50
+ /**
51
+ * A sandbox reads no config or registry and its token is accepted only by its
52
+ * own deployment, so a registered environment could never be used.
53
+ */
54
+ function refuseSandboxAdd(sandbox) {
55
+ console.error(`envs add: refused in sandbox token mode — no environment you add can be reached from here. ` +
56
+ describeSandboxTarget(sandbox));
57
+ return 1;
58
+ }
59
+ function listSandbox(sandbox) {
60
+ console.log(`* ${SANDBOX_ENV_NAME} ${sandbox.baseUrl} (active default, SEQ_STUDIO_BASE_URL)`);
61
+ console.log('');
62
+ console.log(describeSandboxTarget(sandbox));
63
+ return 0;
64
+ }
39
65
  async function addCommand(rest) {
40
66
  const [name, baseUrl, ...extra] = rest;
41
67
  if (!name || !baseUrl || extra.length > 0) {
package/dist/main.js CHANGED
@@ -26,6 +26,8 @@
26
26
  import { parseArgs } from './argv.js';
27
27
  import { renderCapabilities } from './command-contract.js';
28
28
  import { staticHelp } from './command-help.js';
29
+ import { ignoredSandboxEnvNotice } from './env-flags.js';
30
+ import { sandboxUsageFooter } from './sandbox-auth.js';
29
31
  // Lazy-load artifact delegate: published @sequenceholdings/artifact-studio/cli
30
32
  // still auto-runs runCli() at module load; importing it here breaks doctor/process.
31
33
  const TOP_LEVEL_USAGE = `usage:
@@ -63,8 +65,6 @@ const TOP_LEVEL_USAGE = `usage:
63
65
  If this CLI cannot complete a documented step, read that environment's docs
64
66
  before trying another tool. \`seq-studio envs list\` prints each environment URL.
65
67
  Docs: <url>/docs. Feedback guide: <url>/docs/raw/seq-studio/feedback.md.
66
- Sequence: https://sequence.seqholdings.com/docs
67
- and https://sequence.seqholdings.com/docs/raw/seq-studio/feedback.md.
68
68
  `;
69
69
  const PROCESS_USAGE = `usage:
70
70
  seq-studio process init <dir>
@@ -107,7 +107,7 @@ const SUBCOMMANDS = {
107
107
  export async function run(argv = process.argv.slice(2)) {
108
108
  const [namespace, sub, ...rest] = argv;
109
109
  if (!namespace || namespace === 'help' || namespace === '--help' || namespace === '-h') {
110
- console.log(TOP_LEVEL_USAGE);
110
+ console.log(`${TOP_LEVEL_USAGE}${sandboxUsageFooter()}`);
111
111
  return namespace ? 0 : 1;
112
112
  }
113
113
  if (namespace === 'capabilities' && hasHelpFlag(sub, rest)) {
@@ -130,6 +130,9 @@ export async function run(argv = process.argv.slice(2)) {
130
130
  return 0;
131
131
  }
132
132
  }
133
+ const ignoredEnv = ignoredSandboxEnvNotice([sub, ...rest].filter((a) => Boolean(a)));
134
+ if (ignoredEnv)
135
+ console.error(ignoredEnv);
133
136
  switch (namespace) {
134
137
  case 'init': {
135
138
  const { runAppInitCommand } = await import('./app/commands.js');
@@ -5,6 +5,7 @@
5
5
  import { getAccessToken, getAccessTokenWithMode, NotLoggedInError } from '../auth.js';
6
6
  import { AtlasApiError, getJson, postJson } from '../atlas-client.js';
7
7
  import { resolveConfiguredEnv } from '../config.js';
8
+ import { explicitOrSandboxEnv } from '../env-flags.js';
8
9
  import { parseDurationMs } from '@sequenceholdings/lattice';
9
10
  import { assertCloneDeployAllowed, publishCloneForDeploy } from './clone-deploy.js';
10
11
  import { printReconcileResult, reconcileStageCredentials } from './stage-secrets.js';
@@ -53,7 +54,7 @@ function deploymentStatusLabel(detail) {
53
54
  return detail.status;
54
55
  }
55
56
  export async function envAndToken(args, options = {}) {
56
- const requested = typeof args.flags.e === 'string' ? args.flags.e : typeof args.flags.env === 'string' ? args.flags.env : undefined;
57
+ const requested = explicitOrSandboxEnv(typeof args.flags.e === 'string' ? args.flags.e : typeof args.flags.env === 'string' ? args.flags.env : undefined);
57
58
  if (!requested) {
58
59
  throw new Error('missing -e/--env <environment>');
59
60
  }
@@ -3,6 +3,8 @@ import { join, resolve } from 'node:path';
3
3
  import { z } from 'zod';
4
4
  import { getAccessToken } from '../auth.js';
5
5
  import { resolveConfiguredEnv } from '../config.js';
6
+ import { explicitOrSandboxEnv } from '../env-flags.js';
7
+ import { isSandboxTokenMode } from '../sandbox-auth.js';
6
8
  import { loadActiveOrmContracts } from './active-orm-contracts.js';
7
9
  import { commitFileWrites } from './atomic-file-writes.js';
8
10
  import { resolvePipelineTarget } from './lifecycle.js';
@@ -16,7 +18,7 @@ async function loadModules() {
16
18
  }
17
19
  function requestedEnvironment(args) {
18
20
  const value = args.flags.e ?? args.flags.env;
19
- return typeof value === 'string' ? value : undefined;
21
+ return explicitOrSandboxEnv(typeof value === 'string' ? value : undefined);
20
22
  }
21
23
  function hasOrmPin(stage) {
22
24
  return stage.type === 'serving' && stage.satisfies !== undefined;
@@ -63,6 +65,11 @@ async function assertSharedStageContractsAgree({ contracts, orm, stages, target,
63
65
  throw new Error(`cannot verify shared ORM pins for target '${otherTarget}'; ` +
64
66
  'split multi-target stages or use environment-specific pins');
65
67
  }
68
+ if (isSandboxTokenMode()) {
69
+ // Every name resolves to the sandbox deployment, which is not this target's.
70
+ throw new Error(`cannot verify shared ORM pins for target '${otherTarget}' from an agent sandbox; ` +
71
+ 'it reaches only its own deployment');
72
+ }
66
73
  const otherEnv = await resolveConfiguredEnv({ requested: environmentName });
67
74
  const otherToken = await getAccessToken({ env: otherEnv.name, targetUrl: otherEnv.url });
68
75
  const sharedStages = stages.filter((stage) => stage.environments.includes(otherTarget));
@@ -38,6 +38,17 @@ export declare class SandboxAuthError extends Error {
38
38
  */
39
39
  export declare function sandboxTarget(env?: NodeJS.ProcessEnv): SandboxTarget | null;
40
40
  export declare function isSandboxTokenMode(env?: NodeJS.ProcessEnv): boolean;
41
+ /**
42
+ * One line naming the deployment a sandbox is pinned to, for help, envs and
43
+ * whoami. An agent reads it to learn where its commands go and that `-e` and
44
+ * `envs add` cannot point them anywhere else.
45
+ */
46
+ export declare function describeSandboxTarget(target: SandboxTarget): string;
47
+ /**
48
+ * Lines appended to top-level help: the pinned deployment in sandbox token
49
+ * mode, the misconfiguration when only one variable is set, else nothing.
50
+ */
51
+ export declare function sandboxUsageFooter(): string;
41
52
  /** Read the current bearer. Never cached: Atlas rotates the file between requests. */
42
53
  export declare function readSandboxToken(target: SandboxTarget): Promise<string>;
43
54
  export declare function isSandboxOrigin({ target, url }: {
@@ -59,6 +59,28 @@ export function sandboxTarget(env = process.env) {
59
59
  export function isSandboxTokenMode(env = process.env) {
60
60
  return sandboxTarget(env) !== null;
61
61
  }
62
+ /**
63
+ * One line naming the deployment a sandbox is pinned to, for help, envs and
64
+ * whoami. An agent reads it to learn where its commands go and that `-e` and
65
+ * `envs add` cannot point them anywhere else.
66
+ */
67
+ export function describeSandboxTarget(target) {
68
+ return (`Sandbox token mode: ${SANDBOX_BASE_URL_ENV} and ${SANDBOX_TOKEN_FILE_ENV} pin every command to ` +
69
+ `${target.baseUrl} (environment "${SANDBOX_ENV_NAME}"). -e is optional; any value resolves to this deployment.`);
70
+ }
71
+ /**
72
+ * Lines appended to top-level help: the pinned deployment in sandbox token
73
+ * mode, the misconfiguration when only one variable is set, else nothing.
74
+ */
75
+ export function sandboxUsageFooter() {
76
+ try {
77
+ const target = sandboxTarget();
78
+ return target ? `\n ${describeSandboxTarget(target)}\n` : '';
79
+ }
80
+ catch (error) {
81
+ return `\n ${error instanceof Error ? error.message : String(error)}\n`;
82
+ }
83
+ }
62
84
  /** Read the current bearer. Never cached: Atlas rotates the file between requests. */
63
85
  export async function readSandboxToken(target) {
64
86
  let text;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequenceholdings/studio-cli",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
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,10 +42,10 @@
42
42
  "tsx": "^4.20.3",
43
43
  "zod": "^4.1.13",
44
44
  "yaml": "^2.8.4",
45
- "@sequenceholdings/lattice": "0.1.6",
46
- "@sequenceholdings/managed-functions": "0.4.3",
47
45
  "@sequenceholdings/agent-spec": "0.1.4",
48
46
  "@sequenceholdings/artifact-studio": "0.9.2",
47
+ "@sequenceholdings/lattice": "0.1.6",
48
+ "@sequenceholdings/managed-functions": "0.4.3",
49
49
  "@sequenceholdings/storage": "0.1.2"
50
50
  },
51
51
  "peerDependencies": {