Skip to content

feat(whoami): show linked application and add --json output#265

Merged
rafa-thayto merged 1 commit into
mainfrom
rafa-thayto/whoami-linked
May 20, 2026
Merged

feat(whoami): show linked application and add --json output#265
rafa-thayto merged 1 commit into
mainfrom
rafa-thayto/whoami-linked

Conversation

@rafa-thayto
Copy link
Copy Markdown
Contributor

Summary

  • clerk whoami now prints a Linked to MyApp (app_xxx) line on stderr above the next-steps when the working directory is linked to a Clerk application — preserving stdout-as-email so existing pipes (e.g. clerk whoami | grep @) keep working.
  • New --json flag (and matching agent-mode auto-JSON) emits a structured payload on stdout covering email and link state, including normalized nulls for missing optional fields.
  • Adds a tiny profileLabel(profile) helper in lib/config.ts mirroring appLabel(app) from lib/app-picker.ts, so the local Profile shape and the live Application shape have parallel display formatters.

Stacked on #250. Base is rafa-thayto/more-next-steps. GitHub will auto-rebase this onto main when #250 merges. Diff against this PR's base is the whoami-only delta.

JSON shape

{
  "email": "alice@example.com",
  "linked": {
    "appId": "app_xxx",
    "appName": "MyApp",
    "instances": { "development": "ins_dev_xxx", "production": "ins_prod_xxx" },
    "resolvedVia": "remote",
    "path": "github.com/clerk/cli"
  }
}

linked is null when not linked or when profile resolution throws (best-effort path preserved from #250's commit `1652c122`).

Test plan

  • `bun run format && bun run lint && bun run typecheck && bun run test` (all green locally — 97 test files)
  • `bun test packages/cli-core/src/commands/whoami/index.test.ts` (11 cases: 3 prior auth paths + 4 new human-mode + 4 new JSON/agent)
  • Manual smoke — linked path: `clerk whoami` shows email on stdout, "Linked to ..." on stderr, next-steps follow
  • Manual smoke — `clerk whoami --json` emits a single JSON object on stdout, no next-steps
  • Manual smoke — unlinked path (fresh `/tmp` directory): no "Linked to" line
  • Pipe contract: `clerk whoami | grep @` returns just the email
  • `bun changeset status --since=origin/main` exits 0 (changeset `whoami-linked.md` written, `clerk: minor`)

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 6, 2026

🦋 Changeset detected

Latest commit: 0ac923e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
clerk Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rafa-thayto rafa-thayto force-pushed the rafa-thayto/whoami-linked branch 2 times, most recently from 4a7c065 to dbbf9be Compare May 7, 2026 12:12
@rafa-thayto rafa-thayto force-pushed the rafa-thayto/more-next-steps branch from c42b5a2 to 36237e7 Compare May 7, 2026 12:12
Base automatically changed from rafa-thayto/more-next-steps to main May 7, 2026 13:43
@rafa-thayto rafa-thayto force-pushed the rafa-thayto/whoami-linked branch from dbbf9be to 826d9da Compare May 7, 2026 13:48
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR updates clerk whoami to display linked application details and adds a --json flag. It introduces WhoamiOptions and profileLabel, wires --json into the CLI, resolves a local profile best-effort, emits a structured JSON payload when requested or in agent mode, and otherwise prints the email plus a conditional "Linked to …" line to stderr. Tests and documentation were expanded to cover human and JSON modes, normalization rules, and stdout/stderr pipe contract.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main changes: adding linked application display and a --json flag to the whoami command.
Description check ✅ Passed The description is directly related to the changeset, providing detailed context about the linked application feature, --json flag, JSON payload shape, and a comprehensive test plan.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dmoerner
Copy link
Copy Markdown
Contributor

dmoerner commented May 8, 2026

!snapshot

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Snapshot published

npm install -g clerk@1.2.1-snapshot.826d9da
Package Version
clerk 1.2.1-snapshot.826d9da

Published from 826d9da

@rafa-thayto rafa-thayto force-pushed the rafa-thayto/whoami-linked branch from 826d9da to 9173726 Compare May 9, 2026 12:12
@rafa-thayto rafa-thayto requested a review from wyattjoh May 10, 2026 12:11
@rafa-thayto rafa-thayto force-pushed the rafa-thayto/whoami-linked branch from 9173726 to a565eba Compare May 12, 2026 12:10
@rafa-thayto rafa-thayto force-pushed the rafa-thayto/whoami-linked branch from a565eba to cad89f0 Compare May 14, 2026 12:10
@rafa-thayto rafa-thayto requested a review from wyattjoh May 14, 2026 12:10
@rafa-thayto rafa-thayto force-pushed the rafa-thayto/whoami-linked branch from cad89f0 to 7d9b2ca Compare May 16, 2026 12:12
Surfaces the linked Clerk application directly in `clerk whoami` so users
don't have to read between the lines of next-steps to know which app the
working directory is bound to. Adds a `--json` flag (and matching agent-mode
auto-JSON) so scripts and AI agents can consume the email + link state as a
single structured payload.

The human-mode pipe contract is preserved: stdout is still just the email,
the link line and next-steps stay on stderr.
@rafa-thayto rafa-thayto force-pushed the rafa-thayto/whoami-linked branch from 7d9b2ca to 0ac923e Compare May 20, 2026 12:12
@rafa-thayto rafa-thayto merged commit 2647f0d into main May 20, 2026
10 checks passed
@rafa-thayto rafa-thayto deleted the rafa-thayto/whoami-linked branch May 20, 2026 15:02
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.

3 participants