@sequenceholdings/studio-cli 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +333 -29
  2. package/dist/access/commands.d.ts +3 -0
  3. package/dist/access/commands.js +91 -0
  4. package/dist/app/adapters.js +27 -5
  5. package/dist/app/application-registration.d.ts +96 -0
  6. package/dist/app/application-registration.js +146 -0
  7. package/dist/app/deploy.d.ts +8 -0
  8. package/dist/app/deploy.js +42 -8
  9. package/dist/app/manifest-validation.d.ts +20 -1
  10. package/dist/app/manifest-validation.js +130 -6
  11. package/dist/app/manifest.d.ts +110 -2
  12. package/dist/app/manifest.js +109 -3
  13. package/dist/app/primitive-scaffold.js +11 -1
  14. package/dist/app/readme.js +2 -0
  15. package/dist/app/scaffold.js +3 -2
  16. package/dist/app/workspace-scaffold.js +3 -3
  17. package/dist/artifact/delegate.js +8 -4
  18. package/dist/auth-cmds/commands.d.ts +1 -1
  19. package/dist/auth-cmds/commands.js +16 -0
  20. package/dist/cli-errors.js +4 -0
  21. package/dist/command-input.d.ts +15 -0
  22. package/dist/command-input.js +33 -0
  23. package/dist/functions/commands.d.ts +2 -1
  24. package/dist/functions/commands.js +61 -30
  25. package/dist/functions/manifest.d.ts +7 -1
  26. package/dist/functions/manifest.js +40 -12
  27. package/dist/functions/secret-reconcile.d.ts +3 -3
  28. package/dist/functions/secret-reconcile.js +5 -7
  29. package/dist/main.d.ts +3 -1
  30. package/dist/main.js +19 -7
  31. package/dist/manifest-roles-notice.d.ts +33 -0
  32. package/dist/manifest-roles-notice.js +75 -0
  33. package/dist/orm/delegate.js +2 -0
  34. package/dist/pipeline/commands.js +11 -0
  35. package/dist/pipeline/discovery.d.ts +8 -0
  36. package/dist/pipeline/discovery.js +249 -0
  37. package/dist/pipeline/lifecycle.js +35 -10
  38. package/dist/pipeline/stage-secrets.d.ts +4 -1
  39. package/dist/pipeline/stage-secrets.js +6 -2
  40. package/dist/process/commands.js +4 -0
  41. package/dist/repos/commands.d.ts +10 -1
  42. package/dist/repos/commands.js +16 -8
  43. package/dist/repos/pulls.d.ts +3 -0
  44. package/dist/repos/pulls.js +131 -0
  45. package/dist/secrets/commands.d.ts +1 -1
  46. package/dist/secrets/commands.js +97 -16
  47. package/dist/service-accounts/commands.d.ts +3 -0
  48. package/dist/service-accounts/commands.js +50 -0
  49. package/package.json +5 -5
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Roles are created and edited in Atlas (the Permissions UI or the roles API)
3
+ * by capability admins. Role definitions in YAML — `capabilities.roles.definitions`
4
+ * in artifact.bundle.yml, managed-function.yml and namespace.yaml, and
5
+ * `roles` / `collaborators` in sequence.app.yml — are a deprecated one-time
6
+ * seed: a deploy creates any that don't exist yet and never updates them.
7
+ * Capabilities stay in YAML; they are the code's contract.
8
+ *
9
+ * Atlas only logs the drift, so the CLI tells the author before deploying.
10
+ */
11
+ import { existsSync } from 'node:fs';
12
+ import { readFile } from 'node:fs/promises';
13
+ import { join } from 'node:path';
14
+ import { load as loadYaml } from 'js-yaml';
15
+ function isRecord(value) {
16
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
17
+ }
18
+ function definitionKeys(block) {
19
+ if (!isRecord(block) || !isRecord(block.definitions))
20
+ return [];
21
+ return Object.keys(block.definitions);
22
+ }
23
+ /** Role keys an artifact, managed function or ORM namespace manifest defines. */
24
+ export function hostRoleKeys(manifest) {
25
+ if (!isRecord(manifest) || !isRecord(manifest.capabilities))
26
+ return [];
27
+ return definitionKeys(manifest.capabilities.roles).sort();
28
+ }
29
+ /** Runtime and collaborator role keys sequence.app.yml defines. */
30
+ export function applicationRoleKeys(manifest) {
31
+ if (!isRecord(manifest))
32
+ return [];
33
+ return [...definitionKeys(manifest.roles), ...definitionKeys(manifest.collaborators)].sort();
34
+ }
35
+ export function manifestRolesNotice({ file, keys, where, }) {
36
+ if (keys.length === 0)
37
+ return null;
38
+ return (`[seq-studio] ${file} defines roles (${keys.join(', ')}). Roles in YAML are a deprecated one-time seed: ` +
39
+ `a deploy creates any that don't exist yet and never updates them after. Create and edit roles in Atlas ` +
40
+ `(${where}) or through the roles API; keep capabilities in YAML.`);
41
+ }
42
+ /**
43
+ * Print the notice for a manifest in `dir`, if it defines roles. Best-effort:
44
+ * a missing or unreadable file is the deploy's error to report, not this one's.
45
+ */
46
+ export async function warnOnManifestRoles({ dir, file, kind, }) {
47
+ let manifest;
48
+ try {
49
+ manifest = loadYaml(await readFile(join(dir, file), 'utf8'));
50
+ }
51
+ catch {
52
+ return;
53
+ }
54
+ const notice = manifestRolesNotice({
55
+ file,
56
+ keys: kind === 'host' ? hostRoleKeys(manifest) : applicationRoleKeys(manifest),
57
+ where: kind === 'host' ? 'Permissions → Roles' : 'Permissions → Applications → Edit roles',
58
+ });
59
+ if (notice)
60
+ console.warn(notice);
61
+ }
62
+ /** Before `sub` deploys a host manifest from `args`, warn if it defines roles. */
63
+ export async function warnBeforeHostDeploy({ sub, deploySub, args, file, }) {
64
+ if (sub !== deploySub)
65
+ return;
66
+ await warnOnManifestRoles({ dir: manifestDirFromArgs(args, file), file, kind: 'host' });
67
+ }
68
+ /**
69
+ * The directory a command's argv points at that holds `file`: the first
70
+ * argument naming such a directory, else the working directory. Avoids
71
+ * guessing which arguments are flag values.
72
+ */
73
+ export function manifestDirFromArgs(args, file) {
74
+ return args.find((arg) => !arg.startsWith('-') && existsSync(join(arg, file))) ?? '.';
75
+ }
@@ -9,6 +9,7 @@ import { getAccessToken, tryGetAccessToken } from '../auth.js';
9
9
  import { resolveEnvWithDiscovery } from '../config.js';
