@sequenceholdings/studio-cli 0.9.23 → 0.9.26

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.
Files changed (157) hide show
  1. package/README.md +166 -146
  2. package/dist/access/commands.js +3 -5
  3. package/dist/access/principal.js +2 -2
  4. package/dist/access/tier-hosts.js +2 -2
  5. package/dist/agents/commands.d.ts +1 -1
  6. package/dist/agents/commands.js +9 -9
  7. package/dist/agents/scaffold.js +3 -3
  8. package/dist/agents/voice.d.ts +1 -1
  9. package/dist/agents/voice.js +1 -1
  10. package/dist/app/commands.d.ts +2 -2
  11. package/dist/app/commands.js +31 -21
  12. package/dist/app/deploy.d.ts +1 -1
  13. package/dist/app/deploy.js +1 -1
  14. package/dist/app/manifest.d.ts +9 -9
  15. package/dist/app/manifest.js +1 -1
  16. package/dist/app/prepare.js +1 -1
  17. package/dist/app/primitive-scaffold.js +1 -1
  18. package/dist/app/readme.js +6 -6
  19. package/dist/app/scaffold.js +1 -1
  20. package/dist/app/validate.d.ts +1 -1
  21. package/dist/app/workspace-scaffold.js +1 -1
  22. package/dist/app-preview/commands.d.ts +7 -0
  23. package/dist/app-preview/commands.js +264 -0
  24. package/dist/app-preview/fingerprint.d.ts +20 -0
  25. package/dist/app-preview/fingerprint.js +32 -0
  26. package/dist/app-preview/install.d.ts +31 -0
  27. package/dist/app-preview/install.js +53 -0
  28. package/dist/app-preview/namespace-probe.d.ts +13 -0
  29. package/dist/app-preview/namespace-probe.js +50 -0
  30. package/dist/app-preview/plan.d.ts +28 -0
  31. package/dist/app-preview/plan.js +41 -0
  32. package/dist/app-preview/run.d.ts +32 -0
  33. package/dist/app-preview/run.js +48 -0
  34. package/dist/app-preview/runners.d.ts +73 -0
  35. package/dist/app-preview/runners.js +226 -0
  36. package/dist/app-preview/secrets.d.ts +48 -0
  37. package/dist/app-preview/secrets.js +104 -0
  38. package/dist/app-preview/target.d.ts +28 -0
  39. package/dist/app-preview/target.js +62 -0
  40. package/dist/artifact/delegate.d.ts +1 -12
  41. package/dist/artifact/delegate.js +43 -124
  42. package/dist/artifact/sandbox.js +1 -1
  43. package/dist/auth-cmds/commands.js +1 -2
  44. package/dist/auth.js +1 -3
  45. package/dist/bin.js +12 -2
  46. package/dist/cli-attribution.d.ts +4 -0
  47. package/dist/cli-attribution.js +25 -3
  48. package/dist/cli-errors.d.ts +9 -1
  49. package/dist/cli-errors.js +20 -9
  50. package/dist/command-contract.d.ts +7 -182
  51. package/dist/command-contract.js +9 -33
  52. package/dist/command-help.d.ts +6 -6
  53. package/dist/command-help.js +31 -27
  54. package/dist/command-telemetry.js +2 -2
  55. package/dist/config-dir.d.ts +8 -0
  56. package/dist/config-dir.js +35 -0
  57. package/dist/config.d.ts +6 -7
  58. package/dist/config.js +15 -15
  59. package/dist/docs/commands.js +9 -4
  60. package/dist/edge-auth-headers.js +1 -18
  61. package/dist/env-registry.d.ts +4 -0
  62. package/dist/env-registry.js +15 -6
  63. package/dist/envs/commands.d.ts +3 -0
  64. package/dist/envs/commands.js +11 -0
  65. package/dist/exit-codes.d.ts +16 -0
  66. package/dist/exit-codes.js +27 -0
  67. package/dist/functions/bundle.d.ts +1 -1
  68. package/dist/functions/commands.d.ts +15 -0
  69. package/dist/functions/commands.js +86 -29
  70. package/dist/functions/manifest.js +1 -1
  71. package/dist/functions/service-account-guidance.d.ts +1 -1
  72. package/dist/functions/service-account-guidance.js +2 -2
  73. package/dist/lifecycle/check.d.ts +13 -0
  74. package/dist/lifecycle/check.js +116 -0
  75. package/dist/lifecycle/commands.d.ts +14 -0
  76. package/dist/lifecycle/commands.js +121 -0
  77. package/dist/lifecycle/plan.d.ts +28 -0
  78. package/dist/lifecycle/plan.js +113 -0
  79. package/dist/lifecycle/rollback.d.ts +7 -0
  80. package/dist/lifecycle/rollback.js +89 -0
  81. package/dist/lifecycle/seq-ci-tools.d.ts +107 -0
  82. package/dist/lifecycle/seq-ci-tools.js +177 -0
  83. package/dist/lifecycle/upgrade.d.ts +3 -0
  84. package/dist/lifecycle/upgrade.js +38 -0
  85. package/dist/machine-output.d.ts +11 -2
  86. package/dist/machine-output.js +32 -10
  87. package/dist/main.d.ts +16 -6
  88. package/dist/main.js +187 -361
  89. package/dist/orgs.d.ts +45 -0
  90. package/dist/orgs.js +106 -0
  91. package/dist/orm/delegate.d.ts +1 -1
  92. package/dist/orm/delegate.js +32 -18
  93. package/dist/orm/deployment-policy.js +1 -2
  94. package/dist/orm/discover.js +6 -8
  95. package/dist/orm/execute.d.ts +1 -1
  96. package/dist/orm/execute.js +5 -6
  97. package/dist/orm/failures.js +2 -2
  98. package/dist/orm/help.d.ts +1 -1
  99. package/dist/orm/help.js +5 -5
  100. package/dist/orm/history.js +1 -2
  101. package/dist/orm/operation-show.js +1 -2
  102. package/dist/orm/version-guard.d.ts +7 -2
  103. package/dist/orm/version-guard.js +12 -7
  104. package/dist/pipeline/codegen.js +2 -2
  105. package/dist/pipeline/commands.js +9 -7
  106. package/dist/pipeline/discovery.d.ts +1 -1
  107. package/dist/pipeline/discovery.js +2 -3
  108. package/dist/pipeline/help.d.ts +1 -1
  109. package/dist/pipeline/help.js +1 -1
  110. package/dist/pipeline/lifecycle.js +1 -1
  111. package/dist/pipeline/stage-secrets.js +4 -4
  112. package/dist/pipeline/templates.js +2 -2
  113. package/dist/pnpm-auto-update.js +3 -3
  114. package/dist/principals/commands.d.ts +1 -1
  115. package/dist/principals/commands.js +13 -14
  116. package/dist/process/commands.js +4 -1
  117. package/dist/process/run-steps.d.ts +2 -2
  118. package/dist/process/runs.js +1 -2
  119. package/dist/registry/commands.d.ts +4 -0
  120. package/dist/registry/commands.js +281 -0
  121. package/dist/registry/help.d.ts +8 -0
  122. package/dist/registry/help.js +64 -0
  123. package/dist/registry/lifecycle-commands.d.ts +3 -0
  124. package/dist/registry/lifecycle-commands.js +67 -0
  125. package/dist/registry/lookup.d.ts +6 -0
  126. package/dist/registry/lookup.js +18 -0
  127. package/dist/registry/runners.d.ts +14 -0
  128. package/dist/registry/runners.js +206 -0
  129. package/dist/registry/spec.d.ts +45 -0
  130. package/dist/registry/spec.js +8 -0
  131. package/dist/repos/commands.d.ts +1 -4
  132. package/dist/repos/commands.js +3 -21
  133. package/dist/repos/github-connect-command.d.ts +10 -1
  134. package/dist/repos/github-connect-command.js +52 -11
  135. package/dist/repos/github-init.d.ts +9 -2
  136. package/dist/repos/github-init.js +18 -2
  137. package/dist/repos/init-repo.js +1 -2
  138. package/dist/run-pinned.d.ts +48 -0
  139. package/dist/run-pinned.js +127 -0
  140. package/dist/sdk-source.d.ts +64 -0
  141. package/dist/sdk-source.js +199 -0
  142. package/dist/secrets/commands.d.ts +1 -1
  143. package/dist/secrets/commands.js +29 -24
  144. package/dist/service-accounts/commands.d.ts +1 -1
  145. package/dist/service-accounts/commands.js +4 -5
  146. package/dist/staged-env.d.ts +14 -0
  147. package/dist/staged-env.js +73 -0
  148. package/dist/storage/commands.js +21 -22
  149. package/dist/templates/catalog.d.ts +5 -5
  150. package/dist/templates/catalog.js +1 -1
  151. package/dist/update-check.js +3 -3
  152. package/dist/version-support.d.ts +39 -0
  153. package/dist/version-support.js +71 -0
  154. package/package.json +11 -10
  155. package/release-summary.json +4 -1
  156. package/dist/preview.d.ts +0 -90
  157. package/dist/preview.js +0 -292
