Skip to content

feat: add deno deploy whoami and conflict hint#95

Merged
crowlKats merged 2 commits into
mainfrom
feat/agent-whoami
May 28, 2026
Merged

feat: add deno deploy whoami and conflict hint#95
crowlKats merged 2 commits into
mainfrom
feat/agent-whoami

Conversation

@crowlbot
Copy link
Copy Markdown
Contributor

Summary

Stacked on #94 (→ #93#92#91). Adds the auth-verification command an agent typically runs first to confirm the token before doing anything destructive.

What's in this PR

`deno deploy whoami`

  • Calls `orgs.list` (one round-trip to the backend).
  • Human mode prints "Authenticated. N reachable organizations:" plus a slug/name/plan table.
  • `--json` mode emits `{ authenticated: true, user: null, orgs: [...] }`. `user` is currently `null` because the deployng tRPC router does not expose user identity; when an `account.me` procedure lands, the field will gain `{ id, name, email, ... }` and existing consumers reading `authenticated` / `orgs[]` keep working.
  • A bad token surfaces the global `AUTH_INVALID_TOKEN` envelope on stderr with exit 3 — no browser is opened.

Conflict hint in `mapTrpcError()`

When the backend returns `SLUG_ALREADY_IN_USE` (the shared "name in use" error across apps and databases), the global error envelope now carries:
```json
{ "error": { "code": "SLUG_ALREADY_IN_USE", "message": "...", "hint": "A resource with that name already exists. Use a different name, or run the corresponding update/publish command against the existing one." } }
```
The exit code stays `CONFLICT=5` either way.

Test plan

  • `deno fmt` clean
  • `deno lint` clean
  • `deno check main.ts` — pre-existing TS/Cliffy errors only.
  • `deno test -A tests/agent.test.ts` — 7/7 pass (new test asserts `whoami --json` with a bad token returns exit 3 + `AUTH_INVALID_TOKEN` envelope, never opens a browser).

Follow-up

A separate PR against `denoland/deployng` will add a proper `account.me` tRPC procedure so `whoami --json` can return a real `user` payload. The CLI side already has the shape ready for it.

🤖 Generated with Claude Code

@crowlbot crowlbot force-pushed the feat/agent-list-commands branch from 3b79e96 to 83f452e Compare May 13, 2026 13:55
@crowlbot crowlbot force-pushed the feat/agent-whoami branch from fa27fdd to 2ae29f3 Compare May 13, 2026 13:57
@crowlKats crowlKats force-pushed the feat/agent-list-commands branch 3 times, most recently from 141abc7 to 26b8cd0 Compare May 28, 2026 09:54
Base automatically changed from feat/agent-list-commands to main May 28, 2026 10:12
@crowlKats crowlKats force-pushed the feat/agent-whoami branch from 2ae29f3 to dc1e6bd Compare May 28, 2026 10:38
crowlbot and others added 2 commits May 28, 2026 12:41
Make the CLI usable by AI agents and CI bots:

- Global `--json` flag emits a single JSON object/array on stdout and a
  structured `{ error: { code, message, hint, traceId } }` envelope on
  stderr. Suppresses spinners, progress bars, and ANSI color so output
  pipes cleanly into `jq`. Wired into `publish` (final result with
  revisionId, URL, status, timelines) and `create` (including
  `--dry-run`, which now emits the resolved build config as JSON).

- Global `-y, --non-interactive, --yes` flag makes `requireInteractive()`
  fail fast with a clear `NON_INTERACTIVE_REQUIRED` error instead of
  hanging on stdin, even on a TTY. Same flag on both `deploy` and
  `sandbox` roots.

- `ExitCode` enum (OK=0, GENERIC=1, USAGE=2, AUTH=3, NOT_FOUND=4,
  CONFLICT=5, NETWORK=6). `error()` accepts `{ code, errorCode, hint,
  response }` and exits with the matching numeric code. tRPC errors are
  mapped via `mapTrpcError()`: 401/403/NOT_AUTHENTICATED/TOKEN_EXPIRED →
  AUTH, 404 → NOT_FOUND, 409 → CONFLICT, 5xx → NETWORK. Invalid-token
  path emits `AUTH_INVALID_TOKEN` with an explicit hint pointing at
  `DENO_DEPLOY_TOKEN` rather than retrying through a browser.

- Move the keychain-unavailable warning from stdout to stderr so it
  doesn't pollute machine-readable output.

Adds `tests/agent.test.ts` covering JSON dry-run, non-interactive
short-circuit, `AUTH_INVALID_TOKEN` envelope, and the `-y` alias.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`deno deploy whoami` lets an agent verify the current token without
side effects: calls `orgs.list`, prints a slug/name/plan table in human
mode, and emits `{ authenticated, user, orgs }` in `--json` mode.
`user` is currently `null` because the deployng tRPC router does not
expose user identity; when an `account.me` procedure lands, the field
will gain `{ id, name, email, ... }` and existing consumers reading
`authenticated` / `orgs[]` keep working. A bad token surfaces the
global `AUTH_INVALID_TOKEN` envelope on stderr with exit 3 — no
browser is opened.

Also a small idempotency upgrade in `mapTrpcError()`: when the backend
returns `SLUG_ALREADY_IN_USE`, the global error envelope now carries a
hint pointing at the recovery path. Exit code stays `CONFLICT=5`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@crowlKats crowlKats force-pushed the feat/agent-whoami branch from dc1e6bd to 4a56bfe Compare May 28, 2026 10:41
@crowlKats crowlKats merged commit f29d034 into main May 28, 2026
4 checks passed
@crowlKats crowlKats deleted the feat/agent-whoami branch May 28, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants