@sequenceholdings/studio-cli 0.9.22 → 0.9.24

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 (133) hide show
  1. package/README.md +152 -144
  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/artifact/delegate.d.ts +1 -1
  23. package/dist/artifact/delegate.js +43 -3
  24. package/dist/auth-cmds/commands.js +1 -2
  25. package/dist/bin.js +12 -2
  26. package/dist/cli-attribution.d.ts +4 -0
  27. package/dist/cli-attribution.js +25 -3
  28. package/dist/cli-errors.d.ts +9 -1
  29. package/dist/cli-errors.js +20 -9
  30. package/dist/command-contract.d.ts +7 -182
  31. package/dist/command-contract.js +9 -33
  32. package/dist/command-help.d.ts +4 -4
  33. package/dist/command-help.js +24 -24
  34. package/dist/command-telemetry.js +2 -2
  35. package/dist/config-dir.d.ts +8 -0
  36. package/dist/config-dir.js +35 -0
  37. package/dist/config.d.ts +6 -0
  38. package/dist/config.js +15 -3
  39. package/dist/docs/commands.js +9 -4
  40. package/dist/env-registry.d.ts +4 -0
  41. package/dist/env-registry.js +15 -6
  42. package/dist/envs/commands.d.ts +3 -0
  43. package/dist/envs/commands.js +11 -0
  44. package/dist/exit-codes.d.ts +16 -0
  45. package/dist/exit-codes.js +27 -0
  46. package/dist/functions/bundle.d.ts +1 -1
  47. package/dist/functions/commands.js +19 -18
  48. package/dist/functions/manifest.js +1 -1
  49. package/dist/functions/service-account-guidance.d.ts +1 -1
  50. package/dist/functions/service-account-guidance.js +2 -2
  51. package/dist/lifecycle/check.d.ts +13 -0
  52. package/dist/lifecycle/check.js +116 -0
  53. package/dist/lifecycle/commands.d.ts +14 -0
  54. package/dist/lifecycle/commands.js +121 -0
  55. package/dist/lifecycle/plan.d.ts +28 -0
  56. package/dist/lifecycle/plan.js +113 -0
  57. package/dist/lifecycle/rollback.d.ts +7 -0
  58. package/dist/lifecycle/rollback.js +89 -0
  59. package/dist/lifecycle/seq-ci-tools.d.ts +107 -0
  60. package/dist/lifecycle/seq-ci-tools.js +177 -0
  61. package/dist/lifecycle/upgrade.d.ts +3 -0
  62. package/dist/lifecycle/upgrade.js +38 -0
  63. package/dist/machine-output.d.ts +11 -2
  64. package/dist/machine-output.js +32 -10
  65. package/dist/main.d.ts +16 -6
  66. package/dist/main.js +187 -361
  67. package/dist/orgs.d.ts +45 -0
  68. package/dist/orgs.js +106 -0
  69. package/dist/orm/delegate.d.ts +1 -1
  70. package/dist/orm/delegate.js +32 -18
  71. package/dist/orm/deployment-policy.js +1 -2
  72. package/dist/orm/discover.js +6 -8
  73. package/dist/orm/execute.d.ts +1 -1
  74. package/dist/orm/execute.js +5 -6
  75. package/dist/orm/failures.js +2 -2
  76. package/dist/orm/help.d.ts +1 -1
  77. package/dist/orm/help.js +5 -5
  78. package/dist/orm/history.js +1 -2
  79. package/dist/orm/operation-show.js +1 -2
  80. package/dist/orm/version-guard.d.ts +7 -2
  81. package/dist/orm/version-guard.js +12 -7
  82. package/dist/pipeline/codegen.js +2 -2
  83. package/dist/pipeline/commands.js +9 -7
  84. package/dist/pipeline/discovery.d.ts +1 -1
  85. package/dist/pipeline/discovery.js +2 -3
  86. package/dist/pipeline/help.d.ts +1 -1
  87. package/dist/pipeline/help.js +1 -1
  88. package/dist/pipeline/lifecycle.js +1 -1
  89. package/dist/pipeline/stage-secrets.js +4 -4
  90. package/dist/pipeline/templates.js +2 -2
  91. package/dist/pnpm-auto-update.js +3 -3
  92. package/dist/preview.d.ts +1 -1
  93. package/dist/preview.js +1 -1
  94. package/dist/principals/commands.d.ts +1 -1
  95. package/dist/principals/commands.js +13 -14
  96. package/dist/process/commands.js +4 -1
  97. package/dist/process/run-steps.d.ts +2 -2
  98. package/dist/process/runs.js +1 -2
  99. package/dist/registry/commands.d.ts +4 -0
  100. package/dist/registry/commands.js +281 -0
  101. package/dist/registry/help.d.ts +8 -0
  102. package/dist/registry/help.js +64 -0
  103. package/dist/registry/lifecycle-commands.d.ts +3 -0
  104. package/dist/registry/lifecycle-commands.js +60 -0
  105. package/dist/registry/lookup.d.ts +6 -0
  106. package/dist/registry/lookup.js +18 -0
  107. package/dist/registry/runners.d.ts +14 -0
  108. package/dist/registry/runners.js +206 -0
  109. package/dist/registry/spec.d.ts +45 -0
  110. package/dist/registry/spec.js +8 -0
  111. package/dist/repos/commands.js +1 -2
  112. package/dist/repos/github-connect-command.d.ts +10 -1
  113. package/dist/repos/github-connect-command.js +52 -11
  114. package/dist/repos/github-init.d.ts +9 -2
  115. package/dist/repos/github-init.js +18 -2
  116. package/dist/repos/init-repo.js +1 -2
  117. package/dist/run-pinned.d.ts +48 -0
  118. package/dist/run-pinned.js +127 -0
  119. package/dist/sdk-source.d.ts +64 -0
  120. package/dist/sdk-source.js +199 -0
  121. package/dist/secrets/commands.d.ts +1 -1
  122. package/dist/secrets/commands.js +29 -24
  123. package/dist/service-accounts/commands.d.ts +1 -1
  124. package/dist/service-accounts/commands.js +4 -5
  125. package/dist/staged-env.d.ts +14 -0
  126. package/dist/staged-env.js +73 -0
  127. package/dist/storage/commands.js +21 -22
  128. package/dist/templates/catalog.d.ts +4 -4
  129. package/dist/update-check.js +3 -3
  130. package/dist/version-support.d.ts +39 -0
  131. package/dist/version-support.js +71 -0
  132. package/package.json +11 -10
  133. package/release-summary.json +3 -1
