@sequenceholdings/studio-cli 0.3.0 → 0.4.1

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 (110) hide show
  1. package/README.md +465 -28
  2. package/dist/agents/commands.d.ts +1 -1
  3. package/dist/agents/commands.js +5 -0
  4. package/dist/agents/scaffold.js +5 -7
  5. package/dist/agents/voice-authoring.d.ts +5 -0
  6. package/dist/agents/voice-authoring.js +75 -0
  7. package/dist/agents/voice-publication.d.ts +5 -0
  8. package/dist/agents/voice-publication.js +63 -0
  9. package/dist/agents/voice-shared.d.ts +20 -0
  10. package/dist/agents/voice-shared.js +112 -0
  11. package/dist/agents/voice.d.ts +3 -0
  12. package/dist/agents/voice.js +57 -0
  13. package/dist/app/adapters.d.ts +6 -0
  14. package/dist/app/adapters.js +17 -2
  15. package/dist/app/agent-refs.d.ts +16 -0
  16. package/dist/app/agent-refs.js +36 -0
  17. package/dist/app/application-registration.d.ts +31 -5
  18. package/dist/app/application-registration.js +58 -14
  19. package/dist/app/commands.js +19 -2
  20. package/dist/app/deploy.d.ts +3 -0
  21. package/dist/app/deploy.js +18 -4
  22. package/dist/app/env-bindings.d.ts +21 -0
  23. package/dist/app/env-bindings.js +184 -0
  24. package/dist/app/manifest-validation.js +8 -0
  25. package/dist/app/manifest.d.ts +13 -9
  26. package/dist/app/manifest.js +1 -1
  27. package/dist/app/primitive-scaffold.d.ts +4 -1
  28. package/dist/app/primitive-scaffold.js +4 -4
  29. package/dist/app/readme.js +1 -0
  30. package/dist/app/scaffold-files.js +1 -1
  31. package/dist/app/scaffold.d.ts +6 -4
  32. package/dist/app/scaffold.js +7 -4
  33. package/dist/app/workspace-scaffold.js +12 -7
  34. package/dist/argv.d.ts +7 -0
  35. package/dist/argv.js +56 -0
  36. package/dist/artifact/delegate.js +8 -4
  37. package/dist/atlas-client.d.ts +6 -0
  38. package/dist/atlas-client.js +39 -2
  39. package/dist/auth.d.ts +32 -0
  40. package/dist/auth.js +170 -33
  41. package/dist/bin.js +23 -4
  42. package/dist/command-contract.d.ts +137 -0
  43. package/dist/command-contract.js +43 -0
  44. package/dist/command-help.d.ts +8 -0
  45. package/dist/command-help.js +71 -0
  46. package/dist/functions/commands.d.ts +1 -1
  47. package/dist/functions/commands.js +19 -3
  48. package/dist/functions/deploy-preflight.d.ts +21 -0
  49. package/dist/functions/deploy-preflight.js +58 -0
  50. package/dist/functions/egress-postgres.d.ts +7 -0
  51. package/dist/functions/egress-postgres.js +36 -0
  52. package/dist/functions/manifest.d.ts +8 -0
  53. package/dist/functions/manifest.js +9 -0
  54. package/dist/functions/source-selection.js +4 -1
  55. package/dist/main.js +58 -20
  56. package/dist/orm/delegate.d.ts +16 -0
  57. package/dist/orm/delegate.js +140 -7
  58. package/dist/pipeline/clone-deploy.d.ts +37 -0
  59. package/dist/pipeline/clone-deploy.js +125 -0
  60. package/dist/pipeline/codegen.js +6 -2
  61. package/dist/pipeline/commands.js +21 -5
  62. package/dist/pipeline/lifecycle.d.ts +1 -0
  63. package/dist/pipeline/lifecycle.js +95 -44
  64. package/dist/pipeline/repin-orm.js +6 -2
  65. package/dist/pipeline/stage-secrets.js +1 -1
  66. package/dist/process/build.js +17 -0
  67. package/dist/process/codegen.js +16 -0
  68. package/dist/process/commands.d.ts +15 -7
  69. package/dist/process/commands.js +291 -99
  70. package/dist/process/lint.js +35 -0
  71. package/dist/process/plan-diff.js +9 -0
  72. package/dist/process/simulate.js +8 -0
  73. package/dist/release-age.d.ts +12 -0
  74. package/dist/release-age.js +24 -0
  75. package/dist/repos/commands.d.ts +1 -1
  76. package/dist/repos/commands.js +36 -7
  77. package/dist/scaffold-guidance.d.ts +4 -0
  78. package/dist/scaffold-guidance.js +15 -0
  79. package/dist/storage/commands.js +23 -1
  80. package/dist/storage/gcs-download.d.ts +13 -0
  81. package/dist/storage/gcs-download.js +41 -0
  82. package/dist/storage/import-cycle.d.ts +41 -0
  83. package/dist/storage/import-cycle.js +123 -0
  84. package/dist/storage/import-files.d.ts +30 -0
  85. package/dist/storage/import-files.js +133 -0
  86. package/dist/storage/import-gcloud.d.ts +12 -0
  87. package/dist/storage/import-gcloud.js +54 -0
  88. package/dist/storage/import-identity.d.ts +12 -0
  89. package/dist/storage/import-identity.js +15 -0
  90. package/dist/storage/import-plan.d.ts +120 -0
  91. package/dist/storage/import-plan.js +189 -0
  92. package/dist/storage/import-preflight.d.ts +36 -0
  93. package/dist/storage/import-preflight.js +62 -0
  94. package/dist/storage/import-progress-map.d.ts +5 -0
  95. package/dist/storage/import-progress-map.js +22 -0
  96. package/dist/storage/import-recover.d.ts +97 -0
  97. package/dist/storage/import-recover.js +186 -0
  98. package/dist/storage/import-run.d.ts +14 -0
  99. package/dist/storage/import-run.js +140 -0
  100. package/dist/templates/guidance/AGENTS.md +10 -0
  101. package/dist/templates/guidance/CLAUDE.md +1 -0
  102. package/dist/templates/process/package.json +2 -2
  103. package/dist/templates/process/pnpm-workspace.yaml +7 -4
  104. package/dist/validation-detail.d.ts +2 -0
  105. package/dist/validation-detail.js +20 -0
  106. package/package.json +9 -9
  107. package/templates/guidance/AGENTS.md +10 -0
  108. package/templates/guidance/CLAUDE.md +1 -0
  109. package/templates/process/package.json +2 -2
  110. package/templates/process/pnpm-workspace.yaml +7 -4
