Skip to content

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

Open
rafa-thayto wants to merge 1 commit into
mainfrom
rafa-thayto/whoami-linked
Open

feat(whoami): show linked application and add --json output#265
rafa-thayto wants to merge 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: 9173726

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
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4cf00505-30aa-47e1-bc19-a1cce1e1a984

📥 Commits

Reviewing files that changed from the base of the PR and between 826d9da and 9173726.

📒 Files selected for processing (8)
  • .changeset/whoami-linked.md
  • README.md
  • packages/cli-core/src/cli-program.ts
  • packages/cli-core/src/commands/whoami/README.md
  • packages/cli-core/src/commands/whoami/index.test.ts
  • packages/cli-core/src/commands/whoami/index.ts
  • packages/cli-core/src/lib/config.ts
  • packages/cli-core/src/test/lib/stubs.ts
✅ Files skipped from review due to trivial changes (3)
  • .changeset/whoami-linked.md
  • README.md
  • packages/cli-core/src/commands/whoami/README.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/cli-core/src/lib/config.ts
  • packages/cli-core/src/commands/whoami/index.ts
  • packages/cli-core/src/test/lib/stubs.ts
  • packages/cli-core/src/commands/whoami/index.test.ts

📝 Walkthrough

Walkthrough

This PR extends the clerk whoami command to display linked Clerk application details and adds a --json flag for structured output. The implementation introduces a WhoamiOptions interface and profileLabel utility, updates CLI wiring to pass the parsed flag, performs best-effort profile resolution, emits JSON when requested or in agent mode, and otherwise prints email plus a linked-app line to stderr when resolved. Tests and documentation were updated 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 accurately summarizes the main changes: showing linked application info and adding --json output to the whoami command.
Description check ✅ Passed The description is directly related to the changeset, detailing the new linked application display, --json flag, and helper function additions.
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.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

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 826d9da to 9173726 Compare May 9, 2026 12:12
@rafa-thayto rafa-thayto requested a review from wyattjoh May 10, 2026 12:11
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