@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
|
@@ -19,9 +19,9 @@ import { PREVIEW_DOMAIN, PREVIEW_PROJECT, resolvePreviewByPr } from '../preview.
|
|
|
19
19
|
const ARTIFACT_USAGE = `usage:
|
|
20
20
|
seq-studio artifact init <dir> [--template react-vite|nextjs]
|
|
21
21
|
seq-studio artifact validate [dir]
|
|
22
|
-
seq-studio artifact build [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--out file.json]
|
|
23
|
-
seq-studio artifact plan [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] -e <env>
|
|
24
|
-
seq-studio artifact deploy [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] -e <env> [--skip-unchanged] [--no-create] [--project <id>]
|
|
22
|
+
seq-studio artifact build [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--path <dir>] [--out file.json]
|
|
23
|
+
seq-studio artifact plan [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--path <dir>] -e <env>
|
|
24
|
+
seq-studio artifact deploy [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--path <dir>] -e <env> [--skip-unchanged] [--no-create] [--project <id>]
|
|
25
25
|
seq-studio artifact dev [dir] -e <env> [--once] [--key default] [--link <pkgDir>[,<pkgDir>]] [--port <port>]
|
|
26
26
|
seq-studio artifact pull <project-id> -e <env> --out <dir>
|
|
27
27
|
seq-studio artifact promote <deployment-id> -e <env>
|
|
@@ -39,7 +39,8 @@ const ARTIFACT_USAGE = `usage:
|
|
|
39
39
|
|
|
40
40
|
Source for build/plan/deploy: a local [dir] (default), a platform git-service
|
|
41
41
|
repo (--repo <ns>/<name>), or a public HTTPS git URL (--git-url <url>). --ref selects a
|
|
42
|
-
branch/tag/commit (default: the repo's default branch).
|
|
42
|
+
branch/tag/commit (default: the repo's default branch). --path <dir> selects the
|
|
43
|
+
application directory inside that repository (default: its root).
|
|
43
44
|
|
|
44
45
|
Interactive --repo builds clone over smart-HTTP and require ATLAS_GIT_PAT
|
|
45
46
|
(a repo:read PAT — seq-studio auth pat create, or Atlas → Settings → Tokens).
|
|
@@ -54,6 +55,9 @@ const ARTIFACT_USAGE = `usage:
|
|
|
54
55
|
with a Git Service origin on the target Atlas environment also works.
|
|
55
56
|
Use pnpm build for a local production-build check. --once is static-only;
|
|
56
57
|
--port selects the local Next loopback port.
|
|
58
|
+
Deploy rejects source that still points at another environment's API origin
|
|
59
|
+
or workspace UUID. Declare API origins under targets.<environment>.url.
|
|
60
|
+
Workspace IDs in source must exist in the selected environment.
|
|
57
61
|
|
|
58
62
|
Per-PR preview environments (https://studio-atlas-git-<slug>.preview.seqholdings.com):
|
|
59
63
|
-e preview:<branch-or-slug> compute the preview host from a branch name
|
package/dist/atlas-client.d.ts
CHANGED
|
@@ -22,6 +22,12 @@ export declare class AtlasApiError extends Error {
|
|
|
22
22
|
readonly name = "AtlasApiError";
|
|
23
23
|
constructor(status: number, message: string, path: string, statusText?: string, body?: unknown);
|
|
24
24
|
}
|
|
25
|
+
/** Bounded single attempt for commands whose uncertain result must be reconciled by the caller. */
|
|
26
|
+
export declare function requestJsonOnce({ baseUrl, token, path, method, body, }: ClientOptions & {
|
|
27
|
+
path: string;
|
|
28
|
+
method: 'GET' | 'POST' | 'PUT';
|
|
29
|
+
body?: unknown;
|
|
30
|
+
}): Promise<unknown>;
|
|
25
31
|
export declare function getJson<T>({ baseUrl, token, path, }: ClientOptions & {
|
|
26
32
|
path: string;
|
|
27
33
|
}): Promise<T>;
|
package/dist/atlas-client.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* the caller — this file knows nothing about token files or config TOMLs.
|
|
6
6
|
*/
|
|
7
7
|
import { authenticatedRequestUrl } from '@sequenceholdings/artifact-studio/deployment-validation';
|
|
8
|
+
import { validationDetail } from './validation-detail.js';
|
|
8
9
|
import { PREVIEW_DOMAIN } from './preview.js';
|
|
9
10
|
const MAX_503_RETRIES = 5;
|
|
10
11
|
const DEFAULT_RETRY_AFTER_SECONDS = 2;
|
|
@@ -36,9 +37,10 @@ async function fetchWith503Retry(input, init) {
|
|
|
36
37
|
await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
|
-
async function authenticatedFetch({ baseUrl, init = {}, path, token, }) {
|
|
40
|
+
async function authenticatedFetch({ baseUrl, init = {}, path, token, retry503 = true, }) {
|
|
40
41
|
const url = authenticatedRequestUrl({ baseUrl, path });
|
|
41
|
-
|
|
42
|
+
const send = retry503 ? fetchWith503Retry : fetch;
|
|
43
|
+
return send(url, {
|
|
42
44
|
...init,
|
|
43
45
|
redirect: 'manual',
|
|
44
46
|
headers: {
|
|
@@ -49,6 +51,38 @@ async function authenticatedFetch({ baseUrl, init = {}, path, token, }) {
|
|
|
49
51
|
},
|
|
50
52
|
});
|
|
51
53
|
}
|
|
54
|
+
/** Bounded single attempt for commands whose uncertain result must be reconciled by the caller. */
|
|
55
|
+
export async function requestJsonOnce({ baseUrl, token, path, method, body, }) {
|
|
56
|
+
const response = await authenticatedFetch({ baseUrl, token, path, retry503: false,
|
|
57
|
+
init: { method, signal: AbortSignal.timeout(30_000),
|
|
58
|
+
headers: body === undefined ? {} : { 'Content-Type': 'application/json' },
|
|
59
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }) } });
|
|
60
|
+
const reader = response.body?.getReader();
|
|
61
|
+
if (!reader)
|
|
62
|
+
throw new Error('Missing response body');
|
|
63
|
+
const chunks = [];
|
|
64
|
+
let size = 0;
|
|
65
|
+
try {
|
|
66
|
+
for (;;) {
|
|
67
|
+
const item = await reader.read();
|
|
68
|
+
if (item.done)
|
|
69
|
+
break;
|
|
70
|
+
size += item.value.byteLength;
|
|
71
|
+
if (size > 8_388_608)
|
|
72
|
+
throw new Error('Response exceeds 8 MiB');
|
|
73
|
+
chunks.push(item.value);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
void reader.cancel().catch(() => { });
|
|
78
|
+
reader.releaseLock();
|
|
79
|
+
}
|
|
80
|
+
const raw = Buffer.concat(chunks).toString('utf8');
|
|
81
|
+
const parsed = parseErrorBody(raw, response.headers.get('content-type') ?? '');
|
|
82
|
+
if (!response.ok)
|
|
83
|
+
throw new AtlasApiError(response.status, messageFromBody(parsed, response.status, response.statusText), path, response.statusText, parsed);
|
|
84
|
+
return parsed;
|
|
85
|
+
}
|
|
52
86
|
function previewAccessHeaders(baseUrl) {
|
|
53
87
|
const secret = process.env.PREVIEW_ACCESS_HEADER?.trim();
|
|
54
88
|
if (!secret)
|
|
@@ -114,6 +148,9 @@ function messageFromBody(body, status, statusText) {
|
|
|
114
148
|
const record = body;
|
|
115
149
|
const violations = violationLines(record.violations);
|
|
116
150
|
const withViolations = (headline) => violations.length > 0 ? [headline, ...violations].join('\n') : headline;
|
|
151
|
+
const fields = validationDetail(record.errors);
|
|
152
|
+
if (fields)
|
|
153
|
+
return withViolations(fields);
|
|
117
154
|
if (typeof record.detail === 'string' && record.detail.length > 0) {
|
|
118
155
|
return withViolations(record.detail);
|
|
119
156
|
}
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/** A token-cache failure is distinct from an absent or expired login. */
|
|
2
|
+
export declare class AuthTokenStoreError extends Error {
|
|
3
|
+
readonly kind: 'permission' | 'invalid' | 'io';
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly name = "AuthTokenStoreError";
|
|
6
|
+
constructor(message: string, kind: 'permission' | 'invalid' | 'io', path: string, options?: ErrorOptions);
|
|
7
|
+
}
|
|
1
8
|
/**
|
|
2
9
|
* seq-studio and seqapi share one token file and one Auth0 application:
|
|
3
10
|
* same tenant, client id, audience, and token shape. Either CLI can log in,
|
|
@@ -55,6 +62,7 @@ export interface SeqapiTokens {
|
|
|
55
62
|
}
|
|
56
63
|
interface RealmResolutionOptions {
|
|
57
64
|
fetchImpl?: typeof fetch;
|
|
65
|
+
offline?: boolean;
|
|
58
66
|
targetUrl?: string;
|
|
59
67
|
}
|
|
60
68
|
/**
|
|
@@ -133,6 +141,30 @@ export declare function tryGetAccessToken(options?: {
|
|
|
133
141
|
env?: string;
|
|
134
142
|
targetUrl?: string;
|
|
135
143
|
}): Promise<string | null>;
|
|
144
|
+
export interface AuthPreflightDiagnostics {
|
|
145
|
+
authMode: 'auto' | 'm2m';
|
|
146
|
+
realm: string;
|
|
147
|
+
realmVerified: boolean;
|
|
148
|
+
tokenCachePath: string;
|
|
149
|
+
tokenCache: 'readable' | 'missing' | 'permission-denied' | 'invalid-json' | 'io-error';
|
|
150
|
+
cachedUserToken: 'valid' | 'expired' | 'missing' | 'unavailable';
|
|
151
|
+
cachedM2mToken: 'valid' | 'expired' | 'missing' | 'unavailable';
|
|
152
|
+
m2mCredentialConfigured: boolean;
|
|
153
|
+
selectedCredential: 'user' | 'm2m' | 'none' | 'unavailable';
|
|
154
|
+
detail?: string;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Read-only, non-interactive authentication preflight. This never returns a
|
|
158
|
+
* credential, launches a browser, contacts Auth0, or writes the shared cache.
|
|
159
|
+
* Atomic rename means reading the cache without taking its write lock is safe;
|
|
160
|
+
* importantly, a read-only doctor still works when the cache directory cannot
|
|
161
|
+
* create the lock file.
|
|
162
|
+
*/
|
|
163
|
+
export declare function inspectAuthPreflight(options?: {
|
|
164
|
+
env?: string;
|
|
165
|
+
offline?: boolean;
|
|
166
|
+
targetUrl?: string;
|
|
167
|
+
}): Promise<AuthPreflightDiagnostics>;
|
|
136
168
|
/**
|
|
137
169
|
* Refuse to persist a token minted for another audience or Auth0
|
|
138
170
|
* organization. Auth0/server-side JWT verification remains authoritative;
|
package/dist/auth.js
CHANGED
|
@@ -8,6 +8,30 @@ import { withCrossProcessFileLock } from './file-lock.js';
|
|
|
8
8
|
function hasErrorCode(error, code) {
|
|
9
9
|
return error instanceof Error && Reflect.get(error, 'code') === code;
|
|
10
10
|
}
|
|
11
|
+
function errorCode(error) {
|
|
12
|
+
const code = error instanceof Error ? Reflect.get(error, 'code') : undefined;
|
|
13
|
+
return typeof code === 'string' ? code : undefined;
|
|
14
|
+
}
|
|
15
|
+
/** A token-cache failure is distinct from an absent or expired login. */
|
|
16
|
+
export class AuthTokenStoreError extends Error {
|
|
17
|
+
kind;
|
|
18
|
+
path;
|
|
19
|
+
name = 'AuthTokenStoreError';
|
|
20
|
+
constructor(message, kind, path, options) {
|
|
21
|
+
super(message, options);
|
|
22
|
+
this.kind = kind;
|
|
23
|
+
this.path = path;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function tokenStoreError(error, operation) {
|
|
27
|
+
const code = errorCode(error);
|
|
28
|
+
if (code !== 'EACCES' && code !== 'EPERM')
|
|
29
|
+
return undefined;
|
|
30
|
+
const path = seqapiTokenPath();
|
|
31
|
+
return new AuthTokenStoreError(`Cannot ${operation} the shared Sequence token cache at ${path}: ${code}. ` +
|
|
32
|
+
`This is a file-permission problem, not an expired login. Check ownership and permissions for ${seqapiTokenDir()}; ` +
|
|
33
|
+
'do not remove a lock file while another Sequence CLI is running.', 'permission', path, { cause: error });
|
|
34
|
+
}
|
|
11
35
|
/**
|
|
12
36
|
* seq-studio and seqapi share one token file and one Auth0 application:
|
|
13
37
|
* same tenant, client id, audience, and token shape. Either CLI can log in,
|
|
@@ -168,6 +192,8 @@ async function discoverLoopbackRealm({ envName, fetchImpl = fetch, targetUrl, })
|
|
|
168
192
|
};
|
|
169
193
|
}
|
|
170
194
|
async function maybeDiscoverLoopbackRealm({ envName, options, }) {
|
|
195
|
+
if (options.offline)
|
|
196
|
+
return undefined;
|
|
171
197
|
if (!envName || !isLoopbackEnvName(envName))
|
|
172
198
|
return undefined;
|
|
173
199
|
const targetUrl = loopbackTargetUrl({
|
|
@@ -261,18 +287,14 @@ function tokenStillValid(entry) {
|
|
|
261
287
|
return Boolean(entry?.accessToken && (entry.expiresAt ?? 0) > now + 60);
|
|
262
288
|
}
|
|
263
289
|
async function loadPersistedM2m(realmName) {
|
|
264
|
-
|
|
290
|
+
const file = await readTokenFile();
|
|
291
|
+
const entry = file?.m2m?.[realmName];
|
|
292
|
+
if (!entry?.access_token)
|
|
265
293
|
return null;
|
|
266
|
-
return
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return null;
|
|
271
|
-
return {
|
|
272
|
-
accessToken: entry.access_token,
|
|
273
|
-
expiresAt: entry.expires_at ?? 0,
|
|
274
|
-
};
|
|
275
|
-
});
|
|
294
|
+
return {
|
|
295
|
+
accessToken: entry.access_token,
|
|
296
|
+
expiresAt: entry.expires_at ?? 0,
|
|
297
|
+
};
|
|
276
298
|
}
|
|
277
299
|
async function persistM2m({ realmName, accessToken, expiresAt, }) {
|
|
278
300
|
await withTokenFileLock(async () => {
|
|
@@ -486,6 +508,8 @@ export async function tryGetAccessTokenWithMode(options) {
|
|
|
486
508
|
catch (err) {
|
|
487
509
|
if (err instanceof UnsafeAuthTargetError)
|
|
488
510
|
throw err;
|
|
511
|
+
if (err instanceof AuthTokenStoreError)
|
|
512
|
+
throw err;
|
|
489
513
|
if (options?.failClosedForM2m) {
|
|
490
514
|
// Do not replace an invalid tenant registration with the Sequence realm:
|
|
491
515
|
// that could hide a rejected discovery token host or inspect the wrong
|
|
@@ -500,6 +524,94 @@ export async function tryGetAccessTokenWithMode(options) {
|
|
|
500
524
|
export async function tryGetAccessToken(options) {
|
|
501
525
|
return (await tryGetAccessTokenWithMode(options))?.token ?? null;
|
|
502
526
|
}
|
|
527
|
+
/**
|
|
528
|
+
* Read-only, non-interactive authentication preflight. This never returns a
|
|
529
|
+
* credential, launches a browser, contacts Auth0, or writes the shared cache.
|
|
530
|
+
* Atomic rename means reading the cache without taking its write lock is safe;
|
|
531
|
+
* importantly, a read-only doctor still works when the cache directory cannot
|
|
532
|
+
* create the lock file.
|
|
533
|
+
*/
|
|
534
|
+
export async function inspectAuthPreflight(options) {
|
|
535
|
+
const authMode = authModePrefersM2m() ? 'm2m' : 'auto';
|
|
536
|
+
// Offline diagnostics intentionally avoid local Auth0 discovery. A local
|
|
537
|
+
// target's actual realm stays unverified until an online command resolves it.
|
|
538
|
+
const realm = await realmForEnv(options?.env, {
|
|
539
|
+
...(options?.offline ? { offline: true } : { targetUrl: options?.targetUrl }),
|
|
540
|
+
});
|
|
541
|
+
const realmVerified = !(options?.offline && options.env && isLoopbackEnvName(options.env));
|
|
542
|
+
const cachePath = seqapiTokenPath();
|
|
543
|
+
const credentialConfigured = Boolean(realm.m2mClientId && process.env[m2mSecretEnvName(realm)]?.trim());
|
|
544
|
+
let file;
|
|
545
|
+
try {
|
|
546
|
+
file = await readTokenFile();
|
|
547
|
+
}
|
|
548
|
+
catch (error) {
|
|
549
|
+
const status = error instanceof AuthTokenStoreError ? error.kind : 'io';
|
|
550
|
+
const tokenCache = status === 'permission'
|
|
551
|
+
? 'permission-denied'
|
|
552
|
+
: status === 'invalid'
|
|
553
|
+
? 'invalid-json'
|
|
554
|
+
: 'io-error';
|
|
555
|
+
return {
|
|
556
|
+
authMode,
|
|
557
|
+
realm: realm.name,
|
|
558
|
+
realmVerified,
|
|
559
|
+
tokenCachePath: cachePath,
|
|
560
|
+
tokenCache,
|
|
561
|
+
cachedUserToken: 'unavailable',
|
|
562
|
+
cachedM2mToken: 'unavailable',
|
|
563
|
+
m2mCredentialConfigured: credentialConfigured,
|
|
564
|
+
selectedCredential: 'unavailable',
|
|
565
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
if (!file) {
|
|
569
|
+
const selectedCredential = credentialConfigured ? 'm2m' : 'none';
|
|
570
|
+
return {
|
|
571
|
+
authMode,
|
|
572
|
+
realm: realm.name,
|
|
573
|
+
realmVerified,
|
|
574
|
+
tokenCachePath: cachePath,
|
|
575
|
+
tokenCache: 'missing',
|
|
576
|
+
cachedUserToken: 'missing',
|
|
577
|
+
cachedM2mToken: 'missing',
|
|
578
|
+
m2mCredentialConfigured: credentialConfigured,
|
|
579
|
+
selectedCredential,
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
const user = realm.name === SEQUENCE_REALM ? file : file.realms?.[realm.name];
|
|
583
|
+
const m2m = file.m2m?.[realm.name];
|
|
584
|
+
const userState = user?.access_token
|
|
585
|
+
? tokenStillValid({ accessToken: user.access_token, expiresAt: user.expires_at })
|
|
586
|
+
? 'valid'
|
|
587
|
+
: 'expired'
|
|
588
|
+
: 'missing';
|
|
589
|
+
const m2mState = m2m?.access_token
|
|
590
|
+
? tokenStillValid({ accessToken: m2m.access_token, expiresAt: m2m.expires_at })
|
|
591
|
+
? 'valid'
|
|
592
|
+
: 'expired'
|
|
593
|
+
: 'missing';
|
|
594
|
+
const selectedCredential = authMode === 'm2m'
|
|
595
|
+
? credentialConfigured
|
|
596
|
+
? 'm2m'
|
|
597
|
+
: 'none'
|
|
598
|
+
: userState === 'valid'
|
|
599
|
+
? 'user'
|
|
600
|
+
: credentialConfigured
|
|
601
|
+
? 'm2m'
|
|
602
|
+
: 'none';
|
|
603
|
+
return {
|
|
604
|
+
authMode,
|
|
605
|
+
realm: realm.name,
|
|
606
|
+
realmVerified,
|
|
607
|
+
tokenCachePath: cachePath,
|
|
608
|
+
tokenCache: 'readable',
|
|
609
|
+
cachedUserToken: userState,
|
|
610
|
+
cachedM2mToken: m2mState,
|
|
611
|
+
m2mCredentialConfigured: credentialConfigured,
|
|
612
|
+
selectedCredential,
|
|
613
|
+
};
|
|
614
|
+
}
|
|
503
615
|
/**
|
|
504
616
|
* Decode the `sub` claim from a JWT without verification. Verification is the
|
|
505
617
|
* server's job — this is only used to compare identities locally (e.g. to
|
|
@@ -572,13 +684,27 @@ export async function currentIdentitySubject(options = {}) {
|
|
|
572
684
|
}
|
|
573
685
|
async function readTokenFile() {
|
|
574
686
|
const path = seqapiTokenPath();
|
|
575
|
-
|
|
576
|
-
return null;
|
|
687
|
+
let text;
|
|
577
688
|
try {
|
|
578
|
-
|
|
689
|
+
text = await readFile(path, 'utf8');
|
|
579
690
|
}
|
|
580
|
-
catch {
|
|
581
|
-
|
|
691
|
+
catch (error) {
|
|
692
|
+
if (hasErrorCode(error, 'ENOENT'))
|
|
693
|
+
return null;
|
|
694
|
+
const permissionError = tokenStoreError(error, 'read');
|
|
695
|
+
if (permissionError)
|
|
696
|
+
throw permissionError;
|
|
697
|
+
throw new AuthTokenStoreError(`Could not read the shared Sequence token cache at ${path}: ${error instanceof Error ? error.message : String(error)}`, 'io', path, { cause: error });
|
|
698
|
+
}
|
|
699
|
+
try {
|
|
700
|
+
const parsed = JSON.parse(text);
|
|
701
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
702
|
+
throw new Error('expected a JSON object');
|
|
703
|
+
}
|
|
704
|
+
return parsed;
|
|
705
|
+
}
|
|
706
|
+
catch (error) {
|
|
707
|
+
throw new AuthTokenStoreError(`The shared Sequence token cache at ${path} is not valid JSON. Preserve a copy before repairing it; do not delete it while another Sequence CLI is running.`, 'invalid', path, { cause: error });
|
|
582
708
|
}
|
|
583
709
|
}
|
|
584
710
|
function stripPersistedRefreshTokens(file) {
|
|
@@ -598,26 +724,37 @@ function stripPersistedRefreshTokens(file) {
|
|
|
598
724
|
return changed;
|
|
599
725
|
}
|
|
600
726
|
export async function loadCachedUserTokens(realmName = SEQUENCE_REALM) {
|
|
601
|
-
|
|
727
|
+
const file = await readTokenFile();
|
|
728
|
+
if (!file)
|
|
602
729
|
return null;
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
730
|
+
const entry = realmName === SEQUENCE_REALM ? file : file.realms?.[realmName];
|
|
731
|
+
if (!entry?.access_token)
|
|
732
|
+
return null;
|
|
733
|
+
if (stripPersistedRefreshTokens(file)) {
|
|
734
|
+
await withTokenFileLock(async () => {
|
|
735
|
+
// Re-read under the inter-CLI lock before the atomic rewrite so another
|
|
736
|
+
// process's realm update is preserved.
|
|
737
|
+
const current = (await readTokenFile()) ?? {};
|
|
738
|
+
if (stripPersistedRefreshTokens(current))
|
|
739
|
+
await writeTokenFile(current);
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
return {
|
|
743
|
+
access_token: entry.access_token,
|
|
744
|
+
expires_at: entry.expires_at,
|
|
745
|
+
};
|
|
618
746
|
}
|
|
619
747
|
async function withTokenFileLock(operation) {
|
|
620
|
-
|
|
748
|
+
const path = seqapiTokenPath();
|
|
749
|
+
try {
|
|
750
|
+
return await withCrossProcessFileLock({ operation, path });
|
|
751
|
+
}
|
|
752
|
+
catch (error) {
|
|
753
|
+
const permissionError = tokenStoreError(error, 'lock or update');
|
|
754
|
+
if (permissionError)
|
|
755
|
+
throw permissionError;
|
|
756
|
+
throw error;
|
|
757
|
+
}
|
|
621
758
|
}
|
|
622
759
|
async function writeTokenFile(tokens) {
|
|
623
760
|
const path = seqapiTokenPath();
|
package/dist/bin.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { run } from './main.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { parseArgs } from './argv.js';
|
|
4
|
+
// A consumer may close stdout while a remote operation continues. Stop local
|
|
5
|
+
// output quietly; never cancel or retry the remote operation.
|
|
6
|
+
process.stdout.on('error', (error) => {
|
|
7
|
+
if (error.code === 'EPIPE')
|
|
8
|
+
process.exit(0);
|
|
9
|
+
else
|
|
10
|
+
throw error;
|
|
11
|
+
});
|
|
12
|
+
const argv = process.argv.slice(2);
|
|
13
|
+
const isHelpOrDiscovery = argv.includes('--help') || argv.includes('-h') || argv[0] === 'help' || argv[0] === 'capabilities';
|
|
14
|
+
const doctorOffline = argv[0] === 'doctor' && (() => {
|
|
15
|
+
const value = parseArgs(argv.slice(1)).flags.offline;
|
|
16
|
+
return value === true || value === 'true';
|
|
17
|
+
})();
|
|
18
|
+
run(argv)
|
|
5
19
|
.catch((error) => {
|
|
6
20
|
console.error(error instanceof Error ? error.message : error);
|
|
7
21
|
return 1;
|
|
@@ -9,6 +23,11 @@ run()
|
|
|
9
23
|
// The update notice runs after the command so it never delays real output,
|
|
10
24
|
// and it is best-effort (never throws, never changes the exit code).
|
|
11
25
|
.then(async (code) => {
|
|
12
|
-
|
|
13
|
-
|
|
26
|
+
if (!isHelpOrDiscovery && !doctorOffline) {
|
|
27
|
+
const { maybeNotifyUpdate } = await import('./update-check.js');
|
|
28
|
+
await maybeNotifyUpdate();
|
|
29
|
+
}
|
|
30
|
+
// Forced exit discards queued stdout/stderr when callers pipe large JSON
|
|
31
|
+
// responses. Let Node drain pending writes before exiting with this status.
|
|
32
|
+
process.exitCode = code;
|
|
14
33
|
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/** Machine-readable summary of the CLI surface, kept independent of command implementations. */
|
|
2
|
+
export declare const COMMAND_CONTRACT: readonly [{
|
|
3
|
+
readonly name: "init";
|
|
4
|
+
readonly description: "Scaffold an app workspace";
|
|
5
|
+
readonly lifecycle: "internal";
|
|
6
|
+
readonly access: "offline";
|
|
7
|
+
readonly subcommands: readonly [];
|
|
8
|
+
}, {
|
|
9
|
+
readonly name: "add";
|
|
10
|
+
readonly description: "Add a primitive to an app workspace";
|
|
11
|
+
readonly lifecycle: "internal";
|
|
12
|
+
readonly access: "offline";
|
|
13
|
+
readonly subcommands: readonly [];
|
|
14
|
+
}, {
|
|
15
|
+
readonly name: "deploy";
|
|
16
|
+
readonly description: "Deploy an app workspace";
|
|
17
|
+
readonly lifecycle: "internal";
|
|
18
|
+
readonly access: "authenticated";
|
|
19
|
+
readonly subcommands: readonly [];
|
|
20
|
+
}, {
|
|
21
|
+
readonly name: "process";
|
|
22
|
+
readonly description: "Build and operate Lattice processes";
|
|
23
|
+
readonly lifecycle: "preview";
|
|
24
|
+
readonly access: "mixed";
|
|
25
|
+
readonly subcommands: readonly ["init", "lint", "plan", "apply", "test", "simulate", "bundle", "promote", "pull", "safety-baseline"];
|
|
26
|
+
}, {
|
|
27
|
+
readonly name: "artifact";
|
|
28
|
+
readonly description: "Build and operate Artifact Studio apps";
|
|
29
|
+
readonly lifecycle: "stable";
|
|
30
|
+
readonly access: "mixed";
|
|
31
|
+
readonly subcommands: readonly ["init", "whoami", "link", "env", "status", "list", "show", "validate", "build", "plan", "deploy", "dev", "promote", "pull", "rollback"];
|
|
32
|
+
}, {
|
|
33
|
+
readonly name: "functions";
|
|
34
|
+
readonly description: "Build and operate Managed Functions";
|
|
35
|
+
readonly lifecycle: "stable";
|
|
36
|
+
readonly access: "authenticated";
|
|
37
|
+
readonly subcommands: readonly ["init", "build", "deploy", "list", "show", "limits", "invoke", "logs", "promote", "rollback", "delete"];
|
|
38
|
+
}, {
|
|
39
|
+
readonly name: "agents";
|
|
40
|
+
readonly description: "Validate and deploy typed agent definitions";
|
|
41
|
+
readonly lifecycle: "preview";
|
|
42
|
+
readonly access: "mixed";
|
|
43
|
+
readonly subcommands: readonly ["init", "validate", "plan", "apply", "list", "show"];
|
|
44
|
+
}, {
|
|
45
|
+
readonly name: "secrets";
|
|
46
|
+
readonly description: "Manage organization-owned secrets";
|
|
47
|
+
readonly lifecycle: "stable";
|
|
48
|
+
readonly access: "authenticated";
|
|
49
|
+
readonly subcommands: readonly ["create", "set", "list", "attach", "detach", "apply"];
|
|
50
|
+
}, {
|
|
51
|
+
readonly name: "repos";
|
|
52
|
+
readonly description: "Manage platform Git Service repositories";
|
|
53
|
+
readonly lifecycle: "stable";
|
|
54
|
+
readonly access: "authenticated";
|
|
55
|
+
readonly subcommands: readonly ["list", "namespaces", "show", "create", "clone", "pull", "pulls", "delete"];
|
|
56
|
+
}, {
|
|
57
|
+
readonly name: "pipeline";
|
|
58
|
+
readonly description: "Discover and operate Data Pipelines";
|
|
59
|
+
readonly lifecycle: "preview";
|
|
60
|
+
readonly access: "staff";
|
|
61
|
+
readonly subcommands: readonly ["list", "assets", "search", "describe", "schema", "sample", "query", "init", "validate", "plan", "deploy", "status", "migrate", "adopt", "unbind", "run-now", "promote", "rollback"];
|
|
62
|
+
}, {
|
|
63
|
+
readonly name: "auth";
|
|
64
|
+
readonly description: "Manage Git Service personal access tokens";
|
|
65
|
+
readonly lifecycle: "stable";
|
|
66
|
+
readonly access: "authenticated";
|
|
67
|
+
readonly subcommands: readonly ["whoami", "pat"];
|
|
68
|
+
}, {
|
|
69
|
+
readonly name: "orm";
|
|
70
|
+
readonly description: "Author and operate ORM namespaces";
|
|
71
|
+
readonly lifecycle: "preview";
|
|
72
|
+
readonly access: "mixed";
|
|
73
|
+
readonly subcommands: readonly ["init", "generate", "validate", "plan", "apply", "execute", "diff", "migrate-from-yaml", "import"];
|
|
74
|
+
}, {
|
|
75
|
+
readonly name: "envs";
|
|
76
|
+
readonly description: "Manage CLI environments";
|
|
77
|
+
readonly lifecycle: "stable";
|
|
78
|
+
readonly access: "mixed";
|
|
79
|
+
readonly subcommands: readonly ["add", "list", "refresh"];
|
|
80
|
+
}, {
|
|
81
|
+
readonly name: "login";
|
|
82
|
+
readonly description: "Authenticate with Sequence";
|
|
83
|
+
readonly lifecycle: "stable";
|
|
84
|
+
readonly access: "public";
|
|
85
|
+
readonly subcommands: readonly [];
|
|
86
|
+
}, {
|
|
87
|
+
readonly name: "logout";
|
|
88
|
+
readonly description: "Remove cached user tokens";
|
|
89
|
+
readonly lifecycle: "stable";
|
|
90
|
+
readonly access: "public";
|
|
91
|
+
readonly subcommands: readonly [];
|
|
92
|
+
}, {
|
|
93
|
+
readonly name: "doctor";
|
|
94
|
+
readonly description: "Diagnose CLI configuration and access";
|
|
95
|
+
readonly lifecycle: "stable";
|
|
96
|
+
readonly access: "mixed";
|
|
97
|
+
readonly subcommands: readonly [];
|
|
98
|
+
}, {
|
|
99
|
+
readonly name: "version";
|
|
100
|
+
readonly description: "Print the installed CLI version";
|
|
101
|
+
readonly lifecycle: "stable";
|
|
102
|
+
readonly access: "offline";
|
|
103
|
+
readonly subcommands: readonly [];
|
|
104
|
+
}, {
|
|
105
|
+
readonly name: "help";
|
|
106
|
+
readonly description: "Show command help";
|
|
107
|
+
readonly lifecycle: "stable";
|
|
108
|
+
readonly access: "offline";
|
|
109
|
+
readonly subcommands: readonly [];
|
|
110
|
+
}, {
|
|
111
|
+
readonly name: "storage";
|
|
112
|
+
readonly description: "Manage platform storage";
|
|
113
|
+
readonly lifecycle: "blocked";
|
|
114
|
+
readonly access: "authenticated";
|
|
115
|
+
readonly subcommands: readonly ["init", "validate", "apply", "list", "show", "mkdir", "upload", "download", "access", "trash", "restore", "purge", "operations", "abort", "delete"];
|
|
116
|
+
}, {
|
|
117
|
+
readonly name: "access";
|
|
118
|
+
readonly description: "Manage runtime resource access";
|
|
119
|
+
readonly lifecycle: "preview";
|
|
120
|
+
readonly access: "authenticated";
|
|
121
|
+
readonly subcommands: readonly ["definitions", "list", "grant", "revoke", "resolve"];
|
|
122
|
+
}, {
|
|
123
|
+
readonly name: "service-accounts";
|
|
124
|
+
readonly description: "Manage runtime service accounts";
|
|
125
|
+
readonly lifecycle: "preview";
|
|
126
|
+
readonly access: "authenticated";
|
|
127
|
+
readonly subcommands: readonly ["list", "show", "create"];
|
|
128
|
+
}, {
|
|
129
|
+
readonly name: "capabilities";
|
|
130
|
+
readonly description: "Print the supported CLI command surface";
|
|
131
|
+
readonly lifecycle: "blocked";
|
|
132
|
+
readonly access: "offline";
|
|
133
|
+
readonly subcommands: readonly [];
|
|
134
|
+
}];
|
|
135
|
+
export declare function renderCapabilities({ json }?: {
|
|
136
|
+
json?: boolean;
|
|
137
|
+
}): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Machine-readable summary of the CLI surface, kept independent of command implementations. */
|
|
2
|
+
export const COMMAND_CONTRACT = [
|
|
3
|
+
{ name: 'init', description: 'Scaffold an app workspace', lifecycle: 'internal', access: 'offline', subcommands: [] },
|
|
4
|
+
{ name: 'add', description: 'Add a primitive to an app workspace', lifecycle: 'internal', access: 'offline', subcommands: [] },
|
|
5
|
+
{ name: 'deploy', description: 'Deploy an app workspace', lifecycle: 'internal', access: 'authenticated', subcommands: [] },
|
|
6
|
+
{ name: 'process', description: 'Build and operate Lattice processes', lifecycle: 'preview', access: 'mixed', subcommands: ['init', 'lint', 'plan', 'apply', 'test', 'simulate', 'bundle', 'promote', 'pull', 'safety-baseline'] },
|
|
7
|
+
{ name: 'artifact', description: 'Build and operate Artifact Studio apps', lifecycle: 'stable', access: 'mixed', subcommands: ['init', 'whoami', 'link', 'env', 'status', 'list', 'show', 'validate', 'build', 'plan', 'deploy', 'dev', 'promote', 'pull', 'rollback'] },
|
|
8
|
+
{ name: 'functions', description: 'Build and operate Managed Functions', lifecycle: 'stable', access: 'authenticated', subcommands: ['init', 'build', 'deploy', 'list', 'show', 'limits', 'invoke', 'logs', 'promote', 'rollback', 'delete'] },
|
|
9
|
+
{ name: 'agents', description: 'Validate and deploy typed agent definitions', lifecycle: 'preview', access: 'mixed', subcommands: ['init', 'validate', 'plan', 'apply', 'list', 'show'] },
|
|
10
|
+
{ name: 'secrets', description: 'Manage organization-owned secrets', lifecycle: 'stable', access: 'authenticated', subcommands: ['create', 'set', 'list', 'attach', 'detach', 'apply'] },
|
|
11
|
+
{ name: 'repos', description: 'Manage platform Git Service repositories', lifecycle: 'stable', access: 'authenticated', subcommands: ['list', 'namespaces', 'show', 'create', 'clone', 'pull', 'pulls', 'delete'] },
|
|
12
|
+
{ name: 'pipeline', description: 'Discover and operate Data Pipelines', lifecycle: 'preview', access: 'staff', subcommands: ['list', 'assets', 'search', 'describe', 'schema', 'sample', 'query', 'init', 'validate', 'plan', 'deploy', 'status', 'migrate', 'adopt', 'unbind', 'run-now', 'promote', 'rollback'] },
|
|
13
|
+
{ name: 'auth', description: 'Manage Git Service personal access tokens', lifecycle: 'stable', access: 'authenticated', subcommands: ['whoami', 'pat'] },
|
|
14
|
+
{ name: 'orm', description: 'Author and operate ORM namespaces', lifecycle: 'preview', access: 'mixed', subcommands: ['init', 'generate', 'validate', 'plan', 'apply', 'execute', 'diff', 'migrate-from-yaml', 'import'] },
|
|
15
|
+
{ name: 'envs', description: 'Manage CLI environments', lifecycle: 'stable', access: 'mixed', subcommands: ['add', 'list', 'refresh'] },
|
|
16
|
+
{ name: 'login', description: 'Authenticate with Sequence', lifecycle: 'stable', access: 'public', subcommands: [] },
|
|
17
|
+
{ name: 'logout', description: 'Remove cached user tokens', lifecycle: 'stable', access: 'public', subcommands: [] },
|
|
18
|
+
{ name: 'doctor', description: 'Diagnose CLI configuration and access', lifecycle: 'stable', access: 'mixed', subcommands: [] },
|
|
19
|
+
{ name: 'version', description: 'Print the installed CLI version', lifecycle: 'stable', access: 'offline', subcommands: [] },
|
|
20
|
+
{ name: 'help', description: 'Show command help', lifecycle: 'stable', access: 'offline', subcommands: [] },
|
|
21
|
+
{ name: 'storage', description: 'Manage platform storage', lifecycle: 'blocked', access: 'authenticated', subcommands: ['init', 'validate', 'apply', 'list', 'show', 'mkdir', 'upload', 'download', 'access', 'trash', 'restore', 'purge', 'operations', 'abort', 'delete'] },
|
|
22
|
+
{ name: 'access', description: 'Manage runtime resource access', lifecycle: 'preview', access: 'authenticated', subcommands: ['definitions', 'list', 'grant', 'revoke', 'resolve'] },
|
|
23
|
+
{ name: 'service-accounts', description: 'Manage runtime service accounts', lifecycle: 'preview', access: 'authenticated', subcommands: ['list', 'show', 'create'] },
|
|
24
|
+
{ name: 'capabilities', description: 'Print the supported CLI command surface', lifecycle: 'blocked', access: 'offline', subcommands: [] },
|
|
25
|
+
];
|
|
26
|
+
export function renderCapabilities({ json = false } = {}) {
|
|
27
|
+
const commands = COMMAND_CONTRACT.map(({ name, description, lifecycle, access, subcommands }) => ({
|
|
28
|
+
name,
|
|
29
|
+
description,
|
|
30
|
+
lifecycle,
|
|
31
|
+
access,
|
|
32
|
+
subcommands: [...subcommands],
|
|
33
|
+
}));
|
|
34
|
+
if (json)
|
|
35
|
+
return JSON.stringify({ version: 1, commands }, null, 2);
|
|
36
|
+
return [
|
|
37
|
+
'seq-studio capabilities (version 1)',
|
|
38
|
+
...commands.map(({ name, description, lifecycle, access, subcommands }) => ` ${name.padEnd(18)} ${lifecycle}/${access} ${description}${subcommands.length ? ` [${subcommands.join(', ')}]` : ''}`),
|
|
39
|
+
'',
|
|
40
|
+
'Lifecycle: stable, preview, internal, or blocked. Access: offline, public, mixed, authenticated, or staff.',
|
|
41
|
+
'Use `seq-studio <command> --help` for command usage. This summary does not promise an underlying HTTP API.',
|
|
42
|
+
].join('\n');
|
|
43
|
+
}
|