Skip to content

Fix #10: Add --json output to klaatcode whoami - #12

Merged
aakashrajput merged 2 commits into
KlaatAI:mainfrom
nandanadileep:fix-issue-10
Jul 18, 2026
Merged

Fix #10: Add --json output to klaatcode whoami#12
aakashrajput merged 2 commits into
KlaatAI:mainfrom
nandanadileep:fix-issue-10

Conversation

@nandanadileep

Copy link
Copy Markdown
Contributor

Fixes #10

#10

@aakashrajput

Copy link
Copy Markdown
Member

@nandanadileep please attach the ss of the output. Thanks

@github-actions

Copy link
Copy Markdown
Contributor

🤖 KlaatAI Review Bot (powered by Klaatu, advisory only — a maintainer makes the real call)

Issue match
The diff correctly updates runWhoami in src/auth/login.ts to accept the json parameter and outputs the exact fields requested (signedIn, email, plan, backend) while preserving the original colored text when json is false. However, the issue explicitly requested adding the --json flag to the CLI parser in src/main.tsx. That file is missing from the changed files list.

Test coverage
No tests were added or modified. Tests need to verify that runWhoami(url, true) outputs valid JSON with the correct schema for all three states: unauthenticated, authenticated (success), and authenticated but API unreachable (catch block). They should also assert that runWhoami(url, false) produces the original string format unchanged.

Correctness concerns
In src/auth/login.ts, the catch block outputs the JSON error state to console.log. While correct for machine parsing on stdout, it diverges from the non-JSON path which uses console.error. Additionally, the diff removes the trailing newline at the end of the file, which may trigger linting failures. Finally, if src/main.tsx wasn't updated, the json argument will never be passed as true from the CLI.

Verdict
Needs human judgment call on whether the CLI flag wiring in src/main.tsx is missing from this PR or handled in a separate commit, and whether the stdout/stderr divergence in the JSON catch block is intentional.

This is an automated review to help triage faster, not a gate. Nothing here blocks merging.

- Add --json option to `klaatai whoami` in src/main.tsx and pass it through to runWhoami
- Emit JSON error state on console.error (consistent with non-JSON catch path that also uses stderr)
- Restore trailing newline at end of src/auth/login.ts
- Add src/auth/login.test.ts covering all three states (unauthenticated / authenticated+online / authenticated+unreachable) for both json:false and json:true
@nandanadileep

Copy link
Copy Markdown
Contributor Author

Addressed the review bot's concerns + attaching the requested output (cc @aakashrajput).

Changes in this push (8d661e9)

  1. src/main.tsx — wired the missing --json flag into the whoami command. opts.json === true is now passed to runWhoami.
  2. src/auth/login.ts catch block — JSON error state now goes to console.error (was console.log), matching the non-JSON path that already uses stderr.
  3. src/auth/login.ts EOL — restored the missing trailing newline.
  4. src/auth/login.test.ts — new file covering all three observable states for both json:false and json:true:
    • unauthenticated
    • authenticated + backend online
    • authenticated + backend unreachable (catch)

Typecheck (tsc --noEmit) passes. Tests run under bun:test (couldn't run them locally — bun isn't installed on this machine — but they typecheck against the project's tests-tsconfig.json).

`klaatai whoami` output

===== STATE 1: Unauthenticated =====
  Not signed in. Run: klaatai login
--- (json) ---
{
  "signedIn": false,
  "backend": "unknown"
}

===== STATE 2: Authenticated, API unreachable =====
  Could not reach KlaatAI API.
--- (json) ---
{
  "signedIn": true,
  "email": null,
  "plan": null,
  "backend": "offline"
}

===== STATE 3: Authenticated, API online =====

  Account:  demo@klaatai.com
  Plan:     pro
  Session:  subscription (JWT)
  Backend:  Online

--- (json) ---
{
  "signedIn": true,
  "email": "demo@klaatai.com",
  "plan": "pro",
  "backend": "online"
}

Note: output captured via a local mock HTTP server for the "API online" state. Stderr/stdout split verified (e.g. STATE 2 non-JSON line and STATE 2 JSON object both go to stderr, per the change).

@github-actions

Copy link
Copy Markdown
Contributor

🤖 KlaatAI Review Bot (powered by Klaatu, advisory only — a maintainer makes the real call)

Issue match
Perfectly addresses the linked issue. Adds the --json flag in src/main.tsx, threads it to runWhoami in src/auth/login.ts, and outputs the exact requested JSON schema while preserving the original colored output when the flag is omitted.

Test coverage
Excellent coverage in the new src/auth/login.test.ts. It mocks credentials and the API client to test all three observable states (unauthenticated, online, offline) for both json: false and json: true. It also explicitly asserts that no ANSI/colored banners leak into JSON mode. No critical test gaps for this scope.

Correctness concerns
One interaction to flag: in the catch block of src/auth/login.ts, JSON output is routed to console.error (stderr) instead of console.log (stdout). While the tests explicitly verify this, it breaks the expectation that klaatcode whoami --json | jq . works cleanly when the backend is offline, since stdout will be empty and the pipe will fail.

Verdict
Needs human judgment call on whether JSON error output should route to stdout instead of stderr to preserve pipeability in CI scripts.

This is an automated review to help triage faster, not a gate. Nothing here blocks merging.

@aakashrajput

Copy link
Copy Markdown
Member

@nandanadileep
Thanks a lot for your contribution! 🎉

Really appreciate you taking the time to improve KlaatCode. Your contribution helps make the project better for everyone.

If you haven't already, we'd love it if you could ⭐ star the repository and follow @KlaatAI on GitHub to stay updated with new features and releases.

Feel free to keep using KlaatAI for your projects, and don't hesitate to open more issues, suggest ideas, or submit future PRs—we're always happy to have contributors like you in the community.

Looking forward to seeing your next contribution. Happy coding! 🚀

@aakashrajput
aakashrajput merged commit 841fb44 into KlaatAI:main Jul 18, 2026
2 checks passed
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.

Add --json output to klaatcode whoami

2 participants