package/dist/main.js CHANGED
@@ -7,150 +7,58 @@
7
7
  * seq-studio deploy deploy all primitives from sequence.app.yml
8
8
  * seq-studio process <sub> manage Lattice processes
9
9
  * seq-studio artifact <sub> manage Artifact Studio apps
10
- * seq-studio functions <sub> manage Managed Functions
11
- * seq-studio agents <sub> manage typed agent definitions
12
- * seq-studio secrets <sub> manage org-owned Managed Secrets
10
+ * seq-studio function <sub> manage Managed Functions
11
+ * seq-studio agent <sub> manage typed agent definitions
12
+ * seq-studio secret <sub> manage org-owned Managed Secrets
13
13
  * seq-studio repos <sub> manage platform git-service repos
14
14
  * seq-studio templates <sub> publish and synchronize Git-backed templates
15
15
  * seq-studio pipeline <sub> discover, query, author and operate Data Pipelines
16
16
  * seq-studio auth <sub> manage Git authentication
17
17
  * seq-studio docs <sub> search and read the environment's developer docs
18
18
  * seq-studio feedback submit submit agent feedback
19
- * seq-studio service-accounts <sub> provision runtime identities
19
+ * seq-studio service-account <sub> provision runtime identities
20
20
  * seq-studio access <sub> manage resource access on every primitive
21
- * seq-studio principals <sub> find users, groups and service accounts to grant
21
+ * seq-studio principal <sub> find users, groups and service accounts to grant
22
22
  * seq-studio envs <sub> add/list environments
23
23
  * seq-studio login authenticate interactively with Auth0
24
24
  * seq-studio logout remove cached user tokens
25
25
  * seq-studio doctor check token + env + writer gate
26
26
  * seq-studio help show usage
27
27
  */
28
- import { parseArgs } from './argv.js';
29
- import { renderCapabilities } from './command-contract.js';
28
+ import { SDK_ENV, takeSdkFlag } from './sdk-source.js';
30
29
  import { staticHelp } from './command-help.js';
31
30
  import { ignoredSandboxEnvNotice } from './env-flags.js';
32
31
  import { guardMachineOutput, requestsMachineOutput } from './machine-output.js';
32
+ import { findCommand, findSubcommand, knowsSubcommand } from './registry/commands.js';
33
+ import { renderTopLevelHelp, suggest, topLevelNames } from './registry/help.js';
34
+ import { ExitCode } from './exit-codes.js';
35
+ import { hasHelpFlag } from './registry/runners.js';
33
36
  import { sandboxUsageFooter } from './sandbox-auth.js';