10
10
  import { normalizeShortEnvFlag, readEnvFromArgv } from '../env-flags.js';
11
11
  import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
12
+ import { warnBeforeHostDeploy } from '../manifest-roles-notice.js';
12
13
  /**
13
14
  * ORM subcommands that talk to Atlas — must not silently target `local`.
14
15
  * `init`, `generate`, `validate`, `diff`, and `migrate-from-yaml` are offline.
@@ -103,5 +104,6 @@ export async function runOrmCommand(sub, rest) {
103
104
  return null;
104
105
  }
105
106
  });
107
+ await warnBeforeHostDeploy({ sub, deploySub: 'apply', args: normalized, file: 'namespace.yaml' });
106
108
  return runCli([sub, ...normalized]);
107
109
  }
@@ -17,11 +17,13 @@ import { join, resolve } from 'node:path';
17
17
  import { authenticatedRequestUrl, validateDeploymentBaseUrl, } from '@sequenceholdings/artifact-studio/deployment-validation';
18
18
  import { tryGetAccessToken } from '../auth.js';
19
19
  import { readConfig } from '../config.js';
20
+ import { PIPELINE_DISCOVERY_USAGE, runPipelineDiscoveryCommand } from './discovery.js';
20
21
  import { renderEntrypointStub, renderStageTemplate, STAGE_TYPES, } from './templates.js';
21
22
  const LOG = '[seq-studio]';
22
23
  /** Conventional ORM contract catalog filename beside stage specs (CI auto-loads this). */
23
24
  export const ORM_CONTRACTS_FILENAME = 'orm-contracts.json';
