@sequenceholdings/studio-cli 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +226 -7
  2. package/dist/agents/source.js +2 -1
  3. package/dist/app/adapters.js +2 -1
  4. package/dist/app/commands.js +4 -4
  5. package/dist/artifact/delegate.js +32 -12
  6. package/dist/atlas-client.d.ts +2 -1
  7. package/dist/atlas-client.js +7 -3
  8. package/dist/auth-cmds/commands.d.ts +1 -1
  9. package/dist/auth-cmds/commands.js +3 -0
  10. package/dist/auth.d.ts +2 -1
  11. package/dist/auth.js +16 -0
  12. package/dist/command-contract.d.ts +8 -8
  13. package/dist/command-contract.js +6 -6
  14. package/dist/command-help.d.ts +5 -4
  15. package/dist/command-help.js +41 -4
  16. package/dist/command-input.js +2 -2
  17. package/dist/config.d.ts +5 -0
  18. package/dist/config.js +14 -1
  19. package/dist/env-flags.d.ts +6 -0
  20. package/dist/env-flags.js +9 -0
  21. package/dist/functions/commands.d.ts +4 -1
  22. package/dist/functions/commands.js +63 -5
  23. package/dist/functions/deploy-preflight.js +2 -2
  24. package/dist/functions/manifest.d.ts +43 -29
  25. package/dist/functions/manifest.js +37 -74
  26. package/dist/main.js +42 -2
  27. package/dist/orm/delegate.js +25 -4
  28. package/dist/orm/read.d.ts +54 -0
  29. package/dist/orm/read.js +308 -0
  30. package/dist/pipeline/commands.js +30 -5
  31. package/dist/pipeline/discovery.js +3 -16
  32. package/dist/pipeline/lifecycle.js +37 -6
  33. package/dist/pipeline/retirement.d.ts +3 -0
  34. package/dist/pipeline/retirement.js +34 -0
  35. package/dist/pipeline/source.d.ts +21 -0
  36. package/dist/pipeline/source.js +76 -0
  37. package/dist/process/build.js +4 -0
  38. package/dist/process/codegen.js +2 -0
  39. package/dist/process/commands.js +57 -18
  40. package/dist/process/plan-diff.js +1 -0
  41. package/dist/process/runs.d.ts +14 -0
  42. package/dist/process/runs.js +238 -0
  43. package/dist/repos/ci-status.js +28 -0
  44. package/dist/repos/commands.js +11 -1
  45. package/dist/repos/git-credential.d.ts +3 -2
  46. package/dist/repos/git-credential.js +52 -3
  47. package/dist/repos/pulls.d.ts +7 -1
  48. package/dist/repos/pulls.js +162 -22
  49. package/dist/sandbox-auth.d.ts +52 -0
  50. package/dist/sandbox-auth.js +105 -0
  51. package/dist/storage/commands.js +6 -5
  52. package/dist/text-table.d.ts +7 -0
  53. package/dist/text-table.js +16 -0
  54. package/package.json +9 -9
package/README.md CHANGED
@@ -32,6 +32,8 @@ verifies and copies the selected release into a new or empty directory.
32
32
  > `agents validate`, offline `agents plan`, `pipeline init`, `pipeline validate`) work.
33
33
  > Repo and function command help is also available without an account; for
34
34
  > example, `seq-studio repos create --help` and `seq-studio functions invoke --help`.
35
+ > An unknown subcommand, including one followed by `--help`, exits nonzero and
36
+ > points to the namespace help; check command spelling before retrying.
35
37
  > Sequence-internal contributors: see `INTERNAL.md` in the monorepo for
36
38
  > rollout SOPs, preview environments, and publishing docs.
37
39
 
@@ -129,6 +131,40 @@ user-scoped/private resources.
129
131
  Artifact commands do not accept bearer tokens through argv or environment.
130
132
  Use interactive login or the realm-specific M2M secret above.
131
133
 
134
+ ### Sandbox token mode (agent sandboxes)
135
+
136
+ An agent sandbox provisioned by Atlas has no browser and can reach only its
137
+ Atlas origin. Atlas writes a short-lived token scoped to the calling user into
138
+ a file and exports two variables:
139
+
140
+ ```bash
141
+ export SEQ_STUDIO_BASE_URL=https://<your-atlas-origin>
142
+ export SEQ_STUDIO_TOKEN_FILE=/run/seq/token
143
+ seq-studio auth whoami # authMode: sandbox
144
+ seq-studio orm read lending loans --limit 5 --json
145
+ ```
146
+
147
+ With both set, every command targets `SEQ_STUDIO_BASE_URL` with the token from
148
+ `SEQ_STUDIO_TOKEN_FILE`. There is no login, token cache, or environment
149
+ registry lookup, and `-e` is optional (any value is ignored). The file is read
150
+ again for every request, so a token Atlas rotates mid-command is picked up.
151
+ Setting only one of the two variables is an error rather than a fallback to a
152
+ cached login. `seq-studio doctor` reports the mode.
153
+
154
+ Git uses the same token: `repos clone` installs the usual helper, and the helper
155
+ answers only for git-service repositories on `SEQ_STUDIO_BASE_URL`. To use plain
156
+ `git` against that host, configure the helper once:
157
+
158
+ ```bash
159
+ git config --global credential."$SEQ_STUDIO_BASE_URL".helper '!seq-studio auth git-credential'
160
+ git config --global credential."$SEQ_STUDIO_BASE_URL".useHttpPath true
161
+ ```
162
+
163
+ Repository sources for `--repo` builds are materialized through the JSON API,
164
+ like other headless callers; public `--git-url` sources are refused. Artifact
165
+ commands are not available in sandbox token mode: like `--token`, Artifact Studio
166
+ accepts only credentials the CLI obtained itself.
167
+
132
168
  ## Environments
133
169
 
134
170
  The CLI ships with a single built-in environment, `local`
@@ -786,6 +822,8 @@ compiled to canonical SQL before registration.
786
822
  | `seq-studio orm diff [dir] [--check]` | Author the next committed migration, or verify the migration/snapshot chain offline for CI. |
787
823
  | `seq-studio orm apply [dir] -e <env>` | Author a migration if needed, register/apply the namespace, activate its operation set, publish roles/capabilities, and refresh generated outputs. |
788
824
  | `seq-studio orm execute <operation> [dir] --variables-file <file> -e <env>` | Execute one named persisted operation from `operations.manifest.json` with variables from a JSON object file, as the signed-in caller. |
825
+ | `seq-studio orm read <namespace> <table> -e <env> [--where …] [--select …] [--order …] [--limit N] [--offset N] [--json\|--jsonl]` | Read rows of a deployed v2 namespace's table as the caller. |
826
+ | `seq-studio orm sql <namespace> --query <sql> \| --file <path> -e <env> [--param …] [--json\|--jsonl]` | Run read-only SQL against a deployed v2 namespace as the caller. |
789
827
  | `seq-studio orm migrate-from-yaml <dir>` | Convert a legacy YAML namespace to TypeScript authoring while preserving its committed migrations. |