34
- // Lazy-load artifact delegate: published @sequenceholdings/artifact-studio/cli
35
- // still auto-runs runCli() at module load; importing it here breaks doctor/process.
36
- const TOP_LEVEL_USAGE = `usage:
37
- seq-studio init <dir> [options] scaffold an app or use a published template
38
- seq-studio add <kind> <name> [internal] add a primitive to the current app monorepo
39
- seq-studio validate [--dir <path>] validate an app manifest offline
40
- seq-studio deploy -e <env> [internal] deploy primitives from sequence.app.yml
41
- seq-studio process <sub> [args] lint | plan | apply | runs | test | simulate | bundle | init
42
- seq-studio artifact <sub> [args] init | whoami | link | env | status | list | show | validate | build | plan | deploy | dev | promote | pull | rollback
43
- seq-studio functions <sub> [args] init | build | deploy | list | show | limits | invoke | logs | promote | rollback | delete
44
- seq-studio storage <sub> [args] init | validate | apply | list | show | mkdir | upload | download | access | trash | restore | purge | operations | abort | delete
45
- seq-studio agents <sub> [args] init | validate | bundle | plan | apply | list | show | voice (internal)
46
- seq-studio secrets <sub> [args] create | set | list | attach | detach | apply
47
- seq-studio repo init [--check] set up a GitHub checkout: workflows, Renovate, agent skill, branch rules
48
- seq-studio repos <sub> [args] list | namespaces | show | identity | create | clone | pull | pulls | delete | ci
49
- seq-studio templates <sub> [args] publish | sync | list
50
- seq-studio pipeline <sub> [args] list | assets | search | describe | schema | sample | query | init | validate | repin-orm | codegen | plan | adopt | unbind | retire | deploy | status | migrate | promote | rollback | run-now
51
- seq-studio auth <sub> [args] whoami | git-credential
52
- seq-studio docs <sub> -e <env> search <query> | read <slug> | list (read before guessing commands)
53
- seq-studio feedback submit --file report.json [-e <env>] [--json]
54
- seq-studio orm <sub> [args] init | generate | validate | plan | apply | deployment-policy | execute | read | sql | diff | migrate-from-yaml | import
55
- seq-studio service-accounts <sub> list | show | create (requires provisioning authority)
56
- seq-studio access <sub> definitions | list | grant | revoke | resolve
57
- seq-studio principals <sub> search | users search | groups list/show/create/members
58
- seq-studio envs <sub> add | list environments
59
- seq-studio login [--env <name>] authenticate in the browser
60
- seq-studio logout [--env <name>] remove one realm's cached user tokens
61
- seq-studio doctor [-e <env>] [--json] [--offline] diagnose config, auth, toolchain, and writer gate
62
- seq-studio telemetry enable|disable|status control authenticated command metrics
63
- seq-studio updater status | track latest|next control global pnpm auto-updates
64
- seq-studio version print the installed version
65
- seq-studio capabilities [--json] describe command availability and access
66
- seq-studio help show this message
67
-
68
- Authenticate with: seq-studio login
69
- init, orm init, functions init, artifact init, and agents init take
70
- --repo <ns>/<name> to scaffold straight into a git-service repo; commit and push from there.
71
- In an agent sandbox, SEQ_STUDIO_BASE_URL + SEQ_STUDIO_TOKEN_FILE select the
72
- deployment and token instead (no login; -e optional).
73
- Where supported, --json writes only JSON to stdout (status lines go to stderr);
74
- check exit status and pagination.
75
- Built-in env: local. Add your organization's deployment with
76
- \`seq-studio envs add <name> <url>\`; custom entries live in ~/.config/lattice/config.toml.
77
- If this CLI cannot complete a documented step, read that environment's docs
78
- before trying another tool. \`seq-studio envs list\` prints each environment URL.
79
- Docs: seq-studio docs search <query> -e <env>, or <url>/docs. Feedback guide: <url>/docs/raw/seq-studio/feedback.md.
80
- `;
81
- const PROCESS_USAGE = `usage:
82
- seq-studio process init <dir>
83
- seq-studio process lint [--dir <path>] [--offline]
84
- seq-studio process plan [--dir <path>] [-e <env>]
85
- seq-studio process apply [--dir <path>] [-e <env>] [--only <id1,id2,...>] [--platform-managed]
86
- seq-studio process apply --repo <namespace>/<name> [--ref <r>] -e <env> [--only <id1,id2,...>] [--platform-managed]
87
- seq-studio process promote <processId> --version <v> [-e <env>]
88
- seq-studio process pull <processId> [--version <v>] [-e <env>] [--out <dir>] [--no-children]
89
- seq-studio process runs start|retry|list|show|cancel [args] -e <env> (see process runs --help)
90
- seq-studio process test [-e <env>] [--offline]
91
- seq-studio process simulate <process-id>
92
- seq-studio process bundle build [-o file.json] [-e <env>] [--offline]
93
- seq-studio process bundle pull <hash> [-o file.json] [-e <env>]
94
- seq-studio process bundle archive <hash> [-e <env>]
95
- seq-studio process bundle inspect <bundle.json>
96
- seq-studio process bundle list [-e <env>] [--limit N] [--cursor <hash>]
97
- seq-studio process bundle publish <hash|bundle.json> [-e <env>]
98
- seq-studio process safety-baseline [--repo-root <dir>] [--write]
99
- `;
100
- // Validate command names before the offline help shortcut. Otherwise a typo such
101
- // as `repos creat --help` appears successful without ever reaching the router.
102
- const SUBCOMMANDS = {
103
- process: new Set(['init', 'lint', 'plan', 'apply', 'promote', 'pull', 'runs', 'test', 'simulate', 'bundle', 'safety-baseline']),
104
- artifact: new Set(['init', 'whoami', 'link', 'env', 'status', 'list', 'show', 'validate', 'build', 'plan', 'deploy', 'dev', 'promote', 'pull', 'rollback', 'login', 'logout']),
105
- functions: new Set(['init', 'dev', 'build', 'register', 'deploy', 'list', 'show', 'limits', 'invoke', 'logs', 'promote', 'rollback', 'delete']),
106
- storage: new Set(['init', 'validate', 'apply', 'list', 'show', 'mkdir', 'upload', 'import', 'uploads', 'reconcile', 'download', 'access', 'trash', 'restore', 'purge', 'operations', 'abort', 'delete']),
107
- agents: new Set(['init', 'validate', 'bundle', 'plan', 'apply', 'list', 'show', 'voice']),
108
- secrets: new Set(['create', 'set', 'list', 'attach', 'detach', 'apply', 'versions', 'set-default', 'pin']),
109
- repos: new Set(['list', 'namespaces', 'show', 'identity', 'create', 'clone', 'attach-login', 'pull', 'pulls', 'delete', 'ci']),
110
- templates: new Set(['publish', 'sync', 'list']),
111
- 'service-accounts': new Set(['list', 'show', 'create']),
112
- access: new Set(['definitions', 'resolve', 'list', 'grant', 'revoke', 'roles']),
113
- principals: new Set(['search', 'users', 'groups']),
114
- auth: new Set(['whoami', 'git-credential', 'pat']),
115
- feedback: new Set(['submit']),
116
- docs: new Set(['search', 'read', 'list']),
117
- orm: new Set(['init', 'generate', 'validate', 'plan', 'apply', 'history', 'deployment-policy', 'execute', 'namespaces', 'describe', 'read', 'sql', 'diff', 'migrate-from-yaml', 'import']),
118
- pipeline: new Set(['list', 'assets', 'search', 'describe', 'schema', 'sample', 'query', 'init', 'validate', 'repin-orm', 'codegen', 'adopt', 'unbind', 'retire', 'plan', 'deploy', 'status', 'migrate', 'promote', 'rollback', 'run-now']),
119
- envs: new Set(['add', 'list']),
120
- updater: new Set(['status', 'track']),
121
- };
122
- const TELEMETRY_EXCLUDED = new Set(['validate', 'telemetry', 'updater', 'version', 'capabilities', 'help', 'login', 'logout', 'envs']);
123
- const TELEMETRY_TOP_LEVEL = new Set(['init', 'add', 'deploy', 'doctor']);
124
- const TELEMETRY_NESTED = {
125
- 'repos pulls': new Set(['list', 'show', 'create', 'diff', 'merge', 'edit', 'close', 'comment', 'comments', 'resolve', 'unresolve', 'review', 'reviews', 'checks']),
126
- 'process runs': new Set(['start', 'retry', 'list', 'show', 'cancel']),
127
- 'process bundle': new Set(['build', 'pull', 'archive', 'inspect', 'list', 'publish']),
128
- };
129
- /** Only command words from the router; never operands, flags, paths, or arguments. */
37
+ /** Only command words from the router; never operands, flags, paths, or arguments. Always the current spelling. */
130
38
  export function commandTelemetryName(argv) {
131
39
  if (argv.some((arg) => arg === '--help' || arg === '-h'))
132
40
  return null;
133
41
  const [namespace, sub] = argv;
134
- if (!namespace || TELEMETRY_EXCLUDED.has(namespace))
42
+ const command = namespace ? findCommand(namespace) : undefined;
43
+ if (!command || command.telemetry === 'never' || command.aliases?.includes(namespace ?? ''))
135
44
  return null;
136
- if (namespace === 'doctor' && (argv.includes('--offline') || argv.includes('--offline=true')))
45
+ if (command.name === 'doctor' && (argv.includes('--offline') || argv.includes('--offline=true')))
137
46
  return null;
138
- if (namespace === 'auth' && sub === 'git-credential')
47
+ if (command.name === 'auth' && sub === 'git-credential')
139
48
  return null;
140
- if (TELEMETRY_TOP_LEVEL.has(namespace))
141
- return namespace;
142
- if (!sub || !SUBCOMMANDS[namespace]?.has(sub))
49
+ if (command.telemetry === 'command')
50
+ return command.name;
51
+ const subcommand = sub && command.checkSubcommands ? findSubcommand(command, sub) : undefined;
52
+ if (!subcommand)
143
53
  return null;
144
- const command = `${namespace} ${sub}`;
145
- const nested = TELEMETRY_NESTED[command];
146
- if (!nested)
147
- return command;
148
- return argv[2] && nested.has(argv[2]) ? `${command} ${argv[2]}` : null;
54
+ if (!subcommand.nested)
55
+ return `${command.name} ${subcommand.name}`;
56
+ return argv[2] && subcommand.nested.includes(argv[2]) ? `${command.name} ${subcommand.name} ${argv[2]}` : null;
149
57
  }
