@sequenceholdings/studio-cli 0.4.6 → 0.5.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.
- package/README.md +180 -74
- package/dist/app/commands.d.ts +1 -1
- package/dist/app/commands.js +28 -3
- package/dist/app/readme.js +12 -4
- package/dist/app/scaffold.js +1 -1
- package/dist/artifact/delegate.js +4 -4
- package/dist/auth-cmds/commands.d.ts +1 -13
- package/dist/auth-cmds/commands.js +11 -246
- package/dist/bin.js +1 -1
- package/dist/command-contract.d.ts +14 -8
- package/dist/command-contract.js +5 -4
- package/dist/command-help.d.ts +2 -2
- package/dist/command-help.js +19 -19
- package/dist/main.d.ts +3 -2
- package/dist/main.js +12 -6
- package/dist/pipeline/clone-deploy.d.ts +1 -2
- package/dist/pipeline/clone-deploy.js +6 -8
- package/dist/pipeline/commands.js +1 -1
- package/dist/pipeline/lifecycle.d.ts +3 -1
- package/dist/pipeline/lifecycle.js +12 -4
- package/dist/repos/ci-config.d.ts +5 -0
- package/dist/repos/ci-config.js +29 -0
- package/dist/repos/ci-init.d.ts +4 -0
- package/dist/repos/ci-init.js +35 -0
- package/dist/repos/ci-status.d.ts +9 -0
- package/dist/repos/ci-status.js +49 -0
- package/dist/repos/commands.d.ts +8 -20
- package/dist/repos/commands.js +182 -233
- package/dist/repos/git-clone.d.ts +1 -10
- package/dist/repos/git-clone.js +1 -49
- package/dist/repos/git-credential.d.ts +15 -0
- package/dist/repos/git-credential.js +91 -0
- package/dist/templates/catalog.d.ts +69 -0
- package/dist/templates/catalog.js +68 -0
- package/dist/templates/commands.d.ts +29 -0
- package/dist/templates/commands.js +443 -0
- package/package.json +12 -11
- package/dist/pat-hints.d.ts +0 -15
- package/dist/pat-hints.js +0 -28
|
@@ -61,7 +61,9 @@ export interface PipelineTarget {
|
|
|
61
61
|
label: string;
|
|
62
62
|
requiresApproval: boolean;
|
|
63
63
|
}
|
|
64
|
-
export declare function envAndToken(args: ParsedArgs
|
|
64
|
+
export declare function envAndToken(args: ParsedArgs, options?: {
|
|
65
|
+
human?: boolean;
|
|
66
|
+
}): Promise<{
|
|
65
67
|
env: ResolvedEnv;
|
|
66
68
|
token: string;
|
|
67
69
|
}>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Deploy lifecycle verbs for `seq-studio pipeline plan|deploy|promote|rollback`
|
|
3
3
|
* (SEQ-2450). Wraps the /api/data-pipelines plan/deploy APIs.
|
|
4
4
|
*/
|
|
5
|
-
import { getAccessToken, NotLoggedInError } from '../auth.js';
|
|
5
|
+
import { getAccessToken, getAccessTokenWithMode, NotLoggedInError } from '../auth.js';
|
|
6
6
|
import { AtlasApiError, getJson, postJson } from '../atlas-client.js';
|
|
7
7
|
import { resolveConfiguredEnv } from '../config.js';
|
|
8
8
|
import { parseDurationMs } from '@sequenceholdings/lattice';
|
|
@@ -51,7 +51,7 @@ function deploymentStatusLabel(detail) {
|
|
|
51
51
|
return `${detail.status} — ${detail.statusDetail}`;
|
|
52
52
|
return detail.status;
|
|
53
53
|
}
|
|
54
|
-
export async function envAndToken(args) {
|
|
54
|
+
export async function envAndToken(args, options = {}) {
|
|
55
55
|
const requested = typeof args.flags.e === 'string' ? args.flags.e : typeof args.flags.env === 'string' ? args.flags.env : undefined;
|
|
56
56
|
if (!requested) {
|
|
57
57
|
throw new Error('missing -e/--env <environment>');
|
|
@@ -59,7 +59,15 @@ export async function envAndToken(args) {
|
|
|
59
59
|
const env = await resolveConfiguredEnv({ requested });
|
|
60
60
|
let token;
|
|
61
61
|
try {
|
|
62
|
-
|
|
62
|
+
if (options.human) {
|
|
63
|
+
const auth = await getAccessTokenWithMode({ env: env.name, targetUrl: env.url });
|
|
64
|
+
if (auth.authMode !== 'user')
|
|
65
|
+
throw new Error('Publishing a local clone requires a user login. Run seq-studio login for this environment, then retry.');
|
|
66
|
+
token = auth.token;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
token = await getAccessToken({ env: env.name, targetUrl: env.url });
|
|
70
|
+
}
|
|
63
71
|
}
|
|
64
72
|
catch (error) {
|
|
65
73
|
if (error instanceof NotLoggedInError)
|
|
@@ -201,7 +209,7 @@ export async function pipelineDeployCommand(args) {
|
|
|
201
209
|
const runNow = flagOn(args.flags, 'run-now');
|
|
202
210
|
const waitTimeoutMs = deploymentWaitTimeoutMs(args);
|
|
203
211
|
const allowDestructiveResourceKeys = repeatedFlagStrings(args, 'allow-destructive');
|
|
204
|
-
const { env, token } = await envAndToken(args);
|
|
212
|
+
const { env, token } = await envAndToken(args, { human: Boolean(dir) });
|
|
205
213
|
let target;
|
|
206
214
|
try {
|
|
207
215
|
target = await resolvePipelineTarget({ args, env, token });
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Keep the bounded data-only parser aligned with Atlas git-service/ci-config.ts.
|
|
2
|
+
import { JSON_SCHEMA, load } from 'js-yaml';
|
|
3
|
+
/** Data-only configuration: duplicate keys fail and aliases cannot expand without bound. */
|
|
4
|
+
export function parseCiConfigText({ text, path }) {
|
|
5
|
+
if (Buffer.byteLength(text, 'utf8') > 1024 * 1024)
|
|
6
|
+
throw new Error('CI configuration exceeds the 1 MiB limit');
|
|
7
|
+
const value = path.endsWith('.json') ? JSON.parse(text) : load(text, { schema: JSON_SCHEMA });
|
|
8
|
+
const seen = new Set();
|
|
9
|
+
const active = new Set();
|
|
10
|
+
let aliases = 0;
|
|
11
|
+
let nodes = 0;
|
|
12
|
+
const visit = (entry, depth) => {
|
|
13
|
+
if (++nodes > 10000 || depth > 64)
|
|
14
|
+
throw new Error('CI configuration exceeds the expanded node or depth limit');
|
|
15
|
+
if (entry === null || typeof entry !== 'object')
|
|
16
|
+
return;
|
|
17
|
+
if (active.has(entry))
|
|
18
|
+
throw new Error('Recursive YAML aliases are not supported in CI configuration');
|
|
19
|
+
if (seen.has(entry) && ++aliases > 100)
|
|
20
|
+
throw new Error('CI configuration exceeds the YAML alias limit');
|
|
21
|
+
seen.add(entry);
|
|
22
|
+
active.add(entry);
|
|
23
|
+
for (const child of Object.values(entry))
|
|
24
|
+
visit(child, depth + 1);
|
|
25
|
+
active.delete(entry);
|
|
26
|
+
};
|
|
27
|
+
visit(value, 0);
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { lstat, mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
const defaultPipeline = `# Native checks use platform-managed tools and the repository's resource manifests.
|
|
4
|
+
# Add target overrides here when a resource needs different commands or inputs.
|
|
5
|
+
schema_version: 2
|
|
6
|
+
targets: []
|
|
7
|
+
`;
|
|
8
|
+
/** Create the opt-in file without replacing authored configuration or following .seq symlinks. */
|
|
9
|
+
export async function initializeRepositoryPipeline({ directory }) {
|
|
10
|
+
const root = resolve(directory);
|
|
11
|
+
if (!(await lstat(root)).isDirectory())
|
|
12
|
+
throw new Error('CI initialization requires an existing repository directory');
|
|
13
|
+
const configurationDirectory = join(root, '.seq');
|
|
14
|
+
await mkdir(configurationDirectory, { recursive: true });
|
|
15
|
+
if (!(await lstat(configurationDirectory)).isDirectory())
|
|
16
|
+
throw new Error('CI initialization requires .seq to be a regular directory');
|
|
17
|
+
try {
|
|
18
|
+
await lstat(join(configurationDirectory, 'ci.json'));
|
|
19
|
+
throw new Error('Legacy .seq/ci.json already exists; migrate it to .seq/pipeline.yml instead of creating both files');
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT'))
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
const filename = join(configurationDirectory, 'pipeline.yml');
|
|
26
|
+
try {
|
|
27
|
+
await writeFile(filename, defaultPipeline, { flag: 'wx' });
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof Error && 'code' in error && error.code === 'EEXIST')
|
|
31
|
+
throw new Error('.seq/pipeline.yml already exists; edit the existing pipeline');
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
return filename;
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type CommandContext } from '../functions/commands.js';
|
|
2
|
+
/** Read the authoritative server plan; the CLI never infers execution or deployment authority. */
|
|
3
|
+
export declare function showRepositoryPrCi({ ctx, repoId, repoPath, number, json }: {
|
|
4
|
+
ctx: CommandContext;
|
|
5
|
+
repoId: string;
|
|
6
|
+
repoPath: string;
|
|
7
|
+
number: number;
|
|
8
|
+
json: boolean;
|
|
9
|
+
}): Promise<number>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { getJson } from '../atlas-client.js';
|
|
3
|
+
import { clientOptions } from '../functions/commands.js';
|
|
4
|
+
const actionSchema = z.object({ name: z.string(), phase: z.string(), cwd: z.string(), command: z.array(z.string()) });
|
|
5
|
+
const statusSchema = z.object({
|
|
6
|
+
discovery: z.object({ source: z.enum(['pipeline', 'policy', 'none']), state: z.enum(['ready', 'not-configured', 'unavailable']), message: z.string().optional() }).optional(),
|
|
7
|
+
planningIssue: z.object({ code: z.string(), message: z.string() }).nullable(),
|
|
8
|
+
plan: z.object({
|
|
9
|
+
planHash: z.string(), headSha: z.string(),
|
|
10
|
+
targets: z.array(z.object({ key: z.string(), kind: z.string(), root: z.string(), affected: z.boolean(), checks: z.array(actionSchema), build: actionSchema.nullable() })),
|
|
11
|
+
findings: z.array(z.object({ severity: z.string(), code: z.string(), message: z.string() })),
|
|
12
|
+
}).nullable(),
|
|
13
|
+
currentRunId: z.string().nullable(),
|
|
14
|
+
runs: z.array(z.object({ id: z.string(), state: z.string(), error: z.string().nullable().optional() })),
|
|
15
|
+
});
|
|
16
|
+
function printPlan({ plan }) {
|
|
17
|
+
console.log(` Head: ${plan.headSha}; plan: ${plan.planHash}`);
|
|
18
|
+
for (const target of plan.targets) {
|
|
19
|
+
console.log(` ${target.key} (${target.kind}, ${target.root}): ${target.affected ? 'affected' : 'unchanged'}`);
|
|
20
|
+
for (const action of [...target.checks, ...(target.build ? [target.build] : [])])
|
|
21
|
+
console.log(` ${action.phase}: ${JSON.stringify(action.command)} (cwd ${action.cwd})`);
|
|
22
|
+
}
|
|
23
|
+
for (const finding of plan.findings)
|
|
24
|
+
console.log(` ${finding.severity} ${finding.code}: ${finding.message}`);
|
|
25
|
+
}
|
|
26
|
+
/** Read the authoritative server plan; the CLI never infers execution or deployment authority. */
|
|
27
|
+
export async function showRepositoryPrCi({ ctx, repoId, repoPath, number, json }) {
|
|
28
|
+
const response = await getJson({ ...clientOptions(ctx), path: `/api/git-service/repos/${repoId}/pulls/${number}/ci` });
|
|
29
|
+
const status = statusSchema.parse(response);
|
|
30
|
+
const blocked = status.discovery?.state === 'unavailable' || status.planningIssue !== null || status.plan?.findings.some((finding) => finding.severity === 'error');
|
|
31
|
+
if (json) {
|
|
32
|
+
console.log(JSON.stringify(response, null, 2));
|
|
33
|
+
return blocked ? 1 : 0;
|
|
34
|
+
}
|
|
35
|
+
console.log(`CI for ${repoPath} pull request #${number} on ${ctx.env.name}:`);
|
|
36
|
+
if (status.discovery)
|
|
37
|
+
console.log(` Discovery: ${status.discovery.state} (${status.discovery.source})${status.discovery.message ? ` — ${status.discovery.message}` : ''}`);
|
|
38
|
+
if (status.planningIssue)
|
|
39
|
+
console.log(` ${status.planningIssue.code}: ${status.planningIssue.message}`);
|
|
40
|
+
if (status.plan) {
|
|
41
|
+
printPlan({ plan: status.plan });
|
|
42
|
+
}
|
|
43
|
+
else if (!status.planningIssue && status.discovery?.state !== 'unavailable') {
|
|
44
|
+
console.log(' No native plan yet. Commit .seq/pipeline.yml with your resource manifests and open or update a pull request.');
|
|
45
|
+
}
|
|
46
|
+
for (const run of status.runs.slice(0, 5))
|
|
47
|
+
console.log(` ${run.id === status.currentRunId ? 'Current' : 'Previous'} run ${run.id}: ${run.state}${run.error ? ` — ${run.error}` : ''}`);
|
|
48
|
+
return blocked ? 1 : 0;
|
|
49
|
+
}
|
package/dist/repos/commands.d.ts
CHANGED
|
@@ -45,57 +45,45 @@ export declare function reposListCommand(args: ParsedArgs): Promise<number>;
|
|
|
45
45
|
export declare function reposShowCommand(args: ParsedArgs): Promise<number>;
|
|
46
46
|
export declare function reposCreateCommand(args: ParsedArgs): Promise<number>;
|
|
47
47
|
export declare function reposPullCommand(args: ParsedArgs): Promise<number>;
|
|
48
|
-
/**
|
|
49
|
-
* Preferred clone verb.
|
|
50
|
-
*
|
|
51
|
-
* With `ATLAS_GIT_PAT`:
|
|
52
|
-
* - `--url <clone-url>` or `--id <repo-uuid>` → smart-HTTP clone with no seqapi
|
|
53
|
-
* - `<ns>/<name>` → needs Auth0 to resolve the UUID, then smart-HTTP clone
|
|
54
|
-
* Without a PAT: JSON materialize (needs Auth0) + PAT setup hints.
|
|
55
|
-
*
|
|
56
|
-
* `gitClone` is injectable for tests.
|
|
57
|
-
*/
|
|
48
|
+
/** Git clone always uses the selected human login, never an ambient PAT. */
|
|
58
49
|
export declare function reposCloneCommand(args: ParsedArgs, deps?: {
|
|
59
50
|
gitClone?: RunGitClone;
|
|
60
51
|
}): Promise<number>;
|
|
61
52
|
/**
|
|
62
53
|
* Validate clone URL shape and that the origin matches the resolved Atlas env
|
|
63
|
-
* so askpass never sends
|
|
54
|
+
* so askpass never sends a login token to an attacker-controlled host.
|
|
64
55
|
*/
|
|
65
56
|
export declare function normalizeCloneUrl(raw: string, env: ResolvedEnv): string;
|
|
66
57
|
type DiscoveredCliCheck = {
|
|
67
58
|
name: string;
|
|
68
59
|
script?: string;
|
|
69
60
|
command?: string[];
|
|
70
|
-
source: 'autodiscover' | 'ci.json';
|
|
61
|
+
source: 'autodiscover' | 'ci.json' | 'pipeline.yml';
|
|
71
62
|
};
|
|
72
63
|
/**
|
|
73
64
|
* Pure discovery shared by `repos ci show` / `import`. Mirrors atlas
|
|
74
65
|
* `discoverCiChecks` / `parseCiJson` so CLI preview matches execution.
|
|
75
66
|
*/
|
|
76
|
-
export declare function discoverCliChecks({ ciJson, packageScripts, }: {
|
|
67
|
+
export declare function discoverCliChecks({ ciYaml, ciJson, packageScripts, }: {
|
|
68
|
+
ciYaml?: unknown;
|
|
77
69
|
ciJson?: unknown;
|
|
78
70
|
packageScripts?: Record<string, string>;
|
|
79
71
|
}): {
|
|
80
72
|
ok: true;
|
|
81
73
|
checks: DiscoveredCliCheck[];
|
|
74
|
+
native?: boolean;
|
|
82
75
|
} | {
|
|
83
76
|
ok: false;
|
|
84
77
|
error: string;
|
|
85
78
|
};
|
|
86
|
-
/**
|
|
87
|
-
* Load `.seq/ci.json` / `package.json` for CI preview.
|
|
88
|
-
*
|
|
89
|
-
* Matches the runner: only a true 404 means "file absent". Invalid JSON and
|
|
90
|
-
* non-404 API errors fail closed (no silent package.json fallback over a bad
|
|
91
|
-
* `.seq/ci.json`).
|
|
92
|
-
*/
|
|
79
|
+
/** Load YAML or legacy JSON; only a true 404 means configuration is absent. */
|
|
93
80
|
export declare function loadRemoteCiSources({ ctx, repoId, ref, }: {
|
|
94
81
|
ctx: CommandContext;
|
|
95
82
|
repoId: string;
|
|
96
83
|
ref: string;
|
|
97
84
|
}): Promise<{
|
|
98
85
|
ok: true;
|
|
86
|
+
ciYaml?: unknown;
|
|
99
87
|
ciJson?: unknown;
|
|
100
88
|
packageScripts?: Record<string, string>;
|
|
101
89
|
} | {
|