diff --git a/.changeset/skills-agent-starts-device-login.md b/.changeset/skills-agent-starts-device-login.md new file mode 100644 index 0000000000..ef8e583d59 --- /dev/null +++ b/.changeset/skills-agent-starts-device-login.md @@ -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. diff --git a/skills/stash-auth/SKILL.md b/skills/stash-auth/SKILL.md index a2ea408b55..5b46d8b82c 100644 --- a/skills/stash-auth/SKILL.md +++ b/skills/stash-auth/SKILL.md @@ -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 ` 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 + 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:.:`) 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`. diff --git a/skills/stash-cli/SKILL.md b/skills/stash-cli/SKILL.md index 4ea65c39ca..ec7d78cab5 100644 --- a/skills/stash-cli/SKILL.md +++ b/skills/stash-cli/SKILL.md @@ -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:.:`). +- 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 ` (env `STASH_REGION`), `--json`, `--no-open`, `--supabase` / `--drizzle` / `--prisma` (referrer tracking only).