150
58
  export async function run(argv = process.argv.slice(2)) {
151
59
  if (!requestsMachineOutput(argv))
152
60
  return dispatch(argv);
153
- const restore = guardMachineOutput();
61
+ const restore = guardMachineOutput({ schema: schemaName(argv), argv });
154
62
  try {
155
63
  return await dispatch(argv);
156
64
  }
@@ -158,27 +66,49 @@ export async function run(argv = process.argv.slice(2)) {
158
66
  restore();
159
67
  }
160
68
  }
161
- async function dispatch(argv) {
162
- const [namespace, sub, ...rest] = argv;
163
- if (!namespace || namespace === 'help' || namespace === '--help' || namespace === '-h') {
164
- console.log(`${TOP_LEVEL_USAGE}${sandboxUsageFooter()}`);
165
- return namespace ? 0 : 1;
166
- }
167
- if (namespace === 'capabilities' && hasHelpFlag(sub, rest)) {
168
- console.log('usage: seq-studio capabilities [--json]');
169
- return 0;
170
- }
171
- if (namespace === 'artifact' && [sub, ...rest].some((arg) => arg === '--token' || arg?.startsWith('--token='))) {
172
- console.error('Artifact Studio does not accept --token bearer injection. Authenticate with seq-studio login.');
173
- return 1;
69
+ /**
70
+ * Flags any command takes, removed before routing and handed on through the environment: `--sdk` (read by
71
+ * sdk-source.ts wherever a command loads an SDK) and `--break-glass` (sent on every Atlas request, cli-attribution.ts).
72
+ */
73
+ function takeGlobalFlags(rawArgv) {
74
+ const { argv: withoutSdk, sdk } = takeSdkFlag(rawArgv);
75
+ if (sdk instanceof Error)
76
+ return sdk;
77
+ const { argv, breakGlass } = takeBreakGlass(withoutSdk);
78
+ if (breakGlass instanceof Error)
79
+ return breakGlass;
80
+ if (sdk !== undefined)
81
+ process.env[SDK_ENV] = sdk;
82
+ if (breakGlass !== undefined)
83
+ process.env.SEQ_STUDIO_BREAK_GLASS = breakGlass;
84
+ return argv;
85
+ }
86
+ async function dispatch(rawArgv) {
87
+ const argv = takeGlobalFlags(rawArgv);
88
+ if (argv instanceof Error) {
89
+ console.error(`error ${argv.message}`);
90
+ return ExitCode.Usage;
174
91
  }
175
- if (hasHelpFlag(sub, rest) && sub && !['help', '--help', '-h'].includes(sub) &&
176
- SUBCOMMANDS[namespace] && !SUBCOMMANDS[namespace].has(sub)) {
177
- console.error(`unknown ${namespace} command: ${sub}. See seq-studio ${namespace} --help.`);
92
+ const [namespace, sub, ...rest] = argv;
93
+ const early = answeredBeforeRouting({ namespace, sub, rest });
94
+ if (early !== null)
95
+ return early;
96
+ if (!namespace)
178
97
  return 1;
179
- }
98
+ const command = findCommand(namespace);
99
+ if (!command)
100
+ return unknownCommand(namespace);
101
+ // Reject an unknown subcommand before offline help or the command's router runs.
102
+ // Otherwise a typo such as `repos creat --help` appears successful.
103
+ if (sub && !sub.startsWith('-') && sub !== 'help' && knowsSubcommand(command, sub) === false) {
104
+ return unknownSubcommand(command, sub);
105
+ }
106
+ const subcommand = sub && command.checkSubcommands ? findSubcommand(command, sub) : undefined;
107
+ noteRenamed({ command, namespace, subcommand, sub });
108
+ // Implementations still read their original words; the registry maps current spellings to them.
109
+ const implementationSub = subcommand?.implementation ?? sub;
180
110
  if (hasHelpFlag(sub, rest)) {
181
- const help = staticHelp({ namespace, sub });
111
+ const help = staticHelp({ namespace: command.name, sub: implementationSub });
182
112
  if (help) {
183
113
  console.log(help);
184
114
  return 0;
@@ -187,241 +117,137 @@ async function dispatch(argv) {
187
117
  const ignoredEnv = ignoredSandboxEnvNotice([sub, ...rest].filter((a) => Boolean(a)));
188
118
  if (ignoredEnv)
189
119
  console.error(ignoredEnv);
190
- switch (namespace) {
191
- case 'init': {
192
- const { runAppInitCommand } = await import('./app/commands.js');
193
- return runAppInitCommand(parseArgs([sub, ...rest].filter((a) => Boolean(a))));
194
- }
195
- case 'add': {
196
- const { runAppAddCommand } = await import('./app/commands.js');
197
- return runAppAddCommand({
198
- kindArg: sub,
199
- args: parseArgs(rest),
200
- });
201
- }
202
- case 'deploy': {
203
- const { runAppDeployCommand } = await import('./app/commands.js');
204
- return runAppDeployCommand(parseArgs([sub, ...rest].filter((a) => Boolean(a))));
205
- }
206
- case 'validate': {
207
- const { runAppValidateCommand } = await import('./app/commands.js');
208
- return runAppValidateCommand(parseArgs([sub, ...rest].filter((a) => Boolean(a))));
209
- }
210
- case 'process':
211
- return runProcessNamespace(sub, rest);
212
- case 'artifact': {
213
- const { runArtifactCommand } = await import('./artifact/delegate.js');
214
- if (sub === 'init')
215
- return (await import('./repos/primitive-declaration.js')).runStandaloneInit({ kind: 'artifact', argv: rest, defaultDir: '.', run: () => runArtifactCommand(sub, rest) });
216
- return runArtifactCommand(sub, rest);
217
- }
218
- case 'functions': {
219
- const { runFunctionsCommand } = await import('./functions/commands.js');
220
- if (sub === 'init')
221
- return (await import('./repos/primitive-declaration.js')).runStandaloneInit({ kind: 'function', argv: rest, run: () => runFunctionsCommand(sub, parseArgs(rest)) });
222
- return runFunctionsCommand(sub, parseArgs(rest));
223
- }
224
- case 'storage': {
225
- const { runStorageCommand } = await import('./storage/commands.js');
226
- return runStorageCommand(sub, parseArgs(rest));
227
- }
228
- case 'agents': {
229
- const { runAgentsCommand } = await import('./agents/commands.js');
230
- return runAgentsCommand(sub, parseArgs(rest));
231
- }
232
- case 'secrets': {
233
- const { runSecretsCommand } = await import('./secrets/commands.js');
234
- return runSecretsCommand(sub, parseArgs(rest));
235
- }
236
- case 'repo': {
237
- if (sub === 'connect' || sub === 'disconnect' || sub === 'status' || sub === 'bind') {
238
- const { runRepoConnectCommand } = await import('./repos/github-connect-command.js');
239
- return runRepoConnectCommand(sub, parseArgs(rest));
240
- }
241
- if (sub !== 'init') {
242
- console.error('usage: seq-studio repo init|connect|bind|disconnect|status (see seq-studio repo <command> --help)');
243
- return 2;
244
- }
245
- const { runRepoInitCommand } = await import('./repos/github-init-command.js');
246
- return runRepoInitCommand(parseArgs(rest));
247
- }
248
- case 'repos': {
249
- const { runReposCommand } = await import('./repos/commands.js');
250
- return runReposCommand(sub, parseArgs(rest));
251
- }
252
- case 'templates': {
253
- const { runTemplatesCommand } = await import('./templates/commands.js');
254
- return runTemplatesCommand(sub, parseArgs(rest));
255
- }
256
- case 'service-accounts': {
257
- const { runServiceAccountsCommand } = await import('./service-accounts/commands.js');
258
- return runServiceAccountsCommand(sub, parseArgs(rest));
259
- }
260
- case 'access': {
261
- const { runAccessCommand } = await import('./access/commands.js');
262
- return runAccessCommand(sub, parseArgs(rest));
263
- }
264
- case 'principals': {
265
- const { runPrincipalsCommand } = await import('./principals/commands.js');
266
- return runPrincipalsCommand(sub, parseArgs(rest));
267
- }
268
- case 'feedback':
269
- return (await import('./feedback/commands.js')).runFeedbackCommand(sub, parseArgs(rest));
270
- case 'docs':
271
- return (await import('./docs/commands.js')).runDocsCommand(sub, parseArgs(rest));
272
- case 'auth': {
273
- const { runAuthCommand } = await import('./auth-cmds/commands.js');
274
- return runAuthCommand(sub, parseArgs(rest));
275
- }
276
- case 'orm': {
277
- const { runOrmCommand } = await import('./orm/delegate.js');
278
- if (sub === 'init')
279
- return (await import('./repos/primitive-declaration.js')).runStandaloneInit({ kind: 'orm', argv: rest, run: () => runOrmCommand(sub, rest) });
280
- return runOrmCommand(sub, rest);
281
- }
282
- case 'pipeline': {
283
- // Lazy import keeps doctor/process from pulling in @sequenceholdings/pipeline-spec
284
- // (an optional peer, same posture as @sequenceholdings/orm).
285
- const { runPipelineCommand } = await import('./pipeline/commands.js');
286
- return runPipelineCommand(sub, parseArgs(rest));
287
- }
288
- case 'envs': {
289
- const { runEnvsCommand } = await import('./envs/commands.js');
290
- return runEnvsCommand(sub, rest);
291
- }
292
- case 'login':
293
- case 'logout':
294
- return runSessionCommand({ args: [sub, ...rest].filter((a) => Boolean(a)), command: namespace });
295
- case 'version':
296
- case '--version':
297
- case '-v': {
298
- const { currentVersion } = await import('./update-check.js');
299
- console.log(currentVersion());
300
- return 0;
301
- }
302
- case 'updater':
303
- return (await import('./pnpm-auto-update.js')).updaterCommand([sub, ...rest].filter((arg) => Boolean(arg)));
304
- case 'capabilities':
305
- return runCapabilities([sub, ...rest].filter((value) => Boolean(value)));
306
- case 'doctor':
307
- return (await import('./process/commands.js')).doctorCommand(parseArgs([sub, ...rest].filter(Boolean)));
308
- case 'telemetry': {
309
- const { setTelemetryEnabled, telemetryEnabled } = await import('./command-telemetry.js');
310
- if (sub === '--help' || sub === '-h' || sub === 'help') {
311
- console.log('usage: seq-studio telemetry enable|disable|status');
312
- return 0;
313
- }
314
- if (rest.length > 0) {
315
- console.error('usage: seq-studio telemetry enable|disable|status');
316
- return 1;
317
- }
318
- if (sub === 'enable' || sub === 'disable')
319
- await setTelemetryEnabled(sub === 'enable');
320
- else if (sub !== 'status') {
321
- console.error('usage: seq-studio telemetry enable|disable|status');
322
- return 1;
323
- }
324
- console.log(`Command telemetry: ${await telemetryEnabled() ? 'on' : 'off'}`);
325
- return 0;
326
- }
327
- default:
328
- console.error(`unknown command: ${namespace}`);
329
- console.error(TOP_LEVEL_USAGE);
330
- return 1;
331
- }
120
+ const envError = await checkStagedEnv([sub, ...rest]);
121
+ if (envError !== null)
122
+ return envError;
123
+ if (!PIN_EXEMPT.has(command.name)) {
124
+ const pinnedExit = await honorPin({ argv, offline: command.access === 'offline' || argv.includes('--offline') });
125
+ if (pinnedExit !== null)
126
+ return pinnedExit;
127
+ }
128
+ return command.run({ sub: implementationSub, rest });
332
129
  }
333
- function runCapabilities(argv) {
334
- const args = parseArgs(argv);
335
- const unknown = Object.keys(args.flags).find((flag) => flag !== 'json');
336
- if (unknown || args.positional.length > 0 || (args.flags.json !== undefined && args.flags.json !== true)) {
337
- console.error('usage: seq-studio capabilities [--json]');
338
- return 1;
339
- }
340
- console.log(renderCapabilities({ json: args.flags.json === true }));
341
- return 0;
342
- }
343
- async function runSessionCommand({ args, command, }) {
344
- const usage = `usage: seq-studio ${command} [--env <name>]`;
345
- if (args[0] === 'help' || args[0] === '--help' || args[0] === '-h') {
346
- console.log(usage);
347
- return 0;
348
- }
349
- let envName;
350
- if (args.length > 0) {
351
- const flags = parseArgs(args).flags;
352
- envName =
353
- (typeof flags.env === 'string' ? flags.env : undefined) ??
354
- (typeof flags.e === 'string' ? flags.e : undefined);
355
- if (!envName) {
356
- console.error(usage);
357
- return 1;
358
- }
359
- }
360
- const auth = await import('./login.js');
361
- if (command === 'logout') {
362
- await auth.logout(envName);
363
- }
364
- else {
365
- // An OpCo env name (registered via `seq-studio envs add` or `seqapi env add`)
366
- // logs into that environment's Auth0 realm; omitted or a built-in name uses Sequence.
367
- await auth.login(envName);
368
- }
369
- return 0;
130
+ /** Run the repository's pinned CLI when opted in (run-pinned.ts); otherwise note a mismatch. Null: run it here. */
131
+ async function honorPin({ argv, offline }) {
132
+ const [{ pinNote }, { repositoryCliPin }, { runPinned, wantsPinnedRun }, { currentVersion }] = await Promise.all([
133
+ import('./version-support.js'), import('./orgs.js'), import('./run-pinned.js'), import('./update-check.js')
134
+ ]);
135
+ const pin = await repositoryCliPin();
136
+ if (wantsPinnedRun())
137
+ return runPinned({ pin, installed: currentVersion(), argv, offline });
138
+ const note = pinNote({ pin });
139
+ if (note)
140
+ console.error(note);
141
+ return null;
370
142
  }
371
- async function runProcessNamespace(sub, rest) {
372
- if (sub === 'runs') {
373
- const { processRunsCommand } = await import('./process/runs.js');
374
- return processRunsCommand(parseArgs(rest));
143
+ /** Top-level help and flag checks that never reach a command's router. */
144
+ function answeredBeforeRouting({ namespace, sub, rest }) {
145
+ if (!namespace || namespace === 'help' || namespace === '--help' || namespace === '-h') {
146
+ console.log(`${renderTopLevelHelp()}${sandboxUsageFooter()}`);
147
+ return namespace ? 0 : 1;
375
148
  }
376
- if (hasHelpFlag(sub, rest)) {
377
- console.log(PROCESS_USAGE);
149
+ if (namespace === 'capabilities' && hasHelpFlag(sub, rest)) {
150
+ console.log('usage: seq-studio capabilities [--json]');
378
151
  return 0;
379
152
  }
380
- if (!sub) {
381
- console.error(PROCESS_USAGE);
153
+ if (namespace === 'artifact' && [sub, ...rest].some((arg) => arg === '--token' || arg?.startsWith('--token='))) {
154
+ console.error('Artifact Studio does not accept --token bearer injection. Authenticate with seq-studio login.');
382
155
  return 1;
383
156
  }
384
- const processCommands = await import('./process/commands.js');
385
- const args = processCommands.parseArgs(sub === 'bundle' ? [sub, ...rest] : rest);
386
- switch (sub) {
387
- case 'init':
388
- return processCommands.initCommand(args);
389
- case 'lint':
390
- return processCommands.lintCommand(args);
391
- case 'plan':
392
- return processCommands.planCommand(args);
393
- case 'apply':
394
- return processCommands.applyCommand(args);
395
- case 'promote':
396
- return processCommands.promoteCommand(args);
397
- case 'pull':
398
- return processCommands.pullCommand(args);
399
- case 'test':
400
- return processCommands.testCommand(args);
401
- case 'simulate':
402
- return processCommands.simulateCommand(args);
403
- case 'bundle':
404
- // bundle command needs the subcommand (build/pull/inspect) in positional[0].
405
- // parseArgs already includes it because we threaded sub into args.
406
- return processCommands.bundleCommand({
407
- positional: args.positional.slice(1),
408
- flags: args.flags,
409
- });
410
- case 'safety-baseline': {
411
- const { safetyBaselineCommand } = await import('./process/safety-baseline.js');
412
- return safetyBaselineCommand({ flags: args.flags });
413
- }
414
- case 'help':
415
- case '--help':
416
- case '-h':
417
- console.log(PROCESS_USAGE);
418
- return 0;
419
- default:
420
- console.error(`unknown process command: ${sub}`);
421
- console.error(PROCESS_USAGE);
422
- return 1;
157
+ return null;
158
+ }
159
+ /** Commands that work the same on any version, or that move the pin itself. */
160
+ const PIN_EXEMPT = new Set(['help', 'version', 'capabilities', 'telemetry', 'updater', 'upgrade', 'login', 'logout']);
161
+ function noteRenamed({ command, namespace, subcommand, sub }) {
162
+ const nounRenamed = command.renamedFrom?.includes(namespace) ?? false;
163
+ const verbRenamed = subcommand !== undefined && sub !== undefined && sub !== subcommand.name;
164
+ if (!nounRenamed && !verbRenamed)
165
+ return;
166
+ // Only command words: a flag or operand in the second position is not part of the name.
167
+ const before = [namespace, subcommand ? sub : undefined].filter(Boolean).join(' ');
168
+ const after = [command.name, subcommand?.name].filter(Boolean).join(' ');
169
+ console.error(`note: seq-studio ${before} is now seq-studio ${after}`);
170
+ }
171
+ function unknownCommand(word) {
172
+ console.error(`error unknown command: ${word}`);
173
+ const match = suggest(word, topLevelNames());
174
+ if (match)
175
+ console.error(` did you mean: seq-studio ${match}`);
176
+ console.error(' see: seq-studio help');
177
+ return ExitCode.Usage;
178
+ }
179
+ function unknownSubcommand(command, sub) {
180
+ console.error(`error unknown ${command.name} command: ${sub}`);
181
+ // A typo of an old spelling (`describ`) suggests its current name (`show`).
182
+ const spellings = new Map(command.subcommands.filter(({ listed }) => listed !== false)
183
+ .flatMap(({ name, renamedFrom }) => [name, ...(renamedFrom ?? [])].map((word) => [word, name])));
184
+ const match = suggest(sub, [...spellings.keys()]);
185
+ if (match)
186
+ console.error(` did you mean: seq-studio ${command.name} ${spellings.get(match)}`);
187
+ console.error(` see: seq-studio ${command.name} --help`);
188
+ return ExitCode.Usage;
189
+ }
190
+ /** The command words that name a JSON document's schema, e.g. `repo status`. Always the current spelling. */
191
+ export function schemaName(argv) {
192
+ const [namespace, sub, third] = argv;
193
+ const command = namespace ? findCommand(namespace) : undefined;
194
+ if (!command)
195
+ return undefined;
196
+ const subcommand = sub ? findSubcommand(command, sub) : undefined;
197
+ if (!subcommand)
198
+ return command.name;
199
+ return third && subcommand.nested?.includes(third) ? `${command.name} ${subcommand.name} ${third}` : `${command.name} ${subcommand.name}`;
200
+ }
201
+ function requestedEnv(args) {
202
+ for (let index = 0; index < args.length; index++) {
203
+ const arg = args[index];
204
+ if (arg === '--')
205
+ return undefined;
206
+ if (arg === '-e' || arg === '--env')
207
+ return args[index + 1];
208
+ if (arg?.startsWith('--env='))
209
+ return arg.slice('--env='.length);
210
+ }
211
+ return undefined;
212
+ }
213
+ /**
214
+ * Resolve an `-e <org>/<stage>` or bare-stage value before the command runs, so
215
+ * its usage errors exit 2 the same way for every command, delegated ones included.
216
+ * Other values are left to the command, unchanged.
217
+ */
218
+ async function checkStagedEnv(args) {
219
+ const requested = requestedEnv(args);
220
+ if (!requested || !(requested.includes('/') || requested === 'staging' || requested === 'prod'))
221
+ return null;
222
+ if (requested.startsWith('preview:') || requested.startsWith('local:'))
223
+ return null;
224
+ const [{ resolveConfiguredEnv }, { UsageError }, { printCliError }] = await Promise.all([
225
+ import('./config.js'), import('./exit-codes.js'), import('./cli-errors.js'),
226
+ ]);
227
+ try {
228
+ await resolveConfiguredEnv({ requested });
229
+ return null;
230
+ }
231
+ catch (error) {
232
+ // Anything but a usage error is the command's to report, as before.
233
+ return error instanceof UsageError ? printCliError(error) : null;
423
234
  }
424
235
  }
425
- function hasHelpFlag(sub, rest) {
426
- return sub === 'help' || sub === '--help' || sub === '-h' || rest.some((arg) => arg === '--help' || arg === '-h');
236
+ /**
237
+ * `--break-glass "<reason>"` on any command: removed from argv so no command's own parser sees it. An empty or
238
+ * missing reason is a usage error.
239
+ */
240
+ export function takeBreakGlass(argv) {
241
+ const index = argv.findIndex((arg) => arg === '--break-glass' || arg.startsWith('--break-glass='));
242
+ if (index < 0)
243
+ return { argv };
244
+ const arg = argv[index];
245
+ const inline = arg.startsWith('--break-glass=') ? arg.slice('--break-glass='.length) : undefined;
246
+ const value = inline ?? argv[index + 1];
247
+ const consumed = inline === undefined && value !== undefined && !value.startsWith('-') ? 2 : 1;
248
+ const reason = consumed === 2 || inline !== undefined ? value?.trim() : undefined;
249
+ const rest = [...argv.slice(0, index), ...argv.slice(index + consumed)];
250
+ if (!reason)
251
+ return { argv: rest, breakGlass: new Error('--break-glass needs a reason: --break-glass "<why CI cannot deploy this>"') };
252
+ return { argv: rest, breakGlass: reason };
427
253
  }