24
25
  const PIPELINE_USAGE = `usage:
26
+ ${PIPELINE_DISCOVERY_USAGE}
25
27
  seq-studio pipeline init --type ingestion|transformation|serving <name> [--dir <dir>]
26
28
  scaffold <name>.stage.yml (commented template) + src/ entrypoint stub
27
29
 
@@ -407,6 +409,15 @@ export async function pipelineValidateCommand(args) {
407
409
  }
408
410
  export async function runPipelineCommand(sub, args) {
409
411
  switch (sub) {
412
+ case 'list':
413
+ case 'assets':
414
+ case 'search':
415
+ case 'describe':
416
+ case 'schema':
417
+ case 'sample':
418
+ case 'query': {
419
+ return runPipelineDiscoveryCommand({ sub, args });
420
+ }
410
421
  case 'init':
411
422
  return pipelineInitCommand(args);
412
423
  case 'validate':
@@ -0,0 +1,8 @@
1
+ import type { ParsedArgs } from '../process/commands.js';
2
+ type DiscoveryCommand = 'list' | 'assets' | 'search' | 'describe' | 'schema' | 'sample' | 'query';
3
+ export declare const PIPELINE_DISCOVERY_USAGE = " seq-studio pipeline list -e <env> [--limit 1..200] [--offset N] [--json]\n list pipeline repositories (default 50 per page), health and descriptions\n\n seq-studio pipeline assets -e <env> [--repo <namespace>/<name>] [--json]\n discover exact asset IDs from the latest declared specs; --repo filters\n both assets and the SDK export. Declarations may not be deployed yet.\n\n seq-studio pipeline search <query> -e <env> [--target <id>] [--repo <namespace>/<name>]\n [--limit 1..100] [--offset N] [--json]\n search active asset/column names and descriptions without contacting Databricks\n Case-insensitive literal text (1..200 characters); default 20 assets per page.\n\n seq-studio pipeline describe <asset> -e <env> [--target <id>] [--repo <namespace>/<name>] [--json]\n read active deployed descriptions and declared columns without contacting Databricks\n Includes deployment/source provenance; physical schema is not verified.\n\n seq-studio pipeline schema <asset> -e <env> [--target <id>] [--json]\n read observed columns, types and available descriptions from the active deployment\n\n seq-studio pipeline sample <asset> -e <env> [--target <id>] [--limit 1..100] [--json]\n preview rows (default 25); output reports deployment and truncation\n\n seq-studio pipeline query <asset> --sql <sql> -e <env> [--target <id>] [--limit 1..1000] [--json]\n run read-only SQL against the virtual relation asset (default limit 1000)\n Example: --sql 'SELECT * FROM asset LIMIT 5'. Cross-asset joins are unsupported.\n\n Discovery requires staff access. Search, then describe a relevant asset; use\n schema to verify physical columns, then sample and query values before authoring.\n Metadata reflects active deployments, not unactivated edits. Descriptions do not prove keys\n or relationships. Use --json for the full response, including deployment context.\n -e selects the connection; --target selects its logical deployment target when needed.\n";
4
+ export declare function runPipelineDiscoveryCommand({ sub, args }: {
5
+ sub: DiscoveryCommand;
6
+ args: ParsedArgs;
7
+ }): Promise<number>;
8
+ export {};
@@ -0,0 +1,249 @@
1
+ import { getAccessToken } from '../auth.js';
2
+ import { getJson, postJson } from '../atlas-client.js';
3
+ import { printCliError } from '../cli-errors.js';
4
+ import { resolveEnvWithDiscovery } from '../config.js';
5
+ import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
6
+ import { resolvePipelineTarget } from './lifecycle.js';
7
+ export const PIPELINE_DISCOVERY_USAGE = ` seq-studio pipeline list -e <env> [--limit 1..200] [--offset N] [--json]
8
+ list pipeline repositories (default 50 per page), health and descriptions
9
+
10
+ seq-studio pipeline assets -e <env> [--repo <namespace>/<name>] [--json]
11
+ discover exact asset IDs from the latest declared specs; --repo filters
12
+ both assets and the SDK export. Declarations may not be deployed yet.
13
+
14
+ seq-studio pipeline search <query> -e <env> [--target <id>] [--repo <namespace>/<name>]
15
+ [--limit 1..100] [--offset N] [--json]
16
+ search active asset/column names and descriptions without contacting Databricks
17
+ Case-insensitive literal text (1..200 characters); default 20 assets per page.
18
+
19
+ seq-studio pipeline describe <asset> -e <env> [--target <id>] [--repo <namespace>/<name>] [--json]
20
+ read active deployed descriptions and declared columns without contacting Databricks
21
+ Includes deployment/source provenance; physical schema is not verified.
22
+
23
+ seq-studio pipeline schema <asset> -e <env> [--target <id>] [--json]
24
+ read observed columns, types and available descriptions from the active deployment
25
+
26
+ seq-studio pipeline sample <asset> -e <env> [--target <id>] [--limit 1..100] [--json]
27
+ preview rows (default 25); output reports deployment and truncation
28
+
29
+ seq-studio pipeline query <asset> --sql <sql> -e <env> [--target <id>] [--limit 1..1000] [--json]
30
+ run read-only SQL against the virtual relation asset (default limit 1000)
31
+ Example: --sql 'SELECT * FROM asset LIMIT 5'. Cross-asset joins are unsupported.
32
+
33
+ Discovery requires staff access. Search, then describe a relevant asset; use
34
+ schema to verify physical columns, then sample and query values before authoring.
35
+ Metadata reflects active deployments, not unactivated edits. Descriptions do not prove keys
36
+ or relationships. Use --json for the full response, including deployment context.
37
+ -e selects the connection; --target selects its logical deployment target when needed.
38
+ `;
39
+ function valueFlag({ args, name }) {
40
+ const value = args.flags[name];
41
+ if (value === true || value?.trim() === '')
42
+ throw new Error(`--${name} requires a value`);
43
+ return value;
44
+ }
45
+ function integerFlag({ args, name, min, max }) {
46
+ const value = valueFlag({ args, name });
47
+ if (value === undefined)
48
+ return undefined;
49
+ const number = Number(value);
50
+ if (!/^\d+$/.test(value) || !Number.isSafeInteger(number) || number < min || number > max) {
51
+ throw new Error(`--${name} must be an integer from ${min} to ${max}`);
52
+ }
53
+ return number;
54
+ }
55
+ function discoveryEnvironment(args) {
56
+ const shortEnv = valueFlag({ args, name: 'e' });
57
+ const longEnv = valueFlag({ args, name: 'env' });
58
+ const values = [shortEnv, longEnv, ...args.repeatedFlags?.env ?? [], ...args.repeatedFlags?.e ?? []].filter(Boolean);
59
+ if (new Set(values).size > 1)
60
+ throw new Error('-e and --env must select the same environment');
61
+ const environment = shortEnv ?? longEnv;
62
+ if (!environment)
63
+ throw new Error(REQUIRE_EXPLICIT_ENV_MESSAGE);
64
+ return environment;
65
+ }
66
+ function validateDiscoveryArguments({ sub, args }) {
67
+ const readsAsset = sub === 'describe' || sub === 'schema' || sub === 'sample' || sub === 'query';
68
+ const readsPositional = readsAsset || sub === 'search';
69
+ const options = {
70
+ list: ['limit', 'offset'], assets: ['repo'], schema: ['target'],
71
+ search: ['target', 'repo', 'limit', 'offset'], describe: ['target', 'repo'],
72
+ sample: ['target', 'limit'], query: ['target', 'limit', 'sql'],
73
+ };
74
+ const allowed = new Set(['e', 'env', 'json', ...options[sub]]);
75
+ for (const flag of Object.keys(args.flags)) {
76
+ if (!allowed.has(flag))
77
+ throw new Error(`unknown option --${flag} for pipeline ${sub}; run seq-studio pipeline ${sub} --help`);
78
+ }
79
+ if (args.positional.length !== (readsPositional ? 1 : 0) || (readsPositional && !args.positional[0]?.trim())) {
80
+ const requirement = sub === 'search'
81
+ ? 'requires one search query; quote queries containing spaces'
82
+ : readsAsset ? 'requires one exact asset ID; discover IDs with pipeline search or pipeline assets' : 'does not accept positional arguments';
83
+ throw new Error(`pipeline ${sub} ${requirement}`);
84
+ }
85
+ const json = args.flags.json;
86
+ if (json !== undefined && json !== true && json !== 'true' && json !== 'false')
87
+ throw new Error('--json is a boolean flag; put the asset ID before options');
88
+ }
89
+ function discoveryOptions({ sub, args }) {
90
+ validateDiscoveryArguments({ sub, args });
91
+ const environment = discoveryEnvironment(args);
92
+ valueFlag({ args, name: 'target' });
93
+ const repo = valueFlag({ args, name: 'repo' });
94
+ if (repo && !/^[^/\s]+\/[^/\s]+$/.test(repo))
95
+ throw new Error('--repo must be <namespace>/<name>');
96
+ const sql = valueFlag({ args, name: 'sql' });
97
+ if (sub === 'query' && !sql)
98
+ throw new Error('pipeline query requires --sql, for example --sql "SELECT * FROM asset LIMIT 5"');
99
+ if (sql && sql.length > 10_000)
100
+ throw new Error('--sql must be at most 10000 characters');
101
+ const query = sub === 'search' ? args.positional[0].trim() : undefined;
102
+ if (query && query.length > 200)
103
+ throw new Error('search query must be at most 200 characters');
104
+ const limit = integerFlag({ args, name: 'limit', min: 1, max: sub === 'list' ? 200 : sub === 'sample' || sub === 'search' ? 100 : 1000 });
105
+ const offset = integerFlag({ args, name: 'offset', min: 0, max: Number.MAX_SAFE_INTEGER });
106
+ return { environment, json: args.flags.json === true || args.flags.json === 'true', repo, sql, query, limit, offset };
107
+ }
108
+ function cell(value) {
109
+ if (value === undefined)
110
+ return '—';
111
+ if (typeof value !== 'string')
112
+ return JSON.stringify(value) ?? '—';
113
+ // Preserve readable text while escaping control characters from source data.
114
+ return value.replace(/\p{Cc}/gu, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`);
115
+ }
116
+ function table({ headers, rows }) {
117
+ const lines = [headers, ...rows].map((row) => row.map(cell));
118
+ const widths = headers.map((_, index) => Math.max(...lines.map((line) => line[index]?.length ?? 0)));
119
+ for (const line of lines)
120
+ console.log(line.map((value, index) => value.padEnd(widths[index] ?? 0)).join(' ').trimEnd());
121
+ }
122
+ function printAssetResult(result) {
123
+ console.log(`Asset: ${cell(result.assetId)}`);
124
+ console.log(`Target: ${cell(result.environment)} | ${cell(result.target.engine)} | ${cell(result.target.fullName)}`);
125
+ console.log(`Deployment: ${cell(result.target.deploymentId)}`);
126
+ if (result.target.volumePath)
127
+ console.log(`Volume: ${cell(result.target.volumePath)}`);
128
+ if (result.description)
129
+ console.log(`Description: ${cell(result.description)}`);
130
+ if (result.mode === 'schema') {
131
+ table({ headers: ['COLUMN', 'TYPE', 'NULLABLE', 'DESCRIPTION'], rows: result.columns.map((column) => [column.name, column.type, column.nullable, column.description]) });
132
+ console.log(`${result.columns.length} column(s) | ${result.durationMs} ms`);
133
+ return;
134
+ }
135
+ table({ headers: result.columns.map((column) => column.name), rows: result.rows.map((row) => result.columns.map((column) => row[column.name])) });
136
+ console.log(`${result.rowCount} row(s) | limit ${result.limit} | truncated: ${result.truncated ? 'yes' : 'no'} | ${result.durationMs} ms`);
137
+ }
138
+ function printMetadataSource({ source, environment }) {
139
+ console.log(`Target: ${cell(environment)} | Source: ${cell(source)} | Physical schema: not verified`);
140
+ }
141
+ function printAssetSearch({ result, environment }) {
142
+ printMetadataSource({ source: result.source, environment });
143
+ table({
144
+ headers: ['ASSET', 'KIND', 'REPOSITORY', 'DESCRIPTION', 'MATCHED COLUMNS'],
145
+ rows: result.assets.map((asset) => {
146
+ const names = asset.matchedColumns.map((column) => column.name).join(', ');
147
+ const remaining = asset.matchedColumnCount - asset.matchedColumns.length;
148
+ const description = asset.description && asset.description.length > 120 ? `${asset.description.slice(0, 117)}...` : asset.description;
149
+ return [asset.assetId, asset.kind, asset.stage.repo, description, remaining > 0 ? `${names} (+${remaining} more)` : names || undefined];
150
+ }),
151
+ });
152
+ const { offset, limit, total } = result.pagination;
153
+ console.log(`${result.assets.length} of ${total} matching asset(s) | offset ${offset}`);
154
+ if (offset + limit < total)
155
+ console.log(`Next page: --offset ${offset + limit} --limit ${limit}`);
156
+ console.log('Use pipeline describe <asset> for full declared metadata, then pipeline schema <asset> to verify physical columns.');
157
+ }
158
+ function printAssetDescription(result) {
159
+ console.log(`Asset: ${cell(result.assetId)} | Kind: ${cell(result.kind)}`);
160
+ console.log(`Repository: ${cell(result.stage.repo)} | Stage: ${cell(result.stage.slug)}`);
161
+ printMetadataSource(result);
162
+ console.log(`Deployment: ${cell(result.deploymentId)} | Source commit: ${cell(result.sourceCommit)}`);
163
+ if (result.description)
164
+ console.log(`Description: ${cell(result.description)}`);
165
+ table({ headers: ['COLUMN', 'DECLARED TYPE', 'DECLARED NULLABLE', 'DESCRIPTION'], rows: result.columns.map((column) => [column.name, column.declaredType, column.declaredNullable, column.description]) });
166
+ console.log(`${result.columns.length} declared column(s). Use pipeline schema <asset> to verify physical columns and types.`);
167
+ }
168
+ export async function runPipelineDiscoveryCommand({ sub, args }) {
169
+ if (args.flags.help || args.flags.h || args.positional.includes('-h')) {
170
+ console.log(PIPELINE_DISCOVERY_USAGE);
171
+ return 0;
172
+ }
173
+ try {
174
+ const options = discoveryOptions({ sub, args });
175
+ const env = await resolveEnvWithDiscovery({ requested: options.environment });
176
+ const token = await getAccessToken({ env: env.name, targetUrl: env.url });
177
+ const client = { baseUrl: env.url, token };
178
+ if (sub === 'list') {
179
+ const params = new URLSearchParams({ limit: String(options.limit ?? 50), offset: String(options.offset ?? 0) });
180
+ const result = await getJson({ ...client, path: `/api/data-pipelines/pipelines?${params}` });
181
+ if (options.json)
182
+ console.log(JSON.stringify(result, null, 2));
183
+ else {
184
+ table({ headers: ['REPOSITORY', 'HEALTH', 'STAGES', 'ENVIRONMENTS', 'DESCRIPTION'], rows: result.pipelines.map((pipeline) => [pipeline.repo, pipeline.health, pipeline.stageCounts.total, pipeline.environments.join(', '), pipeline.description]) });
185
+ const { offset, limit, total } = result.pagination;
186
+ console.log(`${result.pipelines.length} of ${total} pipeline(s) | offset ${offset}`);
187
+ if (offset + limit < total)
188
+ console.log(`Next page: --offset ${offset + limit} --limit ${limit}`);
189
+ }
190
+ }
191
+ else if (sub === 'assets') {
192
+ const result = await getJson({ ...client, path: '/api/data-pipelines/assets' });
193
+ if (options.repo) {
194
+ result.assets = result.assets.filter((asset) => asset.stage.repo === options.repo);
195
+ const ids = new Set(result.assets.map((asset) => asset.id));
196
+ result.export = { ...result.export, assets: Object.fromEntries(Object.entries(result.export.assets).filter(([id]) => ids.has(id))) };
197
+ result.total = result.assets.length;
198
+ }
199
+ if (options.json)
200
+ console.log(JSON.stringify(result, null, 2));
201
+ else {
202
+ table({ headers: ['ASSET', 'KIND', 'REPOSITORY'], rows: result.assets.map((asset) => [asset.id, asset.kind, asset.stage.repo]) });
203
+ console.log(`${result.total} declared asset(s). Use pipeline schema <asset> to inspect the active deployment.`);
204
+ }
205
+ }
206
+ else if (sub === 'search' || sub === 'describe') {
207
+ const target = await resolvePipelineTarget({ args, env, token });
208
+ const params = new URLSearchParams({ environment: target.id });
209
+ if (sub === 'search')
210
+ params.set('q', options.query);
211
+ else
212
+ params.set('assetId', args.positional[0]);
213
+ if (options.repo)
214
+ params.set('repo', options.repo);
215
+ if (sub === 'search') {
216
+ params.set('limit', String(options.limit ?? 20));
217
+ params.set('offset', String(options.offset ?? 0));
218
+ const result = await getJson({ ...client, path: `/api/data-pipelines/assets/search?${params}` });
219
+ if (options.json)
220
+ console.log(JSON.stringify(result, null, 2));
221
+ else
222
+ printAssetSearch({ result, environment: target.id });
223
+ }
224
+ else {
225
+ const result = await getJson({ ...client, path: `/api/data-pipelines/assets/describe?${params}` });
226
+ if (options.json)
227
+ console.log(JSON.stringify(result, null, 2));
228
+ else
229
+ printAssetDescription(result);
230
+ }
231
+ }
232
+ else {
233
+ const target = await resolvePipelineTarget({ args, env, token });
234
+ const result = await postJson({
235
+ ...client, path: '/api/data-pipelines/assets/query',
236
+ body: { assetId: args.positional[0], environment: target.id, mode: sub, ...(options.sql !== undefined ? { sql: options.sql } : {}), ...(options.limit !== undefined ? { limit: options.limit } : {}) },
237
+ });
238
+ if (options.json)
239
+ console.log(JSON.stringify(result, null, 2));
240
+ else
241
+ printAssetResult(result);
242
+ }
243
+ return 0;
244
+ }
245
+ catch (error) {
246
+ printCliError(error);
247
+ return 1;
248
+ }
249
+ }
@@ -8,6 +8,19 @@ import { resolveEnvWithDiscovery } from '../config.js';
8
8
  import { parseDurationMs } from '@sequenceholdings/lattice';
