@sequenceholdings/studio-cli 0.4.3 → 0.4.6

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 (45) hide show
  1. package/README.md +92 -19
  2. package/dist/app/agent-refs.d.ts +16 -0
  3. package/dist/app/agent-refs.js +18 -6
  4. package/dist/app/application-registration.d.ts +11 -3
  5. package/dist/app/application-registration.js +20 -6
  6. package/dist/app/application-suggestions.d.ts +58 -0
  7. package/dist/app/application-suggestions.js +164 -0
  8. package/dist/app/deploy.js +7 -4
  9. package/dist/app/env-bindings.js +2 -2
  10. package/dist/app/manifest-validation.d.ts +5 -0
  11. package/dist/app/manifest-validation.js +60 -22
  12. package/dist/app/manifest.d.ts +33 -0
  13. package/dist/app/manifest.js +16 -0
  14. package/dist/app/readme.d.ts +6 -3
  15. package/dist/app/readme.js +36 -6
  16. package/dist/app/scaffold.js +2 -1
  17. package/dist/artifact/delegate.js +6 -34
  18. package/dist/auth-cmds/commands.js +2 -2
  19. package/dist/auth.d.ts +0 -9
  20. package/dist/auth.js +2 -29
  21. package/dist/command-help.d.ts +2 -0
  22. package/dist/command-help.js +89 -0
  23. package/dist/config.d.ts +7 -20
  24. package/dist/config.js +22 -64
  25. package/dist/envs/commands.js +17 -67
  26. package/dist/functions/commands.d.ts +0 -1
  27. package/dist/functions/commands.js +3 -49
  28. package/dist/functions/deploy-preflight.d.ts +1 -1
  29. package/dist/functions/deploy-preflight.js +2 -1
  30. package/dist/functions/manifest.d.ts +3 -0
  31. package/dist/functions/manifest.js +27 -17
  32. package/dist/login.d.ts +0 -6
  33. package/dist/login.js +3 -34
  34. package/dist/main.js +2 -2
  35. package/dist/orm/delegate.js +2 -2
  36. package/dist/pipeline/discovery.js +2 -2
  37. package/dist/pipeline/lifecycle.js +2 -2
  38. package/dist/pipeline/repin-orm.js +3 -3
  39. package/dist/process/commands.js +4 -8
  40. package/dist/repos/commands.d.ts +0 -1
  41. package/dist/repos/commands.js +3 -40
  42. package/dist/storage/commands.js +2 -2
  43. package/package.json +9 -9
  44. package/dist/env-catalog.d.ts +0 -63
  45. package/dist/env-catalog.js +0 -121
package/dist/login.d.ts CHANGED
@@ -12,12 +12,6 @@ interface LoginOptions {
12
12
  }
13
13
  export declare function openSystemBrowser(authorizationUrl: string): Promise<void>;
14
14
  export declare function loginWithPkce({ fetchImpl, now, openBrowser, port, realm, timeoutMs, }: LoginOptions): Promise<string>;
15
- /**
16
- * Best-effort catalog refresh after a successful login. Drop the old cache
17
- * first so a prior identity's tier never lingers; discovery failures must not
18
- * fail login. Exported for unit tests.
19
- */
20
- export declare function refreshCatalogAfterLogin(): Promise<void>;
21
15
  export declare function login(envName?: string): Promise<void>;
22
16
  export declare function logout(envName?: string): Promise<void>;
23
17
  export {};
package/dist/login.js CHANGED
@@ -5,8 +5,7 @@ import { spawn } from 'node:child_process';
5
5
  import { homedir } from 'node:os';
6
6
  import { join } from 'node:path';
7
7
  import { deleteRealmTokens, realmForEnv, saveTokens, seqapiTokenPath, SEQUENCE_AUTH_REALM, SEQUENCE_REALM, verifyTokenMatchesRealm, } from './auth.js';
8
- import { localAuthRealmOptions, manualEnvConfigHint } from './config.js';
9
- import { bootstrapUrl, clearCatalog, fetchCatalog } from './env-catalog.js';
8
+ import { localAuthRealmOptions } from './config.js';
10
9
  const DEFAULT_REDIRECT_PORT = 5099;
