@sequenceholdings/studio-cli 0.2.2 → 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 (128) hide show
  1. package/README.md +616 -78
  2. package/dist/access/commands.d.ts +3 -0
  3. package/dist/access/commands.js +91 -0
  4. package/dist/agents/commands.d.ts +1 -1
  5. package/dist/agents/commands.js +5 -0
  6. package/dist/agents/scaffold.js +5 -7
  7. package/dist/agents/voice-authoring.d.ts +5 -0
  8. package/dist/agents/voice-authoring.js +75 -0
  9. package/dist/agents/voice-publication.d.ts +5 -0
  10. package/dist/agents/voice-publication.js +63 -0
  11. package/dist/agents/voice-shared.d.ts +20 -0
  12. package/dist/agents/voice-shared.js +112 -0
  13. package/dist/agents/voice.d.ts +3 -0
  14. package/dist/agents/voice.js +57 -0
  15. package/dist/app/adapters.d.ts +6 -0
  16. package/dist/app/adapters.js +17 -2
  17. package/dist/app/agent-refs.d.ts +16 -0
  18. package/dist/app/agent-refs.js +36 -0
  19. package/dist/app/application-registration.d.ts +36 -6
  20. package/dist/app/application-registration.js +60 -15
  21. package/dist/app/commands.js +19 -2
  22. package/dist/app/deploy.d.ts +3 -0
  23. package/dist/app/deploy.js +22 -6
  24. package/dist/app/env-bindings.d.ts +21 -0
  25. package/dist/app/env-bindings.js +184 -0
  26. package/dist/app/manifest-validation.js +8 -0
  27. package/dist/app/manifest.d.ts +32 -14
  28. package/dist/app/manifest.js +16 -6
  29. package/dist/app/primitive-scaffold.d.ts +4 -1
  30. package/dist/app/primitive-scaffold.js +4 -4
  31. package/dist/app/readme.js +1 -0
  32. package/dist/app/scaffold-files.js +1 -1
  33. package/dist/app/scaffold.d.ts +6 -4
  34. package/dist/app/scaffold.js +7 -4
  35. package/dist/app/workspace-scaffold.js +12 -7
  36. package/dist/argv.d.ts +7 -0
  37. package/dist/argv.js +56 -0
  38. package/dist/artifact/delegate.js +8 -4
  39. package/dist/atlas-client.d.ts +6 -0
  40. package/dist/atlas-client.js +39 -2
  41. package/dist/auth-cmds/commands.d.ts +1 -1
  42. package/dist/auth-cmds/commands.js +16 -0
  43. package/dist/auth.d.ts +32 -0
  44. package/dist/auth.js +170 -33
  45. package/dist/bin.js +23 -4
  46. package/dist/command-contract.d.ts +137 -0
  47. package/dist/command-contract.js +43 -0
  48. package/dist/command-help.d.ts +8 -0
  49. package/dist/command-help.js +71 -0
  50. package/dist/command-input.d.ts +15 -0
  51. package/dist/command-input.js +33 -0
  52. package/dist/functions/commands.d.ts +2 -1
  53. package/dist/functions/commands.js +78 -33
  54. package/dist/functions/deploy-preflight.d.ts +21 -0
  55. package/dist/functions/deploy-preflight.js +58 -0
  56. package/dist/functions/egress-postgres.d.ts +7 -0
  57. package/dist/functions/egress-postgres.js +36 -0
  58. package/dist/functions/manifest.d.ts +15 -1
  59. package/dist/functions/manifest.js +49 -12
  60. package/dist/functions/secret-reconcile.d.ts +3 -3
  61. package/dist/functions/secret-reconcile.js +5 -7
  62. package/dist/functions/source-selection.js +4 -1
  63. package/dist/main.d.ts +2 -0
  64. package/dist/main.js +75 -25
  65. package/dist/manifest-roles-notice.d.ts +33 -0
  66. package/dist/manifest-roles-notice.js +75 -0
  67. package/dist/orm/delegate.d.ts +16 -0
  68. package/dist/orm/delegate.js +142 -7
  69. package/dist/pipeline/clone-deploy.d.ts +37 -0
  70. package/dist/pipeline/clone-deploy.js +125 -0
  71. package/dist/pipeline/codegen.js +6 -2
  72. package/dist/pipeline/commands.js +21 -5
  73. package/dist/pipeline/lifecycle.d.ts +1 -0
  74. package/dist/pipeline/lifecycle.js +95 -44
  75. package/dist/pipeline/repin-orm.js +6 -2
  76. package/dist/pipeline/stage-secrets.d.ts +4 -1
  77. package/dist/pipeline/stage-secrets.js +7 -3
  78. package/dist/process/build.js +17 -0
  79. package/dist/process/codegen.js +16 -0
  80. package/dist/process/commands.d.ts +15 -7
  81. package/dist/process/commands.js +294 -98
  82. package/dist/process/lint.js +35 -0
  83. package/dist/process/plan-diff.js +9 -0
  84. package/dist/process/simulate.js +8 -0
  85. package/dist/release-age.d.ts +12 -0
  86. package/dist/release-age.js +24 -0
  87. package/dist/repos/commands.d.ts +10 -1
  88. package/dist/repos/commands.js +42 -8
  89. package/dist/repos/pulls.d.ts +3 -0
  90. package/dist/repos/pulls.js +131 -0
  91. package/dist/scaffold-guidance.d.ts +4 -0
  92. package/dist/scaffold-guidance.js +15 -0
  93. package/dist/secrets/commands.d.ts +1 -1
  94. package/dist/secrets/commands.js +97 -16
  95. package/dist/service-accounts/commands.d.ts +3 -0
  96. package/dist/service-accounts/commands.js +50 -0
  97. package/dist/storage/commands.js +23 -1
  98. package/dist/storage/gcs-download.d.ts +13 -0
  99. package/dist/storage/gcs-download.js +41 -0
  100. package/dist/storage/import-cycle.d.ts +41 -0
  101. package/dist/storage/import-cycle.js +123 -0
  102. package/dist/storage/import-files.d.ts +30 -0
  103. package/dist/storage/import-files.js +133 -0
  104. package/dist/storage/import-gcloud.d.ts +12 -0
  105. package/dist/storage/import-gcloud.js +54 -0
  106. package/dist/storage/import-identity.d.ts +12 -0
  107. package/dist/storage/import-identity.js +15 -0
  108. package/dist/storage/import-plan.d.ts +120 -0
  109. package/dist/storage/import-plan.js +189 -0
  110. package/dist/storage/import-preflight.d.ts +36 -0
  111. package/dist/storage/import-preflight.js +62 -0
  112. package/dist/storage/import-progress-map.d.ts +5 -0
  113. package/dist/storage/import-progress-map.js +22 -0
  114. package/dist/storage/import-recover.d.ts +97 -0
  115. package/dist/storage/import-recover.js +186 -0
  116. package/dist/storage/import-run.d.ts +14 -0
  117. package/dist/storage/import-run.js +140 -0
  118. package/dist/templates/guidance/AGENTS.md +10 -0
  119. package/dist/templates/guidance/CLAUDE.md +1 -0
  120. package/dist/templates/process/package.json +2 -2
  121. package/dist/templates/process/pnpm-workspace.yaml +7 -4
  122. package/dist/validation-detail.d.ts +2 -0
  123. package/dist/validation-detail.js +20 -0
  124. package/package.json +9 -9
  125. package/templates/guidance/AGENTS.md +10 -0
  126. package/templates/guidance/CLAUDE.md +1 -0
  127. package/templates/process/package.json +2 -2
  128. package/templates/process/pnpm-workspace.yaml +7 -4
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Publish a local pipeline checkout into an environment's git service, then
3
+ * let the ordinary deploy read that commit back. The plan/deploy worker
4
+ * materializes source from the target environment's git service, so a laptop
5
+ * directory cannot be the deploy source by itself.
6
+ *
7
+ * Clone publish is limited to targets that do not require approval. BankSouth
8
+ * and production keep deploying commits that already live in that
9
+ * environment's git service.
10
+ */
11
+ import { spawn } from 'node:child_process';
12
+ import { execFile } from 'node:child_process';
13
+ import { promisify } from 'node:util';
14
+ import { postJson } from '../atlas-client.js';
15
+ import { gitServiceCloneUrl, resolveGitPatFromEnv, withGitAskpass, } from '@sequenceholdings/artifact-studio/git-clone';
16
+ import { resolveRepo } from '@sequenceholdings/artifact-studio/git-service-client';
17
+ const execFileAsync = promisify(execFile);
18
+ export function assertCloneDeployAllowed(target) {
19
+ if (!target.requiresApproval)
20
+ return;
21
+ throw new Error(`pipeline deploy from a local clone is only supported on targets that do not require approval (got '${target.id}'). ` +
22
+ 'Push the commit to that environment\'s git service, then deploy with --repo and --ref.');
23
+ }
24
+ const RELEASE_REPO = /^(pipelines|apps)\/([a-z][a-z0-9-]*)$/;
25
+ export function parseCloneDeployRepo(repo) {
26
+ const match = RELEASE_REPO.exec(repo);
27
+ if (!match) {
28
+ throw new Error(`--repo must be pipelines/<name> or apps/<name> (got '${repo}')`);
29
+ }
30
+ return { namespace: match[1], name: match[2] };
31
+ }
32
+ export async function readCloneHead(dir) {
33
+ const branch = (await gitOutput(dir, ['rev-parse', '--abbrev-ref', 'HEAD'])).trim();
34
+ if (!branch || branch === 'HEAD') {
35
+ throw new Error(`check out a branch in ${dir} before deploying it`);
36
+ }
37
+ if (!/^[A-Za-z0-9._/-]+$/.test(branch) || branch.includes('..') || branch.startsWith('/') || branch.endsWith('/')) {
38
+ throw new Error(`refusing to publish branch '${branch}'`);
39
+ }
40
+ const sha = (await gitOutput(dir, ['rev-parse', 'HEAD'])).trim().toLowerCase();
41
+ if (!/^[0-9a-f]{40}$/.test(sha)) {
42
+ throw new Error(`${dir} HEAD is not a commit (${sha || 'empty'})`);
43
+ }
44
+ const dirty = await gitOutput(dir, ['status', '--porcelain']);
45
+ if (dirty.trim()) {
46
+ throw new Error('clone deploy requires a clean worktree. Commit or stash local changes, then retry.');
47
+ }
48
+ return { sha, branch };
49
+ }
50
+ async function gitOutput(dir, args) {
51
+ try {
52
+ const { stdout } = await execFileAsync('git', args, { cwd: dir });
53
+ return stdout;
54
+ }
55
+ catch (error) {
56
+ const detail = error instanceof Error ? error.message : String(error);
57
+ throw new Error(`git ${args.join(' ')} failed in ${dir}: ${detail}`);
58
+ }
59
+ }
60
+ export async function pushCloneHead({ dir, cloneUrl, sha, branch, pat, }) {
61
+ await withGitAskpass({
62
+ pat,
63
+ fn: (env) => spawnGit({
64
+ args: ['push', cloneUrl, `${sha}:refs/heads/${branch}`],
65
+ cwd: dir,
66
+ env,
67
+ }),
68
+ });
69
+ }
70
+ function spawnGit({ args, cwd, env, }) {
71
+ return new Promise((resolve, reject) => {
72
+ const child = spawn('git', args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'] });
73
+ let stderr = '';
74
+ child.stderr?.on('data', (chunk) => {
75
+ stderr += chunk.toString();
76
+ });
77
+ child.on('error', reject);
78
+ child.on('close', (code) => {
79
+ if (code === 0) {
80
+ resolve();
81
+ return;
82
+ }
83
+ reject(new Error(`git push failed (exit ${code ?? 'null'}): ${stderr.trim() || 'no stderr'}`));
84
+ });
85
+ });
86
+ }
87
+ /**
88
+ * Ensure `<repo>` exists on the target environment and contains this
89
+ * checkout's HEAD. Returns the SHA the caller should pass as `--ref`.
90
+ */
91
+ export async function publishCloneForDeploy({ dir, repo, baseUrl, token, pat = resolveGitPatFromEnv(), }) {
92
+ if (!pat) {
93
+ throw new Error('Deploying a local clone requires a git PAT. Set ATLAS_GIT_PAT to a token with repo:write ' +
94
+ '(create one in Atlas → Settings → Tokens, or `seq-studio auth pat create`).');
95
+ }
96
+ const { namespace, name } = parseCloneDeployRepo(repo);
97
+ const head = await readCloneHead(dir);
98
+ const destination = await ensureReleaseRepo({ baseUrl, token, namespace, name });
99
+ const cloneUrl = gitServiceCloneUrl(baseUrl, destination.id);
100
+ await pushCloneHead({ dir, cloneUrl, sha: head.sha, branch: head.branch, pat });
101
+ // A new walgit repo's default branch is main, but the ref does not exist until
102
+ // something is pushed to it. Publishing only the checkout branch leaves
103
+ // `repos clone` (no --ref) unable to resolve main.
104
+ if (destination.created && head.branch !== 'main') {
105
+ await pushCloneHead({ dir, cloneUrl, sha: head.sha, branch: 'main', pat });
106
+ }
107
+ return { ...head, repoId: destination.id, created: destination.created };
108
+ }
109
+ async function ensureReleaseRepo({ baseUrl, token, namespace, name, }) {
110
+ try {
111
+ const existing = await resolveRepo({ baseUrl, token, namespace, name });
112
+ return { id: existing.id, created: false };
113
+ }
114
+ catch (error) {
115
+ if (!(error instanceof Error) || !error.message.startsWith('Repo "'))
116
+ throw error;
117
+ }
118
+ const created = await postJson({
119
+ baseUrl,
120
+ token,
121
+ path: '/api/git-service/repos',
122
+ body: { namespaceSlug: namespace, name, gitBackend: 'walgit' },
123
+ });
124
+ return { id: created.id, created: true };
125
+ }
@@ -55,7 +55,11 @@ export async function pipelineCodegenTablesCommand(args) {
55
55
  const from = typeof args.flags.from === 'string'
56
56
  ? args.flags.from
57
57
  : join(process.cwd(), 'authoring.tables.ts');
58
- const dir = resolve(typeof args.flags.dir === 'string' ? args.flags.dir : '.');
58
+ const pipelineRoot = resolve(typeof args.flags.dir === 'string' ? args.flags.dir : '.');
59
+ const config = await spec.loadPipelineConfig({ dir: pipelineRoot, allowMissingRoot: true });
60
+ const stageDirectory = config.stage_directories[0] ?? '.';
61
+ const dir = resolve(pipelineRoot, stageDirectory);
62
+ await spec.assertStageDirectoryContained({ root: pipelineRoot, directory: stageDirectory });
59
63
  const dryRun = args.flags['dry-run'] === true;
60
64
  let authoring;
61
65
  try {
@@ -113,6 +117,6 @@ export async function pipelineCodegenTablesCommand(args) {
113
117
  await writeFile(target, file.yaml, 'utf8');
114
118
  console.log(`${LOG} wrote ${target}`);
115
119
  }
116
- console.log(`${LOG} next: seq-studio pipeline validate ${dir === process.cwd() ? '.' : dir}`);
120
+ console.log(`${LOG} next: seq-studio pipeline validate ${pipelineRoot === process.cwd() ? '.' : pipelineRoot}`);
117
121
  return 0;
118
122
  }
@@ -17,6 +17,7 @@ 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 { writeScaffoldGuidance } from '../scaffold-guidance.js';
20
21
  import { PIPELINE_DISCOVERY_USAGE, runPipelineDiscoveryCommand } from './discovery.js';
21
22
  import { renderEntrypointStub, renderStageTemplate, STAGE_TYPES, } from './templates.js';
22
23
  const LOG = '[seq-studio]';
@@ -25,7 +26,8 @@ export const ORM_CONTRACTS_FILENAME = 'orm-contracts.json';
25
26
  const PIPELINE_USAGE = `usage:
26
27
  ${PIPELINE_DISCOVERY_USAGE}
27
28
  seq-studio pipeline init --type ingestion|transformation|serving <name> [--dir <dir>]
28
- scaffold <name>.stage.yml (commented template) + src/ entrypoint stub
29
+ scaffold <name>.stage.yml in the first configured stage directory (or
30
+ package root without config) + package-root-relative src/ entrypoint stub
29
31
 
30
32
  seq-studio pipeline validate [dir] [--assets <file|url>] [--orm-contracts <file|url>] [--json]
31
33
  run the offline spec gate: envelope + body validation, schema_ref
@@ -55,11 +57,20 @@ ${PIPELINE_DISCOVERY_USAGE}
55
57
  skips this
56
58
  --migration adds a coordinated writer/ORM assessment; it cannot be
57
59
  applied through ordinary deploy
60
+ seq-studio pipeline plan --plan-request-id <id> -e <env> [--json]
61
+ read and poll an existing plan without enqueueing a new one or attaching
62
+ credentials. Use the request id printed when planning started.
63
+ JSON results use stdout; enqueue/polling progress uses stderr.
58
64
 
59
65
  seq-studio pipeline deploy --repo <namespace>/<slug> --ref <sha|branch> -e <env>
60
66
  [--target <id>] [--approved-by <sub>]
61
67
  [--allow-destructive <resource-key> ...]
62
68
  [--run-now] [--wait-timeout <duration>] [--no-wait] [--no-provision] [--json]
69
+ seq-studio pipeline deploy --dir <checkout> --repo <namespace>/<slug> -e <env>
70
+ publish a clean local checkout into that environment's git service, then
71
+ deploy the published commit. Only targets that do not require approval
72
+ (dev, staging). BankSouth and production still deploy a commit that
73
+ already exists in that environment's git service. Requires ATLAS_GIT_PAT.
63
74
  plan (attaching missing credentials as for plan) then enqueue Trigger deploy (DAB bundle validate hard-gates before
64
75
  bundle deploy). Default is plant-only: jobs/pipelines are created, not
65
76
  run. Pass --run-now to run in-unit producer roots after bundle deploy.
@@ -79,12 +90,12 @@ ${PIPELINE_DISCOVERY_USAGE}
79
90
 
80
91
  seq-studio pipeline promote --stage <slug> --version <v> -e <env>
81
92
  [--target <id>] [--repo <namespace>/<slug>] [--approved-by <you>]
82
- [--wait-timeout <duration>] [--no-wait]
93
+ [--wait-timeout <duration>] [--no-wait] [--json]
83
94
  promote a validated version to the next environment (approvals are
84
95
  self-recorded: --approved-by must name the authenticated caller)
85
96
 
86
97
  seq-studio pipeline rollback --stage <slug> -e <env> [--target <id>] [--repo <namespace>/<slug>]
87
- [--approved-by <you>] [--wait-timeout <duration>] [--no-wait]
98
+ [--approved-by <you>] [--wait-timeout <duration>] [--no-wait] [--json]
88
99
  redeploy the previously retired deployment's version (production/
89
100
  banksouth require --approved-by — approvals are explicit even for
90
101
  rollbacks)
@@ -168,12 +179,16 @@ export async function pipelineInitCommand(args) {
168
179
  return 1;
169
180
  }
170
181
  const dir = resolve(typeof args.flags.dir === 'string' ? args.flags.dir : '.');
171
- const specPath = join(dir, `${name}.stage.yml`);
182
+ const config = await spec.loadPipelineConfig({ dir, allowMissingRoot: true });
183
+ const stageDirectory = config.stage_directories[0] ?? '.';
184
+ const stageRoot = resolve(dir, stageDirectory);
185
+ await spec.assertStageDirectoryContained({ root: dir, directory: stageDirectory });
186
+ const specPath = join(stageRoot, `${name}.stage.yml`);
172
187
  if (existsSync(specPath)) {
173
188
  console.error(`${LOG} ${specPath} already exists — refusing to overwrite`);
174
189
  return 1;
175
190
  }
176
- await mkdir(dir, { recursive: true });
191
+ await mkdir(stageRoot, { recursive: true });
177
192
  await writeFile(specPath, renderStageTemplate(name, type), 'utf8');
178
193
  console.log(`${LOG} wrote ${specPath}`);
179
194
  // Serving stages are declarative — no entrypoint stub. The template's
@@ -189,6 +204,7 @@ export async function pipelineInitCommand(args) {
189
204
  console.log(`${LOG} wrote ${stubPath}`);
190
205
  }
191
206
  }
207
+ await writeScaffoldGuidance({ directory: dir });
192
208
  const displayDir = typeof args.flags.dir === 'string' ? args.flags.dir : '.';
193
209
  if (type === 'serving') {
194
210
  // A serving stage inherently references its producer — the scaffold's
@@ -6,6 +6,7 @@ import { type ResolvedEnv } from '../config.js';
6
6
  import type { ParsedArgs } from '../process/commands.js';
7
7
  export declare const DEFAULT_DEPLOYMENT_WAIT_TIMEOUT_MS: number;
8
8
  export interface PlanApiResponse {
9
+ planRequestId?: string;
9
10
  plan: {
10
11
  hasDestructive: boolean;
11
12
  findings: Array<{
@@ -6,6 +6,7 @@ import { getAccessToken, NotLoggedInError } from '../auth.js';
6
6
  import { AtlasApiError, getJson, postJson } from '../atlas-client.js';
7
7
  import { resolveEnvWithDiscovery } from '../config.js';
8
8
  import { parseDurationMs } from '@sequenceholdings/lattice';
9
+ import { assertCloneDeployAllowed, publishCloneForDeploy } from './clone-deploy.js';
9
10
  import { printReconcileResult, reconcileStageCredentials } from './stage-secrets.js';
10
11
  const LOG = '[seq-studio]';
11
12
  function rootOption(root) {
@@ -58,7 +59,7 @@ export async function envAndToken(args) {
58
59
  const env = await resolveEnvWithDiscovery({ requested });
59
60
  let token;
60
61
  try {
61
- token = await getAccessToken();
62
+ token = await getAccessToken({ env: env.name, targetUrl: env.url });
62
63
  }
63
64
  catch (error) {
64
65
  if (error instanceof NotLoggedInError)
@@ -122,6 +123,7 @@ export async function resolvePipelineTarget({ args, env, token, }) {
122
123
  export async function pipelinePlanCommand(args) {
123
124
  const repo = flagString(args.flags, 'repo');
124
125
  const ref = flagString(args.flags, 'ref');
126
+ const planRequestId = flagString(args.flags, 'plan-request-id');
125
127
  const root = flagString(args.flags, 'root');
126
128
  const migrationId = flagString(args.flags, 'migration');
127
129
  const inPlace = flagOn(args.flags, 'in-place');
@@ -129,35 +131,39 @@ export async function pipelinePlanCommand(args) {
129
131
  console.error(`${LOG} --in-place requires --migration; choose the mode when planning`);
130
132
  return 1;
131
133
  }
132
- if (!repo || !ref) {
133
- console.error('usage: seq-studio pipeline plan --repo <namespace>/<slug> --ref <sha|branch> [--root <directory>] -e <env> [--migration <id> [--in-place]] [--json]');
134
+ if (planRequestId && ['repo', 'ref', 'root', 'target', 'migration', 'in-place', 'no-provision'].some((flag) => args.flags[flag] !== undefined)) {
135
+ console.error(`${LOG} --plan-request-id reads an existing plan; do not combine it with planning options`);
134
136
  return 1;
135
137
  }
136
- const { env, token } = await envAndToken(args);
137
- const json = args.flags.json === true || args.flags.json === 'true';
138
- let target;
139
- try {
140
- target = await resolvePipelineTarget({ args, env, token });
141
- }
142
- catch (error) {
143
- console.error(`${LOG} plan failed: ${error instanceof Error ? error.message : String(error)}`);
138
+ if (!planRequestId && (!repo || !ref)) {
139
+ console.error('usage: seq-studio pipeline plan --repo <namespace>/<slug> --ref <sha|branch> [--root <directory>] -e <env> [--migration <id> [--in-place]] [--json]\n seq-studio pipeline plan --plan-request-id <id> -e <env> [--json]');
144
140
  return 1;
145
141
  }
142
+ const { env, token } = await envAndToken(args);
143
+ const json = args.flags.json === true || args.flags.json === 'true';
146
144
  let response;
147
145
  try {
148
- response = await planAttachingCredentials({
149
- request: {
150
- baseUrl: env.url,
151
- token,
152
- repo,
153
- ref,
154
- ...rootOption(root),
155
- environment: target.id,
156
- ...(migrationId ? { migrationId } : {}),
157
- ...(inPlace ? { executionMode: 'in_place' } : {}),
158
- },
159
- provision: !flagOn(args.flags, 'no-provision'),
160
- });
146
+ if (planRequestId) {
147
+ response = completedPlanResponse(await waitForPlanRequest({
148
+ baseUrl: env.url, token, planRequestId,
149
+ }));
150
+ }
151
+ else {
152
+ // Required source arguments were checked before authentication.
153
+ if (!repo || !ref)
154
+ return 1;
155
+ const target = await resolvePipelineTarget({ args, env, token });
156
+ response = await planAttachingCredentials({
157
+ request: {
158
+ baseUrl: env.url, token, repo, ref,
159
+ ...rootOption(root),
160
+ environment: target.id,
161
+ ...(migrationId ? { migrationId } : {}),
162
+ ...(inPlace ? { executionMode: 'in_place' } : {}),
163
+ },
164
+ provision: !flagOn(args.flags, 'no-provision'),
165
+ });
166
+ }
161
167
  }
162
168
  catch (error) {
163
169
  console.error(`${LOG} plan failed: ${error instanceof Error ? error.message : String(error)}`);
@@ -170,6 +176,9 @@ export async function pipelinePlanCommand(args) {
170
176
  console.log(response.text);
171
177
  printFindingsTable(response.plan.findings);
172
178
  }
179
+ return planResultExitCode({ response, inPlace, migrationId });
180
+ }
181
+ function planResultExitCode({ response, inPlace, migrationId, }) {
173
182
  if (inPlace && response.plan.migrationExecutionMode !== 'in_place') {
174
183
  console.error(`${LOG} server did not confirm in-place mode; do not start this plan`);
175
184
  return 1;
@@ -185,6 +194,7 @@ export async function pipelineDeployCommand(args) {
185
194
  }
186
195
  const repo = flagString(args.flags, 'repo');
187
196
  const ref = flagString(args.flags, 'ref');
197
+ const dir = flagString(args.flags, 'dir');
188
198
  const root = flagString(args.flags, 'root');
189
199
  const deploymentId = flagString(args.flags, 'deployment-id');
190
200
  const approvedBy = flagString(args.flags, 'approved-by');
@@ -225,13 +235,36 @@ export async function pipelineDeployCommand(args) {
225
235
  });
226
236
  }
227
237
  else {
228
- if (!repo || !ref) {
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]');
238
+ if (dir && ref) {
239
+ console.error(`${LOG} pass either --dir or --ref, not both`);
240
+ return 1;
241
+ }
242
+ let sourceRef = ref;
243
+ if (dir) {
244
+ if (!repo) {
245
+ console.error('usage: seq-studio pipeline deploy --dir <checkout> --repo <namespace>/<slug> -e <env>');
246
+ return 1;
247
+ }
248
+ try {
249
+ assertCloneDeployAllowed(target);
250
+ const published = await publishCloneForDeploy({ dir, repo, baseUrl: env.url, token });
251
+ sourceRef = published.sha;
252
+ console.error(`${LOG} published ${repo}@${published.sha.slice(0, 12)} ` +
253
+ `(${published.branch}${published.created ? ', created repo' : ''}) on ${env.name}`);
254
+ }
255
+ catch (error) {
256
+ console.error(`${LOG} deploy failed: ${error instanceof Error ? error.message : String(error)}`);
257
+ return 1;
258
+ }
259
+ }
260
+ if (!repo || !sourceRef) {
261
+ 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]\n' +
262
+ ' seq-studio pipeline deploy --dir <checkout> --repo <namespace>/<slug> -e <env>');
230
263
  return 1;
231
264
  }
232
265
  // Plan then deploy the first planning deployment.
233
266
  const plan = await planAttachingCredentials({
234
- request: { baseUrl: env.url, token, repo, ref, environment: target.id, ...rootOption(root) },
267
+ request: { baseUrl: env.url, token, repo, ref: sourceRef, environment: target.id, ...rootOption(root) },
235
268
  provision: !flagOn(args.flags, 'no-provision'),
236
269
  });
237
270
  if (plan.plan.hasDestructive && allowDestructiveResourceKeys.length === 0) {
@@ -273,8 +306,10 @@ export async function pipelineDeployCommand(args) {
273
306
  }
274
307
  throw error;
275
308
  }
276
- console.log(`${LOG} enqueued deploy ${enqueue.deploymentId} (trigger=${enqueue.triggerRunId ?? 'n/a'})`);
277
- if (args.flags['no-wait'] === true || args.flags['no-wait'] === 'true') {
309
+ console.error(`${LOG} enqueued deploy ${enqueue.deploymentId} (trigger=${enqueue.triggerRunId ?? 'n/a'})`);
310
+ if (flagOn(args.flags, 'no-wait')) {
311
+ if (flagOn(args.flags, 'json'))
312
+ console.log(JSON.stringify(enqueue, null, 2));
278
313
  return 0;
279
314
  }
280
315
  return pollDeployment({
@@ -283,6 +318,7 @@ export async function pipelineDeployCommand(args) {
283
318
  deploymentId: enqueue.deploymentId,
284
319
  environment: env.name,
285
320
  timeoutMs: waitTimeoutMs,
321
+ json: flagOn(args.flags, 'json'),
286
322
  });
287
323
  }
288
324
  export async function pipelineStatusCommand(args) {
@@ -359,9 +395,12 @@ export async function pipelinePromoteCommand(args) {
359
395
  }
360
396
  throw error;
361
397
  }
362
- console.log(`${LOG} enqueued promote plan ${enqueue.planRequestId} (trigger=${enqueue.triggerRunId ?? 'n/a'})`);
363
- if (args.flags['no-wait'] === true || args.flags['no-wait'] === 'true')
398
+ console.error(`${LOG} enqueued promote plan ${enqueue.planRequestId} (trigger=${enqueue.triggerRunId ?? 'n/a'})`);
399
+ if (flagOn(args.flags, 'no-wait')) {
400
+ if (flagOn(args.flags, 'json'))
401
+ console.log(JSON.stringify(enqueue, null, 2));
364
402
  return 0;
403
+ }
365
404
  const plan = await waitForPlanRequest({
366
405
  baseUrl: env.url,
367
406
  token,
@@ -378,6 +417,7 @@ export async function pipelinePromoteCommand(args) {
378
417
  deploymentId,
379
418
  environment: env.name,
380
419
  timeoutMs: waitTimeoutMs,
420
+ json: flagOn(args.flags, 'json'),
381
421
  });
382
422
  }
383
423
  export async function pipelineRunNowCommand(args) {
@@ -473,15 +513,19 @@ export async function pipelineRollbackCommand(args) {
473
513
  }
474
514
  throw error;
475
515
  }
476
- console.log(`${LOG} enqueued rollback ${enqueue.deploymentId}`);
477
- if (args.flags['no-wait'] === true || args.flags['no-wait'] === 'true')
516
+ console.error(`${LOG} enqueued rollback ${enqueue.deploymentId}`);
517
+ if (flagOn(args.flags, 'no-wait')) {
518
+ if (flagOn(args.flags, 'json'))
519
+ console.log(JSON.stringify(enqueue, null, 2));
478
520
  return 0;
521
+ }
479
522
  return pollDeployment({
480
523
  baseUrl: env.url,
481
524
  token,
482
525
  deploymentId: enqueue.deploymentId,
483
526
  environment: env.name,
484
527
  timeoutMs: waitTimeoutMs,
528
+ json: flagOn(args.flags, 'json'),
485
529
  });
486
530
  }
487
531
  function printFindingsTable(findings) {
@@ -497,7 +541,7 @@ function printFindingsTable(findings) {
497
541
  console.log(`${LOG} ${klass.padEnd(12)} ${f.resourceKey.padEnd(32)} ${f.message}`);
498
542
  }
499
543
  }
500
- async function pollDeployment({ baseUrl, token, deploymentId, environment, timeoutMs, }) {
544
+ async function pollDeployment({ baseUrl, token, deploymentId, environment, timeoutMs, json, }) {
501
545
  const started = Date.now();
502
546
  let lastLoggedLabel = null;
503
547
  let lastLogAt = started;
@@ -509,10 +553,12 @@ async function pollDeployment({ baseUrl, token, deploymentId, environment, timeo
509
553
  });
510
554
  const elapsedMs = Date.now() - started;
511
555
  if (TERMINAL.has(detail.status)) {
556
+ if (json)
557
+ console.log(JSON.stringify(detail, null, 2));
512
558
  const elapsed = formatElapsed(elapsedMs);
513
559
  const progressSuffix = deploymentProgressSuffix(detail);
514
560
  if (detail.status === 'active') {
515
- console.log(`${LOG} deployment ${deploymentId} succeeded (${elapsed})${progressSuffix}`);
561
+ console.error(`${LOG} deployment ${deploymentId} succeeded (${elapsed})${progressSuffix}`);
516
562
  return 0;
517
563
  }
518
564
  const detailText = detail.statusDetail ? `: ${detail.statusDetail}` : '';
@@ -522,12 +568,12 @@ async function pollDeployment({ baseUrl, token, deploymentId, environment, timeo
522
568
  const progressSuffix = deploymentProgressSuffix(detail);
523
569
  const statusLabel = deploymentStatusLabel(detail);
524
570
  if (statusLabel !== lastLoggedLabel) {
525
- console.log(`${LOG} deployment ${deploymentId}: ${statusLabel} (${formatElapsed(elapsedMs)})${progressSuffix}`);
571
+ console.error(`${LOG} deployment ${deploymentId}: ${statusLabel} (${formatElapsed(elapsedMs)})${progressSuffix}`);
526
572
  lastLoggedLabel = statusLabel;
527
573
  lastLogAt = Date.now();
528
574
  }
529
575
  else if (Date.now() - lastLogAt >= HEARTBEAT_INTERVAL_MS) {
530
- console.log(`${LOG} deployment ${deploymentId}: still ${statusLabel} (${formatElapsed(elapsedMs)})${progressSuffix}`);
576
+ console.error(`${LOG} deployment ${deploymentId}: still ${statusLabel} (${formatElapsed(elapsedMs)})${progressSuffix}`);
531
577
  lastLogAt = Date.now();
532
578
  }
533
579
  await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
@@ -556,13 +602,13 @@ async function planAttachingCredentials({ request, provision, }) {
556
602
  throw error;
557
603
  if (!(await attachUnattachedCredentials({ request, stageIds: error.stageIds })))
558
604
  throw error;
559
- console.log(`${LOG} re-planning with the attached secrets`);
605
+ console.error(`${LOG} re-planning with the attached secrets`);
560
606
  return enqueueAndWaitForPlan(request);
561
607
  }
562
608
  // A new stage can also plan the legacy way (a same-named secret exists) with
563
609
  // nothing attached, and its get_credential would then fail at runtime.
564
610
  if (provision && (await attachUnattachedCredentials({ request, stageIds: response.stageIds }))) {
565
- console.log(`${LOG} re-planning with the attached secrets`);
611
+ console.error(`${LOG} re-planning with the attached secrets`);
566
612
  return enqueueAndWaitForPlan(request);
567
613
  }
568
614
  return response;
@@ -615,16 +661,20 @@ async function enqueueAndWaitForPlan({ baseUrl, token, repo, ref, root, environm
615
661
  path: '/api/data-pipelines/pipelines/plan',
616
662
  body: { repo, ref, environment, ...rootOption(root), ...(migrationId ? { migration_id: migrationId } : {}), ...(executionMode ? { execution_mode: executionMode } : {}) },
617
663
  });
618
- console.log(`${LOG} enqueued plan ${enqueue.planRequestId} (trigger=${enqueue.triggerRunId ?? 'n/a'})`);
664
+ console.error(`${LOG} enqueued plan ${enqueue.planRequestId} (trigger=${enqueue.triggerRunId ?? 'n/a'})`);
619
665
  const detail = await waitForPlanRequest({
620
666
  baseUrl,
621
667
  token,
622
668
  planRequestId: enqueue.planRequestId,
623
669
  });
670
+ return completedPlanResponse(detail);
671
+ }
672
+ function completedPlanResponse(detail) {
624
673
  if (!detail.plan || !detail.text) {
625
674
  throw new Error(`plan request ${detail.planRequestId} succeeded without a plan result`);
626
675
  }
627
676
  return {
677
+ planRequestId: detail.planRequestId,
628
678
  plan: detail.plan,
629
679
  deploymentIds: detail.deploymentIds,
630
680
  stageIds: detail.stageIds,
@@ -640,7 +690,7 @@ async function waitForPlanRequest({ baseUrl, token, planRequestId, }) {
640
690
  const detail = await getJson({
641
691
  baseUrl,
642
692
  token,
643
- path: `/api/data-pipelines/plan-requests/${planRequestId}`,
693
+ path: `/api/data-pipelines/plan-requests/${encodeURIComponent(planRequestId)}`,
644
694
  });
645
695
  const elapsed = Date.now() - started;
646
696
  const statusLabel = detail.statusDetail
@@ -653,18 +703,19 @@ async function waitForPlanRequest({ baseUrl, token, planRequestId, }) {
653
703
  if (detail.status === 'succeeded')
654
704
  return detail;
655
705
  if (statusLabel !== lastStatus) {
656
- console.log(`${LOG} plan ${detail.planRequestId}: ${statusLabel} (${formatElapsed(elapsed)})`);
706
+ console.error(`${LOG} plan ${detail.planRequestId}: ${statusLabel} (${formatElapsed(elapsed)})`);
657
707
  lastStatus = statusLabel;
658
708
  lastLoggedAt = Date.now();
659
709
  }
660
710
  else if (Date.now() - lastLoggedAt >= HEARTBEAT_INTERVAL_MS) {
661
- console.log(`${LOG} plan ${detail.planRequestId}: still ${statusLabel} (${formatElapsed(elapsed)})`);
711
+ console.error(`${LOG} plan ${detail.planRequestId}: still ${statusLabel} (${formatElapsed(elapsed)})`);
662
712
  lastLoggedAt = Date.now();
663
713
  }
664
714
  await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
665
715
  }
666
716
  throw new Error(`timed out waiting for plan request ${planRequestId} ` +
667
- `(${formatElapsed(Date.now() - started)})`);
717
+ `(${formatElapsed(Date.now() - started)}). Local polling stopped without cancelling the remote plan. ` +
718
+ `Read it again with: seq-studio pipeline plan --plan-request-id ${planRequestId} -e <environment> --json`);
668
719
  }
669
720
  export async function pipelineAdoptCommand(args) {
670
721
  const stage = flagString(args.flags, 'stage');
@@ -162,8 +162,12 @@ export async function pipelineRepinOrmCommand(args) {
162
162
  }
163
163
  const writes = [];
164
164
  for (const stage of pinnedStages) {
165
- const file = pipeline.files.find((candidate) => candidate === `${stage.stage}.stage.yml` ||
166
- candidate === `${stage.stage}.stage.yaml`) ?? `${stage.stage}.stage.yml`;
165
+ const file = pipeline.files.find((candidate) => {
166
+ const basename = candidate.split('/').at(-1);
167
+ return basename === `${stage.stage}.stage.yml` || basename === `${stage.stage}.stage.yaml`;
168
+ });
169
+ if (!file)
170
+ throw new Error(`could not find the source file for stage '${stage.stage}'`);
167
171
  const current = await readFile(join(dir, file), 'utf8');
168
172
  const nextHash = nextHashes.get(stage.stage);
169
173
  if (!nextHash)
@@ -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,
@@ -156,7 +160,7 @@ function unresolvedReason({ credential, named, matches, }) {
156
160
  }
157
161
  export function printReconcileResult({ result, deployTarget }) {
158
162
  for (const { stage, symbolic, managedSecretName } of result.attached) {
159
- console.log(`${LOG} attached ${managedSecretName} to ${stage.slug} (${symbolic}) for ${deployTarget}`);
163
+ console.error(`${LOG} attached ${managedSecretName} to ${stage.slug} (${symbolic}) for ${deployTarget}`);
160
164
  }
161
165
  for (const { stage, symbolic, managedSecretName, reason } of result.unresolved) {
162
166
  console.error(`${LOG} ${stage.slug}: credential ${symbolic} has nothing attached for ${deployTarget} — ${reason}. ` +
@@ -387,6 +387,23 @@ function serializeNodeMetadata(node) {
387
387
  serializeMapperSlot(meta, 'output_mapper', mf.output);
388
388
  return meta;
389
389
  }
390
+ case 'managed_server': {
391
+ const server = node;
392
+ const meta = {
393
+ server_id: server.server,
394
+ path: server.path,
395
+ };
396
+ if (server.limits)
397
+ meta.limits = server.limits;
398
+ if (server.bindings)
399
+ meta.bindings = server.bindings;
400
+ if (server.run_as?.service_account) {
401
+ meta.run_as = { service_account: server.run_as.service_account };
402
+ }
403
+ serializeMapperSlot(meta, 'input_mapper', server.input);
404
+ serializeMapperSlot(meta, 'output_mapper', server.output);
405
+ return meta;
406
+ }
390
407
  default:
391
408
  return {};
392
409
  }