9
9
  import { printReconcileResult, reconcileStageCredentials } from './stage-secrets.js';
10
10
  const LOG = '[seq-studio]';
11
+ function rootOption(root) {
12
+ return root ? { root } : {};
13
+ }
14
+ function releaseUnitRepo({ repo, root }) {
15
+ if (!root)
16
+ return repo;
17
+ if (!repo)
18
+ throw new Error('--root requires --repo');
19
+ if (!/^(?!.*(?:^|\/)\.{1,2}(?:\/|$))[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/.test(root)) {
20
+ throw new Error('--root must be a contained relative directory');
21
+ }
22
+ return `${repo}@${root}`;
23
+ }
11
24
  const TERMINAL = new Set(['active', 'failed', 'retired']);
12
25
  const POLL_INTERVAL_MS = 2000;
13
26
  const HEARTBEAT_INTERVAL_MS = 20_000;
@@ -109,6 +122,7 @@ export async function resolvePipelineTarget({ args, env, token, }) {
109
122
  export async function pipelinePlanCommand(args) {
110
123
  const repo = flagString(args.flags, 'repo');
111
124
  const ref = flagString(args.flags, 'ref');
125
+ const root = flagString(args.flags, 'root');
112
126
  const migrationId = flagString(args.flags, 'migration');
113
127
  const inPlace = flagOn(args.flags, 'in-place');
114
128
  if (inPlace && !migrationId) {
@@ -116,7 +130,7 @@ export async function pipelinePlanCommand(args) {
116
130
  return 1;
117
131
  }
118
132
  if (!repo || !ref) {
119
- console.error('usage: seq-studio pipeline plan --repo <namespace>/<slug> --ref <sha|branch> -e <env> [--migration <id> [--in-place]] [--json]');
133
+ console.error('usage: seq-studio pipeline plan --repo <namespace>/<slug> --ref <sha|branch> [--root <directory>] -e <env> [--migration <id> [--in-place]] [--json]');
120
134
  return 1;
121
135
  }
122
136
  const { env, token } = await envAndToken(args);
@@ -137,6 +151,7 @@ export async function pipelinePlanCommand(args) {
137
151
  token,
138
152
  repo,
139
153
  ref,
154
+ ...rootOption(root),
140
155
  environment: target.id,
141
156
  ...(migrationId ? { migrationId } : {}),
142
157
  ...(inPlace ? { executionMode: 'in_place' } : {}),
@@ -170,6 +185,7 @@ export async function pipelineDeployCommand(args) {
170
185
  }
171
186
  const repo = flagString(args.flags, 'repo');
172
187
  const ref = flagString(args.flags, 'ref');
188
+ const root = flagString(args.flags, 'root');
173
189
  const deploymentId = flagString(args.flags, 'deployment-id');
174
190
  const approvedBy = flagString(args.flags, 'approved-by');
175
191
  const runNow = flagOn(args.flags, 'run-now');
@@ -210,12 +226,12 @@ export async function pipelineDeployCommand(args) {
210
226
  }
211
227
  else {
212
228
  if (!repo || !ref) {
213
- console.error('usage: seq-studio pipeline deploy --repo <namespace>/<slug> --ref <sha|branch> -e <env> [--target <id>] [--approved-by <sub>] [--allow-destructive <resource-key> ...] [--run-now] [--wait-timeout <duration>] [--no-wait]');
229
+ console.error('usage: seq-studio pipeline deploy --repo <namespace>/<slug> --ref <sha|branch> [--root <directory>] -e <env> [--target <id>] [--approved-by <sub>] [--allow-destructive <resource-key> ...] [--run-now] [--wait-timeout <duration>] [--no-wait]');
214
230
  return 1;
215
231
  }
216
232
  // Plan then deploy the first planning deployment.
217
233
  const plan = await planAttachingCredentials({
218
- request: { baseUrl: env.url, token, repo, ref, environment: target.id },
234
+ request: { baseUrl: env.url, token, repo, ref, environment: target.id, ...rootOption(root) },
219
235
  provision: !flagOn(args.flags, 'no-provision'),
220
236
  });
221
237
  if (plan.plan.hasDestructive && allowDestructiveResourceKeys.length === 0) {
@@ -562,9 +578,12 @@ async function attachUnattachedCredentials({ request, stageIds, }) {
562
578
  try {
563
579
  const client = { baseUrl: request.baseUrl, token: request.token };
564
580
  const { secrets } = await getJson({ ...client, path: '/api/managed-secrets' });
581
+ const repo = releaseUnitRepo({ repo: request.repo, root: request.root });
582
+ if (!repo)
583
+ throw new Error('pipeline credential reconciliation requires a repository');
565
584
  const result = await reconcileStageCredentials({
566
585
  client,
567
- repo: request.repo,
586
+ repo,
568
587
  stageIds,
569
588
  deployTarget: request.environment,
570
589
  secrets,
@@ -589,12 +608,12 @@ class PlanRequestFailedError extends Error {
589
608
  this.stageIds = stageIds;
590
609
  }
591
610
  }
592
- async function enqueueAndWaitForPlan({ baseUrl, token, repo, ref, environment, migrationId, executionMode, }) {
611
+ async function enqueueAndWaitForPlan({ baseUrl, token, repo, ref, root, environment, migrationId, executionMode, }) {
593
612
  const enqueue = await postJson({
594
613
  baseUrl,
595
614
  token,
596
615
  path: '/api/data-pipelines/pipelines/plan',
597
- body: { repo, ref, environment, ...(migrationId ? { migration_id: migrationId } : {}), ...(executionMode ? { execution_mode: executionMode } : {}) },
616
+ body: { repo, ref, environment, ...rootOption(root), ...(migrationId ? { migration_id: migrationId } : {}), ...(executionMode ? { execution_mode: executionMode } : {}) },
598
617
  });
599
618
  console.log(`${LOG} enqueued plan ${enqueue.planRequestId} (trigger=${enqueue.triggerRunId ?? 'n/a'})`);
600
619
  const detail = await waitForPlanRequest({
@@ -653,7 +672,7 @@ export async function pipelineAdoptCommand(args) {
653
672
  const nativeId = flagString(args.flags, 'native-id');
654
673
  const approvedBy = flagString(args.flags, 'approved-by');
655
674
  if (!stage || !ref || !nativeId || !approvedBy) {
656
- console.error('usage: seq-studio pipeline adopt --stage <slug> --ref <sha|branch> -e <env> ' +
675
+ console.error('usage: seq-studio pipeline adopt --stage <slug> --ref <sha|branch> [--root <directory>] -e <env> ' +
657
676
  '--native-id <id> --approved-by <you> [--resource-key <key>] [--kind job|dlt_pipeline] ' +
658
677
  '[--old-source-removal-pr <url>] [--repo <namespace>/<slug>] [--json]');
659
678
  return 1;
@@ -668,7 +687,10 @@ export async function pipelineAdoptCommand(args) {
668
687
  console.error(`${LOG} adopt failed: ${error instanceof Error ? error.message : String(error)}`);
669
688
  return 1;
670
689
  }
671
- const repo = flagString(args.flags, 'repo');
690
+ const repo = releaseUnitRepo({
691
+ repo: flagString(args.flags, 'repo'),
692
+ root: flagString(args.flags, 'root'),
693
+ });
672
694
  const resourceKey = flagString(args.flags, 'resource-key') ?? stage.replace(/-/g, '_');
673
695
  const kind = flagString(args.flags, 'kind') ?? 'job';
674
696
  if (kind !== 'job' && kind !== 'dlt_pipeline') {
@@ -718,7 +740,7 @@ export async function pipelineUnbindCommand(args) {
718
740
  const ref = flagString(args.flags, 'ref');
719
741
  const approvedBy = flagString(args.flags, 'approved-by');
720
742
  if (!stage || !ref || !approvedBy) {
721
- console.error('usage: seq-studio pipeline unbind --stage <slug> --ref <sha|branch> -e <env> ' +
743
+ console.error('usage: seq-studio pipeline unbind --stage <slug> --ref <sha|branch> [--root <directory>] -e <env> ' +
722
744
  '--approved-by <you> [--resource-key <key>] [--repo <namespace>/<slug>] [--json]');
723
745
  return 1;
724
746
  }
@@ -732,7 +754,10 @@ export async function pipelineUnbindCommand(args) {
732
754
  console.error(`${LOG} unbind failed: ${error instanceof Error ? error.message : String(error)}`);
733
755
  return 1;
734
756
  }
735
- const repo = flagString(args.flags, 'repo');
757
+ const repo = releaseUnitRepo({
758
+ repo: flagString(args.flags, 'repo'),
759
+ root: flagString(args.flags, 'root'),
760
+ });
736
761
  const resourceKey = flagString(args.flags, 'resource-key');
737
762
  const stageId = await resolveStageIdBySlug({
738
763
  baseUrl: env.url,
@@ -10,6 +10,7 @@ export interface StageRef {
10
10
  export interface AttachableSecret {
11
11
  id: string;
12
12
  name: string;
13
+ valueType?: 'single' | 'key_value';
13
14
  orgId: string;
14
15
  currentUserAccess: string | null;
15
16
  }
@@ -33,17 +34,19 @@ export declare function resolveStage({ client, slug, repo, }: {
33
34
  slug: string;
34
35
  repo?: string;
35
36
  }): Promise<StageRef>;
36
- export declare function attachSecretToStage({ client, stageId, deployTarget, symbolic, secretId, }: {
37
+ export declare function attachSecretToStage({ client, stageId, deployTarget, symbolic, secretId, entryKey, }: {
37
38
  client: ClientOptions;
38
39
  stageId: string;
39
40
  deployTarget: string;
40
41
  symbolic: string;
41
42
  secretId: string;
43
+ entryKey?: string;
42
44
  }): Promise<void>;
43
45
  export interface StageBinding {
44
46
  deployTarget: string;
45
47
  symbolic: string;
46
48
  secretId: string;
49
+ entryKey?: string | null;
47
50
  secretName: string;
48
51
  }
49
52
  export declare function listStageBindings({ client, stageId }: {
@@ -34,11 +34,11 @@ export async function resolveStage({ client, slug, repo, }) {
34
34
  }
35
35
  return stages[0];
36
36
  }
37
- export async function attachSecretToStage({ client, stageId, deployTarget, symbolic, secretId, }) {
37
+ export async function attachSecretToStage({ client, stageId, deployTarget, symbolic, secretId, entryKey, }) {
38
38
  await postJson({
39
39
  ...client,
40
40
  path: `/api/data-pipelines/stages/${encodeURIComponent(stageId)}/secret-bindings`,
41
- body: { deployTarget, symbolic, secretId },
41
+ body: { deployTarget, symbolic, secretId, ...(entryKey ? { entryKey } : {}) },
42
42
  });
43
43
  }
44
44
  export async function listStageBindings({ client, stageId }) {
@@ -134,6 +134,10 @@ export async function reconcileStageCredentials({ client, repo, stageIds, deploy
134
134
  result.unresolved.push({ ...credential, reason: `you are not an editor on ${credential.managedSecretName}` });
135
135
  continue;
136
136
  }
137
+ if (secret.valueType === 'key_value') {
138
+ result.unresolved.push({ ...credential, reason: `${credential.managedSecretName} is a key/value set; attach a selected entry with seq-studio secrets attach ${credential.managedSecretName} --stage ${credential.stage.slug} --credential ${credential.symbolic} --entry KEY` });
139
+ continue;
140
+ }
137
141
  await attachSecretToStage({
138
142
  client,
139
143
  stageId: credential.stage.id,
@@ -810,6 +810,10 @@ export async function simulateCommand(args) {
810
810
  // doctor (token + env + FGA gate)
811
811
  // ---------------------------------------------------------------------------
812
812
  export async function doctorCommand(args) {
813
+ if (args.flags.help || args.positional.includes('-h') || args.positional[0] === 'help') {
814
+ console.log('usage: seq-studio doctor [-e <env>]\n\nDiagnose configuration, authentication, and deployment access. Help is offline.');
815
+ return 0;
816
+ }
813
817
  const lines = [];
814
818
  let ok = true;
815
819
  const config = await readConfig().catch(() => null);
@@ -23,6 +23,15 @@ export declare function smartHttpCloneDepth({ ref, full, }: {
23
23
  ref?: string;
24
24
  full: boolean;
25
25
  }): number | undefined;
26
+ /**
27
+ * buildContext for repos commands: rejects a valueless -e/--env (which would
28
+ * silently fall back to the default environment — dangerous with `delete
29
+ * --yes`) and threads the Cloudflare preview WAF bypass header to
30
+ * artifact-studio's HTTP client, which resolveRepo/materializeRepo use
31
+ * (mirrors applyPreviewAccessHeader in ../artifact/delegate.ts — studio-cli's
32
+ * own atlas-client reads PREVIEW_ACCESS_HEADER directly).
33
+ */
34
+ export declare function reposContext(args: ParsedArgs): Promise<CommandContext>;
26
35
  /** Smart-HTTP clone base (aligned with PLA-83: `…/repos/<id>/git`). */
27
36
  export declare function cloneUrl(ctx: CommandContext, repoId: string): string;
28
37
  /**
@@ -106,6 +115,6 @@ export declare function reposCiRequireCommand(args: ParsedArgs): Promise<number>
106
115
  export declare function reposCiImportCommand(args: ParsedArgs): Promise<number>;
107
116
  export declare function reposCiCommand(args: ParsedArgs): Promise<number>;
108
117
  export declare function reposDeleteCommand(args: ParsedArgs): Promise<number>;
109
- 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 gcs_isomorphic|walgit]\n create a repo (GCS default, seed README;\n walgit starts empty on main; needs namespace write)\n seq-studio repos clone <ns>/<name> -e <env> [--ref r] [--output dir] [--force] [--full]\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 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). Without ATLAS_GIT_PAT, <ns>/<name> falls back to the JSON API and prints\n how to get a PAT (seq-studio or Atlas UI /settings/tokens).\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";
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]\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). Without ATLAS_GIT_PAT, <ns>/<name> falls back to the JSON API and prints\n how to get a PAT (seq-studio or Atlas UI /settings/tokens).\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";
110
119
  export declare function runReposCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;
111
120
  export {};