@@ -4,6 +4,8 @@ import { z } from 'zod';
4
4
  * managed header, and only what's missing or stale; `check` reports the same without writing.
5
5
  */
6
6
  export declare const TEMPLATE_VERSION = 1;
7
+ /** `<major>.<minor>` of the running CLI. */
8
+ export declare function installedMajorMinor(): string;
7
9
  export declare const MANAGED_MARKER = "Managed by seq-studio";
8
10
  export declare const SEQ_CI_REPOSITORY = "sequenceholdings/seq-ci";
9
11
  export declare const githubSettingsSchema: z.ZodObject<{
@@ -23,6 +25,11 @@ export declare const githubSettingsSchema: z.ZodObject<{
23
25
  reuse: "reuse";
24
26
  rebuild: "rebuild";
25
27
  }>>;
28
+ cli: z.ZodOptional<z.ZodString>;
29
+ sdk: z.ZodOptional<z.ZodEnum<{
30
+ bundled: "bundled";
31
+ project: "project";
32
+ }>>;
26
33
  }, z.core.$strict>;
27
34
  export type GitHubSettings = z.infer<typeof githubSettingsSchema>;
28
35
  export declare const GITHUB_SETTINGS_PATH = ".seq/github.yml";
@@ -61,8 +68,7 @@ export interface FileReport {
61
68
  path: string;
62
69
  status: FileStatus;
63
70
  }