790
828
  | `seq-studio orm import [dir] --spec <file>` | Plan a batched copy from an existing Postgres relation (a synced warehouse table) into an owned ORM table. Writes a SQL script; it does not connect or apply row policies. |
791
829
 
@@ -824,6 +862,44 @@ starting another rehearsal.
824
862
  > depends on `@sequenceholdings/orm@^2.0.0`; use the matching published major
825
863
  > version and keep generated manifests and migrations committed with source.
826
864
 
865
+ ### Ad-hoc reads (`orm read`, `orm sql`)
866
+
867
+ `read` and `sql` query a deployed ORM v2 namespace without authoring an
868
+ operation. Both run the namespace's built-in read-only SQL operation (the same
869
+ one `orm.sql()` uses in apps and functions) as you: grants and row-level
870
+ security apply, the server accepts only its read-only SQL grammar, and a result
871
+ is bounded to 1,000 rows, 8 MiB, and a 10-second statement timeout. Legacy v1
872
+ YAML namespaces are not supported; convert them with `orm migrate-from-yaml`.
873
+
874
+ ```bash
875
+ seq-studio orm read lending loans -e <env> \
876
+ --where status=eq.open --where balance=gte.1000 \
877
+ --select id,officer,balance --order balance.desc --limit 50 --json
878
+
879
+ seq-studio orm sql lending -e <env> \
880
+ --query 'SELECT officer, sum(balance) AS total FROM lending.loans WHERE status = :status GROUP BY officer' \
881
+ --param status=open --jsonl | jq -r '.officer'
882
+ ```
883
+
884
+ - `read` filters with repeatable `--where <column>=<op>.<value>`. Operators: `eq`, `ne`,
885
+ `gt`, `gte`, `lt`, `lte`, `in` (`id=in.(a,b,c)`), and `is` (`closed_at=is.null`,
886
+ `active=is.true`). Values bind as parameters typed like their columns, which `read`
887
+ looks up with one extra request. `--order <column>[.asc|.desc]` is repeatable or
888
+ comma-separated.
889
+ - `sql` takes the statement from `--query` or `--file` and binds `:name` placeholders.
890
+ `--param <name>[:<type>]=<value>` is repeatable; the type defaults to `text` and may be
891
+ `uuid`, `date`, `timestamptz`, `numeric`, `bigint`, `integer`, `double`, or `boolean`.
892
+ `--params '{"closed": {"type": "timestamptz", "value": null}}'` passes the wire shape,
893
+ including null values.
894
+ - `sql` must reference every table as `<namespace>.<table>` (`FROM lending.loans`, not
895
+ `FROM loans`); unqualified names and queries without a table (`SELECT 1`) are rejected.
896
+ The grammar is read-only `SELECT` with joins, CTEs, `UNION`, aggregates, and comparison
897
+ operators; it has no `LIKE` or `IN`. When the server rejects a statement it says only
898
+ "SQL query is invalid or unsupported", so the CLI adds a hint with these rules.
899
+ - `--json` prints a JSON array of row objects (`pandas.read_json`), `--jsonl` one
900
+ object per line (`pandas.read_json(lines=True)`, `jq`). Without either, rows print
901
+ as a table. Counts, truncation, and next-page hints (`--offset`) go to stderr.
902
+
827
903
  ### Registered SQL operations in development builds
828
904
 
829
905
  The planned Studio CLI 0.5.0 package chain also carries default namespace SQL:
@@ -881,12 +957,36 @@ datasets before adopting this path for latency-sensitive reads.
881
957
  | `seq-studio process bundle inspect <bundle.json>` | Show a saved bundle's summary |
882
958
  | `seq-studio process bundle list [-e <env>] [--limit N] [--cursor <hash>]` | List registered bundles (paginated; CLI auto-fetches all pages) |
883
959
  | `seq-studio process bundle publish <hash or bundle.json> [-e <env>]` | Register a local bundle (no promote) |
960
+ | `seq-studio process runs start <process-id> -e <env> [--version <v>] [--run-id <id>] [--metadata-file <file>]` | Start a run as you (needs `invoker` on the process) |
961
+ | `seq-studio process runs list -e <env> [--process <id>] [--status <s>] [--limit N]` | List runs you can view, newest first |
962
+ | `seq-studio process runs show <run-id> -e <env> [--wait]` | Show a run's status and steps; `--wait` polls until it finishes |
963
+ | `seq-studio process runs cancel <run-id> -e <env>` | Cancel a run (needs `invoker` on the process) |
884
964
 
885
965
  Use `lint --offline` for checks without live registry lookups. `test --offline`
886
966
  also skips agent-schema lookup and permits skipping the active-version diff when
887
967
  environment/auth is unavailable, but it still attempts that live diff and resolves
888
968
  subprocess versions when needed. It is not a guarantee of network-free execution.
889
969
 
970
+ ### Runs
971
+
972
+ ```bash
973
+ seq-studio process runs start credit-memo -e <env> \
974
+ --run-id memo-loan-1042 --metadata-file run.json --json
975
+ seq-studio process runs show memo-loan-1042 -e <env> --wait --json
976
+ seq-studio process runs list -e <env> --process credit-memo --status failed --limit 20
977
+ ```
978
+
979
+ `--version` pins a published version; without it the active version runs.
980
+ `--run-id` makes `start` idempotent: repeating it for the same process returns
981
+ the existing run (`idempotent_replay: true`) rather than starting another, and
982
+ reusing it for a different process is refused. `--metadata-file` must hold a
983
+ JSON object. `list` filters by `--process`, `--status` (`pending`, `running`,
984
+ `completed`, `failed`, `cancelled`, `timed_out`), `--entity-type`/`--entity-id`,
985
+ and `--archived`; it returns the newest runs up to `--limit` (default 50,
986
+ maximum 500). The run API has no cursor, so narrow the filters to reach older
987
+ runs. `show --wait` stops waiting after `--timeout` seconds (default 600); the
988
+ run itself continues. `--json` prints the API response on every command.
989
+
890
990
  ### JSONata mapper contracts
891
991
 
892
992
  `jsonata('…')` expressions are serialized as `*_expr` data and run in a
@@ -966,6 +1066,16 @@ seq-studio process lint --dir my-processes --offline # finds both processes
966
1066
  Add `--help` to a function command to read its usage offline, without an
967
1067
  environment, credentials, or `managed-function.yml`.
968
1068
 