11
10
  const DEFAULT_LOGIN_TIMEOUT_MS = 300_000;
12
11
  function base64Url(input) {
@@ -193,33 +192,11 @@ export async function loginWithPkce({ fetchImpl = fetch, now = Date.now, openBro
193
192
  }, realm.name);
194
193
  return tokens.accessToken;
195
194
  }
196
- /**
197
- * Best-effort catalog refresh after a successful login. Drop the old cache
198
- * first so a prior identity's tier never lingers; discovery failures must not
199
- * fail login. Exported for unit tests.
200
- */
201
- export async function refreshCatalogAfterLogin() {
202
- await clearCatalog();
203
- try {
204
- const catalog = await fetchCatalog();
205
- if (catalog) {
206
- console.log(`Environment catalog refreshed (tier: ${catalog.tier}, ` +
207
- `${catalog.environments.length} environment(s)).`);
208
- return;
209
- }
210
- }
211
- catch {
212
- // Network / non-auth discovery errors fall through to the same hint.
213
- }
214
- console.log(`Could not load the environment catalog from ${bootstrapUrl()} — ` +
215
- 'run: seq-studio envs refresh');
216
- console.log(manualEnvConfigHint());
217
- }
218
195
  export async function login(envName) {
219
196
  const realm = await realmForEnv(envName, await localAuthRealmOptions(envName));
220
197
  if (envName && realm.name === SEQUENCE_REALM && envName !== SEQUENCE_REALM) {
221
- // A name that only exists in the Sequence catalog (staging, banksouth…)
222
- // resolves to the Sequence realm — one login covers all of those. A typo'd
198
+ // A reserved Sequence name (staging, production…) resolves to the
199
+ // Sequence realm — one login covers all of those. A typo'd
223
200
  // OpCo name would silently do a Sequence login otherwise, so say which
224
201
  // realm we're using.
225
202
  console.error(`'${envName}' uses the shared Sequence login ` +
@@ -227,11 +204,6 @@ export async function login(envName) {
227
204
  }
228
205
  await loginWithPkce({ realm });
229
206
  console.log(`Authenticated [${realm.name}]. Short-lived access token saved to ${seqapiTokenPath()}.`);
230
- // The environment catalog is a Sequence-deployment surface; OpCo realm
231
- // logins target a single known deployment and have nothing to discover.
232
- if (realm.name === SEQUENCE_REALM) {
233
- await refreshCatalogAfterLogin();
234
- }
235
207
  }
236
208
  /**
237
209
  * Pre-unification artifact-studio token file. New builds never read it, but
@@ -245,9 +217,6 @@ export async function logout(envName) {
245
217
  await deleteRealmTokens(realm.name);
246
218
  if (realm.name === SEQUENCE_REALM) {
247
219
  await rm(legacyArtifactTokenPath(), { force: true });
248
- // The environment catalog belongs to the Sequence identity; tenant logout
249
- // must not discard a still-authenticated Sequence user's cached tier.
250
- await clearCatalog();
251
220
  }
252
221
  console.log(`Logged out [${realm.name}] from seq-studio and seqapi.`);
253
222
  }
package/dist/main.js CHANGED
@@ -52,8 +52,8 @@ const TOP_LEVEL_USAGE = `usage:
52
52
 
53
53
  Authenticate with: seq-studio login
54
54
  Where supported, --json writes structured stdout; check exit status and pagination.
55
- Built-in env: local. Authenticated identities discover more via
56
- \`seq-studio envs refresh\`; custom entries live in ~/.config/lattice/config.toml.
55
+ Built-in env: local. Add your organization's deployment with
56
+ \`seq-studio envs add <name> <url>\`; custom entries live in ~/.config/lattice/config.toml.
57
57
  `;
58
58
  const PROCESS_USAGE = `usage:
59
59
  seq-studio process init <dir>
@@ -8,7 +8,7 @@
8
8
  import { fileURLToPath } from 'node:url';
9
9
  import { parseSourceSpec, resolveArtifactSource, } from '@sequenceholdings/artifact-studio/source-resolver';
10
10
  import { getAccessToken, tryGetAccessTokenWithMode } from '../auth.js';
11
- import { resolveEnvWithDiscovery } from '../config.js';
11
+ import { resolveConfiguredEnv } from '../config.js';
12
12
  import { normalizeShortEnvFlag, readEnvFromArgv } from '../env-flags.js';
13
13
  import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
14
14
  import { resolveFunctionSourceDir } from '../functions/source-selection.js';
@@ -211,7 +211,7 @@ export async function runOrmCommand(sub, rest) {
211
211
  }
212
212
  let targetUrl;
213
213
  if (requested) {
214
- const resolved = await resolveEnvWithDiscovery({ requested });
214
+ const resolved = await resolveConfiguredEnv({ requested });
215
215
  targetUrl = resolved.url;
216
216
  process.env['SEQUENCE_ORM_BASE_URL'] = resolved.url;
217
217
  }
@@ -1,7 +1,7 @@
1
1
  import { getAccessToken } from '../auth.js';
2
2
  import { getJson, postJson } from '../atlas-client.js';
3
3
  import { printCliError } from '../cli-errors.js';
4
- import { resolveEnvWithDiscovery } from '../config.js';
4
+ import { resolveConfiguredEnv } from '../config.js';
5
5
  import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
6
6
  import { resolvePipelineTarget } from './lifecycle.js';
7
7
  export const PIPELINE_DISCOVERY_USAGE = ` seq-studio pipeline list -e <env> [--limit 1..200] [--offset N] [--json]
@@ -172,7 +172,7 @@ export async function runPipelineDiscoveryCommand({ sub, args }) {
172
172
  }
173
173
  try {
174
174
  const options = discoveryOptions({ sub, args });
175
- const env = await resolveEnvWithDiscovery({ requested: options.environment });
175
+ const env = await resolveConfiguredEnv({ requested: options.environment });
176
176
  const token = await getAccessToken({ env: env.name, targetUrl: env.url });
177
177
  const client = { baseUrl: env.url, token };
178
178
  if (sub === 'list') {
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { getAccessToken, NotLoggedInError } from '../auth.js';
6
6
  import { AtlasApiError, getJson, postJson } from '../atlas-client.js';
7
- import { resolveEnvWithDiscovery } from '../config.js';
7
+ import { resolveConfiguredEnv } from '../config.js';
8
8
  import { parseDurationMs } from '@sequenceholdings/lattice';
9
9
  import { assertCloneDeployAllowed, publishCloneForDeploy } from './clone-deploy.js';
10
10
  import { printReconcileResult, reconcileStageCredentials } from './stage-secrets.js';
@@ -56,7 +56,7 @@ export async function envAndToken(args) {
56
56
  if (!requested) {
57
57
  throw new Error('missing -e/--env <environment>');
58
58
  }
59
- const env = await resolveEnvWithDiscovery({ requested });
59
+ const env = await resolveConfiguredEnv({ requested });
60
60
  let token;
61
61
  try {
62
62
  token = await getAccessToken({ env: env.name, targetUrl: env.url });
@@ -2,7 +2,7 @@ import { readFile } from 'node:fs/promises';
2
2
  import { join, resolve } from 'node:path';
3
3
  import { z } from 'zod';
4
4
  import { getAccessToken } from '../auth.js';
5
- import { resolveEnvWithDiscovery } from '../config.js';
5
+ import { resolveConfiguredEnv } from '../config.js';
6
6
  import { loadActiveOrmContracts } from './active-orm-contracts.js';
7
7
  import { commitFileWrites } from './atomic-file-writes.js';
8
8
  import { resolvePipelineTarget } from './lifecycle.js';
@@ -63,7 +63,7 @@ async function assertSharedStageContractsAgree({ contracts, orm, stages, target,
63
63
  throw new Error(`cannot verify shared ORM pins for target '${otherTarget}'; ` +
64
64
  'split multi-target stages or use environment-specific pins');
65
65
  }
66
- const otherEnv = await resolveEnvWithDiscovery({ requested: environmentName });
66
+ const otherEnv = await resolveConfiguredEnv({ requested: environmentName });
67
67
  const otherToken = await getAccessToken({ env: otherEnv.name, targetUrl: otherEnv.url });
68
68
  const sharedStages = stages.filter((stage) => stage.environments.includes(otherTarget));
69
69
  const otherContracts = await loadActiveOrmContracts({
@@ -106,7 +106,7 @@ export async function pipelineRepinOrmCommand(args) {
106
106
  console.log(`${LOG} no ORM satisfies pins found in ${dirArg}`);
107
107
  return 0;
108
108
  }
109
- const env = await resolveEnvWithDiscovery({ requested });
109
+ const env = await resolveConfiguredEnv({ requested });
110
110
  const token = await getAccessToken({ env: env.name, targetUrl: env.url });
111
111
  const target = (await resolvePipelineTarget({ args, env, token })).id;
112
112
  const pinnedStages = allPinnedStages.filter((stage) => stage.environments.includes(target));
@@ -13,7 +13,7 @@ import { forEachSerializedNode, } from '@sequenceholdings/lattice/bundle';
13
13
  import { getJson, getJsonOr404, postJson, AtlasApiError } from '../atlas-client.js';
14
14
  import { generateProcessFiles } from './codegen.js';
15
15
  import { getAccessToken, getAccessTokenWithMode, inspectAuthPreflight, AuthTokenStoreError, NotLoggedInError, } from '../auth.js';
16
- import { readConfig, resolveEnv, resolveEnvWithDiscovery } from '../config.js';
16
+ import { readConfig, resolveEnv, resolveConfiguredEnv } from '../config.js';
17
17
  import { writeScaffoldGuidance } from '../scaffold-guidance.js';
18
18
  import { finalizeCompiledBundle, summarizeBundle } from './build.js';
19
19
  import { buildResolveProcessPinFromEnv } from './resolve-process-pin.js';
@@ -29,7 +29,7 @@ import { compileProcessSourceIsolated, simulateProcessIsolated, } from './compil
29
29
  export { parseArgs } from '../argv.js';
30
30
  async function getEnvAndToken(args) {
31
31
  const requested = typeof args.flags.env === 'string' ? args.flags.env : undefined;
32
- const env = await resolveEnvWithDiscovery({ requested });
32
+ const env = await resolveConfiguredEnv({ requested });
33
33
  let token;
34
34
  try {
35
35
  token = await getAccessToken({ env: env.name, targetUrl: env.url });
@@ -44,7 +44,7 @@ async function getEnvAndToken(args) {
44
44
  }
45
45
  async function getEnvAndAuth(args) {
46
46
  const requested = typeof args.flags.env === 'string' ? args.flags.env : undefined;
47
- const env = await resolveEnvWithDiscovery({ requested });
47
+ const env = await resolveConfiguredEnv({ requested });
48
48
  const auth = await getAccessTokenWithMode({ env: env.name, targetUrl: env.url });
49
49
  return { authMode: auth.authMode, env, token: auth.token };
50
50
  }
@@ -961,10 +961,6 @@ export async function doctorCommand(args) {
961
961
  }
962
962
  else {
963
963
  lines.push(`config: ok — default_env=${config.defaultEnv}, envs=${Object.keys(config.envs).join(',')}`);
964
- lines.push(`tier: ${config.tier}` +
965
- (config.tier === 'anonymous'
966
- ? ' — no environment catalog cached; run `seq-studio envs refresh` to discover more environments'
967
- : ''));
968
964
  }
969
965
  const requested = typeof args.flags.env === 'string' ? args.flags.env : undefined;
970
966
  let env = null;
@@ -972,7 +968,7 @@ export async function doctorCommand(args) {
972
968
  try {
973
969
  env = offline
974
970
  ? resolveEnv({ config, requested })
975
- : await resolveEnvWithDiscovery({ requested });
971
+ : await resolveConfiguredEnv({ requested });
976
972
  lines.push(`env: ok — ${env.name} (${env.url})`);
977
973
  }
978
974
  catch (err) {
@@ -115,6 +115,5 @@ export declare function reposCiRequireCommand(args: ParsedArgs): Promise<number>
115
115
  export declare function reposCiImportCommand(args: ParsedArgs): Promise<number>;
116
116
  export declare function reposCiCommand(args: ParsedArgs): Promise<number>;
117
117
  export declare function reposDeleteCommand(args: ParsedArgs): Promise<number>;
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] [--transport auto|git|json]\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). --transport auto (default) uses Git when ATLAS_GIT_PAT is set and JSON\n materialization otherwise; --transport git requires a repo:read PAT; --transport\n json ignores ATLAS_GIT_PAT and uses the signed-in Atlas identity (<ns>/<name>\n only; no .git directory). Authentication failures explain this retry path.\n JSON materialization requires repo read access and prints how to create a PAT.\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";
119
118
  export declare function runReposCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;
120
119
  export {};
@@ -1,3 +1,4 @@
1
+ import { REPOS_USAGE } from '../command-help.js';
1
2
  /**
2
3
  * `seq-studio repos <sub>` — basic management of platform git-service repos
3
4
  * over the JSON API.
@@ -25,7 +26,7 @@ import { buildContext, clientOptions, flagBool, LOG, } from '../functions/comman
25
26
  import { looksLikeCommitSha, resolveGitPatFromEnv, runGitClone, } from './git-clone.js';
26
27
  import { formatPatSetupHint } from '../pat-hints.js';
27
28
  import { tryGetAccessToken } from '../auth.js';
28
- import { resolveEnvWithDiscovery } from '../config.js';
29
+ import { resolveConfiguredEnv } from '../config.js';
29
30
  import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
30
31
  const PAGE_SIZE = 200;
31
32
  // ---------------------------------------------------------------------------
@@ -499,7 +500,7 @@ async function resolveEnvOnly(args) {
499
500
  if (!requested) {
500
501
  throw new Error(REQUIRE_EXPLICIT_ENV_MESSAGE);
501
502
  }
502
- return resolveEnvWithDiscovery({ requested });
503
+ return resolveConfiguredEnv({ requested });
503
504
  }
504
505
  /**
505
506
  * Validate clone URL shape and that the origin matches the resolved Atlas env
@@ -819,44 +820,6 @@ export async function reposDeleteCommand(args) {
819
820
  // ---------------------------------------------------------------------------
820
821
  // Router
821
822
  // ---------------------------------------------------------------------------
822
- export const REPOS_USAGE = `usage:
823
- seq-studio repos list -e <env> [--namespace <slug>] [--mine] repos visible on the environment
824
- seq-studio repos namespaces [create <slug>] -e <env> list or create namespaces
825
- seq-studio repos show <ns>/<name> -e <env> repo detail (branches, clone URL)
826
- seq-studio repos create <ns>/<name> -e <env> [--default-branch b] [--git-backend walgit]
827
- create a repo seeded with a README; --git-backend
828
- walgit creates it empty (for pushing existing
829
- history); needs namespace write
830
- seq-studio repos clone <ns>/<name> -e <env> [--ref r] [--output dir] [--force] [--full] [--transport auto|git|json]
831
- seq-studio repos clone --url <https://…/repos/<id>/git> -e <env> [--ref r] [--output dir] [--full]
832
- seq-studio repos clone --id <uuid> -e <env> [--ref r] [--output dir] [--full]
833
- smart-HTTP when ATLAS_GIT_PAT is set;
834
- otherwise JSON materialize (<ns>/<name>)
835
- seq-studio repos pull <ns>/<name> -e <env> [--ref r] [--out dir] [--force]
836
- materialize the tree at a ref (JSON API)
837
- seq-studio repos pulls <list|show|create|diff|merge> [args] review requests (see pulls --help)
838
- seq-studio repos delete <ns>/<name> -e <env> [--yes] delete a repo (confirm prompt)
839
- seq-studio repos ci show <ns>/<name> -e <env> [--ref r] preview discovered CI checks
840
- seq-studio repos ci require <ns>/<name> --check <name> -e <env> reserved (refuses write until sandboxed runner)
841
- seq-studio repos ci import <ns>/<name> -e <env> [--ref r] reserved (refuses write until sandboxed runner)
842
-
843
- Flags: -e/--env <env> (required; see: seq-studio envs list)
844
-
845
- clone prefers real git clone (PAT via askpass — never written into the remote
846
- URL). --transport auto (default) uses Git when ATLAS_GIT_PAT is set and JSON
847
- materialization otherwise; --transport git requires a repo:read PAT; --transport
848
- json ignores ATLAS_GIT_PAT and uses the signed-in Atlas identity (<ns>/<name>
849
- only; no .git directory). Authentication failures explain this retry path.
850
- JSON materialization requires repo read access and prints how to create a PAT.
851
- PAT without Auth0 login: use --id from Repositories → Clone
852
- (or --url with the environment's canonical HTTPS origin).
853
- --ref accepts a branch, tag, or commit SHA (SHA → full clone, then checkout).
854
- Branch and tag clones are shallow (--depth 1). Pass --full for history.
855
- --output selects the clone directory (--out remains an alias).
856
-
857
- Authenticate JSON API calls with: seq-studio login
858
- Authenticate git clone/push with: ATLAS_GIT_PAT (from Atlas Settings → Tokens)
859
- `;
860
823
  export async function runReposCommand(sub, args) {
861
824
  try {
862
825
  switch (sub) {
@@ -7,7 +7,7 @@ import { randomUUID } from 'node:crypto';
7
7
  import { load as yaml } from 'js-yaml';
8
8
  import { storageClient, workspaceManifestSchema, startUploadSchema, updateStorageAccessSchema, } from '@sequenceholdings/storage';
9
9
  import { getAccessTokenWithMode } from '../auth.js';
10
- import { resolveEnvWithDiscovery } from '../config.js';
10
+ 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';
@@ -66,7 +66,7 @@ export async function runStorageCommand(sub, args) {
66
66
  }
67
67
  if (!flag('env'))
68
68
  throw new Error(REQUIRE_EXPLICIT_ENV_MESSAGE);
69
- const env = await resolveEnvWithDiscovery({ requested: flag('env') });
69
+ const env = await resolveConfiguredEnv({ requested: flag('env') });
70
70
  const { token } = await getAccessTokenWithMode({
71
71
  env: env.name,
72
72
  targetUrl: env.url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequenceholdings/studio-cli",
3
- "version": "0.4.3",
3
+ "version": "0.4.6",
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": {
@@ -41,15 +41,15 @@
41
41
  "smol-toml": "^1.9.0",
42
42
  "tsx": "^4.20.3",
43
43
  "zod": "^4.1.13",
44
- "@sequenceholdings/artifact-studio": "0.6.4",
45
- "@sequenceholdings/agent-spec": "0.1.3",
46
44
  "@sequenceholdings/lattice": "0.1.5",
47
- "@sequenceholdings/managed-functions": "0.3.2",
48
- "@sequenceholdings/storage": "0.1.0"
45
+ "@sequenceholdings/artifact-studio": "0.6.6",
46
+ "@sequenceholdings/agent-spec": "0.1.3",
47
+ "@sequenceholdings/storage": "0.1.1",
48
+ "@sequenceholdings/managed-functions": "0.3.5"
49
49
  },
50
50
  "peerDependencies": {
51
- "@sequenceholdings/orm": "2.4.0",
52
- "@sequenceholdings/pipeline-spec": "0.2.2"
51
+ "@sequenceholdings/orm": "2.5.0",
52
+ "@sequenceholdings/pipeline-spec": "0.2.3"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "@sequenceholdings/orm": {
@@ -64,8 +64,8 @@
64
64
  "@types/node": "^22.0.0",
65
65
  "typescript": "^5.6.0",
66
66
  "vitest": "^4.1.11",
67
- "@sequenceholdings/orm": "2.4.0",
68
- "@sequenceholdings/pipeline-spec": "0.2.2"
67
+ "@sequenceholdings/orm": "2.5.0",
68
+ "@sequenceholdings/pipeline-spec": "0.2.3"
69
69
  },
70
70
  "engines": {
71
71
  "node": ">=20"
@@ -1,63 +0,0 @@
1
- /**
2
- * Tiered environment discovery.
3
- *
4
- * The published package ships with only the `local` environment baked in.
5
- * Every other deployment URL is *discovered* from the authenticated
6
- * `GET /api/platform/environments` endpoint and cached on disk:
7
- *
8
- * - `anonymous` — no usable token (or the endpoint rejected it):
9
- * `local` only, no catalog cached.
10
- * - `sequence` — Sequence staff / trusted M2M: full catalog
11
- * (local, staging, production, banksouth) + preview targeting.
12
- * - `partner` — any other authenticated identity: local + their
13
- * deployment(s).
14
- *
15
- * This is a visibility/UX layer, not access control — every deployment
16
- * still enforces Auth0 + FGA per request. A user who knows a URL can
17
- * always add it to config.toml; the server rejecting their token is the
18
- * real gate.
19
- *
20
- * One bootstrap hostname is baked into the package for the discovery
21
- * call itself. All deployments share the same Auth0 audience, so any
22
- * identity's token validates there; the endpoint 401s anonymously.
23
- */
24
- export type EnvTier = 'anonymous' | 'sequence' | 'partner';
25
- export interface CatalogEnvironment {
26
- name: string;
27
- url: string;
28
- }
29
- export interface EnvCatalog {
30
- tier: Exclude<EnvTier, 'anonymous'>;
31
- environments: CatalogEnvironment[];
32
- /** Unix ms timestamp of the successful fetch. */
33
- fetchedAt: number;
34
- /**
35
- * Auth0 `sub` of the identity that fetched this catalog. Reads ignore the
36
- * cache when the current identity differs (logout, seqapi re-login as
37
- * someone else), so one user's tier never carries over to another.
38
- */
39
- subject: string;
40
- }
41
- /** The host the discovery call goes to. Override for tests / self-hosting. */
42
- export declare function bootstrapUrl(): string;
43
- export declare function catalogPath(): string;
44
- /**
45
- * Read the cached catalog from disk. Returns null when missing, malformed,
46
- * or fetched by a *different* identity than the one the CLI would
47
- * authenticate as right now — callers treat all of those as tier
48
- * `anonymous`. The subject check means a logout (token file removed) or a
49
- * re-login as someone else invalidates the cache immediately, without
50
- * waiting for the next discovery call.
51
- */
52
- export declare function readCachedCatalog(): Promise<EnvCatalog | null>;
53
- export declare function clearCatalog(): Promise<void>;
54
- /**
55
- * Fetch the environment catalog from the discovery endpoint and cache it.
56
- *
57
- * Returns the fresh catalog, or null when the caller is effectively
58
- * anonymous: no token available, or the endpoint rejected the token
59
- * (401/403 — the stale cache is cleared so visibility downgrades too).
60
- * Network/server errors leave any existing cache in place and rethrow so
61
- * callers can distinguish "offline" from "not authorized".
62
- */
63
- export declare function fetchCatalog(): Promise<EnvCatalog | null>;
@@ -1,121 +0,0 @@
1
- import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
2
- import { existsSync } from 'node:fs';
3
- import { homedir } from 'node:os';
4
- import { dirname, join } from 'node:path';
5
- import { authenticatedRequestUrl } from '@sequenceholdings/artifact-studio/deployment-validation';
6
- import { currentIdentitySubject, decodeJwtSub, tryGetAccessToken } from './auth.js';
7
- const DEFAULT_BOOTSTRAP_URL = 'https://atlas.seqholdings.com';
8
- /** The host the discovery call goes to. Override for tests / self-hosting. */
9
- export function bootstrapUrl() {
10
- return (process.env['SEQ_STUDIO_DISCOVERY_URL']?.trim().replace(/\/+$/, '') ||
11
- DEFAULT_BOOTSTRAP_URL);
12
- }
13
- export function catalogPath() {
14
- return join(homedir(), '.config', 'lattice', 'environments.json');
15
- }
16
- function isValidCatalog(value) {
17
- if (typeof value !== 'object' || value === null)
18
- return false;
19
- const candidate = value;
20
- return ((candidate.tier === 'sequence' || candidate.tier === 'partner') &&
21
- Array.isArray(candidate.environments) &&
22
- candidate.environments.every((env) => typeof env === 'object' &&
23
- env !== null &&
24
- typeof env.name === 'string' &&
25
- typeof env.url === 'string') &&
26
- typeof candidate.fetchedAt === 'number' &&
27
- typeof candidate.subject === 'string' &&
28
- candidate.subject.length > 0);
29
- }
30
- /**
31
- * Read the cached catalog from disk. Returns null when missing, malformed,
32
- * or fetched by a *different* identity than the one the CLI would
33
- * authenticate as right now — callers treat all of those as tier
34
- * `anonymous`. The subject check means a logout (token file removed) or a
35
- * re-login as someone else invalidates the cache immediately, without
36
- * waiting for the next discovery call.
37
- */
38
- export async function readCachedCatalog() {
39
- const path = catalogPath();
40
- if (!existsSync(path))
41
- return null;
42
- let catalog;
43
- try {
44
- const parsed = JSON.parse(await readFile(path, 'utf8'));
45
- catalog = isValidCatalog(parsed) ? parsed : null;
46
- }
47
- catch {
48
- return null;
49
- }
50
- if (!catalog)
51
- return null;
52
- const subject = await currentIdentitySubject();
53
- if (subject === null || subject !== catalog.subject)
54
- return null;
55
- return catalog;
56
- }
57
- async function saveCatalog(catalog) {
58
- const path = catalogPath();
59
- await mkdir(dirname(path), { recursive: true });
60
- await writeFile(path, JSON.stringify(catalog, null, 2) + '\n', {
61
- encoding: 'utf8',
62
- mode: 0o600,
63
- });
64
- }
65
- export async function clearCatalog() {
66
- await rm(catalogPath(), { force: true });
67
- }
68
- /**
69
- * Fetch the environment catalog from the discovery endpoint and cache it.
70
- *
71
- * Returns the fresh catalog, or null when the caller is effectively
72
- * anonymous: no token available, or the endpoint rejected the token
73
- * (401/403 — the stale cache is cleared so visibility downgrades too).
74
- * Network/server errors leave any existing cache in place and rethrow so
75
- * callers can distinguish "offline" from "not authorized".
76
- */
77
- export async function fetchCatalog() {
78
- const targetUrl = bootstrapUrl();
79
- const requestUrl = authenticatedRequestUrl({
80
- baseUrl: targetUrl,
81
- path: '/api/platform/environments',
82
- });
83
- // Fail closed when an M2M secret is configured but minting fails, so
84
- // headless callers (CI) see the real Auth0 error instead of a silent
85
- // downgrade to the anonymous tier.
86
- const token = await tryGetAccessToken({
87
- failClosedForM2m: true,
88
- targetUrl,
89
- });
90
- if (!token) {
91
- await clearCatalog();
92
- return null;
93
- }
94
- const response = await fetch(requestUrl, {
95
- headers: { Authorization: `Bearer ${token}` },
96
- redirect: 'manual',
97
- });
98
- if (response.status === 401 || response.status === 403) {
99
- await clearCatalog();
100
- return null;
101
- }
102
- if (!response.ok) {
103
- throw new Error(`Environment discovery failed (${response.status}) against ${targetUrl}.`);
104
- }
105
- const body = (await response.json());
106
- if ((body.tier !== 'sequence' && body.tier !== 'partner') ||
107
- !Array.isArray(body.environments)) {
108
- throw new Error('Environment discovery returned an unexpected response shape.');
109
- }
110
- const catalog = {
111
- tier: body.tier,
112
- environments: body.environments,
113
- fetchedAt: Date.now(),
114
- // Bind the cache to the identity that fetched it. `unknown` never
115
- // matches a real subject, so an undecodable token yields a catalog
116
- // that works for this invocation but is not trusted from disk later.
117
- subject: decodeJwtSub(token) ?? 'unknown',
118
- };
119
- await saveCatalog(catalog);
120
- return catalog;
121
- }