@@ -91,9 +91,9 @@ async function scaffoldOrm({ absPath }) {
91
91
  '(workspace / internal installs today; not yet available via public npm).');
92
92
  }
93
93
  }
94
- async function scaffoldArtifact({ absPath, appId, }) {
94
+ async function scaffoldArtifact({ absPath, appId, template, }) {
95
95
  const { runCli } = await import('@sequenceholdings/artifact-studio/cli');
96
- const code = await runCli(['init', absPath]);
96
+ const code = await runCli(['init', absPath, '--template', template]);
97
97
  if (code !== 0) {
98
98
  throw new Error(`artifact init failed for ${absPath} (exit ${code})`);
99
99
  }
@@ -105,7 +105,7 @@ async function scaffoldFunction({ absPath }) {
105
105
  throw new Error(`functions init failed for ${absPath} (exit ${code})`);
106
106
  }
107
107
  }
108
- export async function scaffoldKind({ kind, appRoot, appId, name, pipelineType = 'transformation', }) {
108
+ export async function scaffoldKind({ kind, appRoot, appId, name, pipelineType = 'transformation', artifactTemplate = 'react-vite', }) {
109
109
  const relPath = relativePathFor({ kind, appId, name }).replace(/\\/g, '/');
110
110
  const absPath = join(appRoot, relPath);
111
111
  const entry = buildPrimitiveEntry({ kind, appId, name, dependsOn: [] });
@@ -119,7 +119,7 @@ export async function scaffoldKind({ kind, appRoot, appId, name, pipelineType =
119
119
  break;
120
120
  case 'artifact':
121
121
  await mkdir(absPath, { recursive: true });
122
- await scaffoldArtifact({ absPath, appId: name });
122
+ await scaffoldArtifact({ absPath, appId: name, template: artifactTemplate });
123
123
  break;
124
124
  case 'agent':
125
125
  if (await agentsInitCommand(parseArgs([absPath])) !== 0) {
@@ -132,6 +132,7 @@ seq-studio deploy -e <environment-name> --yes
132
132
  - **ORM** policies enforce caller access. Change TypeScript schema and operations, then generate migrations; do not edit generated migrations by hand.
133
133
  - **Agent and process identities** are durable. Keep the generated identities stable when changing implementation; generate new identities when copying a resource.
134
134
  - **Official artifact deployments** require the full app checkout to be clean on \`main\`, including shared packages and the root manifest. Use \`seq-studio artifact dev artifact -e <environment-name>\` to preview uncommitted UI.
135
+ - **Environment bindings** are resolved at deploy time. \`-e\` selects the environment. Source may not hardcode another environment's API origin or workspace UUID. Declare API origins in \`artifact.bundle.yml\` \`targets\`, and workspace use with \`uses\` on the workspace primitive.
135
136
 
136
137
  The per-primitive commands remain available for validation and operation; \`seq-studio deploy\` is the app-level deployment entry point. See \`seq-studio deploy --help\` and the [CLI command reference](${SEQUENCE_DOCS_URL}seq-studio/commands).
137
138
  `;
@@ -49,7 +49,7 @@ export async function rollbackAppScaffold({ appRoot, snapshot, paths }) {
49
49
  return;
50
50
  }
51
51
  const generated = new Set([
52
- 'sequence.app.yml', ...WORKSPACE_ROOT_FILES,
52
+ 'sequence.app.yml', 'AGENTS.md', 'CLAUDE.md', ...WORKSPACE_ROOT_FILES,
53
53
  ...paths.map((path) => path.split('/')[0]).filter((name) => Boolean(name)),
54
54
  ]);
55
55
  for (const name of generated) {
@@ -3,25 +3,27 @@
3
3
  * sequence.app.yml in sync. Delegates to each primitive's real `init`.
4
4
  */
5
5
  import { type AppManifest, type PrimitiveEntry, type PrimitiveKind } from './manifest.js';
6
- import { type AppPipelineType } from './primitive-scaffold.js';
7
- export type { AppPipelineType } from './primitive-scaffold.js';
6
+ import { type AppArtifactTemplate, type AppPipelineType } from './primitive-scaffold.js';
7
+ export type { AppArtifactTemplate, AppPipelineType } from './primitive-scaffold.js';
8
8
  export interface ScaffoldNames {
9
9
  functionName: string;
10
10
  }
11
11
  export declare function defaultScaffoldNames(_appId: string): ScaffoldNames;
12
- export declare function initAppMonorepo({ rootDir, appId, kinds, names, description, pipelineType, }: {
12
+ export declare function initAppMonorepo({ rootDir, appId, kinds, names, description, pipelineType, artifactTemplate, }: {
13
13
  rootDir: string;
14
14
  appId: string;
15
15
  kinds: readonly PrimitiveKind[];
16
16
  names?: ScaffoldNames;
17
17
  description?: string;
18
18
  pipelineType?: AppPipelineType;
19
+ artifactTemplate?: AppArtifactTemplate;
19
20
  }): Promise<AppManifest>;
20
- export declare function addPrimitiveToApp({ rootDir, kind, name, pipelineType, dependsOn, }: {
21
+ export declare function addPrimitiveToApp({ rootDir, kind, name, pipelineType, artifactTemplate, dependsOn, }: {
21
22
  rootDir: string;
22
23
  kind: PrimitiveKind;
23
24
  name: string;
24
25
  pipelineType?: AppPipelineType;
26
+ artifactTemplate?: AppArtifactTemplate;
25
27
  dependsOn?: string[];
26
28
  }): Promise<{
27
29
  manifest: AppManifest;
@@ -9,6 +9,7 @@ import { currentVersion, isNewerVersion } from '../update-check.js';
9
9
  import { extendDeployOrder, loadAppManifest, titleizeSlug, writeAppManifest, } from './manifest.js';
10
10
  import { inspectScaffoldTarget, mergeGitignore, rollbackAppScaffold } from './scaffold-files.js';
11
11
  import { renderAppReadme } from './readme.js';
12
+ import { writeScaffoldGuidance } from '../scaffold-guidance.js';
12
13
  import { primitiveIdFor, relativePathFor, scaffoldKind } from './primitive-scaffold.js';
13
14
  import { joinAppWorkspace, scaffoldAppWorkspace, scaffoldSharedPackage } from './workspace-scaffold.js';
14
15
  const LOG = '[seq-studio]';
@@ -31,7 +32,7 @@ function applyDefaultDependsOn(primitives) {
31
32
  return { ...entry, depends_on: [orm.id] };
32
33
  });
33
34
  }
34
- export async function initAppMonorepo({ rootDir, appId, kinds, names = defaultScaffoldNames(appId), description, pipelineType, }) {
35
+ export async function initAppMonorepo({ rootDir, appId, kinds, names = defaultScaffoldNames(appId), description, pipelineType, artifactTemplate, }) {
35
36
  if (kinds.length === 0) {
36
37
  throw new Error('select at least one primitive via --with orm,workspace,function,agent,process,pipeline,artifact (or --orm --function …)');
37
38
  }
@@ -41,11 +42,12 @@ export async function initAppMonorepo({ rootDir, appId, kinds, names = defaultSc
41
42
  const snapshot = await inspectScaffoldTarget(appRoot);
42
43
  await mkdir(appRoot, { recursive: true });
43
44
  try {
45
+ await writeScaffoldGuidance({ directory: appRoot });
44
46
  const version = currentVersion();
45
47
  const primitives = [];
46
48
  for (const kind of kinds) {
47
49
  const name = kind === 'function' ? names.functionName : appId;
48
- primitives.push(await scaffoldKind({ kind, appRoot, appId, name, pipelineType }));
50
+ primitives.push(await scaffoldKind({ kind, appRoot, appId, name, pipelineType, artifactTemplate }));
49
51
  }
50
52
  const withDeps = applyDefaultDependsOn(primitives);
51
53
  const shared = await scaffoldSharedPackage({ rootDir: appRoot, appId, name: 'shared' });
@@ -89,7 +91,7 @@ export async function initAppMonorepo({ rootDir, appId, kinds, names = defaultSc
89
91
  throw error;
90
92
  }
91
93
  }
92
- export async function addPrimitiveToApp({ rootDir, kind, name, pipelineType, dependsOn, }) {
94
+ export async function addPrimitiveToApp({ rootDir, kind, name, pipelineType, artifactTemplate, dependsOn, }) {
93
95
  const appRoot = resolve(rootDir);
94
96
  const manifest = await loadAppManifest(appRoot);
95
97
  const appId = manifest.app.id;
@@ -115,7 +117,7 @@ export async function addPrimitiveToApp({ rootDir, kind, name, pipelineType, dep
115
117
  const workspacePath = join(appRoot, 'pnpm-workspace.yaml');
116
118
  const previousWorkspace = existsSync(workspacePath) ? await readFile(workspacePath, 'utf8') : null;
117
119
  try {
118
- let entry = await scaffoldKind({ kind, appRoot, appId, name, pipelineType });
120
+ let entry = await scaffoldKind({ kind, appRoot, appId, name, pipelineType, artifactTemplate });
119
121
  const orm = manifest.primitives.find((item) => item.kind === 'orm');
120
122
  if (dependsOn !== undefined) {
121
123
  entry = { ...entry, depends_on: dependsOn };
@@ -173,6 +175,7 @@ export function printInitNextSteps({ appRoot, manifest, }) {
173
175
  const rel = relative(process.cwd(), appRoot);
174
176
  const display = !rel || rel.startsWith('..') ? appRoot : rel;
175
177
  console.log(`${LOG} scaffolded app "${manifest.app.id}" in ${display}`);
178
+ console.log(`${LOG} AGENTS.md points to your environment's live docs; CLAUDE.md imports it`);
176
179
  console.log(`${LOG} wrote README.md (Sequence app docs) and ${APP_MANIFEST_LABEL} with ${manifest.primitives.length} primitive(s):`);
177
180
  for (const entry of manifest.primitives) {
178
181
  console.log(`${LOG} - ${entry.kind.padEnd(9)} ${entry.id} (${entry.path})`);
@@ -5,10 +5,20 @@ import { dump as yamlDump, load as yamlLoad } from 'js-yaml';
5
5
  import { z } from 'zod';
6
6
  import { loadAppManifest, usesAppGraph, writeAppManifest } from './manifest.js';
7
7
  import { currentVersion } from '../update-check.js';
8
+ import { FIRST_PARTY_RELEASE_AGE_EXCLUDE } from '../release-age.js';
8
9
  const packageSchema = z.looseObject({
9
10
  dependencies: z.record(z.string(), z.string()).optional(),
10
11
  pnpm: z.strictObject({ overrides: z.record(z.string(), z.string()).optional() }).optional(),
11
12
  });
13
+ const artifactTypeSchema = z.looseObject({ artifact: z.looseObject({ type: z.string().optional() }) });
14
+ /** Hosted Next.js builds need a standalone lockfile with one root importer and no workspace: links. */
15
+ async function isStandaloneNextArtifact({ entry, directory }) {
16
+ const manifestPath = join(directory, 'artifact.bundle.yml');
17
+ if (entry.kind !== 'artifact' || !existsSync(manifestPath))
18
+ return false;
19
+ const parsed = artifactTypeSchema.safeParse(yamlLoad(await readFile(manifestPath, 'utf8')));
20
+ return parsed.success && parsed.data.artifact.type === 'nextjs';
21
+ }
12
22
  const workspaceSchema = z.looseObject({
13
23
  packages: z.array(z.string()).optional(),
14
24
  overrides: z.record(z.string(), z.string()).optional(),
@@ -51,7 +61,7 @@ export async function joinAppWorkspace({ rootDir, manifest, entries, }) {
51
61
  for (const entry of entries) {
52
62
  const directory = join(rootDir, entry.path);
53
63
  const packagePath = join(directory, 'package.json');
54
- if (!existsSync(packagePath))
64
+ if (!existsSync(packagePath) || await isStandaloneNextArtifact({ entry, directory }))
55
65
  continue;
56
66
  const pkg = packageSchema.parse(JSON.parse(await readFile(packagePath, 'utf8')));
57
67
  const { pnpm, ...packageFields } = pkg;
@@ -89,12 +99,7 @@ export async function scaffoldAppWorkspace({ rootDir, manifest, }) {
89
99
  await writeFile(join(rootDir, 'pnpm-workspace.yaml'), yamlDump({
90
100
  packages: [],
91
101
  minimumReleaseAge: 10080,
92
- minimumReleaseAgeExclude: [
93
- '@sequenceholdings/agent-spec', '@sequenceholdings/atlas-ui',
94
- '@sequenceholdings/lattice-form-renderer', '@sequenceholdings/artifact-studio',
95
- '@sequenceholdings/lattice', '@sequenceholdings/orm',
96
- '@sequenceholdings/pipeline-spec', '@sequenceholdings/studio-cli',
97
- ],
102
+ minimumReleaseAgeExclude: [...FIRST_PARTY_RELEASE_AGE_EXCLUDE],
98
103
  strictDepBuilds: true,
99
104
  allowBuilds: { esbuild: true },
100
105
  }));
package/dist/argv.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export interface ParsedArgs {
2
+ positional: string[];
3
+ flags: Record<string, string | true>;
4
+ /** All string values for flags supplied more than once; flags keeps the last value. */
5
+ repeatedFlags?: Record<string, string[]>;
6
+ }
7
+ export declare function parseArgs(rest: string[]): ParsedArgs;
package/dist/argv.js ADDED
@@ -0,0 +1,56 @@
1
+ const SHORT_FLAG_ALIASES = { '-e': 'env', '-m': 'message', '-o': 'out' };
2
+ export function parseArgs(rest) {
3
+ const positional = [];
4
+ const flags = {};
5
+ const repeatedFlags = {};
6
+ const setFlag = (key, value) => {
7
+ flags[key] = value;
8
+ if (typeof value === 'string')
9
+ (repeatedFlags[key] ??= []).push(value);
10
+ };
11
+ for (let i = 0; i < rest.length; i++) {
12
+ const arg = rest[i];
13
+ if (arg === '--') {
14
+ positional.push(...rest.slice(i + 1));
15
+ break;
16
+ }
17
+ if (arg.startsWith('--')) {
18
+ const body = arg.slice(2);
19
+ const eqIdx = body.indexOf('=');
20
+ if (eqIdx >= 0) {
21
+ setFlag(body.slice(0, eqIdx), body.slice(eqIdx + 1));
22
+ continue;
23
+ }
24
+ const next = rest[i + 1];
25
+ if (next && !next.startsWith('-')) {
26
+ setFlag(body, next);
27
+ i += 1;
28
+ }
29
+ else
30
+ setFlag(body, true);
31
+ }
32
+ else if (arg.startsWith('-') && arg.length >= 2 && !arg.startsWith('--')) {
33
+ const eqIdx = arg.indexOf('=');
34
+ const shortName = eqIdx >= 0 ? arg.slice(0, eqIdx) : arg;
35
+ const longName = SHORT_FLAG_ALIASES[shortName];
36
+ if (!longName || shortName.length !== 2) {
37
+ positional.push(arg);
38
+ continue;
39
+ }
40
+ if (eqIdx >= 0) {
41
+ setFlag(longName, arg.slice(eqIdx + 1));
42
+ continue;
43
+ }
44
+ const next = rest[i + 1];
45
+ if (next && !next.startsWith('-')) {
46
+ setFlag(longName, next);
47
+ i += 1;
48
+ }
49
+ else
50
+ setFlag(longName, true);
51
+ }
52
+ else
53
+ positional.push(arg);
54
+ }
55
+ return { positional, flags, ...(Object.keys(repeatedFlags).length ? { repeatedFlags } : {}) };
56
+ }
@@ -19,9 +19,9 @@ import { PREVIEW_DOMAIN, PREVIEW_PROJECT, resolvePreviewByPr } from '../preview.
19
19
  const ARTIFACT_USAGE = `usage:
20
20
  seq-studio artifact init <dir> [--template react-vite|nextjs]
21
21
  seq-studio artifact validate [dir]
22
- seq-studio artifact build [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--out file.json]
23
- seq-studio artifact plan [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] -e <env>
24
- seq-studio artifact deploy [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] -e <env> [--skip-unchanged] [--no-create] [--project <id>]
22
+ seq-studio artifact build [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--path <dir>] [--out file.json]
23
+ seq-studio artifact plan [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--path <dir>] -e <env>
24
+ seq-studio artifact deploy [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--path <dir>] -e <env> [--skip-unchanged] [--no-create] [--project <id>]
25
25
  seq-studio artifact dev [dir] -e <env> [--once] [--key default] [--link <pkgDir>[,<pkgDir>]] [--port <port>]
26
26
  seq-studio artifact pull <project-id> -e <env> --out <dir>
27
27
  seq-studio artifact promote <deployment-id> -e <env>
@@ -39,7 +39,8 @@ const ARTIFACT_USAGE = `usage:
39
39
 
40
40
  Source for build/plan/deploy: a local [dir] (default), a platform git-service
41
41
  repo (--repo <ns>/<name>), or a public HTTPS git URL (--git-url <url>). --ref selects a
42
- branch/tag/commit (default: the repo's default branch).
42
+ branch/tag/commit (default: the repo's default branch). --path <dir> selects the
43
+ application directory inside that repository (default: its root).
43
44
 
44
45
  Interactive --repo builds clone over smart-HTTP and require ATLAS_GIT_PAT
45
46
  (a repo:read PAT — seq-studio auth pat create, or Atlas → Settings → Tokens).
@@ -54,6 +55,9 @@ const ARTIFACT_USAGE = `usage:
54
55
  with a Git Service origin on the target Atlas environment also works.
55
56
  Use pnpm build for a local production-build check. --once is static-only;
56
57
  --port selects the local Next loopback port.
58
+ Deploy rejects source that still points at another environment's API origin
59
+ or workspace UUID. Declare API origins under targets.<environment>.url.
60
+ Workspace IDs in source must exist in the selected environment.
57
61
 
58
62
  Per-PR preview environments (https://studio-atlas-git-<slug>.preview.seqholdings.com):
59
63
  -e preview:<branch-or-slug> compute the preview host from a branch name
@@ -22,6 +22,12 @@ export declare class AtlasApiError extends Error {
22
22
  readonly name = "AtlasApiError";
23
23
  constructor(status: number, message: string, path: string, statusText?: string, body?: unknown);
24
24
  }
25
+ /** Bounded single attempt for commands whose uncertain result must be reconciled by the caller. */
26
+ export declare function requestJsonOnce({ baseUrl, token, path, method, body, }: ClientOptions & {
27
+ path: string;
28
+ method: 'GET' | 'POST' | 'PUT';
29
+ body?: unknown;
30
+ }): Promise<unknown>;
25
31
  export declare function getJson<T>({ baseUrl, token, path, }: ClientOptions & {
26
32
  path: string;
27
33
  }): Promise<T>;
@@ -5,6 +5,7 @@
5
5
  * the caller — this file knows nothing about token files or config TOMLs.
6
6
  */
7
7
  import { authenticatedRequestUrl } from '@sequenceholdings/artifact-studio/deployment-validation';
8
+ import { validationDetail } from './validation-detail.js';
8
9
  import { PREVIEW_DOMAIN } from './preview.js';
9
10
  const MAX_503_RETRIES = 5;
10
11
  const DEFAULT_RETRY_AFTER_SECONDS = 2;
@@ -36,9 +37,10 @@ async function fetchWith503Retry(input, init) {
36
37
  await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
37
38
  }
38
39
  }
39
- async function authenticatedFetch({ baseUrl, init = {}, path, token, }) {
40
+ async function authenticatedFetch({ baseUrl, init = {}, path, token, retry503 = true, }) {
40
41
  const url = authenticatedRequestUrl({ baseUrl, path });
41
- return fetchWith503Retry(url, {
42
+ const send = retry503 ? fetchWith503Retry : fetch;
43
+ return send(url, {
42
44
  ...init,
43
45
  redirect: 'manual',
44
46
  headers: {
@@ -49,6 +51,38 @@ async function authenticatedFetch({ baseUrl, init = {}, path, token, }) {
49
51
  },
50
52
  });
51
53
  }
54
+ /** Bounded single attempt for commands whose uncertain result must be reconciled by the caller. */
55
+ export async function requestJsonOnce({ baseUrl, token, path, method, body, }) {
56
+ const response = await authenticatedFetch({ baseUrl, token, path, retry503: false,
57
+ init: { method, signal: AbortSignal.timeout(30_000),
58
+ headers: body === undefined ? {} : { 'Content-Type': 'application/json' },
59
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }) } });
60
+ const reader = response.body?.getReader();
61
+ if (!reader)
62
+ throw new Error('Missing response body');
63
+ const chunks = [];
64
+ let size = 0;
65
+ try {
66
+ for (;;) {
67
+ const item = await reader.read();
68
+ if (item.done)
69
+ break;
70
+ size += item.value.byteLength;
71
+ if (size > 8_388_608)
72
+ throw new Error('Response exceeds 8 MiB');
73
+ chunks.push(item.value);
74
+ }
75
+ }
76
+ finally {
77
+ void reader.cancel().catch(() => { });
78
+ reader.releaseLock();
79
+ }
80
+ const raw = Buffer.concat(chunks).toString('utf8');
81
+ const parsed = parseErrorBody(raw, response.headers.get('content-type') ?? '');
82
+ if (!response.ok)
83
+ throw new AtlasApiError(response.status, messageFromBody(parsed, response.status, response.statusText), path, response.statusText, parsed);
84
+ return parsed;
85
+ }
52
86
  function previewAccessHeaders(baseUrl) {
53
87
  const secret = process.env.PREVIEW_ACCESS_HEADER?.trim();
54
88
  if (!secret)
@@ -114,6 +148,9 @@ function messageFromBody(body, status, statusText) {
114
148
  const record = body;
115
149
  const violations = violationLines(record.violations);
116
150
  const withViolations = (headline) => violations.length > 0 ? [headline, ...violations].join('\n') : headline;
151
+ const fields = validationDetail(record.errors);
152
+ if (fields)
153
+ return withViolations(fields);
117
154
  if (typeof record.detail === 'string' && record.detail.length > 0) {
118
155
  return withViolations(record.detail);
119
156
  }
package/dist/auth.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ /** A token-cache failure is distinct from an absent or expired login. */
2
+ export declare class AuthTokenStoreError extends Error {
3
+ readonly kind: 'permission' | 'invalid' | 'io';
4
+ readonly path: string;
5
+ readonly name = "AuthTokenStoreError";
6
+ constructor(message: string, kind: 'permission' | 'invalid' | 'io', path: string, options?: ErrorOptions);
7
+ }
1
8
  /**
2
9
  * seq-studio and seqapi share one token file and one Auth0 application:
3
10
  * same tenant, client id, audience, and token shape. Either CLI can log in,
@@ -55,6 +62,7 @@ export interface SeqapiTokens {
55
62
  }
56
63
  interface RealmResolutionOptions {
57
64
  fetchImpl?: typeof fetch;
65
+ offline?: boolean;
58
66
  targetUrl?: string;
59
67
  }
60
68
  /**
@@ -133,6 +141,30 @@ export declare function tryGetAccessToken(options?: {
133
141
  env?: string;
134
142
  targetUrl?: string;
135
143
  }): Promise<string | null>;
144
+ export interface AuthPreflightDiagnostics {
145
+ authMode: 'auto' | 'm2m';
146
+ realm: string;
147
+ realmVerified: boolean;
148
+ tokenCachePath: string;
149
+ tokenCache: 'readable' | 'missing' | 'permission-denied' | 'invalid-json' | 'io-error';
150
+ cachedUserToken: 'valid' | 'expired' | 'missing' | 'unavailable';
151
+ cachedM2mToken: 'valid' | 'expired' | 'missing' | 'unavailable';
152
+ m2mCredentialConfigured: boolean;
153
+ selectedCredential: 'user' | 'm2m' | 'none' | 'unavailable';
154
+ detail?: string;
155
+ }
156
+ /**
157
+ * Read-only, non-interactive authentication preflight. This never returns a
158
+ * credential, launches a browser, contacts Auth0, or writes the shared cache.
159
+ * Atomic rename means reading the cache without taking its write lock is safe;
160
+ * importantly, a read-only doctor still works when the cache directory cannot
161
+ * create the lock file.
162
+ */
163
+ export declare function inspectAuthPreflight(options?: {
164
+ env?: string;
165
+ offline?: boolean;
166
+ targetUrl?: string;
167
+ }): Promise<AuthPreflightDiagnostics>;
136
168
  /**
137
169
  * Refuse to persist a token minted for another audience or Auth0
138
170
  * organization. Auth0/server-side JWT verification remains authoritative;