1069
+ For a function whose source must remain pinned, declare
1070
+ `function.immutable_release: true` before its first deployment using CLI **0.5.5**
1071
+ and a platform that advertises immutable releases. The first successful activation
1072
+ permanently freezes deployment of that function identity, including promote,
1073
+ rollback, and secret-version redeploys. Create a new `function.id` for the next
1074
+ release and retain previous functions while their callers still need them.
1075
+ Removing the flag cannot unfreeze the runtime, and already active mutable
1076
+ functions cannot opt in retroactively. The default remains mutable. See the
1077
+ [Managed Functions SDK guide](../managed-functions/README.md#immutable-function-releases).
1078
+
969
1079
  | Command | What it does |
970
1080
  |---------|--------------|
971
1081
  | `seq-studio functions init <dir>` | Scaffold one standalone TypeScript managed function |
@@ -980,6 +1090,18 @@ environment, credentials, or `managed-function.yml`.
980
1090
  `functions deploy` picks the next `vN` after the highest numbered version of
981
1091
  that function. Versions named by repository CI, such as `ci-abc`, do not reset
982
1092
  the sequence. A function with no numbered versions starts at `v1`.
1093
+ While waiting for a building version, deploy, promote, and rollback print the
1094
+ current lifecycle stage when Atlas confirms it belongs to that version. A failed
1095
+ stage with recovery still running is labeled as recovery in progress; only the
1096
+ version's final status determines whether the command succeeds or fails. If
1097
+ lifecycle status is unavailable, the command continues to report version status.
1098
+ Use `functions logs` for sanitized readiness connection diagnostics.
1099
+
1100
+ Set `runtime: nodejs24` in `managed-function.yml` to use Node.js 24 on a hosted
1101
+ deployment. Node.js 20 (`nodejs20`) remains the default when `runtime` is omitted.
1102
+ These are the supported manifest values; other runtimes are rejected. Keep
1103
+ `package.json`'s `engines.node` compatible with the selected runtime, for example
1104
+ `"24.x"` for Node.js 24. Local development uses the installed Node version.
983
1105
 
984
1106
  A normal function repo keeps `managed-function.yml` at its root and omits
985
1107
  `--path`. A repo may also contain related, independently deployed functions:
@@ -1271,6 +1393,21 @@ A successful direct `seq-studio orm execute` call does not test a function's
1271
1393
  delegated scope. If the same read fails through the function with a 403, check
1272
1394
  the deployed `tables` declaration before requesting broader user grants.
1273
1395
 
1396
+ ### Trusted Lattice context
1397
+
1398
+ Declare `capabilities.lattice.context: true` and attach a top-level
1399
+ `service_account` for functions that read their verified Lattice execution or
1400
+ selected human-action receipts. This requires CLI `0.5.5`, Managed Functions SDK
1401
+ `0.4.2`, and deployed `lattice_context` support; preflight fails before upload
1402
+ when a declaration, attachment or release prerequisite is missing.
1403
+
1404
+ The reviewed process node must explicitly map any context data it exposes as
1405
+ `input.context`. The SDK returns the actual mapped input and platform-owned
1406
+ execution identity. It does not grant arbitrary run reads or treat a run
1407
+ starter, caller-authored actor or service attribution as a human approval.
1408
+ See the [Managed Functions SDK](../managed-functions/README.md#trusted-lattice-execution-and-human-actions)
1409
+ for invocation-scoped context and receipt APIs.
1410
+
1274
1411
  ## Managed Secret commands
1275
1412
 
1276
1413
  | Command | What it does |
@@ -1516,14 +1653,38 @@ writes the completed operation/deployment receipt, not a JavaScript bundle.
1516
1653
  Ctrl+C stops waiting but does not cancel the remote build. Next.js does not
1517
1654
  support `artifact dev --once`; use the hosted build command instead.
1518
1655
 
1519
- Official releases fetch and verify source from the Git Service in the target
1520
- Atlas environment. Push the reviewed clean `main` revision before deploying:
1656
+ Official releases fetch and verify source from Git Service. By default the source
1657
+ and target environment are the same. Push the reviewed clean `main` revision
1658
+ (or `staging` when deploying to staging) before deploying:
1521
1659
 
1522
1660
  ```bash
1523
1661
  seq-studio artifact plan --repo <namespace>/<repository> --ref main --env <environment>
1524
1662
  seq-studio artifact deploy --repo <namespace>/<repository> --ref main --env <environment>
1525
1663
  ```
1526
1664
 
1665
+ To keep one canonical repository while deploying to a different environment,
1666
+ select the source with `--source-env`. This requires a CLI and target Atlas version
1667
+ with verified cross-environment build support; older targets reject the request.
1668
+ The source must be an environment recognized by the target's trusted registry.
1669
+ Log in to both environments using accounts with source repository read access
1670
+ and target project deployment access:
1671
+
1672
+ ```bash
1673
+ seq-studio login -e production
1674
+ seq-studio login -e staging
1675
+ seq-studio artifact deploy --repo apps/customer-portal --source-env production \
1676
+ --ref staging --path web --env staging --no-create
1677
+ ```
1678
+
1679
+ `--source-env` applies to Next.js `build`, `plan`, and `deploy`. It also accepts a
1680
+ clean local checkout whose Git Service origin matches the source environment.
1681
+ The target independently reads the immutable commit through the source's
1682
+ permissions checks and verifies the allowed release branch before building.
1683
+ The deployment records the source environment, repository, commit and directory.
1684
+ The source login is transient: it is never stored with the deployment or passed
1685
+ to build processes. Target bindings, workspace IDs and runtime permissions still
1686
+ belong to `--env`; selecting a source does not copy resources between environments.
1687
+
1527
1688
  The Next.js `plan` command validates local source/toolchain inputs and prints the
1528
1689
  proposed build; it does not currently perform a remote policy diff. Atlas checks
1529
1690
  permissions, bindings and policy when the build is submitted. A local image or
@@ -1615,6 +1776,10 @@ Deploy login-capable server support before upgrading the CLI; this CLI cannot
1615
1776
  authenticate Git against older PAT-only servers. `clone` no longer silently downloads a files-only tree.
1616
1777
  Use `seq-studio repos pull` or `repos clone --transport json` explicitly when you want files without `.git`.
1617
1778
 
1779
+ In sandbox token mode the helper answers with the sandbox token instead of a
1780
+ login, for git-service repositories on `SEQ_STUDIO_BASE_URL` only; see
1781
+ [Sandbox token mode](#sandbox-token-mode-agent-sandboxes).
1782
+
1618
1783
  ### Retired personal access tokens
1619
1784
 
1620
1785
  Git authentication requires a human `seq-studio login --env <env>` session.
@@ -1659,7 +1824,7 @@ JSON API — the same repos `--repo <ns>/<name>` sources build from.
1659
1824
  | `seq-studio repos pull <ns>/<name> -e <env> [--ref <r>] [--out <dir>] [--force]` | always materialize via JSON API (no `.git` dir); refuses a non-empty destination unless `--force` |
1660
1825
  | `seq-studio repos delete <ns>/<name> -e <env> [--yes]` | delete a repo — interactive confirm unless `--yes` |
1661
1826
  | `seq-studio repos ci init [--dir <repository>]` | create `.seq/pipeline.yml` with native defaults; offline, preserves existing configuration |
1662
- | `seq-studio repos ci show <ns>/<name> -e <env> --pr <number> [--json]` | inspect the server's discovered pipeline, exact plan and recent runs; JSON retains the complete status response |
1827
+ | `seq-studio repos ci show <ns>/<name> -e <env> --pr <number> [--json]` | inspect the server's discovered pipeline, exact plan, recent runs, and deployment intents (state, target progress, errors, and live app URL). Text output shows at most five intents and ten targets per intent; `--json` retains the complete status response. |
1663
1828
  | `seq-studio repos ci show <ns>/<name> -e <env> [--ref <r>]` | preview legacy discovery at a ref; an empty result does not establish that the server plan has no targets, checks, or findings. Open or update a PR and use `--pr <number>` for the authoritative plan. |
1664
1829
  | `seq-studio repos ci require <ns>/<name> --check <name> -e <env>` | disabled legacy required-check control; use native pipeline discovery |
1665
1830
  | `seq-studio repos ci import <ns>/<name> -e <env> [--ref <r>]` | disabled legacy required-check control; use native pipeline discovery |
@@ -1811,19 +1976,59 @@ first listed stage directory; without config it keeps using the package root.
1811
1976
  | `seq-studio pipeline query <assetId> --sql <sql> -e <env> [--target <id>] [--limit <rows>] [--json]` | Run a read-only query against the virtual relation `asset`; default and maximum 1,000 result rows |
1812
1977
  | `seq-studio pipeline init --type ingestion\|transformation\|serving <name> [--dir <dir>]` | Scaffold `<name>.stage.yml` in the first configured stage directory (or package root without config), plus a package-root-relative `src/` Databricks-notebook entrypoint stub (begins with `# Databricks notebook source`; serving stages are declarative — no stub). Refuses to overwrite an existing spec |
1813
1978
  | `seq-studio pipeline codegen tables [--from <authoring.ts>] [--dir <dir>] [--dry-run] [--force]` | Generate one ingestion stage spec per table from a `PerTableIngestionAuthoring` TypeScript module. `--from` defaults to `authoring.tables.ts`; `--dir` defaults to the current package root and writes into its first configured stage directory (or the root without config). `--dry-run` lists output files without writing; existing files are preserved unless `--force` is supplied |
1814
- | `seq-studio pipeline validate [dir] [--assets <file\|url>] [--orm-contracts <file\|url>] [--json]` | Run the full offline spec gate: envelope + body validation, `schema_ref` resolution, and repo-level graph validation (reference resolution, single-writer, cycles, column subsets, serving projection checks). Auto-loads `orm-contracts.json` from the pipeline dir when present. Exit 0/1 |
1979
+ | `seq-studio pipeline validate [dir] [--assets <file\|url>] [--orm-contracts <file\|url>] [--json]` | Run the full offline spec gate: envelope + body validation, `schema_ref` resolution, repo-level graph validation, and optional `pipeline.yml` native workflow validation (DAG dependencies and manual stage membership). Auto-loads `orm-contracts.json` from the pipeline dir when present. Exit 0/1 |
1815
1980
  | `seq-studio pipeline repin-orm [dir] -e <env> [--target <id>] [--dry-run]` | Resolve the environment's pipeline target (or use `--target` when ambiguous), fetch its active ORM v2 contracts, verify those serving projections remain compatible, then update `orm-contracts.json` and their `satisfies.content_hash` pins. Refuses to write when compatibility fails |
1816
- | `seq-studio pipeline plan --repo <namespace>/<slug> --ref <sha\|branch> [--root <directory>] -e <env> [--target <id>] [--json]` | Enqueue and poll a durable Pipeline plan (materialize → SDK/`validateSpecGraph` → compile → live-diff → provision findings). `<namespace>` is `pipelines`, `apps`, or your own namespace. Fails closed listing **every** missing target binding (alert channels, workspace, Databricks `source.credential`) plus Data Sync edge-worker machine/operation/`credEnvFamilies` mismatches before registry writes. Does **not** run Databricks `bundle validate` (that is a Trigger deploy-path hard gate). Exit 1 on destructive findings (CI-safe). `--json` emits the completed stable plan envelope |
1817
- | `seq-studio pipeline deploy --repo <namespace>/<slug> --ref <sha\|branch> [--root <directory>] -e <env> [--target <id>] [--approved-by <sub>] [--allow-destructive <resource-key> ...] [--run-now] [--wait-timeout <duration>] [--no-wait] [--json]` | Plan then enqueue deploy; Trigger runs `bundle validate` then `bundle deploy` against reviewed bytes. `<namespace>` is `pipelines`, `apps`, or your own namespace. Default is plant-only (jobs are created, not run). `--run-now` runs in-unit producer roots after bundle deploy; serving refresh provisioning completes before producer trigger.after tasks can run. If a producer fails, the terminal status includes the remote Databricks task/event error when available. `--allow-destructive` is repeatable and must exactly name every deletion/recreation finding in the immutable plan; only authenticated `@seqholdings.com` users may authorize it; permission, ownership, schedule-drift, and provisioning blockers cannot be overridden. Polls to terminal unless `--no-wait`. Targets that require approval need `--approved-by` naming the authenticated caller. |
1981
+ | `seq-studio pipeline plan --repo <namespace>/<slug> --ref <sha\|branch> [--source-env <env>] [--root <directory>] -e <env> [--target <id>] [--json]` | Enqueue and poll a durable Pipeline plan (materialize → SDK/`validateSpecGraph` → compile → live-diff → provision findings). `<namespace>` is `pipelines`, `apps`, or your own namespace. Fails closed listing **every** missing target binding (alert channels, workspace, Databricks `source.credential`) plus Data Sync edge-worker machine/operation/`credEnvFamilies` mismatches before registry writes. Does **not** run Databricks `bundle validate` (that is a Trigger deploy-path hard gate). Exit 1 on destructive findings (CI-safe). `--json` emits the completed stable plan envelope |
1982
+ | `seq-studio pipeline deploy --repo <namespace>/<slug> --ref <sha\|branch> [--source-env <env>] [--root <directory>] -e <env> [--target <id>] [--approved-by <sub>] [--allow-destructive <resource-key> ...] [--run-now] [--wait-timeout <duration>] [--no-wait] [--json]` | Plan then enqueue deploy; Trigger runs `bundle validate` then `bundle deploy` against reviewed bytes. `<namespace>` is `pipelines`, `apps`, or your own namespace. Default is plant-only (jobs are created, not run). `--run-now` runs in-unit producer roots after bundle deploy; serving refresh provisioning completes before producer trigger.after tasks can run. If a producer fails, the terminal status includes the remote Databricks task/event error when available. `--allow-destructive` is repeatable and must exactly name every deletion/recreation finding in the immutable plan; only authenticated `@seqholdings.com` users may authorize it; permission, ownership, schedule-drift, and provisioning blockers cannot be overridden. Polls to terminal unless `--no-wait`. Targets that require approval need `--approved-by` naming the authenticated caller. |
1818
1983
 
1819
1984
  `--root` selects a contained Pipeline package inside the repository. The directory becomes the package and Databricks bundle root, so its `*.stage.yml`, `src/`, manifests, contracts, schemas, and extra resources keep their normal root-relative layout. Each repository/root pair is an independent release unit; sibling pipelines and unrelated app files are not included in its bundle. Omitting `--root` preserves the historical whole-repository release unit.
1820
1985
 
1821
1986
  Creating a release unit requires both **Can create** on Pipelines and Git Service **Writer** on the named repository. Once the release unit exists, further changes require its Pipeline `editor` tier.
1822
1987
 
1823
- `seq-studio pipeline deploy --dir <checkout> --repo <namespace>/<slug> -e <env>` publishes a clean local checkout into that environment's git service, then deploys the published commit through the same path. It is available on targets that do not require approval (`dev`, `staging`). BankSouth and production still deploy a commit that already exists in that environment's git service. Log in with `seq-studio login -e <env>` before publishing; the same user authenticates API and Git requests. Do not pass `--ref` with `--dir`. When the repository is created by this command, `main` is set to the published commit so a later clone without `--ref` resolves; an existing repository's default branch is left unchanged.
1988
+ For an existing pipeline release unit in the target, use
1989
+ `--source-env <first-party-env>` with `pipeline plan` or repository-based
1990
+ `pipeline deploy` to read canonical source from another environment. `-e` still
1991
+ selects the deployment environment, and `--target` selects its pipeline target.
1992
+ The CLI authenticates the two environments separately; source credentials are
1993
+ sent only with planning requests and are never stored in a plan or worker task.
1994
+ The target independently verifies source access and the selected ref, and retains
1995
+ an immutable source snapshot. The CLI refuses a completed plan without matching
1996
+ source repository, environment, release unit, and commit provenance, including
1997
+ responses from older target APIs that ignore source options. Failed source plans
1998
+ do not automatically attach stage credentials because their source is unverified;
1999
+ resolve missing bindings on the intended target stage explicitly and re-plan.
2000
+ Successful verified source plans retain normal credential reconciliation, and any
2001
+ re-plan must verify its source again. This increment supports only the server-owned
2002
+ first-party source origins (`banksouth`, `staging`, and `production`). Registered
2003
+ OpCo source environments are not supported yet. A local CLI environment entry or
2004
+ the target's own `APP_ORIGIN` does not establish trust for a remote source; the
2005
+ server never accepts a caller-selected source URL.
2006
+ First-time creation retains the existing target repository Writer requirement;
2007
+ creating a new release unit solely from a remote repository is not supported yet.
2008
+
2009
+ ```bash
2010
+ seq-studio pipeline plan --repo apps/example --root pipelines/feed --ref staging --source-env banksouth -e staging --json
2011
+ seq-studio pipeline deploy --repo apps/example --root pipelines/feed --ref <reviewed-commit> --source-env banksouth -e staging
2012
+ ```
2013
+
2014
+ This does not create a repository in the target or change pipeline permissions,
2015
+ resource ownership, bindings, target approvals, or destructive-change gates.
2016
+ Do not combine `--source-env` with `--dir`, existing plan/deployment IDs, or
2017
+ coordinated migrations. Existing IDs already identify their immutable source;
2018
+ execute and poll them using target authentication only. A rollback to a deployment
2019
+ that retained a source snapshot reuses that snapshot without source credentials.
2020
+ Older deployments may still depend on their original repository. To deploy a
2021
+ historical canonical commit when that repository is unavailable, create a fresh
2022
+ source-qualified plan with `deploy --ref <sha> --source-env <env>` and review its
2023
+ current findings; this is not an exact replay of the old plan. Promotion of
2024
+ snapshot-backed versions to another target is not supported yet; use the same
2025
+ explicit source-qualified planning workflow instead.
2026
+
2027
+ `seq-studio pipeline deploy --dir <checkout> --repo <namespace>/<slug> -e <env>` publishes a clean local checkout into that environment's git service, then deploys the published commit through the same path. It is available on targets that do not require approval (`dev`, `staging`). Targets that require approval use an existing repository commit; use `--source-env` when that repository is in another trusted environment. Log in with `seq-studio login -e <env>` before publishing; the same user authenticates API and Git requests. Do not pass `--ref` with `--dir`. When the repository is created by this command, `main` is set to the published commit so a later clone without `--ref` resolves; an existing repository's default branch is left unchanged.
1824
2028
  | `seq-studio pipeline status --deployment-id <id> -e <env> [--json]` | Fetch the current remote deployment status without changing it. Use this public command to continue monitoring after local polling stops |
1825
2029
  | `seq-studio pipeline adopt --stage <slug> --ref <sha\|branch> [--root <directory>] -e <env> [--target <id>] --native-id <id> --approved-by <you> [--resource-key <key>] [--kind job\|dlt_pipeline] [--old-source-removal-pr <url>] [--repo <namespace>/<slug>]` | Bind a live Databricks job/pipeline into the stage without recreation (`bundle deployment bind` on Trigger). Always requires `--approved-by` naming the caller. When the key is still in the monorepo DAB, pass `--old-source-removal-pr` and follow the returned cutover checklist: unbind the old bundle state without deleting the remote, then remove its DAB declaration and add the target-specific adopted-resource entry in the same PR before redeploying. |
1826
2030
  | `seq-studio pipeline unbind --stage <slug> --ref <sha\|branch> [--root <directory>] -e <env> [--target <id>] --approved-by <you> [--resource-key <key>] [--repo <namespace>/<slug>]` | Release an adopted binding on Trigger; the remote object stays live (never deleted) |
2031
+ | `seq-studio pipeline retire --repo <release-unit> -e <env> [--target <id>] [--json]` | Preview the exact whole-pipeline inventory. Approve with `--plan-hash <hash> --yes`. Inspect with `--retirement-id <id>`; explicitly resume a stopped failure with `--retirement-id <id> --resume --yes`. Requires a human pipeline administrator and the existing staff destructive-operation gate. Deletes supported execution resources, releases bindings, and archives stages; retains data objects, source repositories, permissions and historical records. |
1827
2032
  | `seq-studio pipeline run-now --stage <slug> -e <env> [--target <id>] [--repo <namespace>/<slug>] [--json]` | Run the stage's active job or DLT pipeline immediately and print its Databricks run URL |
1828
2033
  | `seq-studio pipeline promote --stage <slug> --version <v> -e <env> [--target <id>] [--repo <namespace>/<slug>] [--approved-by <you>] [--wait-timeout <duration>] [--no-wait] [--json]` | Promote a validated version to another target. Targets that require approval need `--approved-by`; `--repo` disambiguates a slug that exists in multiple Pipelines |
1829
2034
  | `seq-studio pipeline rollback --stage <slug> -e <env> [--target <id>] [--repo <namespace>/<slug>] [--approved-by <you>] [--wait-timeout <duration>] [--no-wait] [--json]` | Redeploy the previously retired deployment's version. Targets that require approval need `--approved-by`. |
@@ -2386,6 +2591,11 @@ seq-studio repos pulls list <namespace/name> --state open -e <env>
2386
2591
  seq-studio repos pulls show <namespace/name> <number> -e <env>
2387
2592
  seq-studio repos pulls diff <namespace/name> <number> -e <env>
2388
2593
  seq-studio repos pulls merge <namespace/name> <number> --method squash -e <env>
2594
+ seq-studio repos pulls comment <namespace/name> <number> --body "Looks good" -e <env>
2595
+ seq-studio repos pulls comment <namespace/name> <number> --path src/memo.ts --line 42 --body-file note.md -e <env>
2596
+ seq-studio repos pulls review <namespace/name> <number> --request-changes --body-file review.md -e <env>
2597
+ seq-studio repos pulls checks <namespace/name> <number> -e <env>
2598
+ seq-studio repos pulls close <namespace/name> <number> -e <env>
2389
2599
  ```
2390
2600
 
2391
2601
  All results are JSON (`--json` is accepted). Listing returns one page and `nextCursor`;
@@ -2393,4 +2603,13 @@ use `--cursor` to continue. Diff accepts `--max-files` (maximum 500) and reports
2393
2603
  Merge requires merge/admin authority, confirmation (or approved automation's `--yes`),
2394
2604
  and the existing server review/check policy. It merges the current branch head; a
2395
2605
  displayed SHA is not a head-lock or policy bypass. Complete reviews before merging.
2606
+ `comments` and `reviews` list a Pull's comments and reviews (paginated like `list`).
2607
+ `comment` adds a comment; `--path` with `--line` anchors it to a diff line on the
2608
+ new side (`--side LEFT` for the old side) at the commit the Pull's branch points at
2609
+ now (`--commit <sha>` to pin another), and `--reply-to <comment-id>` answers a thread.
2610
+ `review` takes exactly one of `--approve`, `--request-changes`, or `--comment`, an
2611
+ optional `--body`/`--body-file`, and records the review against the commit the Pull's
2612
+ branch points at now unless `--commit` names another. `checks` returns one object with the Pull's check
2613
+ runs, CI plan and runs, and merge gates (mergeability, review, code-owner, and check
2614
+ gates). `close` needs authorship or repository write and is idempotent.
2396
2615
  `repos pull` remains the singular source-snapshot command.
@@ -1,6 +1,7 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import { join } from 'node:path';
4
+ import { sourceAuthMode } from '../sandbox-auth.js';
4
5
  import { hashAgentBundle, } from '@sequenceholdings/agent-spec';
5
6
  import { agentDeployManifestSchema, assertKnownTargetEnvironment, compileAgentDirectory, selectAgentEntries, selectionStats, } from '@sequenceholdings/agent-spec/compiler';
6
7
  import { parseSourceSpec, resolveArtifactSource, } from '@sequenceholdings/artifact-studio/source-resolver';
@@ -19,7 +20,7 @@ function sourceSpec(args) {
19
20
  }
20
21
  function sourceOptions(context) {
21
22
  return {
22
- ...(context.authMode ? { authMode: context.authMode } : {}),
23
+ ...(context.authMode ? { authMode: sourceAuthMode(context.authMode) } : {}),
23
24
  ...clientOptions(context),
24
25
  };
25
26
  }
@@ -5,6 +5,7 @@ import { join } from 'node:path';
5
5
  import { load as loadYaml } from 'js-yaml';
6
6
  import { z } from 'zod';
7
7
  import { resolveArtifactSource } from '@sequenceholdings/artifact-studio/source-resolver';
8
+ import { sourceAuthMode } from '../sandbox-auth.js';
8
9
  import { checkOfficialArtifactSource } from './official-source.js';
9
10
  const functionIdentitySchema = z.object({ function: z.object({ id: z.string() }) });
10
11
  const artifactIdentitySchema = z.object({ artifact: z.object({ project_id: z.string() }) });
@@ -88,7 +89,7 @@ async function validatePipelineSource(args) {
88
89
  if (!namespace || !name || repo.split('/').length !== 2) {
89
90
  throw new Error(`Pipeline "${args.entry.id}" requires a <namespace>/<name> repository.`);
90
91
  }
91
- const source = await resolveArtifactSource({ kind: 'git-service', namespace, name, ref }, { ...clientOptions(context), ...(context.authMode ? { authMode: context.authMode } : {}) });
92
+ const source = await resolveArtifactSource({ kind: 'git-service', namespace, name, ref }, { ...clientOptions(context), ...(context.authMode ? { authMode: sourceAuthMode(context.authMode) } : {}) });
92
93
  try {
93
94
  const commit = source.provenance.gitCommit;
94
95
  if (!commit || !/^[0-9a-f]{40}$/i.test(commit)) {
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { basename, resolve } from 'node:path';
8
8
  import { parseDurationMs } from '@sequenceholdings/lattice';
9
- import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
9
+ import { REQUIRE_EXPLICIT_ENV_MESSAGE, explicitOrSandboxEnv } from '../env-flags.js';
10
10
  import { deployApp } from './deploy.js';
11
11
  import { DEFAULT_APP_KINDS, resolveRequestedKinds } from './kinds.js';
12
12
  import { AppPreparationError, prepareScaffoldedApp } from './prepare.js';
@@ -49,12 +49,12 @@ export const APP_INIT_USAGE = `usage:
49
49
  Examples:
50
50
  seq-studio init pokedex
51
51
  seq-studio init . --template nextjs
52
- seq-studio init uw362 # a new app inside an existing repository
52
+ seq-studio init reports # a new app inside an existing repository
53
53
  seq-studio init pokedex --with orm,function,artifact
54
54
  seq-studio init pokedex --with orm,function,artifact --function-name get-pokemon
55
55
  seq-studio init loan-tools --with function --function-name get-loan
56
56
  seq-studio init review-app --with orm,function,agent,process,pipeline,artifact
57
- seq-studio init review-app --template full-stack@1.0.0 -e banksouth-mortgage
57
+ seq-studio init review-app --template full-stack@1.0.0 -e staging
58
58
  `;
59
59
  export const APP_ADD_USAGE = `usage:
60
60
  seq-studio add <kind> <name> [--depends-on <ids>] [--pipeline-type <type>] [--template <t>]
@@ -356,7 +356,7 @@ export async function runAppDeployCommand(args) {
356
356
  return 1;
357
357
  }
358
358
  const waitTimeout = flagString(args.flags, 'wait-timeout');
359
- const env = flagString(args.flags, 'env') ?? flagString(args.flags, 'e');
359
+ const env = explicitOrSandboxEnv(flagString(args.flags, 'env') ?? flagString(args.flags, 'e'));
360
360
  if (!env) {
361
361
  console.error(`${LOG} ${REQUIRE_EXPLICIT_ENV_MESSAGE}`);
362
362
  console.error(APP_DEPLOY_USAGE);
@@ -18,9 +18,9 @@ import { PREVIEW_DOMAIN, PREVIEW_PROJECT, resolvePreviewByPr } from '../preview.
18
18
  const ARTIFACT_USAGE = `usage:
19
19
  seq-studio artifact init <dir> [--template react-vite|nextjs]
20
20
  seq-studio artifact validate [dir]
21
- seq-studio artifact build [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--path <dir>] [--out file.json]
22
- seq-studio artifact plan [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--path <dir>] -e <env>
23
- seq-studio artifact deploy [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--path <dir>] -e <env> [--skip-unchanged] [--no-create] [--project <id>]
21
+ seq-studio artifact build [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--path <dir>] [--source-env <env>] [--out file.json]
22
+ seq-studio artifact plan [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--path <dir>] [--source-env <env>] -e <env>
23
+ seq-studio artifact deploy [dir | --repo <ns>/<name> | --git-url <url>] [--ref <ref>] [--path <dir>] [--source-env <env>] -e <env> [--skip-unchanged] [--no-create] [--project <id>]
24
24
  seq-studio artifact dev [dir] -e <env> [--once] [--key default] [--link <pkgDir>[,<pkgDir>]] [--port <port>]
25
25
  seq-studio artifact pull <project-id> -e <env> --out <dir>
26
26
  seq-studio artifact promote <deployment-id> -e <env>
@@ -44,14 +44,18 @@ const ARTIFACT_USAGE = `usage:
44
44
  Interactive --repo builds clone over smart-HTTP using your seq-studio login
45
45
  and repository read access. No PAT is needed. Headless M2M builds use JSON
46
46
  materialize and accept only platform-managed --repo sources. Use --env to
47
- select the same environment for source and deployment.
47
+ select the target environment. Next.js build/plan/deploy accept --source-env
48
+ to read a Git Service repository from a separately authenticated environment.
49
+ Log in to both environments; source read and target deploy permissions apply.
50
+ The target must support verified cross-environment builds. Source credentials
51
+ are used only to fetch source, never passed to the build or stored with it.
48
52
 
49
53
  Next.js applications require Node.js 24 and application-local dependencies
50
54
  (pnpm install). dev runs Next locally with native Fast Refresh through an
51
55
  owner-only Atlas tunnel; no GCP access is required. build -e <env> requests a
52
56
  hosted preview. Official deploys use a reviewed Git Service revision:
53
57
  deploy --repo <namespace>/<name> --ref main -e <env>. A clean local checkout
54
- with a Git Service origin on the target Atlas environment also works.
58
+ with a Git Service origin on the selected source environment also works.
55
59
  Use pnpm build for a local production-build check. --once is static-only;
56
60
  --port selects the local Next loopback port.
57
61
  Deploy rejects source that still points at another environment's API origin
@@ -155,15 +159,31 @@ export async function runArtifactCommand(sub, rest) {
155
159
  const targetUrl = resolved?.url ??
156
160
  process.env['ARTIFACT_STUDIO_BASE_URL']?.trim() ??
157
161
  (authEnvName ? routingConfig.envs[authEnvName]?.url : undefined);
158
- setTokenProvider(({ allowInteractiveLogin }) => allowInteractiveLogin
159
- ? getAccessTokenWithMode({ env: authEnvName, targetUrl })
160
- : tryGetAccessTokenWithMode({
161
- failClosedForM2m: true,
162
- env: authEnvName,
163
- targetUrl,
164
- }));
162
+ if (targetUrl)
163
+ process.env['ARTIFACT_STUDIO_BASE_URL'] = targetUrl;
164
+ setTokenProvider(async ({ allowInteractiveLogin, sourceEnvironment }) => {
165
+ const source = sourceEnvironment
166
+ ? await resolveConfiguredEnv({ requested: sourceEnvironment })
167
+ : undefined;
168
+ const selected = { env: source?.name ?? authEnvName, targetUrl: source?.url ?? targetUrl };
169
+ return artifactCredential(allowInteractiveLogin
170
+ ? await getAccessTokenWithMode(selected)
171
+ : await tryGetAccessTokenWithMode({ failClosedForM2m: true, ...selected }));
172
+ });
165
173
  return runArtifactStudio([sub, ...argvForCli]);
166
174
  }
175
+ /**
176
+ * Artifact Studio uses only credentials the CLI obtained itself. `main.ts`
177
+ * refuses artifact commands in sandbox token mode before reaching here; this
178
+ * keeps the rule if the delegate is ever called directly.
179
+ */
180
+ function artifactCredential(auth) {
181
+ if (!auth)
182
+ return null;
183
+ if (auth.authMode === 'sandbox')
184
+ throw new Error('Artifact Studio does not accept sandbox tokens. Authenticate with seq-studio login.');
185
+ return { authMode: auth.authMode, token: auth.token };
186
+ }
167
187
  /**
168
188
  * Strip the seq-studio-only `--pr <number>` and `--env-url <url>` flags from
169
189
  * argv and return the rest (forwarded to artifact-studio) plus the parsed
@@ -34,9 +34,10 @@ export declare function getJson<T>({ baseUrl, token, path, }: ClientOptions & {
34
34
  export declare function getJsonOr404<T>({ baseUrl, token, path, }: ClientOptions & {
35
35
  path: string;
36
36
  }): Promise<T | null>;
37
- export declare function postJson<T>({ baseUrl, token, path, body, }: ClientOptions & {
37
+ export declare function postJson<T>({ baseUrl, token, path, body, sourceAuthorization, }: ClientOptions & {
38
38
  path: string;
39
39
  body?: unknown;
40
+ sourceAuthorization?: string;
40
41
  }): Promise<T>;
41
42
  /**
42
43
  * JSON POST for passthrough endpoints whose successful response is not
@@ -7,6 +7,7 @@
7
7
  import { authenticatedRequestUrl } from '@sequenceholdings/artifact-studio/deployment-validation';
8
8
  import { validationDetail } from './validation-detail.js';
9
9
  import { PREVIEW_DOMAIN } from './preview.js';
10
+ import { sandboxBearerFor } from './sandbox-auth.js';
10
11
  const MAX_503_RETRIES = 5;
11
12
  const DEFAULT_RETRY_AFTER_SECONDS = 2;
12
13
  const LOG_PREFIX = '[seq-studio]';
@@ -39,6 +40,9 @@ async function fetchWith503Retry(input, init) {
39
40
  }
40
41
  async function authenticatedFetch({ baseUrl, init = {}, path, token, retry503 = true, }) {
41
42
  const url = authenticatedRequestUrl({ baseUrl, path });
43
+ // Sandbox tokens rotate between requests, so a long command re-reads the file
44
+ // for every call instead of reusing the token it resolved at startup.
45
+ const bearer = (await sandboxBearerFor(baseUrl)) ?? token;
42
46
  const send = retry503 ? fetchWith503Retry : fetch;
43
47
  return send(url, {
44
48
  ...init,
@@ -47,7 +51,7 @@ async function authenticatedFetch({ baseUrl, init = {}, path, token, retry503 =
47
51
  ...previewAccessHeaders(baseUrl),
48
52
  ...cfAccessHeaders(baseUrl),
49
53
  ...init.headers,
50
- Authorization: `Bearer ${token}`,
54
+ Authorization: `Bearer ${bearer}`,
51
55
  },
52
56
  });
53
57
  }
@@ -206,14 +210,14 @@ export async function getJsonOr404({ baseUrl, token, path, }) {
206
210
  throw await responseError(response, path);
207
211
  return response.json();
208
212
  }
209
- export async function postJson({ baseUrl, token, path, body, }) {
213
+ export async function postJson({ baseUrl, token, path, body, sourceAuthorization, }) {
210
214
  const response = await authenticatedFetch({
211
215
  baseUrl,
212
216
  token,
213
217
  path,
214
218
  init: {
215
219
  method: 'POST',
216
- headers: { 'Content-Type': 'application/json' },
220
+ headers: { 'Content-Type': 'application/json', ...(sourceAuthorization ? { 'x-sequence-source-authorization': sourceAuthorization } : {}) },
217
221
  body: body === undefined ? undefined : JSON.stringify(body),
218
222
  },
219
223
  });
@@ -1,3 +1,3 @@
1
1
  import type { ParsedArgs } from '../process/commands.js';
2
- export declare const AUTH_USAGE = "usage:\n seq-studio auth whoami -e <env> [--json]\n seq-studio auth git-credential --env <env> --url <clone-url> <get|store|erase>\n Git authentication uses seq-studio login. repos clone installs the helper.\n";
2
+ export declare const AUTH_USAGE = "usage:\n seq-studio auth whoami -e <env> [--json]\n seq-studio auth git-credential --env <env> --url <clone-url> <get|store|erase>\n Git authentication uses seq-studio login. repos clone installs the helper.\n In sandbox token mode (SEQ_STUDIO_BASE_URL + SEQ_STUDIO_TOKEN_FILE) the helper\n answers with the sandbox token for git-service repositories on that origin only;\n --env and --url are optional there.\n";
3
3
  export declare function runAuthCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;
@@ -6,6 +6,9 @@ export const AUTH_USAGE = `usage:
6
6
  seq-studio auth whoami -e <env> [--json]
7
7
  seq-studio auth git-credential --env <env> --url <clone-url> <get|store|erase>
8
8
  Git authentication uses seq-studio login. repos clone installs the helper.
9
+ In sandbox token mode (SEQ_STUDIO_BASE_URL + SEQ_STUDIO_TOKEN_FILE) the helper
10
+ answers with the sandbox token for git-service repositories on that origin only;
11
+ --env and --url are optional there.
9
12
  `;
10
13
  export async function runAuthCommand(sub, args) {
11
14
  try {
package/dist/auth.d.ts CHANGED
@@ -120,7 +120,8 @@ export declare class UnsafeAuthTargetError extends Error {
120
120
  * that must never sign anyone in as a side effect.
121
121
  */
122
122
  export declare function withoutAutoLogin<T>(fn: () => Promise<T>): Promise<T>;
123
- export type AuthMode = 'm2m' | 'user';
123
+ /** `sandbox`: the caller-scoped bearer Atlas writes into an agent sandbox (see sandbox-auth.ts). */
124
+ export type AuthMode = 'm2m' | 'user' | 'sandbox';
124
125
  export interface ResolvedAccessToken {
125
126
  authMode: AuthMode;
126
127
  token: string;
package/dist/auth.js CHANGED
@@ -5,6 +5,7 @@ import { homedir } from 'node:os';
5
5
  import { join } from 'node:path';
6
6
  import { validateDeploymentAudience, validateDeploymentBaseUrl, } from '@sequenceholdings/artifact-studio/deployment-validation';
7
7
  import { withCrossProcessFileLock } from './file-lock.js';
8
+ import { isSandboxOrigin, readSandboxToken, SandboxAuthError, sandboxTarget } from './sandbox-auth.js';
8
9
  function hasErrorCode(error, code) {
9
10
  return error instanceof Error && Reflect.get(error, 'code') === code;
10
11
  }
@@ -475,7 +476,20 @@ function validateRealmTarget({ realm, targetUrl, }) {
475
476
  `${error instanceof Error ? error.message : String(error)}`, { cause: error });
476
477
  }
477
478
  }
479
+ async function sandboxAccessToken(targetUrl) {
480
+ const sandbox = sandboxTarget();
481
+ if (!sandbox)
482
+ return null;
483
+ if (targetUrl && !isSandboxOrigin({ target: sandbox, url: targetUrl })) {
484
+ throw new UnsafeAuthTargetError(`Refusing to send the sandbox token to ${targetUrl}: sandbox token mode only targets ${sandbox.baseUrl}.`);
485
+ }
486
+ return { authMode: 'sandbox', token: await readSandboxToken(sandbox) };
487
+ }
478
488
  export async function getAccessTokenWithMode(options) {
489
+ // Sandbox token mode replaces every other source, before any realm lookup.
490
+ const sandbox = await sandboxAccessToken(options?.targetUrl);
491
+ if (sandbox)
492
+ return sandbox;
479
493
  const realm = await realmForEnv(options?.env, { targetUrl: options?.targetUrl });
480
494
  if (options?.targetUrl)
481
495
  validateRealmTarget({ realm, targetUrl: options.targetUrl });
@@ -539,6 +553,8 @@ export async function tryGetAccessTokenWithMode(options) {
539
553
  throw err;
540
554
  if (err instanceof AuthTokenStoreError)
541
555
  throw err;
556
+ if (err instanceof SandboxAuthError)
557
+ throw err;
542
558
  if (options?.failClosedForM2m) {
543
559
  // Do not replace an invalid tenant registration with the Sequence realm:
544
560
  // that could hide a rejected discovery token host or inspect the wrong