Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/skills-agent-starts-device-login.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"stash": patch
---

The `stash-cli` and `stash-auth` skills now tell an agent to start
`stash auth login --json` itself when local work stops on missing
credentials, and to show the user the approval URL, rather than stop, ask for
`CS_*` values, or run `stash env`. They also say how to choose `--region`
instead of guessing it.
36 changes: 33 additions & 3 deletions skills/stash-auth/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,39 @@ client-side strategy model applies to apps behind the Proxy.
## Quick diagnosis

1. **`NOT_AUTHENTICATED` locally** → `npx stash auth login` (dev profile),
or export the four `CS_*` variables. With `@cipherstash/auth`'s
`AutoStrategy` and `CS_WORKSPACE_CRN` set, log in to that workspace, or
unset it; the default client follows the CLI's current workspace.
or export the four `CS_*` variables. An agent starts the login itself:

- Run `npx stash auth login --json --region <slug>` in the background.
Show the user the `verificationUriComplete` URL and the `userCode` it
prints, and wait for `device_bound`. The code lets the user check that
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
the approval page is the one you started.
- The code expires after about 15 minutes. If the process prints
`{ "status": "error", ... }` or exits without `device_bound`, show the
user its `message` and `hint`. Then start the login again, with a new
code.
- Do not guess the region. Take it from `CS_WORKSPACE_CRN`
(`crn:<region>.<provider>:<workspace-id>`) when one is set. Otherwise
ask the user, offering the slugs from `npx stash auth regions --json`.
- The login gives a key for the workspace the user approves in the
browser. Tell them which one to approve: the one the error names, or
the one in `CS_WORKSPACE_CRN`. If neither names a workspace, ask the
user which workspace the project uses before they approve.
- After `device_bound`, run the failing command again to confirm it
works.

The full loop is in `stash-cli` under Authentication. Do the same for an
SDK in any language that reports no credentials or no client key, except
`@cipherstash/stack/wasm-inline`. That client never reads the profile, so
a login does not help it: it needs `clientId` and `clientKey` in its
config (see `stash-edge`).

The CLI needs Node 22 or later. Where there is none, ask the user to
install it or to log in there themselves. Never run `stash env` to get
local credentials: it mints a new access key.

With `@cipherstash/auth`'s `AutoStrategy` and `CS_WORKSPACE_CRN` set, log
in to that workspace, or unset it. The default client follows the CLI's
current workspace.
2. **Works locally, 401 in CI/production** → the deployed environment lacks
the `CS_*` variables, or they're from the wrong workspace — mint with
`stash env`, compare `CS_WORKSPACE_CRN`.
Expand Down
33 changes: 33 additions & 0 deletions skills/stash-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,39 @@ The working loop is:
4. To confirm, trust the event stream or run any authenticated command —
never inspect `~/.cipherstash` (see "Never read these").

**When to start it.** Start this loop yourself whenever local work stops on
missing credentials. That includes a `stash` command, a test, or an SDK in any
language (TypeScript, Rust, Go) reporting `NOT_AUTHENTICATED`, "no
credentials", "no client key", or "run `stash auth login`", except a client
built from `@cipherstash/stack/wasm-inline`. That one never reads the profile,
so a login does not help it: it needs `clientId` and `clientKey` in its config
(see `stash-edge`). It also includes a
profile that exists but has no key for the workspace the code uses. A login
gives a key for the workspace the user approves in the browser, and the
command has no flag to choose it. So tell the user which workspace to
approve: the one the error names, or the one in `CS_WORKSPACE_CRN`. After
`device_bound`, run the failing command again to confirm it works. Do not
stop the task to hand the problem back. Do not ask the user to paste `CS_*`
values. And do not run `stash env` to get local credentials, because it mints
a new access key each time it runs. The user only has to open one link.

`stash` is a Node CLI, and needs Node 22 or later. If `npx` is not available
where the code runs (a sandbox for a Go or Rust service, say), say so, and ask
the user to install Node there or to run `stash auth login` in that
environment themselves.

**Choose the region; do not guess it.** With `--json`, without a terminal, or
with `CI=true` (or `CI=1`), `auth login` needs `--region` (or
`STASH_REGION`). Without either, it exits with "Cannot resolve a region
without a prompt". A workspace lives in one region:

- If a `CS_WORKSPACE_CRN` is in view, use the region it names
(`crn:<region>.<provider>:<workspace-id>`).
- Otherwise ask the user, offering the slugs from
`npx stash auth regions --json`.

A login in another region does not reach a workspace in this one.

**Authenticate before `stash init`.** Init's authenticate step uses the interactive path, so an agent running `init` unauthenticated makes the CLI try to open a browser on the agent's machine — and in a non-TTY it exits with `region_required` unless `--region` or `STASH_REGION` is set. Once a valid token exists, init logs `Using workspace X (region)` and moves on silently.

Flags: `--region <slug>` (env `STASH_REGION`), `--json`, `--no-open`, `--supabase` / `--drizzle` / `--prisma` (referrer tracking only).
Expand Down
Loading