@sequenceholdings/studio-cli 0.3.0 → 0.4.2
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.
- package/README.md +506 -32
- package/dist/agents/commands.d.ts +1 -1
- package/dist/agents/commands.js +5 -0
- package/dist/agents/scaffold.js +5 -7
- package/dist/agents/voice-authoring.d.ts +5 -0
- package/dist/agents/voice-authoring.js +75 -0
- package/dist/agents/voice-publication.d.ts +5 -0
- package/dist/agents/voice-publication.js +63 -0
- package/dist/agents/voice-shared.d.ts +20 -0
- package/dist/agents/voice-shared.js +112 -0
- package/dist/agents/voice.d.ts +3 -0
- package/dist/agents/voice.js +57 -0
- package/dist/app/adapters.d.ts +6 -0
- package/dist/app/adapters.js +17 -2
- package/dist/app/agent-refs.d.ts +16 -0
- package/dist/app/agent-refs.js +36 -0
- package/dist/app/application-registration.d.ts +45 -8
- package/dist/app/application-registration.js +112 -22
- package/dist/app/commands.js +19 -2
- package/dist/app/deploy.d.ts +3 -0
- package/dist/app/deploy.js +18 -4
- package/dist/app/env-bindings.d.ts +21 -0
- package/dist/app/env-bindings.js +184 -0
- package/dist/app/manifest-validation.d.ts +8 -0
- package/dist/app/manifest-validation.js +97 -5
- package/dist/app/manifest.d.ts +45 -9
- package/dist/app/manifest.js +27 -1
- package/dist/app/primitive-scaffold.d.ts +4 -1
- package/dist/app/primitive-scaffold.js +4 -4
- package/dist/app/readme.js +11 -0
- package/dist/app/scaffold-files.js +1 -1
- package/dist/app/scaffold.d.ts +6 -4
- package/dist/app/scaffold.js +7 -4
- package/dist/app/workspace-scaffold.js +12 -7
- package/dist/argv.d.ts +7 -0
- package/dist/argv.js +56 -0
- package/dist/artifact/delegate.js +8 -4
- package/dist/atlas-client.d.ts +6 -0
- package/dist/atlas-client.js +39 -2
- package/dist/auth.d.ts +32 -0
- package/dist/auth.js +170 -33
- package/dist/bin.js +23 -4
- package/dist/command-contract.d.ts +137 -0
- package/dist/command-contract.js +43 -0
- package/dist/command-help.d.ts +8 -0
- package/dist/command-help.js +71 -0
- package/dist/functions/commands.d.ts +1 -1
- package/dist/functions/commands.js +19 -3
- package/dist/functions/deploy-preflight.d.ts +21 -0
- package/dist/functions/deploy-preflight.js +58 -0
- package/dist/functions/egress-postgres.d.ts +7 -0
- package/dist/functions/egress-postgres.js +36 -0
- package/dist/functions/manifest.d.ts +8 -0
- package/dist/functions/manifest.js +9 -0
- package/dist/functions/source-selection.js +4 -1
- package/dist/main.js +58 -20
- package/dist/orm/delegate.d.ts +16 -0
- package/dist/orm/delegate.js +140 -7
- package/dist/pipeline/clone-deploy.d.ts +37 -0
- package/dist/pipeline/clone-deploy.js +125 -0
- package/dist/pipeline/codegen.js +6 -2
- package/dist/pipeline/commands.js +21 -5
- package/dist/pipeline/lifecycle.d.ts +1 -0
- package/dist/pipeline/lifecycle.js +95 -44
- package/dist/pipeline/repin-orm.js +6 -2
- package/dist/pipeline/stage-secrets.js +1 -1
- package/dist/process/build.js +17 -0
- package/dist/process/codegen.js +16 -0
- package/dist/process/commands.d.ts +15 -7
- package/dist/process/commands.js +291 -99
- package/dist/process/lint.js +35 -0
- package/dist/process/plan-diff.js +9 -0
- package/dist/process/simulate.js +8 -0
- package/dist/release-age.d.ts +12 -0
- package/dist/release-age.js +24 -0
- package/dist/repos/commands.d.ts +1 -1
- package/dist/repos/commands.js +36 -7
- package/dist/scaffold-guidance.d.ts +4 -0
- package/dist/scaffold-guidance.js +15 -0
- package/dist/storage/commands.js +23 -1
- package/dist/storage/gcs-download.d.ts +13 -0
- package/dist/storage/gcs-download.js +41 -0
- package/dist/storage/import-cycle.d.ts +41 -0
- package/dist/storage/import-cycle.js +123 -0
- package/dist/storage/import-files.d.ts +30 -0
- package/dist/storage/import-files.js +133 -0
- package/dist/storage/import-gcloud.d.ts +12 -0
- package/dist/storage/import-gcloud.js +54 -0
- package/dist/storage/import-identity.d.ts +12 -0
- package/dist/storage/import-identity.js +15 -0
- package/dist/storage/import-plan.d.ts +120 -0
- package/dist/storage/import-plan.js +189 -0
- package/dist/storage/import-preflight.d.ts +36 -0
- package/dist/storage/import-preflight.js +62 -0
- package/dist/storage/import-progress-map.d.ts +5 -0
- package/dist/storage/import-progress-map.js +22 -0
- package/dist/storage/import-recover.d.ts +97 -0
- package/dist/storage/import-recover.js +186 -0
- package/dist/storage/import-run.d.ts +14 -0
- package/dist/storage/import-run.js +140 -0
- package/dist/templates/guidance/AGENTS.md +10 -0
- package/dist/templates/guidance/CLAUDE.md +1 -0
- package/dist/templates/process/package.json +2 -2
- package/dist/templates/process/pnpm-workspace.yaml +7 -4
- package/dist/validation-detail.d.ts +2 -0
- package/dist/validation-detail.js +20 -0
- package/package.json +10 -10
- package/templates/guidance/AGENTS.md +10 -0
- package/templates/guidance/CLAUDE.md +1 -0
- package/templates/process/package.json +2 -2
- package/templates/process/pnpm-workspace.yaml +7 -4
package/dist/orm/delegate.js
CHANGED
|
@@ -5,16 +5,22 @@
|
|
|
5
5
|
* `artifact`): resolve `--env` from `~/.config/lattice/config.toml`, set
|
|
6
6
|
* SEQUENCE_ORM_BASE_URL, share the seqapi token, forward argv.
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { parseSourceSpec, resolveArtifactSource, } from '@sequenceholdings/artifact-studio/source-resolver';
|
|
10
|
+
import { getAccessToken, tryGetAccessTokenWithMode } from '../auth.js';
|
|
9
11
|
import { resolveEnvWithDiscovery } from '../config.js';
|
|
10
12
|
import { normalizeShortEnvFlag, readEnvFromArgv } from '../env-flags.js';
|
|
11
13
|
import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
|
|
14
|
+
import { resolveFunctionSourceDir } from '../functions/source-selection.js';
|
|
12
15
|
import { warnBeforeHostDeploy } from '../manifest-roles-notice.js';
|
|
16
|
+
import { ORM_HELP } from '../command-help.js';
|
|
13
17
|
/**
|
|
14
18
|
* ORM subcommands that talk to Atlas — must not silently target `local`.
|
|
15
|
-
* `init`, `generate`, `validate`, `diff`,
|
|
19
|
+
* `init`, `generate`, `validate`, `diff`, `migrate-from-yaml`, and `import` are offline.
|
|
16
20
|
*/
|
|
17
21
|
const ORM_NETWORK_SUBS = new Set(['plan', 'apply', 'execute']);
|
|
22
|
+
/** Subcommands that may read their namespace from a git-service repo (`--repo`). */
|
|
23
|
+
const ORM_REPO_SUBS = new Set(['plan', 'apply']);
|
|
18
24
|
const ORM_USAGE = `usage:
|
|
19
25
|
seq-studio orm init <dir> scaffold a namespace package (v2: TypeScript schema + GraphQL documents)
|
|
20
26
|
seq-studio orm generate [dir] write schema.graphql + operations.manifest.json + typePolicies.gen.ts (offline; runs consumer codegen when codegen.ts is present)
|
|
@@ -23,10 +29,16 @@ const ORM_USAGE = `usage:
|
|
|
23
29
|
seq-studio orm validate [dir] parse + validate definitions and verify committed migrations are in sync
|
|
24
30
|
seq-studio orm plan [dir] -e <env> compile definitions and diff against the registry
|
|
25
31
|
seq-studio orm apply [dir] -e <env> author the migration, register, apply, and refresh the generated outputs (the everyday command)
|
|
32
|
+
seq-studio orm plan|apply --repo <ns>/<name> [--path <dir>] [--ref <ref>] -e <env>
|
|
33
|
+
plan/apply a namespace committed to a platform git-service repo (CI deploy-from-git);
|
|
34
|
+
--path selects the namespace directory (default: repo root). A remote apply never
|
|
35
|
+
authors migrations: the committed ledger must already match the definitions.
|
|
26
36
|
seq-studio orm execute <operation> [dir] --variables-file <file> -e <env>
|
|
27
37
|
execute one named persisted operation as the signed-in caller
|
|
28
38
|
seq-studio orm diff [dir] write/verify the committed migration standalone (--check is the offline CI gate; --allow-destructive consents; --rebase records a v1 -> v2 conversion)
|
|
29
39
|
seq-studio orm migrate-from-yaml <dir> convert a v1 YAML namespace to the v2 TypeScript format (offline; migrations/ preserved)
|
|
40
|
+
seq-studio orm import [dir] --spec <file> | --table <t> --from <schema.table> --map <target=source,...>
|
|
41
|
+
plan a batched copy from an existing Postgres relation into an owned table (writes a SQL script; no database connection)
|
|
30
42
|
|
|
31
43
|
Environments: see \`seq-studio envs list\` (built-in: local; more are
|
|
32
44
|
discovered after you authenticate).
|
|
@@ -44,6 +56,113 @@ export function isOrmPackageMissing(message) {
|
|
|
44
56
|
const specifier = message.match(/Cannot find (?:package|module) '([^']+)'/)?.[1];
|
|
45
57
|
return specifier === '@sequenceholdings/orm' || (specifier?.startsWith('@sequenceholdings/orm/') ?? false);
|
|
46
58
|
}
|
|
59
|
+
const REPO_SOURCE_FLAGS = new Set(['--repo', '--ref', '--path']);
|
|
60
|
+
/**
|
|
61
|
+
* Pull `--repo <ns>/<name>`, `--ref <ref>`, and `--path <dir>` off the argv.
|
|
62
|
+
* Returns null when `--repo` is absent (the local-directory path, unchanged).
|
|
63
|
+
* The ORM CLI's own parser treats every non-flag token as the namespace dir,
|
|
64
|
+
* so these values must never be forwarded to it.
|
|
65
|
+
*/
|
|
66
|
+
export function extractOrmRepoSelection(argv) {
|
|
67
|
+
const values = {};
|
|
68
|
+
const rest = [];
|
|
69
|
+
for (let i = 0; i < argv.length; i++) {
|
|
70
|
+
const arg = argv[i];
|
|
71
|
+
if (arg === undefined)
|
|
72
|
+
continue;
|
|
73
|
+
const eq = arg.indexOf('=');
|
|
74
|
+
const name = eq === -1 ? arg : arg.slice(0, eq);
|
|
75
|
+
if (!REPO_SOURCE_FLAGS.has(name)) {
|
|
76
|
+
rest.push(arg);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const value = eq === -1 ? argv[++i] : arg.slice(eq + 1);
|
|
80
|
+
if (value === undefined || value.length === 0 || value.startsWith('-')) {
|
|
81
|
+
throw new Error(`${name} requires a value.`);
|
|
82
|
+
}
|
|
83
|
+
values[name.slice(2)] = value;
|
|
84
|
+
}
|
|
85
|
+
if (values.repo === undefined) {
|
|
86
|
+
const stray = Object.keys(values);
|
|
87
|
+
if (stray.length > 0)
|
|
88
|
+
throw new Error(`--${stray[0]} only applies together with --repo.`);
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const dir = positionalDir(rest);
|
|
92
|
+
if (dir !== undefined) {
|
|
93
|
+
throw new Error(`A [dir] argument (${dir}) cannot be combined with --repo; select a subdirectory with --path.`);
|
|
94
|
+
}
|
|
95
|
+
const spec = parseSourceSpec({
|
|
96
|
+
positional: [],
|
|
97
|
+
flags: { repo: values.repo, ...(values.ref !== undefined ? { ref: values.ref } : {}) },
|
|
98
|
+
});
|
|
99
|
+
if (spec.kind !== 'git-service')
|
|
100
|
+
throw new Error('--repo must name a platform git-service repository.');
|
|
101
|
+
return { spec, ...(values.path !== undefined ? { path: values.path } : {}), rest };
|
|
102
|
+
}
|
|
103
|
+
/** Mirrors the ORM CLI's positional(): the first non-flag token that is not the `--env` value. */
|
|
104
|
+
function positionalDir(args) {
|
|
105
|
+
for (let i = 0; i < args.length; i++) {
|
|
106
|
+
const arg = args[i];
|
|
107
|
+
if (arg === '--env') {
|
|
108
|
+
i += 1;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (arg !== undefined && !arg.startsWith('-'))
|
|
112
|
+
return arg;
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A materialized repo is a bare source tree — no node_modules — so the
|
|
118
|
+
* namespace's `@sequenceholdings/orm` imports cannot resolve from it. Point
|
|
119
|
+
* them at the ORM package this CLI already runs (the ORM CLI's jiti alias
|
|
120
|
+
* hook), which is also the compiler version validating the definitions.
|
|
121
|
+
* An explicit SEQUENCE_ORM_MODULE_PATH always wins.
|
|
122
|
+
*/
|
|
123
|
+
function aliasOrmModuleForRemoteSource(envName) {
|
|
124
|
+
if (process.env[envName]?.trim())
|
|
125
|
+
return;
|
|
126
|
+
try {
|
|
127
|
+
process.env[envName] = fileURLToPath(import.meta.resolve('@sequenceholdings/orm/authoring'));
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Unresolvable here means the namespace's own imports decide; the load
|
|
131
|
+
// error names the missing module.
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function runOrmFromRepo({ sub, selection, auth, targetUrl, ormCli, }) {
|
|
135
|
+
if (!auth || !targetUrl) {
|
|
136
|
+
console.error('[seq-studio] orm --repo needs a target environment and auth. Pass -e <env> and run `seq-studio login`.');
|
|
137
|
+
return 1;
|
|
138
|
+
}
|
|
139
|
+
const source = await resolveArtifactSource(selection.spec, {
|
|
140
|
+
authMode: auth.authMode,
|
|
141
|
+
baseUrl: targetUrl,
|
|
142
|
+
token: auth.token,
|
|
143
|
+
});
|
|
144
|
+
try {
|
|
145
|
+
const dir = await resolveFunctionSourceDir({
|
|
146
|
+
repoDir: source.dir,
|
|
147
|
+
...(selection.path !== undefined ? { path: selection.path } : {}),
|
|
148
|
+
});
|
|
149
|
+
aliasOrmModuleForRemoteSource(ormCli.ORM_MODULE_PATH_ENV);
|
|
150
|
+
// A local apply authors any missing migration into the working tree for
|
|
151
|
+
// review. A clone is discarded, so an authored migration would be applied
|
|
152
|
+
// unreviewed and then lost: require the committed ledger to be in sync.
|
|
153
|
+
if (sub === 'apply' && (await ormCli.runCli(['diff', dir, '--check'])) !== 0) {
|
|
154
|
+
console.error(`[seq-studio] ${selection.spec.namespace}/${selection.spec.name}${selection.path ? `/${selection.path}` : ''}: ` +
|
|
155
|
+
'committed migrations are out of date — run `seq-studio orm diff` in the repository, commit the migration, and retry.');
|
|
156
|
+
return 1;
|
|
157
|
+
}
|
|
158
|
+
const args = [dir, ...selection.rest];
|
|
159
|
+
await warnBeforeHostDeploy({ sub, deploySub: 'apply', args, file: 'namespace.yaml' });
|
|
160
|
+
return await ormCli.runCli([sub, ...args]);
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
await source.cleanup();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
47
166
|
async function loadOrmCli() {
|
|
48
167
|
try {
|
|
49
168
|
return await import('@sequenceholdings/orm/cli');
|
|
@@ -70,8 +189,20 @@ export async function runOrmCommand(sub, rest) {
|
|
|
70
189
|
}
|
|
71
190
|
const normalized = normalizeShortEnvFlag(rest);
|
|
72
191
|
if (normalized.includes('--help') || normalized.includes('-h')) {
|
|
73
|
-
|
|
74
|
-
return
|
|
192
|
+
console.log(ORM_HELP);
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
let repoSelection;
|
|
196
|
+
try {
|
|
197
|
+
repoSelection = extractOrmRepoSelection(normalized);
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
console.error(`[seq-studio] ${err instanceof Error ? err.message : String(err)}`);
|
|
201
|
+
return 1;
|
|
202
|
+
}
|
|
203
|
+
if (repoSelection && !ORM_REPO_SUBS.has(sub)) {
|
|
204
|
+
console.error(`[seq-studio] --repo applies only to: ${[...ORM_REPO_SUBS].join(', ')}`);
|
|
205
|
+
return 1;
|
|
75
206
|
}
|
|
76
207
|
const requested = readEnvFromArgv(normalized);
|
|
77
208
|
if (ORM_NETWORK_SUBS.has(sub) && !requested) {
|
|
@@ -84,13 +215,13 @@ export async function runOrmCommand(sub, rest) {
|
|
|
84
215
|
targetUrl = resolved.url;
|
|
85
216
|
process.env['SEQUENCE_ORM_BASE_URL'] = resolved.url;
|
|
86
217
|
}
|
|
87
|
-
const
|
|
218
|
+
const auth = await tryGetAccessTokenWithMode({
|
|
88
219
|
failClosedForM2m: true,
|
|
89
220
|
env: requested,
|
|
90
221
|
targetUrl,
|
|
91
222
|
});
|
|
92
|
-
if (
|
|
93
|
-
process.env['SEQUENCE_ORM_TOKEN'] = token;
|
|
223
|
+
if (auth)
|
|
224
|
+
process.env['SEQUENCE_ORM_TOKEN'] = auth.token;
|
|
94
225
|
// Lazy import keeps `process`/`doctor` from pulling in the optional ORM package.
|
|
95
226
|
const ormCli = await loadOrmCli();
|
|
96
227
|
if (!ormCli)
|
|
@@ -104,6 +235,8 @@ export async function runOrmCommand(sub, rest) {
|
|
|
104
235
|
return null;
|
|
105
236
|
}
|
|
106
237
|
});
|
|
238
|
+
if (repoSelection)
|
|
239
|
+
return runOrmFromRepo({ sub, selection: repoSelection, auth, targetUrl, ormCli });
|
|
107
240
|
await warnBeforeHostDeploy({ sub, deploySub: 'apply', args: normalized, file: 'namespace.yaml' });
|
|
108
241
|
return runCli([sub, ...normalized]);
|
|
109
242
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface CloneDeployTarget {
|
|
2
|
+
id: string;
|
|
3
|
+
requiresApproval: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function assertCloneDeployAllowed(target: CloneDeployTarget): void;
|
|
6
|
+
export declare function parseCloneDeployRepo(repo: string): {
|
|
7
|
+
namespace: 'pipelines' | 'apps';
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function readCloneHead(dir: string): Promise<{
|
|
11
|
+
sha: string;
|
|
12
|
+
branch: string;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function pushCloneHead({ dir, cloneUrl, sha, branch, pat, }: {
|
|
15
|
+
dir: string;
|
|
16
|
+
cloneUrl: string;
|
|
17
|
+
sha: string;
|
|
18
|
+
branch: string;
|
|
19
|
+
pat: string;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
export interface PublishedClone {
|
|
22
|
+
sha: string;
|
|
23
|
+
branch: string;
|
|
24
|
+
repoId: string;
|
|
25
|
+
created: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Ensure `<repo>` exists on the target environment and contains this
|
|
29
|
+
* checkout's HEAD. Returns the SHA the caller should pass as `--ref`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function publishCloneForDeploy({ dir, repo, baseUrl, token, pat, }: {
|
|
32
|
+
dir: string;
|
|
33
|
+
repo: string;
|
|
34
|
+
baseUrl: string;
|
|
35
|
+
token: string;
|
|
36
|
+
pat?: string;
|
|
37
|
+
}): Promise<PublishedClone>;
|
|
@@ -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
|
+
}
|
package/dist/pipeline/codegen.js
CHANGED
|
@@ -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
|
|
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 ${
|
|
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
|
|
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
|
|
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(
|
|
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<{
|