Skip to content

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

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

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

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
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 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: 5e534e87-d8fe-4fae-838a-b79aeb53f157

📥 Commits

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

📒 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

📝 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 function, updates CLI program wiring to handle the new flag, implements best-effort profile resolution in the command handler, and routes output to either JSON or human-readable formats. Tests cover authentication, linked app display with fallback labels, best-effort resolution, JSON payload structure, and agent mode behavior. Documentation updates specify stdout/stderr expectations, JSON schema, and pipe-friendly formatting.

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: adding linked application display and a --json output flag to the whoami command.
Description check ✅ Passed The description is directly related to the changeset, providing detailed context about the implementation and test plan for the whoami feature enhancements.
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.

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.

1 participant