@sequenceholdings/studio-cli 0.9.20 → 0.9.22
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 +159 -12
- package/dist/app/commands.js +37 -7
- package/dist/app/deploy.js +2 -0
- package/dist/app/lockfile-preflight.d.ts +31 -0
- package/dist/app/lockfile-preflight.js +47 -0
- package/dist/app/repository-index.d.ts +5 -1
- package/dist/app/repository-index.js +9 -3
- package/dist/app/scaffold.d.ts +3 -1
- package/dist/app/scaffold.js +5 -3
- package/dist/auth.d.ts +13 -9
- package/dist/auth.js +98 -20
- package/dist/cli-errors.js +6 -1
- package/dist/command-contract.d.ts +13 -1
- package/dist/command-contract.js +3 -1
- package/dist/command-help.d.ts +1 -1
- package/dist/command-help.js +8 -1
- package/dist/config.d.ts +14 -0
- package/dist/config.js +29 -3
- package/dist/docs/commands.d.ts +16 -0
- package/dist/docs/commands.js +168 -0
- package/dist/docs/help.d.ts +2 -0
- package/dist/docs/help.js +12 -0
- package/dist/envs/commands.js +10 -2
- package/dist/host-token.d.ts +19 -4
- package/dist/host-token.js +50 -10
- package/dist/main.d.ts +1 -0
- package/dist/main.js +20 -2
- package/dist/orm/discover-operations.d.ts +1 -1
- package/dist/orm/discover-operations.js +3 -3
- package/dist/orm/discover-schema.d.ts +0 -5
- package/dist/orm/discover-schema.js +0 -3
- package/dist/pipeline/commands.d.ts +0 -7
- package/dist/pipeline/commands.js +16 -67
- package/dist/pipeline/discovery.d.ts +1 -1
- package/dist/pipeline/discovery.js +6 -6
- package/dist/process/build.d.ts +2 -5
- package/dist/process/build.js +4 -49
- package/dist/repos/commands.d.ts +11 -1
- package/dist/repos/commands.js +78 -11
- package/dist/repos/git-credential.d.ts +12 -5
- package/dist/repos/git-credential.js +63 -36
- package/dist/repos/github-connect-command.d.ts +35 -0
- package/dist/repos/github-connect-command.js +250 -0
- package/dist/repos/github-init-command.d.ts +16 -0
- package/dist/repos/github-init-command.js +116 -0
- package/dist/repos/github-init.d.ts +146 -0
- package/dist/repos/github-init.js +355 -0
- package/dist/repos/init-github.d.ts +50 -0
- package/dist/repos/init-github.js +181 -0
- package/dist/repos/pulls.d.ts +5 -1
- package/dist/repos/pulls.js +31 -9
- package/dist/scaffold-guidance.d.ts +10 -2
- package/dist/scaffold-guidance.js +27 -2
- package/dist/templates/github/pr-type.mjs +285 -0
- package/dist/templates/github/pr-types.json +40 -0
- package/dist/templates/guidance/AGENTS.md +15 -8
- package/package.json +7 -7
- package/release-summary.json +3 -1
- package/templates/github/pr-type.mjs +285 -0
- package/templates/github/pr-types.json +40 -0
- package/templates/guidance/AGENTS.md +15 -8
- package/dist/pipeline/active-orm-contracts.d.ts +0 -16
- package/dist/pipeline/active-orm-contracts.js +0 -36
- package/dist/pipeline/repin-orm.d.ts +0 -2
- package/dist/pipeline/repin-orm.js +0 -207
package/dist/process/build.js
CHANGED
|
@@ -4,22 +4,16 @@ import { authoredNodeMetadata } from './node-metadata.js';
|
|
|
4
4
|
* source tree.
|
|
5
5
|
*/
|
|
6
6
|
import { execSync } from 'node:child_process';
|
|
7
|
-
import { finalizeBundleIdentity,
|
|
7
|
+
import { finalizeBundleIdentity, pinBundleSubprocessRefs, pinExternalSubprocessRefs, } from '@sequenceholdings/lattice/bundle';
|
|
8
8
|
import { isJsonataExpr, parseDurationMs, serializeRetryConfig, } from '@sequenceholdings/lattice/define';
|
|
9
9
|
export async function buildBundleFromProcesses(defs, options) {
|
|
10
10
|
if (defs.length === 0) {
|
|
11
11
|
throw new Error('no lattice process definitions found in configured roots');
|
|
12
12
|
}
|
|
13
13
|
const processes = defs.map((d) => serializeProcess({ process: d.process }));
|
|
14
|
-
const localProcessIds = new Set(processes.map((p) => p.id));
|
|
15
14
|
if (options?.resolveProcessPin) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// finalizeBundleIdentity to this bundle's own version/hash.
|
|
19
|
-
if (!version && localProcessIds.has(processId))
|
|
20
|
-
return null;
|
|
21
|
-
return options.resolveProcessPin(processId, version);
|
|
22
|
-
});
|
|
15
|
+
// Children from other roots that the resolver cannot find stay unpinned; registration refuses them.
|
|
16
|
+
await pinExternalSubprocessRefs(processes, options.resolveProcessPin);
|
|
23
17
|
}
|
|
24
18
|
const metadata = options?.provenance
|
|
25
19
|
? collectGitMetadataWithOverrides(options.provenance)
|
|
@@ -29,46 +23,7 @@ export async function buildBundleFromProcesses(defs, options) {
|
|
|
29
23
|
return finalizeBundleIdentity({ processes, metadata });
|
|
30
24
|
}
|
|
31
25
|
export async function finalizeCompiledBundle({ bundle, resolveProcessPin, }) {
|
|
32
|
-
|
|
33
|
-
const localProcessIds = new Set(processes.map((process) => process.id));
|
|
34
|
-
await resolveSubprocessPinsInProcesses(processes, async (processId, version) => {
|
|
35
|
-
if (!version && localProcessIds.has(processId))
|
|
36
|
-
return null;
|
|
37
|
-
return resolveProcessPin(processId, version);
|
|
38
|
-
});
|
|
39
|
-
return finalizeBundleIdentity({ processes, metadata: bundle.metadata });
|
|
40
|
-
}
|
|
41
|
-
async function resolveSubprocessPinsInProcesses(processes, resolve) {
|
|
42
|
-
const pins = [];
|
|
43
|
-
for (const proc of processes) {
|
|
44
|
-
forEachSerializedNode(proc.nodes, (node) => {
|
|
45
|
-
if (node.kind !== 'subprocess')
|
|
46
|
-
return;
|
|
47
|
-
pins.push(pinSubprocessNode(proc.id, node, resolve, { allowUnresolved: true }));
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
await Promise.all(pins);
|
|
51
|
-
}
|
|
52
|
-
async function pinSubprocessNode(processId, node, resolve, options) {
|
|
53
|
-
const meta = node.metadata;
|
|
54
|
-
const spec = meta.subprocess;
|
|
55
|
-
if (!spec?.process_id) {
|
|
56
|
-
throw new Error(`process "${processId}": subprocess node "${node.id}" is missing subprocess metadata`);
|
|
57
|
-
}
|
|
58
|
-
if (spec.bundle_hash && spec.version)
|
|
59
|
-
return;
|
|
60
|
-
const resolved = await resolve(spec.process_id, spec.version);
|
|
61
|
-
if (!resolved) {
|
|
62
|
-
if (options?.allowUnresolved)
|
|
63
|
-
return;
|
|
64
|
-
throw new Error(`process "${processId}": subprocess node "${node.id}" references unknown process ` +
|
|
65
|
-
`"${spec.process_id}"${spec.version ? ` version "${spec.version}"` : ''}`);
|
|
66
|
-
}
|
|
67
|
-
meta.subprocess = {
|
|
68
|
-
...spec,
|
|
69
|
-
version: resolved.version,
|
|
70
|
-
bundle_hash: resolved.bundleHash,
|
|
71
|
-
};
|
|
26
|
+
return (await pinBundleSubprocessRefs({ bundle, resolveProcessPin })).bundle;
|
|
72
27
|
}
|
|
73
28
|
function serializeProcess(input) {
|
|
74
29
|
const nodes = input.process.nodes.map((node) => serializeNode(node));
|
package/dist/repos/commands.d.ts
CHANGED
|
@@ -97,21 +97,31 @@ export declare function assertGitCheckoutAuth(ctx: CommandContext): void;
|
|
|
97
97
|
* Clone a resolved repository's default branch (shallow, like `repos clone`)
|
|
98
98
|
* into an absent or empty `destDir`. Returns the origin URL it configured.
|
|
99
99
|
*/
|
|
100
|
-
export declare function cloneRepoById({ ctx, repoId, destDir, gitClone, }: {
|
|
100
|
+
export declare function cloneRepoById({ ctx, repoId, destDir, gitClone, resolveLauncher, }: {
|
|
101
101
|
ctx: CommandContext;
|
|
102
102
|
repoId: string;
|
|
103
103
|
destDir: string;
|
|
104
104
|
gitClone?: RunGitClone;
|
|
105
|
+
resolveLauncher?: () => Promise<string[]>;
|
|
105
106
|
}): Promise<string>;
|
|
106
107
|
/** Git clone always uses the selected human login, never an ambient PAT. */
|
|
107
108
|
export declare function reposCloneCommand(args: ParsedArgs, deps?: {
|
|
108
109
|
gitClone?: RunGitClone;
|
|
110
|
+
resolveLauncher?: () => Promise<string[]>;
|
|
109
111
|
}): Promise<number>;
|
|
110
112
|
/**
|
|
111
113
|
* Validate clone URL shape and that the origin matches the resolved Atlas env
|
|
112
114
|
* so askpass never sends a login token to an attacker-controlled host.
|
|
113
115
|
*/
|
|
114
116
|
export declare function normalizeCloneUrl(raw: string, env: ResolvedEnv): string;
|
|
117
|
+
/**
|
|
118
|
+
* Bind the credential helper to an existing checkout of a git-service
|
|
119
|
+
* repository: one cloned by plain `git clone`, by an older CLI whose clone
|
|
120
|
+
* stopped before configuring login, or whose launcher moved in an upgrade.
|
|
121
|
+
*/
|
|
122
|
+
export declare function reposAttachLoginCommand(args: ParsedArgs, deps?: {
|
|
123
|
+
resolveLauncher?: () => Promise<string[]>;
|
|
124
|
+
}): Promise<number>;
|
|
115
125
|
type DiscoveredCliCheck = {
|
|
116
126
|
name: string;
|
|
117
127
|
script?: string;
|
package/dist/repos/commands.js
CHANGED
|
@@ -12,9 +12,11 @@ import { REPOS_USAGE } from '../command-help.js';
|
|
|
12
12
|
* so commands resolve the path via the namespaces + repos endpoints (the same
|
|
13
13
|
* dance the Repositories UI does — there is no /repos/by-path endpoint).
|
|
14
14
|
*/
|
|
15
|
+
import { execFile } from 'node:child_process';
|
|
15
16
|
import { existsSync, readdirSync, rmSync } from 'node:fs';
|
|
16
17
|
import { homedir } from 'node:os';
|
|
17
|
-
import { resolve, sep } from 'node:path';
|
|
18
|
+
import { join, resolve, sep } from 'node:path';
|
|
19
|
+
import { promisify } from 'node:util';
|
|
18
20
|
import { materializeRepo, resolveCommitSha, resolveRepo, } from '@sequenceholdings/artifact-studio/git-service-client';
|
|
19
21
|
import { z } from 'zod';
|
|
20
22
|
import { parseCiConfigText } from './ci-config.js';
|
|
@@ -24,10 +26,12 @@ import { AtlasApiError, deleteNoContent, getJson, getJsonOr404, postJson, } from
|
|
|
24
26
|
import { printCliError } from '../cli-errors.js';
|
|
25
27
|
import { PREVIEW_DOMAIN } from '../preview.js';
|
|
26
28
|
import { confirmYes } from '../prompt.js';
|
|
29
|
+
import { guideClonedCheckout } from '../scaffold-guidance.js';
|
|
27
30
|
import { buildContext, clientOptions, flagBool, LOG, } from '../functions/commands.js';
|
|
28
31
|
import { looksLikeCommitSha, runGitClone, } from './git-clone.js';
|
|
29
|
-
import { configureGitLogin } from './git-credential.js';
|
|
32
|
+
import { configureGitLogin, resolveGitHelperLauncher } from './git-credential.js';
|
|
30
33
|
import { isSandboxTokenMode } from '../sandbox-auth.js';
|
|
34
|
+
const execFileAsync = promisify(execFile);
|
|
31
35
|
const PAGE_SIZE = 200;
|
|
32
36
|
// ---------------------------------------------------------------------------
|
|
33
37
|
// Helpers
|
|
@@ -429,24 +433,52 @@ async function gitCloneContext(args) {
|
|
|
429
433
|
/**
|
|
430
434
|
* Clone over smart-HTTP into `destDir` (absent or empty unless `force`) and
|
|
431
435
|
* bind the checkout's credential helper to this environment and repository.
|
|
436
|
+
* The launcher Git will run is resolved first, so nothing is cloned that could
|
|
437
|
+
* not be wired up; any later failure removes what the clone wrote.
|
|
432
438
|
*/
|
|
433
|
-
async function cloneCheckout({ ctx, targetUrl, destDir, force, ref, depth, gitClone, }) {
|
|
439
|
+
async function cloneCheckout({ ctx, targetUrl, destDir, force, ref, depth, gitClone, resolveLauncher, }) {
|
|
440
|
+
const launcher = await (resolveLauncher ?? resolveGitHelperLauncher)();
|
|
434
441
|
prepareCloneDest({ destDir, force });
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
442
|
+
const existed = existsSync(destDir);
|
|
443
|
+
try {
|
|
444
|
+
await (gitClone ?? runGitClone)({
|
|
445
|
+
cloneUrl: targetUrl, destDir, pat: ctx.token,
|
|
446
|
+
...(ref ? { ref } : {}),
|
|
447
|
+
...(depth != null ? { depth } : {}),
|
|
448
|
+
});
|
|
449
|
+
await configureGitLogin({ destDir, envName: ctx.env.name, cloneUrl: targetUrl, launcher });
|
|
450
|
+
}
|
|
451
|
+
catch (error) {
|
|
452
|
+
rollBackClone({ destDir, existed });
|
|
453
|
+
throw error;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
/** Remove a failed clone: the directory it created, or what it wrote into an empty one. */
|
|
457
|
+
function rollBackClone({ destDir, existed }) {
|
|
458
|
+
try {
|
|
459
|
+
if (!existed) {
|
|
460
|
+
rmSync(destDir, { recursive: true, force: true });
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
for (const entry of readdirSync(destDir))
|
|
464
|
+
rmSync(join(destDir, entry), { recursive: true, force: true });
|
|
465
|
+
}
|
|
466
|
+
catch (cleanupError) {
|
|
467
|
+
console.error(`${LOG} could not remove the partial clone at ${destDir}: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`);
|
|
468
|
+
}
|
|
441
469
|
}
|
|
442
470
|
/**
|
|
443
471
|
* Clone a resolved repository's default branch (shallow, like `repos clone`)
|
|
444
472
|
* into an absent or empty `destDir`. Returns the origin URL it configured.
|
|
445
473
|
*/
|
|
446
|
-
export async function cloneRepoById({ ctx, repoId, destDir, gitClone, }) {
|
|
474
|
+
export async function cloneRepoById({ ctx, repoId, destDir, gitClone, resolveLauncher, }) {
|
|
447
475
|
assertGitCheckoutAuth(ctx);
|
|
448
476
|
const targetUrl = normalizeCloneUrl(cloneUrl(ctx, repoId), ctx.env);
|
|
449
|
-
await cloneCheckout({
|
|
477
|
+
await cloneCheckout({
|
|
478
|
+
ctx, targetUrl, destDir, force: false, depth: smartHttpCloneDepth({ full: false }),
|
|
479
|
+
...(gitClone ? { gitClone } : {}),
|
|
480
|
+
...(resolveLauncher ? { resolveLauncher } : {}),
|
|
481
|
+
});
|
|
450
482
|
return targetUrl;
|
|
451
483
|
}
|
|
452
484
|
/** Git clone always uses the selected human login, never an ambient PAT. */
|
|
@@ -485,6 +517,7 @@ export async function reposCloneCommand(args, deps = {}) {
|
|
|
485
517
|
...(ref ? { ref } : {}),
|
|
486
518
|
...(depth != null ? { depth } : {}),
|
|
487
519
|
...(deps.gitClone ? { gitClone: deps.gitClone } : {}),
|
|
520
|
+
...(deps.resolveLauncher ? { resolveLauncher: deps.resolveLauncher } : {}),
|
|
488
521
|
});
|
|
489
522
|
console.log(`${LOG} cloned ${positional ?? targetUrl} → ${destDir}` +
|
|
490
523
|
(ref ? ` (ref ${ref})` : '') +
|
|
@@ -493,6 +526,12 @@ export async function reposCloneCommand(args, deps = {}) {
|
|
|
493
526
|
// The sandbox's token file is rewritten before every tool call; there is no login.
|
|
494
527
|
? `${LOG} git pull/push now use this agent sandbox's Atlas credential, which renews on every tool call.`
|
|
495
528
|
: `${LOG} git pull/push now use your seq-studio login. After expiry: seq-studio login --env ${env.name}`);
|
|
529
|
+
try {
|
|
530
|
+
console.log(`${LOG} ${await guideClonedCheckout({ directory: destDir, envName: env.name })}`);
|
|
531
|
+
}
|
|
532
|
+
catch (error) {
|
|
533
|
+
console.error(`${LOG} could not add agent guidance: ${error instanceof Error ? error.message : String(error)}`);
|
|
534
|
+
}
|
|
496
535
|
return 0;
|
|
497
536
|
}
|
|
498
537
|
/**
|
|
@@ -533,6 +572,32 @@ export function normalizeCloneUrl(raw, env) {
|
|
|
533
572
|
}
|
|
534
573
|
return url.toString().replace(/\/$/, '');
|
|
535
574
|
}
|
|
575
|
+
async function gitOutput(cwd, args) {
|
|
576
|
+
return (await execFileAsync('git', ['-C', cwd, ...args])).stdout.trim();
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Bind the credential helper to an existing checkout of a git-service
|
|
580
|
+
* repository: one cloned by plain `git clone`, by an older CLI whose clone
|
|
581
|
+
* stopped before configuring login, or whose launcher moved in an upgrade.
|
|
582
|
+
*/
|
|
583
|
+
export async function reposAttachLoginCommand(args, deps = {}) {
|
|
584
|
+
const dir = resolve(args.positional[0] ?? '.');
|
|
585
|
+
const remote = stringFlag(args.flags, 'remote') ?? 'origin';
|
|
586
|
+
let root;
|
|
587
|
+
let remoteUrl;
|
|
588
|
+
try {
|
|
589
|
+
root = await gitOutput(dir, ['rev-parse', '--show-toplevel']);
|
|
590
|
+
remoteUrl = await gitOutput(root, ['remote', 'get-url', remote]);
|
|
591
|
+
}
|
|
592
|
+
catch {
|
|
593
|
+
throw new Error(`${dir} is not a Git checkout with a '${remote}' remote. Pass the checkout directory and --remote <name>.`);
|
|
594
|
+
}
|
|
595
|
+
const ctx = await gitCloneContext(args);
|
|
596
|
+
const cloneUrl = normalizeCloneUrl(remoteUrl, ctx.env);
|
|
597
|
+
await configureGitLogin({ destDir: root, envName: ctx.env.name, cloneUrl, launcher: await (deps.resolveLauncher ?? resolveGitHelperLauncher)() });
|
|
598
|
+
console.log(`${LOG} ${root}: git pull/push to ${cloneUrl} now use your seq-studio login for ${ctx.env.name}.`);
|
|
599
|
+
return 0;
|
|
600
|
+
}
|
|
536
601
|
function defaultOutFromCloneTarget({ url, id, }) {
|
|
537
602
|
if (id)
|
|
538
603
|
return id;
|
|
@@ -870,6 +935,8 @@ export async function runReposCommand(sub, args) {
|
|
|
870
935
|
return await reposCreateCommand(args);
|
|
871
936
|
case 'clone':
|
|
872
937
|
return await reposCloneCommand(args);
|
|
938
|
+
case 'attach-login':
|
|
939
|
+
return await reposAttachLoginCommand(args);
|
|
873
940
|
case 'pull':
|
|
874
941
|
return await reposPullCommand(args);
|
|
875
942
|
case 'delete':
|
|
@@ -7,17 +7,24 @@ export declare function gitCredentialResponse({ input, operation, envName, clone
|
|
|
7
7
|
envName?: string;
|
|
8
8
|
cloneUrl?: string;
|
|
9
9
|
}): Promise<string>;
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The command Git runs to reach this CLI, as argv. Prefers a stable installed
|
|
12
|
+
* launcher (SEQ_STUDIO_LAUNCHER, the invocation path, or one on PATH) that runs
|
|
13
|
+
* this exact build, so a later PATH change cannot make Git run a different
|
|
14
|
+
* CLI. Without one (`node …/dist/bin.js`), it pins this node and script;
|
|
15
|
+
* `repos attach-login` re-binds a checkout after an upgrade moves either.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveGitHelperLauncher({ scriptPath, launcherHint, searchPath, nodePath, }?: {
|
|
12
18
|
scriptPath?: string;
|
|
13
19
|
launcherHint?: string;
|
|
14
20
|
searchPath?: string;
|
|
15
|
-
|
|
21
|
+
nodePath?: string;
|
|
22
|
+
}): Promise<string[]>;
|
|
16
23
|
/** Store only a helper command, bound to this environment and repository URL. */
|
|
17
|
-
export declare function configureGitLogin({ destDir, envName, cloneUrl,
|
|
24
|
+
export declare function configureGitLogin({ destDir, envName, cloneUrl, launcher, }: {
|
|
18
25
|
destDir: string;
|
|
19
26
|
envName: string;
|
|
20
27
|
cloneUrl: string;
|
|
21
|
-
|
|
28
|
+
launcher?: readonly string[];
|
|
22
29
|
}): Promise<void>;
|
|
23
30
|
export declare function gitCredentialCommand(args: ParsedArgs): Promise<number>;
|
|
@@ -2,7 +2,7 @@ import { execFile } from 'node:child_process';
|
|
|
2
2
|
import { readFile, realpath } from 'node:fs/promises';
|
|
3
3
|
import { basename, delimiter, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
4
|
import { promisify } from 'node:util';
|
|
5
|
-
import { getAccessTokenWithMode } from '../auth.js';
|
|
5
|
+
import { DevboxOwnerTokenMissingError, getAccessTokenWithMode, NotLoggedInError } from '../auth.js';
|
|
6
6
|
import { resolveConfiguredEnv } from '../config.js';
|
|
7
7
|
import { isSandboxOrigin, readSandboxToken, sandboxTarget } from '../sandbox-auth.js';
|
|
8
8
|
const exec = promisify(execFile);
|
|
@@ -89,15 +89,35 @@ export async function gitCredentialResponse({ input, operation, envName, cloneUr
|
|
|
89
89
|
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname))) {
|
|
90
90
|
throw new Error('Git login credentials require HTTPS (except local loopback).');
|
|
91
91
|
}
|
|
92
|
+
let auth;
|
|
92
93
|
try {
|
|
93
|
-
|
|
94
|
-
if (auth.authMode !== 'user' || !auth.token || /[\r\n\0]/.test(auth.token))
|
|
95
|
-
throw new Error('User login required');
|
|
96
|
-
return `username=git\npassword=${auth.token}\n\n`;
|
|
94
|
+
auth = await getAccessTokenWithMode({ env: env.name, targetUrl: env.url, allowInteractiveLogin: false });
|
|
97
95
|
}
|
|
98
|
-
catch {
|
|
99
|
-
throw new Error(
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw new Error(gitLoginUnavailableMessage({ envName, error }));
|
|
98
|
+
}
|
|
99
|
+
if (auth.authMode !== 'user' || !auth.token || /[\r\n\0]/.test(auth.token)) {
|
|
100
|
+
throw new Error(`Git needs a person's login for ${envName}, and only a machine identity is available. Machine identities cannot authenticate Git; use supported JSON source workflows (seq-studio repos pull).`);
|
|
101
|
+
}
|
|
102
|
+
return `username=git\npassword=${auth.token}\n\n`;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Git prints this to whoever ran it, often an agent. There is no refresh
|
|
106
|
+
* token by design, so a login ends after about 12 hours; say so, and say who
|
|
107
|
+
* can renew it, rather than leaving an agent to retry. Other failures keep
|
|
108
|
+
* their detail out of Git's output.
|
|
109
|
+
*/
|
|
110
|
+
function gitLoginUnavailableMessage({ envName, error }) {
|
|
111
|
+
if (error instanceof DevboxOwnerTokenMissingError)
|
|
112
|
+
return `Git login unavailable. ${error.message}`;
|
|
113
|
+
const renew = `A person must renew it: run \`seq-studio login --env ${envName}\` in a terminal with a browser, then retry the git command. ` +
|
|
114
|
+
'An agent cannot complete a browser login; retrying git will not help until then. ' +
|
|
115
|
+
`Check with \`seq-studio auth whoami -e ${envName}\`.`;
|
|
116
|
+
if (error instanceof NotLoggedInError) {
|
|
117
|
+
const expired = error.message.includes('expired');
|
|
118
|
+
return `Git login unavailable: ${expired ? `your seq-studio login for ${envName} has expired (logins last about 12 hours and are not refreshed)` : `there is no seq-studio login for ${envName}`}. ${renew}`;
|
|
100
119
|
}
|
|
120
|
+
return `Git login unavailable for ${envName}. ${renew}`;
|
|
101
121
|
}
|
|
102
122
|
function shellQuote(value) {
|
|
103
123
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
@@ -114,43 +134,50 @@ async function shimRunsScript(candidate, script, target) {
|
|
|
114
134
|
}
|
|
115
135
|
return false;
|
|
116
136
|
}
|
|
117
|
-
/**
|
|
118
|
-
|
|
137
|
+
/** Whether `candidate` runs exactly `script`: a link to it, or a generated shim that execs it. */
|
|
138
|
+
async function launchesScript(candidate, script, target) {
|
|
139
|
+
try {
|
|
140
|
+
if (await realpath(candidate) === target)
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
return await shimRunsScript(candidate, script, target);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The command Git runs to reach this CLI, as argv. Prefers a stable installed
|
|
155
|
+
* launcher (SEQ_STUDIO_LAUNCHER, the invocation path, or one on PATH) that runs
|
|
156
|
+
* this exact build, so a later PATH change cannot make Git run a different
|
|
157
|
+
* CLI. Without one (`node …/dist/bin.js`), it pins this node and script;
|
|
158
|
+
* `repos attach-login` re-binds a checkout after an upgrade moves either.
|
|
159
|
+
*/
|
|
160
|
+
export async function resolveGitHelperLauncher({ scriptPath = process.argv[1], launcherHint = process.env.SEQ_STUDIO_LAUNCHER, searchPath = process.env.PATH, nodePath = process.execPath, } = {}) {
|
|
119
161
|
if (!scriptPath || !isAbsolute(scriptPath))
|
|
120
162
|
throw new Error('Cannot identify the seq-studio launcher. Run repos clone through an installed seq-studio command.');
|
|
121
163
|
const script = resolve(scriptPath);
|
|
122
|
-
if (launcherHint && isAbsolute(launcherHint) && basename(launcherHint) === 'seq-studio') {
|
|
123
|
-
try {
|
|
124
|
-
// Our installed shell shim exports its own path before execing this build.
|
|
125
|
-
// Require the shim to target this exact script, so an inherited hint from
|
|
126
|
-
// another installation cannot make Git run a different CLI.
|
|
127
|
-
if ((await readFile(launcherHint, 'utf8')).includes(`exec node "${script}" "$@"`))
|
|
128
|
-
return resolve(launcherHint);
|
|
129
|
-
}
|
|
130
|
-
catch { /* Stale or unrelated launcher; look for a matching executable. */ }
|
|
131
|
-
}
|
|
132
|
-
if (basename(script) === 'seq-studio')
|
|
133
|
-
return script; // Node preserves the symlink invocation path.
|
|
134
164
|
const target = await realpath(script);
|
|
165
|
+
// An inherited hint from another installation is ignored unless it runs this build.
|
|
166
|
+
if (launcherHint && isAbsolute(launcherHint) && await launchesScript(launcherHint, script, target))
|
|
167
|
+
return [resolve(launcherHint)];
|
|
168
|
+
if (basename(script) === 'seq-studio')
|
|
169
|
+
return [script]; // Node preserves the symlink invocation path.
|
|
135
170
|
for (const directory of (searchPath ?? '').split(delimiter).filter(Boolean)) {
|
|
136
171
|
const candidate = join(directory, 'seq-studio');
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
catch { /* Not an installed launcher in this PATH entry. */ }
|
|
142
|
-
try {
|
|
143
|
-
if (await shimRunsScript(candidate, script, target))
|
|
144
|
-
return resolve(candidate);
|
|
145
|
-
}
|
|
146
|
-
catch { /* Not a matching generated shim. */ }
|
|
147
|
-
}
|
|
148
|
-
throw new Error('Cannot identify a stable seq-studio launcher for Git. Install this CLI with install-cli.sh or invoke its installed executable, then clone again.');
|
|
172
|
+
if (await launchesScript(candidate, script, target))
|
|
173
|
+
return [resolve(candidate)];
|
|
174
|
+
}
|
|
175
|
+
return [nodePath, script];
|
|
149
176
|
}
|
|
150
177
|
/** Store only a helper command, bound to this environment and repository URL. */
|
|
151
|
-
export async function configureGitLogin({ destDir, envName, cloneUrl,
|
|
152
|
-
const
|
|
153
|
-
const helper = `!${shellQuote(
|
|
178
|
+
export async function configureGitLogin({ destDir, envName, cloneUrl, launcher, }) {
|
|
179
|
+
const command = launcher ?? await resolveGitHelperLauncher();
|
|
180
|
+
const helper = `!${command.map(shellQuote).join(' ')} auth git-credential --env ${shellQuote(envName)} --url ${shellQuote(cloneUrl)}`;
|
|
154
181
|
const config = async (...args) => { await exec('git', ['-C', destDir, 'config', '--local', ...args]); };
|
|
155
182
|
// An empty helper resets inherited credential stores for this URL. That keeps
|
|
156
183
|
// an Auth0 access token out of the user's global store/keychain on approval.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ParsedArgs } from '../argv.js';
|
|
2
|
+
export declare const REPO_CONNECT_USAGE = "usage:\n seq-studio repo connect -e <env> --stage staging|prod [--adopt <namespace/repo>:<branch>] [--dir <checkout>] [--json]\n seq-studio repo disconnect -e <env> [--dir <checkout>] [--yes]\n seq-studio repo status -e <env> [--stage staging|prod] [--limit <n>] [--dir <checkout>] [--json]\n seq-studio repo bind -e <env> --stage staging|prod [--dry-run] [--dir <checkout>] [--json]\n\n connect: let this GitHub repository deploy to one stage of an Atlas. The dev branch deploys to staging and the\n release branch to prod (from .seq/github.yml); the Atlas's branch policy pins the images of the repository's\n seq-ci release. --adopt moves a git-service branch's deployments here: its bindings and the resources it controls,\n and it drops to checks-only. release group (Sequence Staff) only; --adopt also needs merge rights on the git-service repository.\n\n disconnect: stop all GitHub deploys of this repository to the Atlas, including queued and retried ones.\n\n status: this repository's releases on the Atlas, newest first, with each target's deployment state.\n\n bind: for a repository whose resources were deployed by hand before it deployed from CI, bind each target to the\n one existing, ready resource of exactly its name that you may deploy, and make the branch its controller. Run it\n after connect and before the first deploy, or every existing resource plans as a new create. Only targets the\n stage's plan deploys are bound: one scoped to other stages (its own or its Application's stages in\n .seq/repository.yml) is skipped and reported. --dry-run previews.\n\n Managed Pipelines are released under the name in .seq/github.yml's release_repository (seq-studio repo init\n --release-repository apps/platform-billing). If a git-service repository of that name exists on the Atlas, they\n keep releasing under it (you need its identity receipt and merge rights); otherwise connect claims the name for\n this repository, and no other repository can use it there.\n\n Uses gh (authenticated) to read the repository id and seq-ci's pinned images.";
|
|
3
|
+
/** The candidate and Next.js images a seq-ci release pins, read from its pipeline workflow. */
|
|
4
|
+
export declare function seqCiImages({ workflowText, release }: {
|
|
5
|
+
workflowText: string;
|
|
6
|
+
release: string;
|
|
7
|
+
}): {
|
|
8
|
+
image: string;
|
|
9
|
+
nextImage: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The staging Atlas a seq-ci release's pipeline names for `org` (its `SEQ_CI_ATLAS_ORIGINS`): where a prod deploy reads
|
|
13
|
+
* promoted builds from. The prod Atlas records it on the release branch's policy and contacts only that origin.
|
|
14
|
+
*/
|
|
15
|
+
export declare function seqCiStagingOrigin({ workflowText, org }: {
|
|
16
|
+
workflowText: string;
|
|
17
|
+
org: string;
|
|
18
|
+
}): string;
|
|
19
|
+
/** `--adopt namespace/repo:branch`. */
|
|
20
|
+
export declare function parseAdopt(value: string): {
|
|
21
|
+
namespace: string;
|
|
22
|
+
name: string;
|
|
23
|
+
branch: string;
|
|
24
|
+
};
|
|
25
|
+
/** A preflight refusal arrives as JSON naming each denied operation; anything else is already prose. */
|
|
26
|
+
export declare function readableReason(reason: string): string;
|
|
27
|
+
interface TreeEntry {
|
|
28
|
+
path: string;
|
|
29
|
+
mode: string;
|
|
30
|
+
sha: string;
|
|
31
|
+
}
|
|
32
|
+
/** The committed tree at HEAD: what CI deploys, never uncommitted edits. */
|
|
33
|
+
export declare function parseLsTree(output: string): TreeEntry[];
|
|
34
|
+
export declare function runRepoConnectCommand(sub: 'connect' | 'disconnect' | 'status' | 'bind', args: ParsedArgs): Promise<number>;
|
|
35
|
+
export {};
|