64
- /** Existing settings win over defaults, so rerunning never changes a repository's org or branches. */
65
- export declare function resolveSettings({ directory, org, dev, release, seqCi, releaseRepository, pullRequestBuilds }: {
71
+ export declare function resolveSettings({ directory, org, dev, release, seqCi, releaseRepository, pullRequestBuilds, cli }: {
66
72
  directory: string;
67
73
  org?: string;
68
74
  dev?: string;
@@ -70,6 +76,7 @@ export declare function resolveSettings({ directory, org, dev, release, seqCi, r
70
76
  seqCi?: string;
71
77
  releaseRepository?: string;
72
78
  pullRequestBuilds?: string;
79
+ cli?: string;
73
80
  }): Promise<GitHubSettings>;
74
81
  /**
75
82
  * Report, or with `write`, create every managed file that's missing or stale. Never overwrites a file it doesn't own:
@@ -1,4 +1,5 @@
1
1
  import { readFileSync } from 'node:fs';
2
+ import { currentVersion } from '../update-check.js';
2
3
  import { lstat, mkdir, readFile, writeFile } from 'node:fs/promises';
3
4
  import { dirname, join, resolve } from 'node:path';
4
5
  import { dump as yamlDump, load as yamlLoad } from 'js-yaml';
@@ -8,6 +9,10 @@ import { z } from 'zod';
8
9
  * managed header, and only what's missing or stale; `check` reports the same without writing.
9
10
  */
10
11
  export const TEMPLATE_VERSION = 1;
12
+ /** `<major>.<minor>` of the running CLI. */
13
+ export function installedMajorMinor() {
14
+ return currentVersion().split('.').slice(0, 2).join('.');
15
+ }
11
16
  export const MANAGED_MARKER = 'Managed by seq-studio';
12
17
  export const SEQ_CI_REPOSITORY = 'sequenceholdings/seq-ci';
13
18
  export const githubSettingsSchema = z.object({
@@ -31,6 +36,10 @@ export const githubSettingsSchema = z.object({
31
36
  * `repo connect --stage prod` records it on the prod Atlas.
32
37
  */
33
38
  promoted_builds: z.enum(['reuse', 'rebuild']).optional(),
39
+ /** The seq-studio `<major>.<minor>` this repository runs; `seq-studio upgrade` moves it. */
40
+ cli: z.string().regex(/^[0-9]+\.[0-9]+$/).optional(),
41
+ /** `project` runs the SDKs this repository's lockfile installed instead of the CLI's bundled copies (sdk-source.ts). */
42
+ sdk: z.enum(['bundled', 'project']).optional(),
34
43
  }).strict();
35
44
  export const GITHUB_SETTINGS_PATH = '.seq/github.yml';
36
45
  const header = (path) => `# ${MANAGED_MARKER} (template ${TEMPLATE_VERSION}). Change it with \`seq-studio repo init\`; check it with \`seq-studio repo init --check\`.\n# ${path}\n`;
@@ -205,7 +214,12 @@ function statusOf({ existing, content }) {
205
214
  return existing.includes(MANAGED_MARKER) ? 'stale' : 'unmanaged';
206
215
  }
207
216
  /** Existing settings win over defaults, so rerunning never changes a repository's org or branches. */
208
- export async function resolveSettings({ directory, org, dev, release, seqCi, releaseRepository, pullRequestBuilds }) {
217
+ /** A new repository pins the CLI that created it; an existing one keeps what it has until `seq-studio upgrade`. */
218
+ function pinnedCli({ cli, current }) {
219
+ const pin = cli ?? (current ? current.cli : installedMajorMinor());
220
+ return pin ? { cli: pin } : {};
221
+ }
222
+ export async function resolveSettings({ directory, org, dev, release, seqCi, releaseRepository, pullRequestBuilds, cli }) {
209
223
  const existing = await readOptional(join(resolve(directory), GITHUB_SETTINGS_PATH));
210
224
  const current = existing === null ? undefined : githubSettingsSchema.parse(yamlLoad(existing));
211
225
  const settings = { schema_version: 1, org: org ?? current?.org, branches: { dev: dev ?? current?.branches.dev ?? 'staging', release: release ?? current?.branches.release ?? 'main' },
@@ -213,7 +227,9 @@ export async function resolveSettings({ directory, org, dev, release, seqCi, rel
213
227
  // On by default: the dev branch ruleset below requires no approvals.
214
228
  pull_request_builds: pullRequestBuilds ?? current?.pull_request_builds ?? 'reuse',
215
229
  ...((releaseRepository ?? current?.release_repository) ? { release_repository: releaseRepository ?? current?.release_repository } : {}),
216
- ...(current?.promoted_builds ? { promoted_builds: current.promoted_builds } : {}) };
230
+ ...(current?.promoted_builds ? { promoted_builds: current.promoted_builds } : {}),
231
+ ...(current?.sdk ? { sdk: current.sdk } : {}),
232
+ ...pinnedCli({ cli, current }) };
217
233
  if (!settings.org)
218
234
  throw new Error('repo init needs --org the first time (for example --org banksouth)');
219
235
  if (settings.branches.dev === settings.branches.release)
@@ -206,8 +206,7 @@ export async function runInitWithRepo({ args, target, scaffold, deps = {} }) {
206
206
  }
207
207
  }
208
208
  catch (error) {
209
- printCliError(error);
210
- return 1;
209
+ return printCliError(error);
211
210
  }
212
211
  const code = await scaffold();
213
212
  if (code !== 0) {
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Opt-in: run the seq-studio a repository pins (`cli: <major.minor>` in `.seq/github.yml`) instead of this one.
3
+ *
4
+ * With `SEQ_STUDIO_USE_PIN=1`, a command run in a repository pinned to another minor re-runs itself with the pinned
5
+ * CLI. That CLI comes from `SEQ_STUDIO_CLI_CACHE` (images that bake pinned versions in point it at theirs) or
6
+ * `~/.cache/seq-studio/cli/<major.minor>`, installed there on first use with pnpm and the machine's own registry
7
+ * configuration, under the same seven-day `minimumReleaseAge` quarantine as every Sequence project. First-party
8
+ * releases are exempt (release-age.ts), so the newest patch of the pinned minor is used; its third-party dependencies
9
+ * are not. A published cache directory is never replaced while a command may be running from it.
10
+ *
11
+ * It never blocks: when the pinned CLI cannot be found or installed, this CLI runs the command itself after a warning.
12
+ * An offline command only uses a cached CLI; it never installs one.
13
+ * Without the opt-in, a mismatch is only noted (version-support.ts `pinNote`).
14
+ */
15
+ import { type SpawnSyncOptions } from 'node:child_process';
16
+ export declare const USE_PIN_ENV = "SEQ_STUDIO_USE_PIN";
17
+ export declare const CLI_CACHE_ENV = "SEQ_STUDIO_CLI_CACHE";
18
+ /** Set on the re-run, so the pinned CLI never re-runs again. */
19
+ export declare const PINNED_RUN_ENV = "SEQ_STUDIO_PINNED_RUN";
20
+ export type Spawn = (command: string, args: string[], options: SpawnSyncOptions) => {
21
+ status: number | null;
22
+ error?: Error;
23
+ stderr?: string | Buffer | null;
24
+ };
25
+ export interface RunPinnedDeps {
26
+ spawn: Spawn;
27
+ cacheRoot: string;
28
+ env: NodeJS.ProcessEnv;
29
+ }
30
+ export declare function wantsPinnedRun(env?: NodeJS.ProcessEnv): boolean;
31
+ /** The pinned CLI's entry point under `<cacheRoot>/<pin>`, if a release of that minor is there. */
32
+ export declare function cachedPinnedCli({ cacheRoot, pin }: {
33
+ cacheRoot: string;
34
+ pin: string;
35
+ }): string | undefined;
36
+ /** The pnpm workspace an install runs in: the release-age quarantine, with first-party releases exempt. */
37
+ export declare function pinnedInstallWorkspace(): string;
38
+ /**
39
+ * Run `argv` with the pinned CLI and return its exit code, or null to run it here: when the repository pins nothing
40
+ * or this CLI's minor, or when the pinned CLI is unavailable (after a warning).
41
+ */
42
+ export declare function runPinned({ pin, installed, argv, offline, deps }: {
43
+ pin: string | undefined;
44
+ installed: string;
45
+ argv: string[];
46
+ offline?: boolean;
47
+ deps?: RunPinnedDeps;
48
+ }): Promise<number | null>;
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Opt-in: run the seq-studio a repository pins (`cli: <major.minor>` in `.seq/github.yml`) instead of this one.
3
+ *
4
+ * With `SEQ_STUDIO_USE_PIN=1`, a command run in a repository pinned to another minor re-runs itself with the pinned
5
+ * CLI. That CLI comes from `SEQ_STUDIO_CLI_CACHE` (images that bake pinned versions in point it at theirs) or
6
+ * `~/.cache/seq-studio/cli/<major.minor>`, installed there on first use with pnpm and the machine's own registry
7
+ * configuration, under the same seven-day `minimumReleaseAge` quarantine as every Sequence project. First-party
8
+ * releases are exempt (release-age.ts), so the newest patch of the pinned minor is used; its third-party dependencies
9
+ * are not. A published cache directory is never replaced while a command may be running from it.
10
+ *
11
+ * It never blocks: when the pinned CLI cannot be found or installed, this CLI runs the command itself after a warning.
12
+ * An offline command only uses a cached CLI; it never installs one.
13
+ * Without the opt-in, a mismatch is only noted (version-support.ts `pinNote`).
14
+ */
15
+ import { spawnSync } from 'node:child_process';
16
+ import { existsSync, readFileSync } from 'node:fs';
17
+ import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
18
+ import { homedir } from 'node:os';
19
+ import { join } from 'node:path';
20
+ import { FIRST_PARTY_RELEASE_AGE_EXCLUDE } from './release-age.js';
21
+ export const USE_PIN_ENV = 'SEQ_STUDIO_USE_PIN';
22
+ export const CLI_CACHE_ENV = 'SEQ_STUDIO_CLI_CACHE';
23
+ /** Set on the re-run, so the pinned CLI never re-runs again. */
24
+ export const PINNED_RUN_ENV = 'SEQ_STUDIO_PINNED_RUN';
25
+ const PACKAGE = '@sequenceholdings/studio-cli';
26
+ const INSTALL_TIMEOUT_MS = 120_000;
27
+ /** Seven days, as every scaffolded project's pnpm-workspace.yaml sets it. */
28
+ const MINIMUM_RELEASE_AGE_MINUTES = 10_080;
29
+ const defaultDeps = () => ({
30
+ spawn: (command, args, options) => spawnSync(command, args, options),
31
+ cacheRoot: process.env[CLI_CACHE_ENV]?.trim() || join(process.env.XDG_CACHE_HOME ?? join(homedir(), '.cache'), 'seq-studio', 'cli'),
32
+ env: process.env,
33
+ });
34
+ export function wantsPinnedRun(env = process.env) {
35
+ const value = env[USE_PIN_ENV]?.trim().toLowerCase();
36
+ return (value === '1' || value === 'true') && env[PINNED_RUN_ENV] !== '1';
37
+ }
38
+ /** The pinned CLI's entry point under `<cacheRoot>/<pin>`, if a release of that minor is there. */
39
+ export function cachedPinnedCli({ cacheRoot, pin }) {
40
+ const directory = join(cacheRoot, pin, 'node_modules', ...PACKAGE.split('/'));
41
+ try {
42
+ const manifest = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8'));
43
+ const version = typeof manifest === 'object' && manifest !== null ? Reflect.get(manifest, 'version') : undefined;
44
+ const bin = join(directory, 'dist', 'bin.js');
45
+ return typeof version === 'string' && version.startsWith(`${pin}.`) && existsSync(bin) ? bin : undefined;
46
+ }
47
+ catch {
48
+ return undefined;
49
+ }
50
+ }
51
+ /** The pnpm workspace an install runs in: the release-age quarantine, with first-party releases exempt. */
52
+ export function pinnedInstallWorkspace() {
53
+ return [`minimumReleaseAge: ${MINIMUM_RELEASE_AGE_MINUTES}`, 'minimumReleaseAgeExclude:',
54
+ ...FIRST_PARTY_RELEASE_AGE_EXCLUDE.map((name) => ` - '${name}'`), ''].join('\n');
55
+ }
56
+ /**
57
+ * Move a finished install into place. A concurrent first use may have published the pin already, and a command may be
58
+ * running from it, so a usable published copy is kept and ours discarded; only an unusable one is replaced.
59
+ */
60
+ async function publish({ staging, cacheRoot, pin }) {
61
+ const target = join(cacheRoot, pin);
62
+ const published = cachedPinnedCli({ cacheRoot, pin });
63
+ if (published)
64
+ return published;
65
+ try {
66
+ await rename(staging, target);
67
+ }
68
+ catch (error) {
69
+ const winner = cachedPinnedCli({ cacheRoot, pin });
70
+ if (winner)
71
+ return winner;
72
+ if (!(error instanceof Error && 'code' in error && (error.code === 'ENOTEMPTY' || error.code === 'EEXIST')))
73
+ throw error;
74
+ await rm(target, { recursive: true, force: true });
75
+ await rename(staging, target);
76
+ }
77
+ return cachedPinnedCli({ cacheRoot, pin });
78
+ }
79
+ /** Install the newest release of the pinned minor into the cache, atomically; undefined with a reason on failure. */
80
+ async function installPinnedCli({ pin, deps }) {
81
+ const staging = `${join(deps.cacheRoot, pin)}.installing-${process.pid}`;
82
+ await mkdir(staging, { recursive: true });
83
+ try {
84
+ await writeFile(join(staging, 'package.json'), `${JSON.stringify({ name: 'seq-studio-pinned-cli', private: true })}\n`);
85
+ await writeFile(join(staging, 'pnpm-workspace.yaml'), pinnedInstallWorkspace());
86
+ const spec = `${PACKAGE}@~${pin}.0`;
87
+ const result = deps.spawn('pnpm', ['add', '--dir', staging, '--ignore-scripts', '--reporter=silent', spec], { encoding: 'utf8', stdio: ['ignore', 'ignore', 'pipe'], timeout: INSTALL_TIMEOUT_MS, env: deps.env });
88
+ if (result.error || result.status !== 0) {
89
+ const lines = String(result.stderr ?? '').split('\n').map((line) => line.trim()).filter(Boolean);
90
+ const detail = result.error?.message ?? lines.find((line) => line.startsWith('ERR_PNPM')) ?? lines.at(-1) ?? `exit ${result.status}`;
91
+ return { reason: `pnpm add ${spec} failed: ${detail}` };
92
+ }
93
+ const bin = await publish({ staging, cacheRoot: deps.cacheRoot, pin });
94
+ return bin ? { bin } : { reason: `the installed ${PACKAGE} is not a ${pin} release` };
95
+ }
96
+ finally {
97
+ await rm(staging, { recursive: true, force: true });
98
+ }
99
+ }
100
+ /**
101
+ * Run `argv` with the pinned CLI and return its exit code, or null to run it here: when the repository pins nothing
102
+ * or this CLI's minor, or when the pinned CLI is unavailable (after a warning).
103
+ */
104
+ export async function runPinned({ pin, installed, argv, offline = false, deps = defaultDeps() }) {
105
+ if (!pin || installed.split('.').slice(0, 2).join('.') === pin)
106
+ return null;
107
+ let bin = cachedPinnedCli({ cacheRoot: deps.cacheRoot, pin });
108
+ if (!bin && offline) {
109
+ console.error(`note: seq-studio ${pin} (this repository's pin) is not installed and this command runs offline; running ${installed}.`);
110
+ return null;
111
+ }
112
+ if (!bin) {
113
+ console.error(`note: installing seq-studio ${pin} (this repository's pin) into ${join(deps.cacheRoot, pin)}…`);
114
+ const installedPin = await installPinnedCli({ pin, deps }).catch((error) => ({ reason: error instanceof Error ? error.message : String(error), bin: undefined }));
115
+ if (!installedPin.bin) {
116
+ console.error(`warning: could not get seq-studio ${pin} (${installedPin.reason}); running ${installed} instead.`);
117
+ return null;
118
+ }
119
+ bin = installedPin.bin;
120
+ }
121
+ const result = deps.spawn(process.execPath, [bin, ...argv], { stdio: 'inherit', env: { ...deps.env, [PINNED_RUN_ENV]: '1' } });
122
+ if (result.error) {
123
+ console.error(`warning: could not run seq-studio ${pin} (${result.error.message}); running ${installed} instead.`);
124
+ return null;
125
+ }
126
+ return result.status ?? 1;
127
+ }
@@ -0,0 +1,64 @@
1
+ export declare const SDK_ENV = "SEQ_STUDIO_SDK";
2
+ export type SdkMode = 'bundled' | 'project';
3
+ export declare const SDK_PACKAGES: readonly ["@sequenceholdings/orm", "@sequenceholdings/lattice", "@sequenceholdings/artifact-studio", "@sequenceholdings/pipeline-spec"];
4
+ export interface InstalledSdk {
5
+ version?: string;
6
+ directory: string;
7
+ }
8
+ /** The package the project at `cwd` installed: the nearest `node_modules/<name>` at or above it. */
9
+ export declare function projectSdk({ name, cwd }: {
10
+ name: string;
11
+ cwd?: string;
12
+ }): InstalledSdk | undefined;
13
+ /** The copy bundled with this CLI, resolved as an import is (an ESM-only package exports no `require` entry). */
14
+ export declare function bundledSdk({ name }: {
15
+ name: string;
16
+ }): InstalledSdk | undefined;
17
+ /** The ESM file a package's `exports` map gives a subpath (`.` or `./cli`), or undefined. */
18
+ export declare function exportedFile({ directory, subpath }: {
19
+ directory: string;
20
+ subpath: string;
21
+ }): string | undefined;
22
+ /** `--sdk`, then `SEQ_STUDIO_SDK`, then `.seq/github.yml`'s `sdk:`; bundled otherwise. */
23
+ export declare function sdkMode({ cwd }?: {
24
+ cwd?: string;
25
+ }): Promise<SdkMode>;
26
+ export interface SdkComparison {
27
+ name: string;
28
+ bundled?: string;
29
+ project?: string;
30
+ differs: boolean;
31
+ }
32
+ export declare function compareSdk({ name, cwd }: {
33
+ name: string;
34
+ cwd?: string;
35
+ }): SdkComparison;
36
+ /** The version of `name` this command loaded through importSdk, or undefined before it has. */
37
+ export declare function selectedSdkVersion(name: string): string | undefined;
38
+ /**
39
+ * The file `<name><subpath>` resolves to in the copy this command loaded, so a module imported indirectly (an ORM
40
+ * schema importing `@sequenceholdings/orm/authoring`) matches it. Undefined when that copy does not export it.
41
+ */
42
+ export declare function selectedSdkFile({ name, subpath }: {
43
+ name: string;
44
+ subpath: string;
45
+ }): string | undefined;
46
+ /**
47
+ * Import `<name><subpath>` from the copy this command runs. `bundled` is the CLI's own static import, so the bundler
48
+ * keeps it. Prints a note once when the project's copy is a different version than the one used.
49
+ */
50
+ export declare function importSdk<T>({ name, subpath, bundled, cwd }: {
51
+ name: string;
52
+ subpath?: string;
53
+ bundled: () => Promise<T>;
54
+ cwd?: string;
55
+ }): Promise<T>;
56
+ /** One `doctor` line per SDK the project installs: both versions and which one commands run. */
57
+ export declare function sdkSourceLines({ cwd }?: {
58
+ cwd?: string;
59
+ }): Promise<string[]>;
60
+ /** `--sdk bundled|project` from any command, stripped before routing like `--break-glass`. */
61
+ export declare function takeSdkFlag(argv: string[]): {
62
+ argv: string[];
63
+ sdk?: SdkMode | Error;
64
+ };
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Which copy of an SDK (ORM, Lattice, artifact-studio, pipeline-spec) a command runs: the one bundled with this CLI,
3
+ * or the one the project's lockfile installed.
4
+ *
5
+ * The bundled copy stays the default. A project opts in to its own with `sdk: project` in `.seq/github.yml`,
6
+ * `SEQ_STUDIO_SDK=project`, or `--sdk project` on any command. Until then a version difference is only reported:
7
+ * `doctor` lists both, and a command that loads a differing SDK prints one `note:`. A project copy that cannot be
8
+ * loaded falls back to the bundled one with a warning, so opting in never stops a command.
9
+ */
10
+ import { existsSync, readFileSync } from 'node:fs';
11
+ import { dirname, join, parse as parsePath, resolve } from 'node:path';
12
+ import { fileURLToPath, pathToFileURL } from 'node:url';
13
+ export const SDK_ENV = 'SEQ_STUDIO_SDK';
14
+ export const SDK_PACKAGES = [
15
+ '@sequenceholdings/orm', '@sequenceholdings/lattice', '@sequenceholdings/artifact-studio', '@sequenceholdings/pipeline-spec',
16
+ ];
17
+ function readPackage(directory) {
18
+ try {
19
+ const parsed = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8'));
20
+ return typeof parsed === 'object' && parsed !== null ? { ...parsed } : undefined;
21
+ }
22
+ catch {
23
+ return undefined;
24
+ }
25
+ }
26
+ const versionOf = (manifest) => (typeof manifest?.version === 'string' ? manifest.version : undefined);
27
+ /** The package the project at `cwd` installed: the nearest `node_modules/<name>` at or above it. */
28
+ export function projectSdk({ name, cwd = process.cwd() }) {
29
+ let directory = resolve(cwd);
30
+ const { root } = parsePath(directory);
31
+ for (;;) {
32
+ const candidate = join(directory, 'node_modules', name);
33
+ if (existsSync(join(candidate, 'package.json')))
34
+ return { version: versionOf(readPackage(candidate)), directory: candidate };
35
+ if (directory === root)
36
+ return undefined;
37
+ directory = dirname(directory);
38
+ }
39
+ }
40
+ /** The copy bundled with this CLI, resolved as an import is (an ESM-only package exports no `require` entry). */
41
+ export function bundledSdk({ name }) {
42
+ try {
43
+ let directory = dirname(fileURLToPath(import.meta.resolve(name)));
44
+ const { root } = parsePath(directory);
45
+ for (;;) {
46
+ const manifest = readPackage(directory);
47
+ if (manifest?.name === name)
48
+ return { version: versionOf(manifest), directory };
49
+ if (directory === root)
50
+ return undefined;
51
+ directory = dirname(directory);
52
+ }
53
+ }
54
+ catch {
55
+ return undefined;
56
+ }
57
+ }
58
+ /** The ESM file a package's `exports` map gives a subpath (`.` or `./cli`), or undefined. */
59
+ export function exportedFile({ directory, subpath }) {
60
+ const exports = readPackage(directory)?.exports;
61
+ const entry = typeof exports === 'string' && subpath === '.' ? exports
62
+ : typeof exports === 'object' && exports !== null ? Reflect.get(exports, subpath) : undefined;
63
+ const pick = (value) => {
64
+ if (typeof value === 'string')
65
+ return value;
66
+ if (typeof value !== 'object' || value === null)
67
+ return undefined;
68
+ for (const condition of ['import', 'node', 'default']) {
69
+ const found = pick(Reflect.get(value, condition));
70
+ if (found)
71
+ return found;
72
+ }
73
+ return undefined;
74
+ };
75
+ const file = pick(entry);
76
+ return file ? join(directory, file) : undefined;
77
+ }
78
+ /** `--sdk`, then `SEQ_STUDIO_SDK`, then `.seq/github.yml`'s `sdk:`; bundled otherwise. */
79
+ export async function sdkMode({ cwd = process.cwd() } = {}) {
80
+ const fromEnv = process.env[SDK_ENV]?.trim();
81
+ if (fromEnv === 'project' || fromEnv === 'bundled')
82
+ return fromEnv;
83
+ const { repositorySettings } = await import('./orgs.js');
84
+ return (await repositorySettings(cwd).catch(() => undefined))?.sdk === 'project' ? 'project' : 'bundled';
85
+ }
86
+ export function compareSdk({ name, cwd }) {
87
+ const bundled = bundledSdk({ name })?.version;
88
+ const project = projectSdk({ name, cwd })?.version;
89
+ return { name, bundled, project, differs: Boolean(bundled && project && bundled !== project) };
90
+ }
91
+ const noted = new Set();
92
+ /** The copy of each SDK this command loaded: its version, and the project's directory when it was the project's. */
93
+ const selected = new Map();
94
+ /** The version of `name` this command loaded through importSdk, or undefined before it has. */
95
+ export function selectedSdkVersion(name) {
96
+ return selected.get(name)?.version;
97
+ }
98
+ /**
99
+ * The file `<name><subpath>` resolves to in the copy this command loaded, so a module imported indirectly (an ORM
100
+ * schema importing `@sequenceholdings/orm/authoring`) matches it. Undefined when that copy does not export it.
101
+ */
102
+ export function selectedSdkFile({ name, subpath }) {
103
+ const projectDirectory = selected.get(name)?.projectDirectory;
104
+ if (projectDirectory)
105
+ return exportedFile({ directory: projectDirectory, subpath });
106
+ try {
107
+ return fileURLToPath(import.meta.resolve(`${name}${subpath.slice(1)}`));
108
+ }
109
+ catch {
110
+ return undefined;
111
+ }
112
+ }
113
+ /** The API of the bundled copy that the project's copy lacks. */
114
+ function missingExports({ loaded, bundled }) {
115
+ if (typeof bundled !== 'object' || bundled === null || typeof loaded !== 'object' || loaded === null)
116
+ return [];
117
+ return Object.keys(bundled).filter((key) => !(key in loaded));
118
+ }
119
+ /** The project's copy at `file`, or the bundled one with a warning when it cannot load or lacks what the CLI calls. */
120
+ async function projectCopy({ name, file, directory, bundled, comparison }) {
121
+ const fallbackTo = comparison.bundled ?? 'copy';
122
+ let loaded;
123
+ try {
124
+ loaded = await import(pathToFileURL(file).href);
125
+ }
126
+ catch (error) {
127
+ note(name, `warning: could not load this project's ${name} (${error instanceof Error ? error.message.split('\n')[0] : String(error)}); using the bundled ${fallbackTo}`);
128
+ return bundled();
129
+ }
130
+ let fallback;
131
+ try {
132
+ fallback = await bundled();
133
+ }
134
+ catch {
135
+ // ORM and pipeline-spec are optional peers of a global CLI: with no bundled copy to compare against or fall
136
+ // back to, the project's copy that loaded is the one to run.
137
+ selected.set(name, { version: comparison.project, projectDirectory: directory });
138
+ // The project's copy of the same package, which loaded.
139
+ return loaded;
140
+ }
141
+ const missing = missingExports({ loaded, bundled: fallback });
142
+ if (missing.length) {
143
+ note(name, `warning: this project's ${name} ${comparison.project ?? ''} lacks ${missing.slice(0, 3).join(', ')}${missing.length > 3 ? ', …' : ''}, ` +
144
+ `which seq-studio uses; using the bundled ${fallbackTo}. Upgrade the project's ${name} to run it.`);
145
+ return fallback;
146
+ }
147
+ if (comparison.differs)
148
+ note(name, `note: using this project's ${name} ${comparison.project} (sdk: project), not the bundled ${comparison.bundled}`);
149
+ selected.set(name, { version: comparison.project, projectDirectory: directory });
150
+ // Same exports as the bundled copy, checked above: the project's copy of the same package.
151
+ return loaded;
152
+ }
153
+ /**
154
+ * Import `<name><subpath>` from the copy this command runs. `bundled` is the CLI's own static import, so the bundler
155
+ * keeps it. Prints a note once when the project's copy is a different version than the one used.
156
+ */
157
+ export async function importSdk({ name, subpath = '.', bundled, cwd }) {
158
+ const comparison = compareSdk({ name, cwd });
159
+ const mode = await sdkMode({ cwd });
160
+ const project = mode === 'project' ? projectSdk({ name, cwd }) : undefined;
161
+ const file = project ? exportedFile({ directory: project.directory, subpath }) : undefined;
162
+ // Every path below and every fallback in projectCopy loads the bundled copy; projectCopy overrides on success.
163
+ selected.set(name, { version: comparison.bundled });
164
+ if (file && project)
165
+ return projectCopy({ name, file, directory: project.directory, bundled, comparison });
166
+ if (mode === 'project' && !project)
167
+ note(name, `note: sdk: project, but this project does not install ${name}; using the bundled ${comparison.bundled ?? 'copy'}`);
168
+ else if (comparison.differs) {
169
+ note(name, `note: this project installs ${name} ${comparison.project}; seq-studio runs its bundled ${comparison.bundled}. ` +
170
+ 'Set sdk: project in .seq/github.yml (or --sdk project) to run the project\'s.');
171
+ }
172
+ return bundled();
173
+ }
174
+ function note(name, message) {
175
+ if (noted.has(`${name}\n${message}`))
176
+ return;
177
+ noted.add(`${name}\n${message}`);
178
+ console.error(message);
179
+ }
180
+ /** One `doctor` line per SDK the project installs: both versions and which one commands run. */
181
+ export async function sdkSourceLines({ cwd } = {}) {
182
+ const mode = await sdkMode({ cwd });
183
+ return SDK_PACKAGES.map((name) => compareSdk({ name, cwd }))
184
+ .filter((entry) => entry.project !== undefined)
185
+ .map((entry) => `sdk source: ${entry.name} bundled ${entry.bundled ?? 'none'}, project ${entry.project}; runs ${mode === 'project' ? 'project' : 'bundled'}${entry.differs && mode === 'bundled' ? ' (differs; sdk: project in .seq/github.yml runs the project\'s)' : ''}`);
186
+ }
187
+ /** `--sdk bundled|project` from any command, stripped before routing like `--break-glass`. */
188
+ export function takeSdkFlag(argv) {
189
+ const index = argv.findIndex((arg) => arg === '--sdk' || arg.startsWith('--sdk='));
190
+ if (index < 0)
191
+ return { argv };
192
+ const arg = argv[index];
193
+ const inline = arg.startsWith('--sdk=') ? arg.slice('--sdk='.length) : undefined;
194
+ const value = inline ?? argv[index + 1];
195
+ const rest = [...argv.slice(0, index), ...argv.slice(index + (inline === undefined && value !== undefined ? 2 : 1))];
196
+ if (value !== 'bundled' && value !== 'project')
197
+ return { argv: rest, sdk: new Error('--sdk must be bundled or project') };
198
+ return { argv: rest, sdk: value };
199
+ }
@@ -22,5 +22,5 @@ export declare function secretsSetDefaultCommand(args: ParsedArgs): Promise<numb
22
22
  * UI: pin + redeploy the function's active version / pin only / cancel.
23
23
  */
24
24
  export declare function secretsPinCommand(args: ParsedArgs): Promise<number>;
25
- export declare const SECRETS_USAGE = "usage:\n seq-studio secrets create <NAME> -e <env> [--type key-value|single] [--org <slug>] [--description text]\n register an org-owned secret\n seq-studio secrets set <NAME> -e <env> [--org <slug>] [--from-file <path>|--from-json <path>] [--merge]\n set the shared default value (write-only)\n seq-studio secrets list -e <env> secrets you can see (never values)\n seq-studio secrets attach <NAME> --fn <slug> -e <env> [--org <slug>] [--map KEY=ENV,KEY=ENV]\n mount default on a function env var\n seq-studio secrets detach <NAME> --fn <slug> -e <env> [--org <slug>]\n remove attachment\n seq-studio secrets attach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>] [--entry KEY | --fields field=KEY,field=KEY]\n attach to a pipeline stage's credential for one deploy target\n seq-studio secrets detach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>]\n remove it (the stage's copy is deleted now)\n seq-studio secrets apply --from-env-file .env -e <env> push defaults + attach (keys default from manifest)\n seq-studio secrets versions <NAME> -e <env> [--org <slug>] value version history (never values)\n seq-studio secrets set-default <NAME> [version] -e <env> [--org <slug>]\n point the default at a prior version (editor)\n seq-studio secrets pin <NAME> --fn <slug> [version] -e <env> [--org <slug>]\n pin one function to a version (sticky; --unpin clears)\n\n Note: for the common deploy loop, secrets declared in managed-function.yml are\n reconciled automatically by `seq-studio functions deploy` using a local .env.\n Explicit function attachments require the same secret source and mapping in the active manifest.\n Use `secrets` commands for CI (no .env), bulk/multi-function ops, or write-only\n value changes without a redeploy.\n\n Pipelines: managed secrets are the preferred way to give a stage a credential.\n Declare source.credential in the stage spec and read it in code with\n pipeline_runtime.get_credential(\"<name>\"). `seq-studio pipeline plan|deploy`\n attaches the secret named by convention (abrigo_oauth -> ABRIGO_OAUTH) when\n you can edit it (stages already deployed the legacy way are left alone); use\n `secrets attach --stage` for any other name.\n\n Flags: -e/--env <env> (required; see: seq-studio envs list)\n --org <slug> (target/select managed-scope org; required when a name exists in multiple orgs)\n set: --from-file <path> for single values; --from-json <path> for key/value sets; --merge changes only listed entries (null removes one)\n --fn <slug> \u00B7 --env-var <NAME> \u00B7 --yes\n --stage <slug> \u00B7 --target <id> (deploy target; default from -e) \u00B7 --credential <name> \u00B7 --entry <KEY> or --fields field=KEY,field=KEY (key/value sets)\n (the spec's source.credential; default: NAME lowercased) \u00B7 --repo <ns>/<name> (disambiguate)\n --functions <f1,f2> \u00B7 --keys <K1,K2> \u00B7 --all (override key selection)\n set-default: [version|version-row-id] (defaults to the most recent non-default) \u00B7 --yes\n pin: [version|version-row-id] (defaults to the current default) \u00B7 --unpin \u00B7 --yes (redeploy) \u00B7 --yes --no-redeploy\n";
25
+ export declare const SECRETS_USAGE = "usage:\n seq-studio secret create <NAME> -e <env> [--type key-value|single] [--org <slug>] [--description text]\n register an org-owned secret\n seq-studio secret set <NAME> -e <env> [--org <slug>] [--from-file <path>|--from-json <path>] [--merge]\n set the shared default value (write-only)\n seq-studio secret list -e <env> secrets you can see (never values)\n seq-studio secret attach <NAME> --fn <slug> -e <env> [--org <slug>] [--map KEY=ENV,KEY=ENV]\n mount default on a function env var\n seq-studio secret detach <NAME> --fn <slug> -e <env> [--org <slug>]\n remove attachment\n seq-studio secret attach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>] [--entry KEY | --fields field=KEY,field=KEY]\n attach to a pipeline stage's credential for one deploy target\n seq-studio secret detach <NAME> --stage <slug> -e <env> [--target <id>] [--credential <name>]\n remove it (the stage's copy is deleted now)\n seq-studio secret apply --from-env-file .env -e <env> push defaults + attach (keys default from manifest)\n seq-studio secret versions <NAME> -e <env> [--org <slug>] value version history (never values)\n seq-studio secret set-default <NAME> [version] -e <env> [--org <slug>]\n point the default at a prior version (editor)\n seq-studio secret pin <NAME> --fn <slug> [version] -e <env> [--org <slug>]\n pin one function to a version (sticky; --unpin clears)\n\n Note: for the common deploy loop, secrets declared in managed-function.yml are\n reconciled automatically by `seq-studio function deploy` using a local .env.\n Explicit function attachments require the same secret source and mapping in the active manifest.\n Use `secrets` commands for CI (no .env), bulk/multi-function ops, or write-only\n value changes without a redeploy.\n\n Pipelines: managed secrets are the preferred way to give a stage a credential.\n Declare source.credential in the stage spec and read it in code with\n pipeline_runtime.get_credential(\"<name>\"). `seq-studio pipeline plan|deploy`\n attaches the secret named by convention (abrigo_oauth -> ABRIGO_OAUTH) when\n you can edit it (stages already deployed the legacy way are left alone); use\n `secrets attach --stage` for any other name.\n\n Flags: -e/--env <env> (required; see: seq-studio envs list)\n --org <slug> (target/select managed-scope org; required when a name exists in multiple orgs)\n set: --from-file <path> for single values; --from-json <path> for key/value sets; --merge changes only listed entries (null removes one)\n --fn <slug> \u00B7 --env-var <NAME> \u00B7 --yes\n --stage <slug> \u00B7 --target <id> (deploy target; default from -e) \u00B7 --credential <name> \u00B7 --entry <KEY> or --fields field=KEY,field=KEY (key/value sets)\n (the spec's source.credential; default: NAME lowercased) \u00B7 --repo <ns>/<name> (disambiguate)\n --functions <f1,f2> \u00B7 --keys <K1,K2> \u00B7 --all (override key selection)\n set-default: [version|version-row-id] (defaults to the most recent non-default) \u00B7 --yes\n pin: [version|version-row-id] (defaults to the current default) \u00B7 --unpin \u00B7 --yes (redeploy) \u00B7 --yes --no-redeploy\n";
26
26
  export declare function runSecretsCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;