@sequenceholdings/studio-cli 0.7.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +390 -54
- package/dist/access/commands.d.ts +1 -1
- package/dist/access/commands.js +102 -55
- package/dist/access/custom-role-hosts.d.ts +3 -0
- package/dist/access/custom-role-hosts.js +88 -0
- package/dist/access/group-rosters.d.ts +6 -0
- package/dist/access/group-rosters.js +33 -0
- package/dist/access/host-contract.d.ts +55 -0
- package/dist/access/host-contract.js +33 -0
- package/dist/access/hosts.d.ts +4 -0
- package/dist/access/hosts.js +60 -0
- package/dist/access/principal.d.ts +16 -0
- package/dist/access/principal.js +36 -0
- package/dist/access/roles.d.ts +18 -0
- package/dist/access/roles.js +89 -0
- package/dist/access/tier-hosts.d.ts +12 -0
- package/dist/access/tier-hosts.js +206 -0
- package/dist/agents/commands.d.ts +1 -1
- package/dist/agents/commands.js +76 -16
- package/dist/agents/scaffold.js +8 -3
- package/dist/app/commands.d.ts +3 -1
- package/dist/app/commands.js +88 -12
- package/dist/app/manifest.d.ts +2 -2
- package/dist/app/official-source.d.ts +4 -2
- package/dist/app/official-source.js +6 -4
- package/dist/app/readme.js +2 -2
- package/dist/app/validate.d.ts +16 -0
- package/dist/app/validate.js +40 -0
- package/dist/app/workspace-model.js +4 -0
- package/dist/app/workspace-scaffold.js +5 -3
- package/dist/app/workspace.d.ts +2 -0
- package/dist/app/workspace.js +1 -1
- package/dist/artifact/delegate.js +26 -3
- package/dist/artifact/sandbox.js +2 -1
- package/dist/atlas-client.d.ts +17 -8
- package/dist/atlas-client.js +146 -62
- package/dist/bin.js +10 -1
- package/dist/cli-errors.js +12 -3
- package/dist/command-contract.d.ts +14 -2
- package/dist/command-contract.js +4 -2
- package/dist/command-help.d.ts +9 -7
- package/dist/command-help.js +56 -12
- package/dist/env-flags.d.ts +7 -0
- package/dist/env-flags.js +23 -0
- package/dist/functions/commands.d.ts +4 -0
- package/dist/functions/commands.js +127 -11
- package/dist/functions/manifest.d.ts +5 -0
- package/dist/functions/manifest.js +44 -23
- package/dist/functions/service-account-guidance.d.ts +21 -0
- package/dist/functions/service-account-guidance.js +62 -0
- package/dist/functions/workspace.d.ts +11 -0
- package/dist/functions/workspace.js +52 -0
- package/dist/main.d.ts +2 -1
- package/dist/main.js +17 -3
- package/dist/orm/delegate.d.ts +1 -0
- package/dist/orm/delegate.js +65 -12
- package/dist/orm/discover-schema.d.ts +26 -0
- package/dist/orm/discover-schema.js +5 -0
- package/dist/orm/execute.js +11 -5
- package/dist/orm/failures.d.ts +32 -0
- package/dist/orm/failures.js +75 -0
- package/dist/orm/operation-show.d.ts +2 -0
- package/dist/orm/operation-show.js +35 -0
- package/dist/orm/read.js +3 -3
- package/dist/orm/version-guard.d.ts +3 -0
- package/dist/orm/version-guard.js +63 -0
- package/dist/pipeline/commands.js +4 -1
- package/dist/principals/commands.d.ts +3 -0
- package/dist/principals/commands.js +124 -0
- package/dist/process/runs.d.ts +4 -3
- package/dist/process/runs.js +52 -10
- package/dist/release-age.d.ts +1 -1
- package/dist/release-age.js +1 -0
- package/dist/repos/commands.d.ts +44 -0
- package/dist/repos/commands.js +55 -15
- package/dist/repos/init-repo.d.ts +45 -0
- package/dist/repos/init-repo.js +257 -0
- package/dist/sandbox-unpushed-warning.d.ts +23 -0
- package/dist/sandbox-unpushed-warning.js +86 -0
- package/dist/service-accounts/commands.js +15 -3
- package/dist/templates/commands.d.ts +14 -2
- package/dist/templates/commands.js +70 -16
- package/dist/templates/process/pnpm-workspace.yaml +1 -0
- package/dist/transient-503.d.ts +4 -0
- package/dist/transient-503.js +25 -0
- package/package.json +14 -10
- package/templates/process/pnpm-workspace.yaml +1 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `--repo <namespace>/<name>` on the init commands (`init`, `orm init`,
|
|
3
|
+
* `functions init`, `artifact init`, `agents init`): put the scaffold in a
|
|
4
|
+
* platform git-service repository's working tree from the start, so the work
|
|
5
|
+
* survives a lost laptop or a reset agent sandbox once it is pushed.
|
|
6
|
+
*
|
|
7
|
+
* The repository is created when it does not exist yet. Then either:
|
|
8
|
+
* - clone mode: the target is not inside a Git checkout, so the repository
|
|
9
|
+
* is cloned into the (absent or empty) target and the scaffold lands in
|
|
10
|
+
* the clone; or
|
|
11
|
+
* - origin mode: the target is inside a Git checkout, so the repository
|
|
12
|
+
* becomes that checkout's `origin` (an existing, different origin is
|
|
13
|
+
* refused) and the scaffold lands in that working tree.
|
|
14
|
+
*
|
|
15
|
+
* Nothing is committed or pushed: the init prints the exact commands instead.
|
|
16
|
+
* Every local refusal happens before the repository is created.
|
|
17
|
+
*/
|
|
18
|
+
import { execFile } from 'node:child_process';
|
|
19
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
20
|
+
import { basename, dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
21
|
+
import { promisify } from 'node:util';
|
|
22
|
+
import { resolveRepo } from '@sequenceholdings/artifact-studio/git-service-client';
|
|
23
|
+
import { AtlasApiError } from '../atlas-client.js';
|
|
24
|
+
import { printCliError } from '../cli-errors.js';
|
|
25
|
+
import { clientOptions, LOG } from '../functions/commands.js';
|
|
26
|
+
import { isSandboxTokenMode } from '../sandbox-auth.js';
|
|
27
|
+
import { assertGitCheckoutAuth, cloneRepoById, cloneUrl, createRepo, normalizeCloneUrl, parseRepoPath, reposContext, stringFlag, } from './commands.js';
|
|
28
|
+
import { configureGitLogin } from './git-credential.js';
|
|
29
|
+
const exec = promisify(execFile);
|
|
30
|
+
const GIT_TIMEOUT_MS = 10_000;
|
|
31
|
+
async function git(args) {
|
|
32
|
+
const { stdout } = await exec('git', args, { encoding: 'utf8', timeout: GIT_TIMEOUT_MS });
|
|
33
|
+
return stdout.trim();
|
|
34
|
+
}
|
|
35
|
+
function nearestExistingDirectory(path) {
|
|
36
|
+
let current = path;
|
|
37
|
+
while (!existsSync(current)) {
|
|
38
|
+
const parent = dirname(current);
|
|
39
|
+
if (parent === current)
|
|
40
|
+
return current;
|
|
41
|
+
current = parent;
|
|
42
|
+
}
|
|
43
|
+
return current;
|
|
44
|
+
}
|
|
45
|
+
/** The Git work tree containing `path` (or its nearest existing ancestor), or null. */
|
|
46
|
+
async function gitWorkTreeRoot(path) {
|
|
47
|
+
try {
|
|
48
|
+
return await git(['-C', nearestExistingDirectory(path), 'rev-parse', '--show-toplevel']);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function originUrl(root) {
|
|
55
|
+
try {
|
|
56
|
+
return await git(['-C', root, 'remote', 'get-url', 'origin']);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Compare remotes without echoing them: an old checkout's URL may embed credentials. */
|
|
63
|
+
function sameRemote(a, b) {
|
|
64
|
+
const normalize = (url) => url.trim().replace(/\/+$/, '').replace(/\.git$/, '').replace(/\/git$/, '');
|
|
65
|
+
return normalize(a) === normalize(b);
|
|
66
|
+
}
|
|
67
|
+
export async function inspectLocalCheckout(targetDir) {
|
|
68
|
+
const root = await gitWorkTreeRoot(targetDir);
|
|
69
|
+
if (root)
|
|
70
|
+
return { mode: 'origin', root, origin: await originUrl(root) };
|
|
71
|
+
if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {
|
|
72
|
+
throw new Error(`${targetDir} exists, is not empty, and is not a Git checkout. --repo clones into a new or empty ` +
|
|
73
|
+
'directory, or sets origin on an existing checkout.');
|
|
74
|
+
}
|
|
75
|
+
return { mode: 'clone', targetDir };
|
|
76
|
+
}
|
|
77
|
+
/** Only "this repository does not exist (for you)" returns null; HTTP failures propagate. */
|
|
78
|
+
async function findRepo({ ctx, namespace, name }) {
|
|
79
|
+
try {
|
|
80
|
+
return await resolveRepo({ ...clientOptions(ctx), namespace, name });
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (typeof Reflect.get(Object(error), 'status') === 'number')
|
|
84
|
+
throw error;
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function findOrCreateRepo({ ctx, namespace, name, empty }) {
|
|
89
|
+
const existing = await findRepo({ ctx, namespace, name });
|
|
90
|
+
if (existing)
|
|
91
|
+
return { ...existing, created: false };
|
|
92
|
+
try {
|
|
93
|
+
// A checkout with its own history needs an empty repository to push into;
|
|
94
|
+
// a clone starts from Atlas's seed (README + .seq/identity.json receipt).
|
|
95
|
+
const repo = await createRepo({ ctx, namespace, name, ...(empty ? { gitBackend: 'walgit' } : {}) });
|
|
96
|
+
console.log(`${LOG} created ${namespace}/${name} on ${ctx.env.name}${empty ? ' (empty)' : ''}`);
|
|
97
|
+
return { id: repo.id, defaultBranch: repo.defaultBranch, created: true };
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
// Lost a race with another creator: use the repository that now exists.
|
|
101
|
+
if (error instanceof AtlasApiError && error.status === 409) {
|
|
102
|
+
const raced = await resolveRepo({ ...clientOptions(ctx), namespace, name });
|
|
103
|
+
return { ...raced, created: false };
|
|
104
|
+
}
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The origin URL the credential helper must be bound to. Git selects a
|
|
110
|
+
* `credential.<url>.helper` by the URL the remote actually uses, and the
|
|
111
|
+
* helper answers only for that exact path (useHttpPath), so a kept origin is
|
|
112
|
+
* bound as is: `…/repos/<id>.git` and `…/repos/<id>/git` are different URLs to
|
|
113
|
+
* Git. A missing origin is added as the canonical clone URL. A kept origin
|
|
114
|
+
* that differs from its validated form only by a trailing slash is rewritten
|
|
115
|
+
* to that form, since the helper never answers for a trailing-slash path.
|
|
116
|
+
*/
|
|
117
|
+
async function originForLogin({ ctx, root, origin, repoId }) {
|
|
118
|
+
if (origin === null) {
|
|
119
|
+
const url = cloneUrl(ctx, repoId);
|
|
120
|
+
await git(['-C', root, 'remote', 'add', 'origin', url]);
|
|
121
|
+
return url;
|
|
122
|
+
}
|
|
123
|
+
let normalized;
|
|
124
|
+
try {
|
|
125
|
+
normalized = normalizeCloneUrl(origin, ctx.env);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
const detail = error instanceof Error ? error.message.replace(/^--url /, '') : String(error);
|
|
129
|
+
throw new Error(`The origin remote of ${root} is not a usable git-service clone URL: ${detail}`);
|
|
130
|
+
}
|
|
131
|
+
if (normalized !== origin)
|
|
132
|
+
await git(['-C', root, 'remote', 'set-url', 'origin', normalized]);
|
|
133
|
+
return normalized;
|
|
134
|
+
}
|
|
135
|
+
/** Quote a printed shell argument only when it needs it. */
|
|
136
|
+
function shellArg(value) {
|
|
137
|
+
return /^[\w./:@=+-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
|
|
138
|
+
}
|
|
139
|
+
function displayPath(path) {
|
|
140
|
+
const fromCwd = relative(process.cwd(), path);
|
|
141
|
+
if (fromCwd === '')
|
|
142
|
+
return '.';
|
|
143
|
+
return fromCwd.startsWith('..') || isAbsolute(fromCwd) ? path : fromCwd;
|
|
144
|
+
}
|
|
145
|
+
export function persistNextSteps({ root, repoPath, envName, defaultBranch, setup }) {
|
|
146
|
+
const dir = shellArg(displayPath(root));
|
|
147
|
+
const gitC = `git -C ${dir}`;
|
|
148
|
+
const lines = [`${LOG} the scaffold is in ${repoPath}'s working tree but not committed. Commit and push it:`];
|
|
149
|
+
if (setup === 'origin-created') {
|
|
150
|
+
// An empty repository has no seed commit, so install its identity receipt here.
|
|
151
|
+
const env = isSandboxTokenMode() ? '' : ` -e ${shellArg(envName)}`;
|
|
152
|
+
lines.push(` seq-studio repos identity ${repoPath}${env} --write --dir ${dir}`);
|
|
153
|
+
}
|
|
154
|
+
const commit = `${gitC} add -A && ${gitC} commit -m ${shellArg(`Scaffold ${basename(root)}`)}`;
|
|
155
|
+
if (setup === 'origin-added') {
|
|
156
|
+
// Commit first: a rebase refuses a working tree the scaffold left with unstaged changes.
|
|
157
|
+
lines.push(` ${commit}`);
|
|
158
|
+
lines.push(` ${gitC} pull --rebase origin ${shellArg(defaultBranch)} # only if ${repoPath} already has commits`);
|
|
159
|
+
lines.push(` ${gitC} push -u origin HEAD`);
|
|
160
|
+
return lines;
|
|
161
|
+
}
|
|
162
|
+
const target = setup === 'origin-created' ? `HEAD:${shellArg(defaultBranch)}` : 'HEAD';
|
|
163
|
+
lines.push(` ${commit} && ${gitC} push -u origin ${target}`);
|
|
164
|
+
return lines;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Prepare the repository checkout for `target`, run `scaffold` in it, then
|
|
168
|
+
* print how to commit and push. Returns the scaffold's exit code (1 when the
|
|
169
|
+
* repository could not be prepared).
|
|
170
|
+
*/
|
|
171
|
+
export async function runInitWithRepo({ args, target, scaffold, deps = {} }) {
|
|
172
|
+
let repoPath;
|
|
173
|
+
let root;
|
|
174
|
+
let setup;
|
|
175
|
+
let defaultBranch;
|
|
176
|
+
let envName;
|
|
177
|
+
try {
|
|
178
|
+
const { namespace, name } = parseRepoPath(stringFlag(args.flags, 'repo'));
|
|
179
|
+
repoPath = `${namespace}/${name}`;
|
|
180
|
+
const checkout = await inspectLocalCheckout(resolve(target));
|
|
181
|
+
const ctx = await reposContext(args);
|
|
182
|
+
envName = ctx.env.name;
|
|
183
|
+
if (checkout.mode === 'origin' && checkout.origin !== null) {
|
|
184
|
+
const existing = await findRepo({ ctx, namespace, name });
|
|
185
|
+
if (!existing || !sameRemote(checkout.origin, cloneUrl(ctx, existing.id))) {
|
|
186
|
+
throw new Error(`${checkout.root} already has an origin remote that is not ${repoPath} on ${ctx.env.name}. ` +
|
|
187
|
+
`Run the init outside that checkout to clone ${repoPath}, or drop --repo.`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (checkout.mode === 'clone')
|
|
191
|
+
assertGitCheckoutAuth(ctx);
|
|
192
|
+
const repo = await findOrCreateRepo({ ctx, namespace, name, empty: checkout.mode === 'origin' });
|
|
193
|
+
defaultBranch = repo.defaultBranch;
|
|
194
|
+
if (checkout.mode === 'clone') {
|
|
195
|
+
await cloneRepoById({ ctx, repoId: repo.id, destDir: checkout.targetDir, gitClone: deps.gitClone });
|
|
196
|
+
root = checkout.targetDir;
|
|
197
|
+
setup = 'cloned';
|
|
198
|
+
console.log(`${LOG} cloned ${repoPath} → ${root}`);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
root = checkout.root;
|
|
202
|
+
const url = await originForLogin({ ctx, root, origin: checkout.origin, repoId: repo.id });
|
|
203
|
+
await configureGitLogin({ destDir: root, envName: ctx.env.name, cloneUrl: url });
|
|
204
|
+
setup = checkout.origin !== null ? 'origin-kept' : repo.created ? 'origin-created' : 'origin-added';
|
|
205
|
+
console.log(`${LOG} ${checkout.origin === null ? 'set origin of' : 'using origin of'} ${root} → ${repoPath}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
printCliError(error);
|
|
210
|
+
return 1;
|
|
211
|
+
}
|
|
212
|
+
const code = await scaffold();
|
|
213
|
+
if (code !== 0) {
|
|
214
|
+
console.error(`${LOG} ${root} is a checkout of ${repoPath}; commit and push what is there once the error is fixed.`);
|
|
215
|
+
return code;
|
|
216
|
+
}
|
|
217
|
+
for (const line of persistNextSteps({ root, repoPath, envName, defaultBranch, setup }))
|
|
218
|
+
console.log(line);
|
|
219
|
+
return code;
|
|
220
|
+
}
|
|
221
|
+
/** The same parsed arguments with `--repo` removed, for the scaffold itself. */
|
|
222
|
+
export function withoutRepoFlag(args) {
|
|
223
|
+
const flags = { ...args.flags };
|
|
224
|
+
delete flags.repo;
|
|
225
|
+
return { ...args, flags };
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* For delegated init commands that forward raw argv: split `--repo <v>` /
|
|
229
|
+
* `--repo=<v>` off. `repo` is undefined when absent and `true` when given
|
|
230
|
+
* without a value (so the caller can report it like any other flag).
|
|
231
|
+
*/
|
|
232
|
+
export function extractRepoFlag(argv) {
|
|
233
|
+
const rest = [];
|
|
234
|
+
let repo;
|
|
235
|
+
for (let i = 0; i < argv.length; i++) {
|
|
236
|
+
const arg = argv[i];
|
|
237
|
+
if (arg === undefined)
|
|
238
|
+
continue;
|
|
239
|
+
if (arg.startsWith('--repo=')) {
|
|
240
|
+
repo = arg.slice('--repo='.length) || true;
|
|
241
|
+
}
|
|
242
|
+
else if (arg === '--repo') {
|
|
243
|
+
const next = argv[i + 1];
|
|
244
|
+
if (next !== undefined && !next.startsWith('-')) {
|
|
245
|
+
repo = next;
|
|
246
|
+
i += 1;
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
repo = true;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
rest.push(arg);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return { repo, rest };
|
|
257
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Runs `git <args>` in `cwd` and resolves its stdout; rejects on any failure. */
|
|
2
|
+
export type GitRunner = (args: {
|
|
3
|
+
cwd: string;
|
|
4
|
+
args: string[];
|
|
5
|
+
}) => Promise<string>;
|
|
6
|
+
export declare const runGitQuietly: GitRunner;
|
|
7
|
+
interface CheckoutState {
|
|
8
|
+
dirty: boolean;
|
|
9
|
+
ahead: number;
|
|
10
|
+
hasUpstream: boolean;
|
|
11
|
+
hasCommits: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** Parse `git status --porcelain=v2 --branch`. */
|
|
14
|
+
export declare function parseStatus(output: string): CheckoutState;
|
|
15
|
+
/** The warning for `cwd`, or null when there is nothing to warn about (or anything fails). */
|
|
16
|
+
export declare function unpushedWorkWarning({ cwd, env, git, }?: {
|
|
17
|
+
cwd?: string;
|
|
18
|
+
env?: NodeJS.ProcessEnv;
|
|
19
|
+
git?: GitRunner;
|
|
20
|
+
}): Promise<string | null>;
|
|
21
|
+
/** Print the warning to stderr, if any. Never throws. */
|
|
22
|
+
export declare function warnUnpushedSandboxWork(): Promise<void>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent sandboxes are temporary: a reset after inactivity can take every file
|
|
3
|
+
* with it. After each command in sandbox token mode, warn on stderr when the
|
|
4
|
+
* working directory is a Git checkout with work that exists only here:
|
|
5
|
+
* uncommitted changes (untracked files included), commits ahead of the
|
|
6
|
+
* upstream, or, without an upstream, commits on no remote-tracking ref.
|
|
7
|
+
*
|
|
8
|
+
* Best effort by design: it never throws, never touches stdout (JSON output
|
|
9
|
+
* stays clean), never changes an exit code, gives up on any Git error or after
|
|
10
|
+
* a short timeout, and does nothing outside sandbox token mode.
|
|
11
|
+
*/
|
|
12
|
+
import { execFile } from 'node:child_process';
|
|
13
|
+
import { isSandboxTokenMode } from './sandbox-auth.js';
|
|
14
|
+
const GIT_TIMEOUT_MS = 1_000;
|
|
15
|
+
export const runGitQuietly = ({ cwd, args }) => new Promise((resolve, reject) => {
|
|
16
|
+
execFile('git', ['-C', cwd, ...args], {
|
|
17
|
+
encoding: 'utf8',
|
|
18
|
+
timeout: GIT_TIMEOUT_MS,
|
|
19
|
+
maxBuffer: 1024 * 1024,
|
|
20
|
+
// Read-only: never take the index lock or prompt for credentials.
|
|
21
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: '0', GIT_TERMINAL_PROMPT: '0' },
|
|
22
|
+
}, (error, stdout) => (error ? reject(error) : resolve(stdout)));
|
|
23
|
+
});
|
|
24
|
+
/** Parse `git status --porcelain=v2 --branch`. */
|
|
25
|
+
export function parseStatus(output) {
|
|
26
|
+
const state = { dirty: false, ahead: 0, hasUpstream: false, hasCommits: true };
|
|
27
|
+
for (const line of output.split('\n')) {
|
|
28
|
+
if (!line)
|
|
29
|
+
continue;
|
|
30
|
+
if (!line.startsWith('# ')) {
|
|
31
|
+
state.dirty = true;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (line === '# branch.oid (initial)')
|
|
35
|
+
state.hasCommits = false;
|
|
36
|
+
else if (line.startsWith('# branch.upstream '))
|
|
37
|
+
state.hasUpstream = true;
|
|
38
|
+
else if (line.startsWith('# branch.ab '))
|
|
39
|
+
state.ahead = Number(/\+(\d+)/.exec(line)?.[1] ?? 0);
|
|
40
|
+
}
|
|
41
|
+
return state;
|
|
42
|
+
}
|
|
43
|
+
function describe({ dirty, unpushed }) {
|
|
44
|
+
if (dirty && unpushed)
|
|
45
|
+
return `uncommitted changes and ${unpushed}`;
|
|
46
|
+
return dirty ? 'uncommitted changes' : unpushed ?? '';
|
|
47
|
+
}
|
|
48
|
+
/** The warning for `cwd`, or null when there is nothing to warn about (or anything fails). */
|
|
49
|
+
export async function unpushedWorkWarning({ cwd = process.cwd(), env = process.env, git = runGitQuietly, } = {}) {
|
|
50
|
+
try {
|
|
51
|
+
if (!isSandboxTokenMode(env))
|
|
52
|
+
return null;
|
|
53
|
+
const root = (await git({ cwd, args: ['rev-parse', '--show-toplevel'] })).trim();
|
|
54
|
+
if (!root)
|
|
55
|
+
return null;
|
|
56
|
+
const state = parseStatus(await git({ cwd: root, args: ['status', '--porcelain=v2', '--branch'] }));
|
|
57
|
+
let unpushed = null;
|
|
58
|
+
if (state.hasUpstream && state.ahead > 0) {
|
|
59
|
+
unpushed = `${state.ahead} unpushed commit${state.ahead === 1 ? '' : 's'}`;
|
|
60
|
+
}
|
|
61
|
+
else if (!state.hasUpstream && state.hasCommits) {
|
|
62
|
+
// No upstream: is HEAD on any remote-tracking branch at all?
|
|
63
|
+
const local = (await git({ cwd: root, args: ['rev-list', '--count', '--max-count=1', 'HEAD', '--not', '--remotes'] })).trim();
|
|
64
|
+
if (local !== '0')
|
|
65
|
+
unpushed = 'commits that are not pushed anywhere';
|
|
66
|
+
}
|
|
67
|
+
if (!state.dirty && !unpushed)
|
|
68
|
+
return null;
|
|
69
|
+
return (`[seq-studio] This sandbox is temporary and ${root} has ${describe({ dirty: state.dirty, unpushed })}. ` +
|
|
70
|
+
`Commit and push them (git -C ${root} status).`);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Print the warning to stderr, if any. Never throws. */
|
|
77
|
+
export async function warnUnpushedSandboxWork() {
|
|
78
|
+
try {
|
|
79
|
+
const warning = await unpushedWorkWarning();
|
|
80
|
+
if (warning)
|
|
81
|
+
console.error(warning);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Never let a warning affect the command.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { operatorPlatformClient } from '../atlas-client.js';
|
|
2
2
|
import { printCliError } from '../cli-errors.js';
|
|
3
3
|
import { requiredStringFlag, validateCommandInput, wantsHelp } from '../command-input.js';
|
|
4
4
|
import { buildContext, clientOptions } from '../functions/commands.js';
|
|
@@ -38,8 +38,20 @@ export async function runServiceAccountsCommand(sub, args) {
|
|
|
38
38
|
if (target !== undefined && !target.trim())
|
|
39
39
|
throw new Error('An account ID or slug is required.');
|
|
40
40
|
const ctx = await buildContext(args);
|
|
41
|
-
const
|
|
42
|
-
|
|
41
|
+
const accounts = operatorPlatformClient(clientOptions(ctx)).controlPlane.serviceAccounts;
|
|
42
|
+
let result;
|
|
43
|
+
if (sub === 'create') {
|
|
44
|
+
if (!body || !body.slug)
|
|
45
|
+
throw new Error('A service account slug is required.');
|
|
46
|
+
result = await accounts.create({ ...body, slug: body.slug });
|
|
47
|
+
}
|
|
48
|
+
else if (sub === 'show') {
|
|
49
|
+
if (!target)
|
|
50
|
+
throw new Error('An account ID is required.');
|
|
51
|
+
result = await accounts.get({ accountId: target });
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
result = await accounts.list();
|
|
43
55
|
console.log(JSON.stringify(result, null, 2));
|
|
44
56
|
return 0;
|
|
45
57
|
}
|
|
@@ -15,15 +15,27 @@ export declare function promotionTargetsFromRegistry(path: string, configuredUrl
|
|
|
15
15
|
}>): Promise<string[]>;
|
|
16
16
|
export declare function validateTemplateTree(entries: readonly TreeEntry[]): TreeEntry[];
|
|
17
17
|
export declare function verifyReleaseFiles(files: readonly RemoteFile[], release: TemplateRelease): void;
|
|
18
|
-
export declare function initFromTemplate({ selection, target, environment }: {
|
|
18
|
+
export declare function initFromTemplate({ selection, target, environment, intoCheckout }: {
|
|
19
19
|
selection: string;
|
|
20
20
|
target: string;
|
|
21
21
|
environment: string;
|
|
22
|
+
/** The target may be a git-service checkout prepared by `init --repo`; see writeTemplateToDirectory. */
|
|
23
|
+
intoCheckout?: boolean;
|
|
22
24
|
}): Promise<void>;
|
|
23
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Verify a release and write it to `target`, which must be new or empty.
|
|
27
|
+
* With `intoCheckout` (from `init --repo`), `target` may instead be a fresh
|
|
28
|
+
* git-service checkout. There `.git` is never written, the template's README
|
|
29
|
+
* replaces the seed README (the seed is a placeholder; its marker exists only to
|
|
30
|
+
* mark the clone as safe to fill), and the checkout's `.seq/identity.json` wins
|
|
31
|
+
* over any the template carries: that receipt is the server-issued identity of
|
|
32
|
+
* THIS repository, and the template's would bind it to the template's source.
|
|
33
|
+
*/
|
|
34
|
+
export declare function writeTemplateToDirectory({ files, release, target, intoCheckout }: {
|
|
24
35
|
files: RemoteFile[];
|
|
25
36
|
release: TemplateRelease;
|
|
26
37
|
target: string;
|
|
38
|
+
intoCheckout?: boolean;
|
|
27
39
|
}): Promise<void>;
|
|
28
40
|
export declare function runTemplatesCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;
|
|
29
41
|
export {};
|
|
@@ -6,6 +6,7 @@ import { AtlasApiError, getJson, getJsonOr404, postJson } from '../atlas-client.
|
|
|
6
6
|
import { readConfig } from '../config.js';
|
|
7
7
|
import { readRegisteredEnvironmentUrls } from '../env-registry.js';
|
|
8
8
|
import { buildContext, clientOptions } from '../functions/commands.js';
|
|
9
|
+
import { isGitServiceSeedReadme } from '../app/readme.js';
|
|
9
10
|
import { stringFlag } from '../repos/commands.js';
|
|
10
11
|
import { TEMPLATE_CATALOG_REPO, TEMPLATE_METADATA_PATH, TEMPLATE_NAMESPACE, TEMPLATE_RELEASE_PATH, ledgerPath, parseTemplateSelection, releaseBranch, targetIncludesRelease, templateDigest, templateMetadataSchema, templateReleaseSchema, validateTemplatePublishRoute, } from './catalog.js';
|
|
11
12
|
const LOG = '[seq-studio]';
|
|
@@ -376,7 +377,7 @@ async function list(args) {
|
|
|
376
377
|
}
|
|
377
378
|
return 0;
|
|
378
379
|
}
|
|
379
|
-
export async function initFromTemplate({ selection, target, environment }) {
|
|
380
|
+
export async function initFromTemplate({ selection, target, environment, intoCheckout = false }) {
|
|
380
381
|
const { name, version } = parseTemplateSelection(selection);
|
|
381
382
|
const ctx = await contextFor(environment);
|
|
382
383
|
const catalog = await findRepo(ctx, TEMPLATE_CATALOG_REPO);
|
|
@@ -389,33 +390,86 @@ export async function initFromTemplate({ selection, target, environment }) {
|
|
|
389
390
|
if (!repo)
|
|
390
391
|
throw new Error(`${TEMPLATE_NAMESPACE}/${name} is missing on ${environment}.`);
|
|
391
392
|
const files = await readFiles(ctx, repo, releaseBranch(version));
|
|
392
|
-
await writeTemplateToDirectory({ files, release, target });
|
|
393
|
+
await writeTemplateToDirectory({ files, release, target, intoCheckout });
|
|
393
394
|
console.log(`${LOG} initialized ${resolve(target)} from ${selection} on ${environment}`);
|
|
394
395
|
console.log(`${LOG} source: ${release.source.repo}@${release.source.commit} sha256:${release.digest}`);
|
|
395
396
|
}
|
|
396
|
-
|
|
397
|
+
/** The server-issued repository receipt a git-service clone starts with. */
|
|
398
|
+
const REPOSITORY_IDENTITY_PATH = '.seq/identity.json';
|
|
399
|
+
/** What a fresh git-service clone may already hold before a template lands in it. */
|
|
400
|
+
const CHECKOUT_ENTRIES = new Set(['.git', '.DS_Store', 'README.md', '.seq']);
|
|
401
|
+
/**
|
|
402
|
+
* Whether `dest` is a fresh git-service checkout a template may populate:
|
|
403
|
+
* Git metadata, the seed README (with its marker), and at most the issued
|
|
404
|
+
* `.seq/identity.json`. Anything else means real content, so it is refused.
|
|
405
|
+
*/
|
|
406
|
+
async function assertFreshCheckout(dest) {
|
|
407
|
+
const entries = await readdir(dest);
|
|
408
|
+
const foreign = entries.find((name) => !CHECKOUT_ENTRIES.has(name));
|
|
409
|
+
if (foreign)
|
|
410
|
+
throw new Error(`${dest} is not empty (${foreign}); a template fills only a new directory or a fresh git-service clone.`);
|
|
411
|
+
if (entries.includes('README.md') && !isGitServiceSeedReadme(await readFile(join(dest, 'README.md'), 'utf8'))) {
|
|
412
|
+
throw new Error(`${dest} already has a README.md that is not a git-service seed; refusing to overwrite it.`);
|
|
413
|
+
}
|
|
414
|
+
if (entries.includes('.seq') && (await readdir(join(dest, '.seq'))).some((name) => name !== 'identity.json')) {
|
|
415
|
+
throw new Error(`${dest}/.seq holds more than the issued identity.json; refusing to write a template into it.`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/** Write the release's source files under `temp`; returns the paths written. */
|
|
419
|
+
async function stageTemplateFiles({ files, temp, intoCheckout }) {
|
|
420
|
+
const written = [];
|
|
421
|
+
for (const file of files) {
|
|
422
|
+
if (file.path === TEMPLATE_RELEASE_PATH)
|
|
423
|
+
continue;
|
|
424
|
+
assertSafePath(file.path);
|
|
425
|
+
if (intoCheckout && (file.path === '.git' || file.path.startsWith('.git/')))
|
|
426
|
+
throw new Error(`Unsafe template file path: ${file.path}`);
|
|
427
|
+
if (intoCheckout && file.path === REPOSITORY_IDENTITY_PATH)
|
|
428
|
+
continue;
|
|
429
|
+
const output = resolve(temp, file.path);
|
|
430
|
+
if (!output.startsWith(temp + sep))
|
|
431
|
+
throw new Error(`Unsafe template file path: ${file.path}`);
|
|
432
|
+
await mkdir(dirname(output), { recursive: true });
|
|
433
|
+
await writeFile(output, Buffer.from(file.content, 'base64'), { mode: file.mode === '100755' ? 0o755 : 0o644 });
|
|
434
|
+
written.push(file.path);
|
|
435
|
+
}
|
|
436
|
+
return written;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Verify a release and write it to `target`, which must be new or empty.
|
|
440
|
+
* With `intoCheckout` (from `init --repo`), `target` may instead be a fresh
|
|
441
|
+
* git-service checkout. There `.git` is never written, the template's README
|
|
442
|
+
* replaces the seed README (the seed is a placeholder; its marker exists only to
|
|
443
|
+
* mark the clone as safe to fill), and the checkout's `.seq/identity.json` wins
|
|
444
|
+
* over any the template carries: that receipt is the server-issued identity of
|
|
445
|
+
* THIS repository, and the template's would bind it to the template's source.
|
|
446
|
+
*/
|
|
447
|
+
export async function writeTemplateToDirectory({ files, release, target, intoCheckout = false }) {
|
|
397
448
|
verifyReleaseFiles(files, release);
|
|
398
449
|
const dest = resolve(target);
|
|
399
450
|
if ((await lstat(dest).catch(() => null))?.isSymbolicLink())
|
|
400
451
|
throw new Error(`${dest} is a symlink.`);
|
|
401
|
-
|
|
452
|
+
const populated = existsSync(dest) && (await readdir(dest)).length > 0;
|
|
453
|
+
if (populated && !intoCheckout)
|
|
402
454
|
throw new Error(`${dest} is not empty.`);
|
|
455
|
+
if (populated)
|
|
456
|
+
await assertFreshCheckout(dest);
|
|
403
457
|
await mkdir(dirname(dest), { recursive: true });
|
|
404
458
|
const temp = await mkdtemp(join(dirname(dest), `.${basename(dest)}-template-`));
|
|
405
459
|
try {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
throw new Error(`Unsafe template file path: ${file.path}`);
|
|
413
|
-
await mkdir(dirname(output), { recursive: true });
|
|
414
|
-
await writeFile(output, Buffer.from(file.content, 'base64'), { mode: file.mode === '100755' ? 0o755 : 0o644 });
|
|
460
|
+
const written = await stageTemplateFiles({ files, temp, intoCheckout: populated });
|
|
461
|
+
if (!populated) {
|
|
462
|
+
if (existsSync(dest))
|
|
463
|
+
await rmdir(dest);
|
|
464
|
+
await rename(temp, dest);
|
|
465
|
+
return;
|
|
415
466
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
467
|
+
// Everything verified and staged; move it into the checkout file by file.
|
|
468
|
+
for (const path of written) {
|
|
469
|
+
await mkdir(dirname(join(dest, path)), { recursive: true });
|
|
470
|
+
await rename(join(temp, path), join(dest, path));
|
|
471
|
+
}
|
|
472
|
+
await rm(temp, { recursive: true, force: true });
|
|
419
473
|
}
|
|
420
474
|
catch (error) {
|
|
421
475
|
await rm(temp, { recursive: true, force: true });
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The structured `error.code` (or top-level `code`) of an Atlas error body, if any. */
|
|
2
|
+
export declare function errorCode(body: unknown): string | null;
|
|
3
|
+
/** Whether a 503 may clear if retried: anything but a known configuration error. */
|
|
4
|
+
export declare function isTransient503(body: unknown): boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured 503 codes that are a standing answer, not a warm-up: the feature
|
|
3
|
+
* is not configured for this environment, so retrying only delays the error.
|
|
4
|
+
* Atlas also sends plain `{ detail }` 503s for transient states without a
|
|
5
|
+
* Retry-After (for example a deploy-permission check that is briefly
|
|
6
|
+
* unavailable), so only a code listed here opts a 503 out of retrying.
|
|
7
|
+
*/
|
|
8
|
+
const PERMANENT_503_CODES = new Set(['storage_configuration']);
|
|
9
|
+
/** The structured `error.code` (or top-level `code`) of an Atlas error body, if any. */
|
|
10
|
+
export function errorCode(body) {
|
|
11
|
+
if (!body || typeof body !== 'object')
|
|
12
|
+
return null;
|
|
13
|
+
const { code, error } = body;
|
|
14
|
+
if (error && typeof error === 'object') {
|
|
15
|
+
const nested = error.code;
|
|
16
|
+
if (typeof nested === 'string')
|
|
17
|
+
return nested;
|
|
18
|
+
}
|
|
19
|
+
return typeof code === 'string' ? code : null;
|
|
20
|
+
}
|
|
21
|
+
/** Whether a 503 may clear if retried: anything but a known configuration error. */
|
|
22
|
+
export function isTransient503(body) {
|
|
23
|
+
const code = errorCode(body);
|
|
24
|
+
return code === null || !PERMANENT_503_CODES.has(code);
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequenceholdings/studio-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Unified Sequence Studio CLI — `seq-studio init` / `add` / `deploy` (app monorepos), `seq-studio agents`, `seq-studio process` (Lattice), `seq-studio artifact`, `seq-studio functions` / `secrets`, `seq-studio repos`, and `seq-studio auth whoami`. Includes Auth0 browser login shared with seqapi.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -36,21 +36,24 @@
|
|
|
36
36
|
"README.md"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"drizzle-orm": "^0.45.2",
|
|
39
40
|
"esbuild": "^0.25.0",
|
|
40
41
|
"js-yaml": "^4.3.2",
|
|
42
|
+
"semver": "^7.8.5",
|
|
41
43
|
"smol-toml": "^1.9.0",
|
|
42
44
|
"tsx": "^4.20.3",
|
|
43
|
-
"zod": "^4.1.13",
|
|
44
45
|
"yaml": "^2.8.4",
|
|
45
|
-
"
|
|
46
|
+
"zod": "^4.1.13",
|
|
47
|
+
"@sequenceholdings/agent-spec": "0.1.5",
|
|
48
|
+
"@sequenceholdings/artifact-studio": "0.11.0",
|
|
46
49
|
"@sequenceholdings/lattice": "0.1.7",
|
|
47
|
-
"@sequenceholdings/
|
|
48
|
-
"@sequenceholdings/
|
|
49
|
-
"@sequenceholdings/
|
|
50
|
+
"@sequenceholdings/managed-functions": "0.5.1",
|
|
51
|
+
"@sequenceholdings/storage": "0.1.3",
|
|
52
|
+
"@sequenceholdings/platform": "0.1.0"
|
|
50
53
|
},
|
|
51
54
|
"peerDependencies": {
|
|
52
|
-
"@sequenceholdings/orm": "2.
|
|
53
|
-
"@sequenceholdings/pipeline-spec": "0.3.
|
|
55
|
+
"@sequenceholdings/orm": "2.8.1",
|
|
56
|
+
"@sequenceholdings/pipeline-spec": "0.3.1"
|
|
54
57
|
},
|
|
55
58
|
"peerDependenciesMeta": {
|
|
56
59
|
"@sequenceholdings/orm": {
|
|
@@ -63,10 +66,11 @@
|
|
|
63
66
|
"devDependencies": {
|
|
64
67
|
"@types/js-yaml": "^4.0.9",
|
|
65
68
|
"@types/node": "^22.0.0",
|
|
69
|
+
"@types/semver": "^7.8.0",
|
|
66
70
|
"typescript": "^5.6.0",
|
|
67
71
|
"vitest": "^4.1.11",
|
|
68
|
-
"@sequenceholdings/
|
|
69
|
-
"@sequenceholdings/
|
|
72
|
+
"@sequenceholdings/pipeline-spec": "0.3.1",
|
|
73
|
+
"@sequenceholdings/orm": "2.8.1"
|
|
70
74
|
},
|
|
71
75
|
"engines": {
|
|
72
76
|
"node": ">=20"
|