@sequenceholdings/studio-cli 0.7.2 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +414 -55
- 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.js +37 -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/repository-index.d.ts +6 -0
- package/dist/app/repository-index.js +2 -2
- 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 +15 -8
- package/dist/atlas-client.js +140 -64
- package/dist/bin.js +9 -1
- package/dist/cli-errors.js +4 -0
- package/dist/command-contract.d.ts +8 -2
- package/dist/command-contract.js +3 -2
- package/dist/command-help.d.ts +8 -6
- package/dist/command-help.js +65 -14
- package/dist/env-flags.d.ts +7 -0
- package/dist/env-flags.js +23 -0
- package/dist/functions/commands.js +66 -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/machine-output.d.ts +7 -0
- package/dist/machine-output.js +56 -0
- package/dist/main.d.ts +2 -1
- package/dist/main.js +32 -4
- package/dist/orm/delegate.js +49 -6
- 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/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/commands.js +9 -3
- package/dist/process/human-input-probe.d.ts +23 -0
- package/dist/process/human-input-probe.js +118 -0
- package/dist/process/lint.d.ts +2 -0
- package/dist/process/lint.js +10 -0
- package/dist/process/run-steps.d.ts +112 -0
- package/dist/process/run-steps.js +123 -0
- package/dist/process/runs.d.ts +4 -3
- package/dist/process/runs.js +69 -21
- package/dist/release-age.d.ts +1 -1
- package/dist/release-age.js +1 -0
- package/dist/repos/commands.d.ts +57 -0
- package/dist/repos/commands.js +83 -15
- package/dist/repos/init-repo.d.ts +45 -0
- package/dist/repos/init-repo.js +257 -0
- package/dist/repos/primitive-declaration.d.ts +43 -0
- package/dist/repos/primitive-declaration.js +212 -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/package.json +15 -12
- package/templates/process/pnpm-workspace.yaml +1 -0
|
@@ -564,19 +564,28 @@ const invocationIpRangeSchema = z
|
|
|
564
564
|
});
|
|
565
565
|
}
|
|
566
566
|
});
|
|
567
|
-
|
|
568
|
-
|
|
567
|
+
/** Issue param that marks the missing-account refusal, so deploy can add caller-specific guidance. */
|
|
568
|
+
export const SERVICE_ACCOUNT_REQUIRED = 'SERVICE_ACCOUNT_REQUIRED';
|
|
569
|
+
/** The refusal for a manifest that needs a service account and names none, without caller-specific guidance. */
|
|
570
|
+
export function missingServiceAccountMessage(requirements) {
|
|
571
|
+
return `This function acts as itself, not as its caller, for ${requirements.join(', ')}, so managed-function.yml must name ` +
|
|
572
|
+
'a service_account. Create one with `seq-studio service-accounts create <slug> --display-name "<name>"` (needs Can create ' +
|
|
573
|
+
'on Service Accounts) or use an existing account you hold the actor role on, then add `service_account: <slug>`. ' +
|
|
574
|
+
'Data access on behalf of the caller alone (capabilities.data without service: true) needs no account.';
|
|
575
|
+
}
|
|
576
|
+
function refineServiceAccountAttachment({ requirements, acceptsServiceAccount, serviceAccount, ctx }) {
|
|
577
|
+
if (requirements.length > 0 && serviceAccount === undefined) {
|
|
569
578
|
ctx.addIssue({
|
|
570
579
|
code: 'custom',
|
|
571
|
-
message:
|
|
572
|
-
'account this function acts as for service access (the deployer needs the actor role on it)',
|
|
580
|
+
message: missingServiceAccountMessage(requirements),
|
|
573
581
|
path: ['service_account'],
|
|
582
|
+
params: { code: SERVICE_ACCOUNT_REQUIRED, requirements: [...requirements] },
|
|
574
583
|
});
|
|
575
584
|
}
|
|
576
|
-
if (!
|
|
585
|
+
if (!acceptsServiceAccount && serviceAccount !== undefined) {
|
|
577
586
|
ctx.addIssue({
|
|
578
587
|
code: 'custom',
|
|
579
|
-
message: 'service_account requires at least one declared service access capability',
|
|
588
|
+
message: 'service_account requires at least one declared service access capability or data namespace',
|
|
580
589
|
path: ['service_account'],
|
|
581
590
|
});
|
|
582
591
|
}
|
|
@@ -705,6 +714,14 @@ export const managedFunctionManifestSchema = z.object({
|
|
|
705
714
|
.max(64)
|
|
706
715
|
.default([]),
|
|
707
716
|
query: z.boolean().default(false),
|
|
717
|
+
/**
|
|
718
|
+
* Act AS the function's attached service account in this namespace
|
|
719
|
+
* (`createFunctionServiceOrmExecutor`, system-runner invocations),
|
|
720
|
+
* not only on behalf of the caller; requires `service_account`.
|
|
721
|
+
* Marking any namespace narrows the account to the marked ones;
|
|
722
|
+
* with none marked, a named account acts in every declared namespace.
|
|
723
|
+
*/
|
|
724
|
+
service: z.boolean().optional(),
|
|
708
725
|
}))
|
|
709
726
|
.default({}),
|
|
710
727
|
}).default({ uses: [], gates: [], data: {} }),
|
|
@@ -747,24 +764,28 @@ export const managedFunctionManifestSchema = z.object({
|
|
|
747
764
|
}
|
|
748
765
|
// A namespace is "reached" when its block declares at least one table,
|
|
749
766
|
// action, operation, or raw query — the same rule the server's floor
|
|
750
|
-
// reconciliation uses (readManifestDataNamespaces).
|
|
751
|
-
|
|
752
|
-
const
|
|
753
|
-
const
|
|
754
|
-
|
|
755
|
-
|
|
767
|
+
// reconciliation uses (readManifestDataNamespaces). Reaching data on behalf
|
|
768
|
+
// of the caller needs no account; `service: true` asks to act as the function.
|
|
769
|
+
const reachedData = Object.entries(manifest.capabilities.data).filter(([, block]) => block.tables.length > 0 || block.actions.length > 0 || block.operations.length > 0 || block.query);
|
|
770
|
+
const requirements = [
|
|
771
|
+
...reachedData.filter(([, block]) => block.service === true).map(([namespace]) => `capabilities.data.${namespace}.service`),
|
|
772
|
+
...[
|
|
773
|
+
['capabilities.storage', Object.keys(readStorageScopes(manifest)).length > 0],
|
|
774
|
+
['capabilities.processes.read', (manifest.capabilities.processes?.read.length ?? 0) > 0],
|
|
775
|
+
['capabilities.agents.read', (manifest.capabilities.agents?.read?.length ?? 0) > 0],
|
|
776
|
+
['capabilities.agents.evidence', (manifest.capabilities.agents?.evidence?.length ?? 0) > 0],
|
|
777
|
+
['capabilities.workflows.read', (manifest.capabilities.workflows?.read?.length ?? 0) > 0],
|
|
778
|
+
['capabilities.workflows.evidence', (manifest.capabilities.workflows?.evidence?.length ?? 0) > 0],
|
|
779
|
+
['capabilities.monitoring.producers', (manifest.capabilities.monitoring?.producers.length ?? 0) > 0],
|
|
780
|
+
['capabilities.lattice.context', manifest.capabilities.lattice?.context === true],
|
|
781
|
+
['capabilities.invocation.identity', manifest.capabilities.invocation?.identity === true],
|
|
782
|
+
['capabilities.directory.resolve', (manifest.capabilities.directory?.resolve?.length ?? 0) > 0],
|
|
783
|
+
['capabilities.abrigo.read', (manifest.capabilities.abrigo?.read.length ?? 0) > 0],
|
|
784
|
+
].filter(([, present]) => present).map(([path]) => path),
|
|
785
|
+
];
|
|
756
786
|
refineServiceAccountAttachment({
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
reachesProcesses,
|
|
760
|
-
reachesAgents,
|
|
761
|
-
reachesWorkflows,
|
|
762
|
-
(manifest.capabilities.abrigo?.read.length ?? 0) > 0,
|
|
763
|
-
receivesLatticeContext,
|
|
764
|
-
manifest.capabilities.invocation?.identity === true,
|
|
765
|
-
(manifest.capabilities.directory?.resolve?.length ?? 0) > 0,
|
|
766
|
-
(manifest.capabilities.monitoring?.producers.length ?? 0) > 0,
|
|
767
|
-
].includes(true),
|
|
787
|
+
requirements,
|
|
788
|
+
acceptsServiceAccount: requirements.length > 0 || reachedData.length > 0,
|
|
768
789
|
serviceAccount: manifest.service_account,
|
|
769
790
|
ctx,
|
|
770
791
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deploy-time guidance for a Managed Function that needs a service account and
|
|
3
|
+
* names none. The manifest schema refuses it offline with a generic message;
|
|
4
|
+
* `functions deploy` can reach Atlas, so it also says whether this caller may
|
|
5
|
+
* create an account and which accounts they can already attach — the same
|
|
6
|
+
* facts `seq-studio service-accounts list` shows. Mirrors the server's refusal
|
|
7
|
+
* (atlas/src/server/services/managed-functions/service-account-guidance.ts).
|
|
8
|
+
*/
|
|
9
|
+
import { type ClientOptions } from '../atlas-client.js';
|
|
10
|
+
/** The requirements carried by the manifest schema's missing-account issue, or null for any other error. */
|
|
11
|
+
export declare function missingServiceAccountRequirements(error: unknown): string[] | null;
|
|
12
|
+
export declare function formatMissingServiceAccount({ requirements, canCreate, attachable }: {
|
|
13
|
+
requirements: readonly string[];
|
|
14
|
+
canCreate: boolean;
|
|
15
|
+
attachable: readonly string[];
|
|
16
|
+
}): string;
|
|
17
|
+
/** Null when Atlas cannot answer; the caller then falls back to the schema's message. */
|
|
18
|
+
export declare function missingServiceAccountGuidance({ client, requirements }: {
|
|
19
|
+
client: ClientOptions;
|
|
20
|
+
requirements: readonly string[];
|
|
21
|
+
}): Promise<string | null>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deploy-time guidance for a Managed Function that needs a service account and
|
|
3
|
+
* names none. The manifest schema refuses it offline with a generic message;
|
|
4
|
+
* `functions deploy` can reach Atlas, so it also says whether this caller may
|
|
5
|
+
* create an account and which accounts they can already attach — the same
|
|
6
|
+
* facts `seq-studio service-accounts list` shows. Mirrors the server's refusal
|
|
7
|
+
* (atlas/src/server/services/managed-functions/service-account-guidance.ts).
|
|
8
|
+
*/
|
|
9
|
+
import { getJson } from '../atlas-client.js';
|
|
10
|
+
import { SERVICE_ACCOUNT_REQUIRED } from './manifest.js';
|
|
11
|
+
const MAX_LISTED_ACCOUNTS = 10;
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
/** The requirements carried by the manifest schema's missing-account issue, or null for any other error. */
|
|
16
|
+
export function missingServiceAccountRequirements(error) {
|
|
17
|
+
if (!(error instanceof Error) || error.name !== 'ZodError')
|
|
18
|
+
return null;
|
|
19
|
+
const issues = Reflect.get(error, 'issues');
|
|
20
|
+
if (!Array.isArray(issues))
|
|
21
|
+
return null;
|
|
22
|
+
for (const issue of issues) {
|
|
23
|
+
const params = isRecord(issue) ? issue.params : undefined;
|
|
24
|
+
if (isRecord(params) && params.code === SERVICE_ACCOUNT_REQUIRED && Array.isArray(params.requirements)) {
|
|
25
|
+
return params.requirements.filter((entry) => typeof entry === 'string');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
export function formatMissingServiceAccount({ requirements, canCreate, attachable }) {
|
|
31
|
+
const lines = [
|
|
32
|
+
`This function needs a service account: it acts as itself, not as its caller, for ${requirements.join(', ')}. ` +
|
|
33
|
+
'Name one with a top-level `service_account: <slug>` in managed-function.yml. ' +
|
|
34
|
+
'Data access on behalf of the caller alone (capabilities.data without `service: true`) needs no account.',
|
|
35
|
+
];
|
|
36
|
+
if (attachable.length > 0) {
|
|
37
|
+
lines.push(`Accounts you can attach (you hold the actor role): ${attachable.join(', ')}.`);
|
|
38
|
+
}
|
|
39
|
+
lines.push(canCreate
|
|
40
|
+
? 'You can create one: `seq-studio service-accounts create <slug> --display-name "<name>" -e <env>`, then add ' +
|
|
41
|
+
'`service_account: <slug>` and redeploy. As its creator you hold the actor role needed to attach it.'
|
|
42
|
+
: 'You cannot create service accounts (that needs Can create on Service Accounts). Ask someone who holds it to create ' +
|
|
43
|
+
'one and grant you its actor role, or attach an existing account you hold the actor role on.');
|
|
44
|
+
return lines.join('\n');
|
|
45
|
+
}
|
|
46
|
+
/** Null when Atlas cannot answer; the caller then falls back to the schema's message. */
|
|
47
|
+
export async function missingServiceAccountGuidance({ client, requirements }) {
|
|
48
|
+
try {
|
|
49
|
+
const body = await getJson({ ...client, path: '/api/service-accounts' });
|
|
50
|
+
if (!isRecord(body) || !Array.isArray(body.serviceAccounts))
|
|
51
|
+
return null;
|
|
52
|
+
const attachable = body.serviceAccounts
|
|
53
|
+
.filter((account) => isRecord(account) && typeof account.slug === 'string' && account.disabled !== true)
|
|
54
|
+
.map((account) => String(account.slug))
|
|
55
|
+
.sort()
|
|
56
|
+
.slice(0, MAX_LISTED_ACCOUNTS);
|
|
57
|
+
return formatMissingServiceAccount({ requirements, canCreate: body.canCreate === true, attachable });
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Select source packages, not deployment prerequisites or Application members.
|
|
2
|
+
* Remote discovery is bounded by the materialized tree; local discovery stops at
|
|
3
|
+
* the nearest Git root. Nothing reads the caller's cwd for a remote source.
|
|
4
|
+
*/
|
|
5
|
+
export declare function prepareFunctionWorkspace({ dir, repoDir }: {
|
|
6
|
+
dir: string;
|
|
7
|
+
repoDir?: string;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
dir: string;
|
|
10
|
+
cleanup: () => Promise<void>;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { realpath } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { APP_MANIFEST_FILENAME, loadAppManifest } from '../app/manifest.js';
|
|
5
|
+
import { resolveContainedPrimitivePath } from '../app/paths.js';
|
|
6
|
+
import { prepareAppWorkspace } from '../app/workspace.js';
|
|
7
|
+
import { DEPENDENCY_SECTIONS, isWithin, readWorkspacePackage } from '../app/workspace-model.js';
|
|
8
|
+
/** Select source packages, not deployment prerequisites or Application members.
|
|
9
|
+
* Remote discovery is bounded by the materialized tree; local discovery stops at
|
|
10
|
+
* the nearest Git root. Nothing reads the caller's cwd for a remote source.
|
|
11
|
+
*/
|
|
12
|
+
export async function prepareFunctionWorkspace({ dir, repoDir }) {
|
|
13
|
+
const unchanged = { dir, cleanup: async () => { } };
|
|
14
|
+
if (!existsSync(join(dir, 'package.json')))
|
|
15
|
+
return unchanged;
|
|
16
|
+
const pkg = await readWorkspacePackage({ dir });
|
|
17
|
+
if (!DEPENDENCY_SECTIONS.some(section => Object.values(pkg[section] ?? {}).some(value => value.startsWith('workspace:')))) {
|
|
18
|
+
return unchanged;
|
|
19
|
+
}
|
|
20
|
+
const selected = await realpath(dir);
|
|
21
|
+
const boundary = repoDir === undefined ? undefined : await realpath(repoDir);
|
|
22
|
+
if (boundary && !isWithin({ root: boundary, path: selected }))
|
|
23
|
+
throw Error('Function source is outside the materialized repository');
|
|
24
|
+
let root = selected;
|
|
25
|
+
while (!existsSync(join(root, APP_MANIFEST_FILENAME))) {
|
|
26
|
+
const parent = dirname(root);
|
|
27
|
+
if (root === boundary || existsSync(join(root, '.git')) || parent === root) {
|
|
28
|
+
throw Error('Workspace dependencies require a containing sequence.app.yml with declared packages and the selected function');
|
|
29
|
+
}
|
|
30
|
+
root = parent;
|
|
31
|
+
}
|
|
32
|
+
if (!isWithin({ root, path: await realpath(join(root, APP_MANIFEST_FILENAME)) })) {
|
|
33
|
+
throw Error('App manifest is outside the containing repository');
|
|
34
|
+
}
|
|
35
|
+
const manifest = await loadAppManifest(root);
|
|
36
|
+
const entries = [];
|
|
37
|
+
for (const entry of manifest.primitives.filter(entry => entry.kind === 'function')) {
|
|
38
|
+
if (await resolveContainedPrimitivePath({ rootDir: root, entryPath: entry.path }) === selected)
|
|
39
|
+
entries.push(entry);
|
|
40
|
+
}
|
|
41
|
+
const entry = entries[0];
|
|
42
|
+
if (entries.length !== 1 || !entry)
|
|
43
|
+
throw Error('sequence.app.yml must declare exactly one function at the selected source directory');
|
|
44
|
+
const prepared = await prepareAppWorkspace({ rootDir: root, manifest, entries: [entry],
|
|
45
|
+
paths: new Map([[entry.id, selected]]), preserveFunctionEnv: false });
|
|
46
|
+
const compiled = prepared.paths.get(entry.id);
|
|
47
|
+
if (!compiled) {
|
|
48
|
+
await prepared.cleanup();
|
|
49
|
+
throw Error('Workspace compilation did not produce the selected function');
|
|
50
|
+
}
|
|
51
|
+
return { dir: compiled, cleanup: prepared.cleanup };
|
|
52
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** True when the arguments ask for JSON (or JSON Lines) on stdout. */
|
|
2
|
+
export declare function requestsMachineOutput(argv: readonly string[]): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Route non-JSON console.log / console.info output to stderr until the
|
|
5
|
+
* returned restore function runs.
|
|
6
|
+
*/
|
|
7
|
+
export declare function guardMachineOutput(): () => void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep stdout parseable when a command prints machine output.
|
|
3
|
+
*
|
|
4
|
+
* `seq-studio … --json | jq` reads all of stdout, so a single `[seq-studio] …`
|
|
5
|
+
* status or progress line on it breaks the pipe. Status lines come from many
|
|
6
|
+
* places (shared source resolution, delegated ORM and Artifact Studio CLIs,
|
|
7
|
+
* per-command progress), so instead of trusting every call site, the CLI
|
|
8
|
+
* routes them centrally: while `--json` or `--jsonl` is set, console.log and
|
|
9
|
+
* console.info pass a value through to stdout only when it is JSON text, and
|
|
10
|
+
* send everything else to stderr. Humans still see every line in a terminal.
|
|
11
|
+
*/
|
|
12
|
+
import { format } from 'node:util';
|
|
13
|
+
const MACHINE_OUTPUT_FLAGS = new Set(['--json', '--jsonl']);
|
|
14
|
+
/** True when the arguments ask for JSON (or JSON Lines) on stdout. */
|
|
15
|
+
export function requestsMachineOutput(argv) {
|
|
16
|
+
for (const arg of argv) {
|
|
17
|
+
if (arg === '--')
|
|
18
|
+
return false;
|
|
19
|
+
if (MACHINE_OUTPUT_FLAGS.has(arg))
|
|
20
|
+
return true;
|
|
21
|
+
const eq = arg.indexOf('=');
|
|
22
|
+
if (eq > 0 && MACHINE_OUTPUT_FLAGS.has(arg.slice(0, eq)) && arg.slice(eq + 1) !== 'false')
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
function isJsonText(text) {
|
|
28
|
+
if (text.trim() === '')
|
|
29
|
+
return false;
|
|
30
|
+
try {
|
|
31
|
+
JSON.parse(text);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Route non-JSON console.log / console.info output to stderr until the
|
|
40
|
+
* returned restore function runs.
|
|
41
|
+
*/
|
|
42
|
+
export function guardMachineOutput() {
|
|
43
|
+
const { log, info } = console;
|
|
44
|
+
const route = (write) => (...args) => {
|
|
45
|
+
if (isJsonText(format(...args)))
|
|
46
|
+
write(...args);
|
|
47
|
+
else
|
|
48
|
+
console.error(...args);
|
|
49
|
+
};
|
|
50
|
+
console.log = route(log);
|
|
51
|
+
console.info = route(info);
|
|
52
|
+
return () => {
|
|
53
|
+
console.log = log;
|
|
54
|
+
console.info = info;
|
|
55
|
+
};
|
|
56
|
+
}
|
package/dist/main.d.ts
CHANGED
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
* seq-studio auth <sub> manage Git authentication
|
|
17
17
|
* seq-studio feedback submit submit agent feedback
|
|
18
18
|
* seq-studio service-accounts <sub> provision runtime identities
|
|
19
|
-
* seq-studio access <sub> manage
|
|
19
|
+
* seq-studio access <sub> manage resource access on every primitive
|
|
20
|
+
* seq-studio principals <sub> find users, groups and service accounts to grant
|
|
20
21
|
* seq-studio envs <sub> add/list environments
|
|
21
22
|
* seq-studio login authenticate interactively with Auth0
|
|
22
23
|
* seq-studio logout remove cached user tokens
|
package/dist/main.js
CHANGED
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
* seq-studio auth <sub> manage Git authentication
|
|
17
17
|
* seq-studio feedback submit submit agent feedback
|
|
18
18
|
* seq-studio service-accounts <sub> provision runtime identities
|
|
19
|
-
* seq-studio access <sub> manage
|
|
19
|
+
* seq-studio access <sub> manage resource access on every primitive
|
|
20
|
+
* seq-studio principals <sub> find users, groups and service accounts to grant
|
|
20
21
|
* seq-studio envs <sub> add/list environments
|
|
21
22
|
* seq-studio login authenticate interactively with Auth0
|
|
22
23
|
* seq-studio logout remove cached user tokens
|
|
@@ -27,6 +28,7 @@ import { parseArgs } from './argv.js';
|
|
|
27
28
|
import { renderCapabilities } from './command-contract.js';
|
|
28
29
|
import { staticHelp } from './command-help.js';
|
|
29
30
|
import { ignoredSandboxEnvNotice } from './env-flags.js';
|
|
31
|
+
import { guardMachineOutput, requestsMachineOutput } from './machine-output.js';
|
|
30
32
|
import { sandboxUsageFooter } from './sandbox-auth.js';
|
|
31
33
|
// Lazy-load artifact delegate: published @sequenceholdings/artifact-studio/cli
|
|
32
34
|
// still auto-runs runCli() at module load; importing it here breaks doctor/process.
|
|
@@ -49,6 +51,7 @@ const TOP_LEVEL_USAGE = `usage:
|
|
|
49
51
|
seq-studio orm <sub> [args] init | generate | validate | plan | apply | execute | read | sql | diff | migrate-from-yaml | import
|
|
50
52
|
seq-studio service-accounts <sub> list | show | create (requires provisioning authority)
|
|
51
53
|
seq-studio access <sub> definitions | list | grant | revoke | resolve
|
|
54
|
+
seq-studio principals <sub> search | users search | groups list | groups show
|
|
52
55
|
seq-studio envs <sub> add | list environments
|
|
53
56
|
seq-studio login [--env <name>] authenticate in the browser
|
|
54
57
|
seq-studio logout [--env <name>] remove one realm's cached user tokens
|
|
@@ -58,9 +61,12 @@ const TOP_LEVEL_USAGE = `usage:
|
|
|
58
61
|
seq-studio help show this message
|
|
59
62
|
|
|
60
63
|
Authenticate with: seq-studio login
|
|
64
|
+
init, orm init, functions init, artifact init, and agents init take
|
|
65
|
+
--repo <ns>/<name> to scaffold straight into a git-service repo; commit and push from there.
|
|
61
66
|
In an agent sandbox, SEQ_STUDIO_BASE_URL + SEQ_STUDIO_TOKEN_FILE select the
|
|
62
67
|
deployment and token instead (no login; -e optional).
|
|
63
|
-
Where supported, --json writes
|
|
68
|
+
Where supported, --json writes only JSON to stdout (status lines go to stderr);
|
|
69
|
+
check exit status and pagination.
|
|
64
70
|
Built-in env: local. Add your organization's deployment with
|
|
65
71
|
\`seq-studio envs add <name> <url>\`; custom entries live in ~/.config/lattice/config.toml.
|
|
66
72
|
If this CLI cannot complete a documented step, read that environment's docs
|
|
@@ -75,7 +81,7 @@ const PROCESS_USAGE = `usage:
|
|
|
75
81
|
seq-studio process apply --repo <namespace>/<name> [--ref <r>] -e <env> [--only <id1,id2,...>] [--platform-managed]
|
|
76
82
|
seq-studio process promote <processId> --version <v> [-e <env>]
|
|
77
83
|
seq-studio process pull <processId> [--version <v>] [-e <env>] [--out <dir>] [--no-children]
|
|
78
|
-
seq-studio process runs start|list|show|cancel [args] -e <env> (see process runs --help)
|
|
84
|
+
seq-studio process runs start|retry|list|show|cancel [args] -e <env> (see process runs --help)
|
|
79
85
|
seq-studio process test [-e <env>] [--offline]
|
|
80
86
|
seq-studio process simulate <process-id>
|
|
81
87
|
seq-studio process bundle build [-o file.json]
|
|
@@ -98,7 +104,8 @@ const SUBCOMMANDS = {
|
|
|
98
104
|
repos: new Set(['list', 'namespaces', 'show', 'identity', 'create', 'clone', 'pull', 'pulls', 'delete', 'ci']),
|
|
99
105
|
templates: new Set(['publish', 'sync', 'list']),
|
|
100
106
|
'service-accounts': new Set(['list', 'show', 'create']),
|
|
101
|
-
access: new Set(['definitions', 'resolve', 'list', 'grant', 'revoke']),
|
|
107
|
+
access: new Set(['definitions', 'resolve', 'list', 'grant', 'revoke', 'roles']),
|
|
108
|
+
principals: new Set(['search', 'users', 'groups']),
|
|
102
109
|
auth: new Set(['whoami', 'git-credential', 'pat']),
|
|
103
110
|
feedback: new Set(['submit']),
|
|
104
111
|
orm: new Set(['init', 'generate', 'validate', 'plan', 'apply', 'execute', 'namespaces', 'describe', 'read', 'sql', 'diff', 'migrate-from-yaml', 'import']),
|
|
@@ -106,6 +113,17 @@ const SUBCOMMANDS = {
|
|
|
106
113
|
envs: new Set(['add', 'list']),
|
|
107
114
|
};
|
|
108
115
|
export async function run(argv = process.argv.slice(2)) {
|
|
116
|
+
if (!requestsMachineOutput(argv))
|
|
117
|
+
return dispatch(argv);
|
|
118
|
+
const restore = guardMachineOutput();
|
|
119
|
+
try {
|
|
120
|
+
return await dispatch(argv);
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
restore();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async function dispatch(argv) {
|
|
109
127
|
const [namespace, sub, ...rest] = argv;
|
|
110
128
|
if (!namespace || namespace === 'help' || namespace === '--help' || namespace === '-h') {
|
|
111
129
|
console.log(`${TOP_LEVEL_USAGE}${sandboxUsageFooter()}`);
|
|
@@ -158,10 +176,14 @@ export async function run(argv = process.argv.slice(2)) {
|
|
|
158
176
|
return runProcessNamespace(sub, rest);
|
|
159
177
|
case 'artifact': {
|
|
160
178
|
const { runArtifactCommand } = await import('./artifact/delegate.js');
|
|
179
|
+
if (sub === 'init')
|
|
180
|
+
return (await import('./repos/primitive-declaration.js')).runStandaloneInit({ kind: 'artifact', argv: rest, defaultDir: '.', run: () => runArtifactCommand(sub, rest) });
|
|
161
181
|
return runArtifactCommand(sub, rest);
|
|
162
182
|
}
|
|
163
183
|
case 'functions': {
|
|
164
184
|
const { runFunctionsCommand } = await import('./functions/commands.js');
|
|
185
|
+
if (sub === 'init')
|
|
186
|
+
return (await import('./repos/primitive-declaration.js')).runStandaloneInit({ kind: 'function', argv: rest, run: () => runFunctionsCommand(sub, parseArgs(rest)) });
|
|
165
187
|
return runFunctionsCommand(sub, parseArgs(rest));
|
|
166
188
|
}
|
|
167
189
|
case 'storage': {
|
|
@@ -192,6 +214,10 @@ export async function run(argv = process.argv.slice(2)) {
|
|
|
192
214
|
const { runAccessCommand } = await import('./access/commands.js');
|
|
193
215
|
return runAccessCommand(sub, parseArgs(rest));
|
|
194
216
|
}
|
|
217
|
+
case 'principals': {
|
|
218
|
+
const { runPrincipalsCommand } = await import('./principals/commands.js');
|
|
219
|
+
return runPrincipalsCommand(sub, parseArgs(rest));
|
|
220
|
+
}
|
|
195
221
|
case 'feedback':
|
|
196
222
|
return (await import('./feedback/commands.js')).runFeedbackCommand(sub, parseArgs(rest));
|
|
197
223
|
case 'auth': {
|
|
@@ -200,6 +226,8 @@ export async function run(argv = process.argv.slice(2)) {
|
|
|
200
226
|
}
|
|
201
227
|
case 'orm': {
|
|
202
228
|
const { runOrmCommand } = await import('./orm/delegate.js');
|
|
229
|
+
if (sub === 'init')
|
|
230
|
+
return (await import('./repos/primitive-declaration.js')).runStandaloneInit({ kind: 'orm', argv: rest, run: () => runOrmCommand(sub, rest) });
|
|
203
231
|
return runOrmCommand(sub, rest);
|
|
204
232
|
}
|
|
205
233
|
case 'pipeline': {
|
package/dist/orm/delegate.js
CHANGED
|
@@ -11,11 +11,12 @@ import { parseSourceSpec, resolveArtifactSource, } from '@sequenceholdings/artif
|
|
|
11
11
|
import { getAccessToken, tryGetAccessTokenWithMode } from '../auth.js';
|
|
12
12
|
import { sourceAuthMode } from '../sandbox-auth.js';
|
|
13
13
|
import { resolveConfiguredEnv } from '../config.js';
|
|
14
|
-
import { explicitOrSandboxEnv, normalizeShortEnvFlag, readEnvFromArgv } from '../env-flags.js';
|
|
14
|
+
import { explicitOrSandboxEnv, normalizeShortEnvFlag, readEnvFromArgv, withoutEnvFlag } from '../env-flags.js';
|
|
15
15
|
import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
|
|
16
16
|
import { resolveFunctionSourceDir } from '../functions/source-selection.js';
|
|
17
17
|
import { warnBeforeHostDeploy } from '../manifest-roles-notice.js';
|
|
18
|
-
import { ORM_DISCOVER_HELP, ORM_EXECUTE_HELP, ORM_HELP } from '../command-help.js';
|
|
18
|
+
import { INIT_INTO_REPO_HELP, ORM_DISCOVER_HELP, ORM_EXECUTE_HELP, ORM_HELP } from '../command-help.js';
|
|
19
|
+
import { ormVersionMismatch, requiresSchemaVersionCheck } from './version-guard.js';
|
|
19
20
|
/**
|
|
20
21
|
* ORM subcommands that talk to Atlas — must not silently target `local`.
|
|
21
22
|
* `init`, `generate`, `validate`, `diff`, `migrate-from-yaml`, and `import` are offline.
|
|
@@ -24,13 +25,17 @@ const ORM_NETWORK_SUBS = new Set(['plan', 'apply', 'execute']);
|
|
|
24
25
|
/** Subcommands that may read their namespace from a git-service repo (`--repo`). */
|
|
25
26
|
const ORM_REPO_SUBS = new Set(['plan', 'apply']);
|
|
26
27
|
const ORM_USAGE = `usage:
|
|
27
|
-
seq-studio orm init <dir>
|
|
28
|
+
seq-studio orm init <dir> [--repo <ns>/<name>]
|
|
29
|
+
scaffold a namespace package (v2: TypeScript schema + GraphQL documents);
|
|
30
|
+
--repo scaffolds into a git-service repo (see Init into a repo below)
|
|
28
31
|
seq-studio orm generate [dir] write schema.graphql + operations.manifest.json + typePolicies.gen.ts (offline; runs consumer codegen when codegen.ts is present)
|
|
29
32
|
seq-studio orm generate [dir] --migration-export [--check]
|
|
30
33
|
export reviewed ORM inputs for a coordinated pipeline migration; --check verifies without writing
|
|
31
34
|
seq-studio orm validate [dir] parse + validate definitions and verify committed migrations are in sync
|
|
32
35
|
seq-studio orm plan [dir] -e <env> compile definitions and diff against the registry
|
|
33
|
-
seq-studio orm apply [dir] -e <env>
|
|
36
|
+
seq-studio orm apply [dir] -e <env> [--timeout <duration>] [--no-wait]
|
|
37
|
+
author the migration, register, apply, and refresh the generated outputs (the everyday command);
|
|
38
|
+
waits until the new version is live (default up to 20m; e.g. --timeout 90s), --no-wait returns once queued
|
|
34
39
|
seq-studio orm plan|apply --repo <ns>/<name> [--path <dir>] [--ref <ref>] -e <env>
|
|
35
40
|
plan/apply a namespace committed to a platform git-service repo (CI deploy-from-git);
|
|
36
41
|
--path selects the namespace directory (default: repo root). A remote apply never
|
|
@@ -55,7 +60,8 @@ const ORM_USAGE = `usage:
|
|
|
55
60
|
Environments: see \`seq-studio envs list\` (built-in: local; more are
|
|
56
61
|
discovered after you authenticate).
|
|
57
62
|
Authenticate with: seq-studio login
|
|
58
|
-
|
|
63
|
+
|
|
64
|
+
${INIT_INTO_REPO_HELP}`;
|
|
59
65
|
/**
|
|
60
66
|
* Classify an ERR_MODULE_NOT_FOUND from importing `@sequenceholdings/orm/cli`:
|
|
61
67
|
* is the orm package itself absent, or is it present but a dependency (e.g.
|
|
@@ -116,7 +122,8 @@ export function extractOrmRepoSelection(argv) {
|
|
|
116
122
|
function positionalDir(args) {
|
|
117
123
|
for (let i = 0; i < args.length; i++) {
|
|
118
124
|
const arg = args[i];
|
|
119
|
-
|
|
125
|
+
// Flags whose value is a separate argument (`-e` is normalized to `--env`).
|
|
126
|
+
if (arg === '--env' || arg === '--timeout') {
|
|
120
127
|
i += 1;
|
|
121
128
|
continue;
|
|
122
129
|
}
|
|
@@ -158,6 +165,11 @@ async function runOrmFromRepo({ sub, selection, auth, targetUrl, ormCli, }) {
|
|
|
158
165
|
repoDir: source.dir,
|
|
159
166
|
...(selection.path !== undefined ? { path: selection.path } : {}),
|
|
160
167
|
});
|
|
168
|
+
const mismatch = await ormVersionMismatch(dir);
|
|
169
|
+
if (mismatch) {
|
|
170
|
+
console.error(`[seq-studio] ${mismatch}`);
|
|
171
|
+
return 1;
|
|
172
|
+
}
|
|
161
173
|
aliasOrmModuleForRemoteSource(ormCli.ORM_MODULE_PATH_ENV);
|
|
162
174
|
// A local apply authors any missing migration into the working tree for
|
|
163
175
|
// review. A clone is discarded, so an authored migration would be applied
|
|
@@ -245,6 +257,27 @@ async function runWithoutOrmPackage({ sub, rest, normalized }) {
|
|
|
245
257
|
const args = parseArgs(rest);
|
|
246
258
|
return (await isDeployedExecute(args)) ? ormExecuteDeployedCommand(args) : null;
|
|
247
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* `orm init <dir> --repo <ns>/<name>`: prepare the git-service checkout, then
|
|
262
|
+
* scaffold into it through the ordinary init. Null when `--repo` is absent.
|
|
263
|
+
* (On plan/apply, `--repo` instead selects a remote source; see above.)
|
|
264
|
+
*/
|
|
265
|
+
async function runOrmInitWithRepo(normalized) {
|
|
266
|
+
if (normalized.includes('--help') || normalized.includes('-h'))
|
|
267
|
+
return null;
|
|
268
|
+
const { extractRepoFlag, runInitWithRepo } = await import('../repos/init-repo.js');
|
|
269
|
+
const { repo, rest: initArgv } = extractRepoFlag(normalized);
|
|
270
|
+
if (repo === undefined)
|
|
271
|
+
return null;
|
|
272
|
+
const args = parseArgs(normalized);
|
|
273
|
+
const target = positionalDir(initArgv);
|
|
274
|
+
if (!target) {
|
|
275
|
+
console.error('usage: seq-studio orm init <dir> [--repo <ns>/<name>]');
|
|
276
|
+
return 1;
|
|
277
|
+
}
|
|
278
|
+
// The environment is for the repository setup; init itself is offline.
|
|
279
|
+
return runInitWithRepo({ args, target, scaffold: () => runOrmCommand('init', withoutEnvFlag(initArgv)) });
|
|
280
|
+
}
|
|
248
281
|
export async function runOrmCommand(sub, rest) {
|
|
249
282
|
if (!sub || sub === 'help' || sub === '--help' || sub === '-h') {
|
|
250
283
|
console.log(ORM_USAGE);
|
|
@@ -253,6 +286,9 @@ export async function runOrmCommand(sub, rest) {
|
|
|
253
286
|
if (NATIVE_ORM_SUBS.has(sub))
|
|
254
287
|
return runNativeOrmCommand(sub, rest);
|
|
255
288
|
const normalized = normalizeShortEnvFlag(rest);
|
|
289
|
+
const repoInit = sub === 'init' ? await runOrmInitWithRepo(normalized) : null;
|
|
290
|
+
if (repoInit !== null)
|
|
291
|
+
return repoInit;
|
|
256
292
|
const answered = await runWithoutOrmPackage({ sub, rest, normalized });
|
|
257
293
|
if (answered !== null)
|
|
258
294
|
return answered;
|
|
@@ -306,6 +342,13 @@ export async function runOrmCommand(sub, rest) {
|
|
|
306
342
|
});
|
|
307
343
|
if (repoSelection)
|
|
308
344
|
return runOrmFromRepo({ sub, selection: repoSelection, auth, targetUrl, ormCli });
|
|
345
|
+
if (requiresSchemaVersionCheck(sub)) {
|
|
346
|
+
const mismatch = await ormVersionMismatch(positionalDir(normalized) ?? '.');
|
|
347
|
+
if (mismatch) {
|
|
348
|
+
console.error(`[seq-studio] ${mismatch}`);
|
|
349
|
+
return 1;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
309
352
|
await warnBeforeHostDeploy({ sub, deploySub: 'apply', args: normalized, file: 'namespace.yaml' });
|
|
310
353
|
return runCli([sub, ...normalized]);
|
|
311
354
|
}
|
package/dist/orm/execute.js
CHANGED
|
@@ -15,6 +15,7 @@ import { getJsonOr404, postJsonResponse } from '../atlas-client.js';
|
|
|
15
15
|
import { printCliError } from '../cli-errors.js';
|
|
16
16
|
import { validateCommandInput } from '../command-input.js';
|
|
17
17
|
import { buildContext, clientOptions } from '../functions/commands.js';
|
|
18
|
+
import { dataPlaneFailure, failureNextStep, failureSummary } from './failures.js';
|
|
18
19
|
import { operationDetailSchema, operationsPageSchema, parseResponse, } from './discover-schema.js';
|
|
19
20
|
/** The operation detail route's name grammar (a GraphQL name). */
|
|
20
21
|
const OPERATION_NAME = /^[_A-Za-z][_0-9A-Za-z]{0,254}$/;
|
|
@@ -154,9 +155,9 @@ function parseEnvelope(body) {
|
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
function failureMessage({ namespace, operation, status, envelope }) {
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const detail =
|
|
158
|
+
const failure = dataPlaneFailure({ status, errors: envelope?.errors });
|
|
159
|
+
const { code } = failure;
|
|
160
|
+
const detail = failureSummary(failure);
|
|
160
161
|
const lines = [`${namespace}.${operation.name} failed: ${detail}`];
|
|
161
162
|
if (code === 'BAD_USER_INPUT' && operation.variables.length > 0) {
|
|
162
163
|
lines.push(`Variables: ${variablesLabel(operation.variables)}`);
|
|
@@ -169,8 +170,13 @@ function failureMessage({ namespace, operation, status, envelope }) {
|
|
|
169
170
|
lines.push(`It requires ${[capability ? `capability ${capability}` : null, role ? `role ${role}` : null].filter(Boolean).join(' and ')}.`);
|
|
170
171
|
}
|
|
171
172
|
}
|
|
172
|
-
if (status === 404) {
|
|
173
|
-
lines.push('The deployed operation
|
|
173
|
+
if (status === 404 && failure.details.cause === 'unknown_operation') {
|
|
174
|
+
lines.push('The deployed operation changed between lookup and execution (the namespace was just redeployed). Retry.');
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
const next = failureNextStep({ failure, namespace });
|
|
178
|
+
if (next && code !== 'BAD_USER_INPUT' && code !== 'FORBIDDEN')
|
|
179
|
+
lines.push(next);
|
|
174
180
|
}
|
|
175
181
|
return lines.join('\n');
|
|
176
182
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human output for a refusal from the ORM data endpoint. The server's GraphQL
|
|
3
|
+
* envelope carries `{message, extensions: {code, details?}}`; `details` names
|
|
4
|
+
* the variable, column, constraint, or requirement at fault (schema names
|
|
5
|
+
* only, never values). Every ORM command prints refusals through here so the
|
|
6
|
+
* same error reads the same way from `execute`, `read`, and `sql`.
|
|
7
|
+
*/
|
|
8
|
+
export interface DataPlaneFailure {
|
|
9
|
+
status: number | null;
|
|
10
|
+
code: string | null;
|
|
11
|
+
message: string | null;
|
|
12
|
+
details: Readonly<Record<string, string>>;
|
|
13
|
+
}
|
|
14
|
+
/** The first error of a data-plane envelope (or of an ORM client error's `errors`). */
|
|
15
|
+
export declare function dataPlaneFailure({ status, errors }: {
|
|
16
|
+
status: number | null;
|
|
17
|
+
errors: unknown;
|
|
18
|
+
}): DataPlaneFailure;
|
|
19
|
+
/** `message (CODE) [variable: x, column: y]`, or `HTTP <status>` when the server sent no envelope. */
|
|
20
|
+
export declare function failureSummary(failure: DataPlaneFailure): string;
|
|
21
|
+
/** One recovery step for the refusal, or null when the message already says it. */
|
|
22
|
+
export declare function failureNextStep({ failure, namespace }: {
|
|
23
|
+
failure: DataPlaneFailure;
|
|
24
|
+
namespace: string;
|
|
25
|
+
}): string | null;
|
|
26
|
+
/** An ORM client error (`@sequenceholdings/orm/client`), matched by name: the CLI may load its own copy. */
|
|
27
|
+
export declare function ormClientFailure(error: unknown): DataPlaneFailure | null;
|
|
28
|
+
/** Print any ORM command error: data-plane refusals with their details and next step, everything else as usual. */
|
|
29
|
+
export declare function printOrmCommandError({ error, namespace }: {
|
|
30
|
+
error: unknown;
|
|
31
|
+
namespace: string;
|
|
32
|
+
}): void;
|