Skip to content

fix(input-json): only read stdin with explicit --input-json -#341

Open
rafa-thayto wants to merge 2 commits into
mainfrom
fix/input-json-explicit-stdin
Open

fix(input-json): only read stdin with explicit --input-json -#341
rafa-thayto wants to merge 2 commits into
mainfrom
fix/input-json-explicit-stdin

Conversation

@rafa-thayto

Copy link
Copy Markdown
Contributor

Summary

In agent mode the program-level --input-json expander consumed any non-TTY stdin and parsed it as the options payload, even when --input-json was never passed. That broke two common patterns:

# shell loops — the clerk process swallows the rest of the worklist
while read -r app ins; do clerk config patch --app "$app" --instance "$ins" --json '' --yes; done < worklist.tsv

# commands that read their own stdin
cat payload.json | clerk api /users   # body was pre-empted and parsed as --input-json

Non-JSON stdin then failed with invalid_json before the command ran. This makes stdin read only with an explicit --input-json -; piped stdin is otherwise left untouched.

Test plan

  • bun test src/lib/input-json.test.ts and src/test/integration/input-json.test.ts pass
  • Updated unit tests assert piped stdin is ignored without --input-json -

Fixes #333

@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9662f59

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

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

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

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

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 Plus

Run ID: a20d8b61-8e1c-4bd2-969c-af86a03ac4a2

📥 Commits

Reviewing files that changed from the base of the PR and between e8a1e1b and 9662f59.

📒 Files selected for processing (4)
  • .changeset/input-json-explicit-stdin.md
  • packages/cli-core/src/commands/users/README.md
  • packages/cli-core/src/lib/input-json.test.ts
  • packages/cli-core/src/lib/input-json.ts
✅ Files skipped from review due to trivial changes (2)
  • packages/cli-core/src/commands/users/README.md
  • .changeset/input-json-explicit-stdin.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/cli-core/src/lib/input-json.test.ts
  • packages/cli-core/src/lib/input-json.ts

📝 Walkthrough

Walkthrough

expandInputJson now returns the original argv unchanged when --input-json is absent, and stdin is only read when --input-json - is explicitly provided. The helper that previously read optional piped stdin is removed. Tests now assert that piped JSON object, array, and non-JSON input are ignored without the flag, while the README and changeset document the updated behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 Title clearly states the stdin behavior fix for --input-json -.
Description check ✅ Passed Description matches the stdin parsing fix and test updates.
Linked Issues check ✅ Passed Changes satisfy #333 by only reading stdin with explicit --input-json - and updating docs and tests accordingly.
Out of Scope Changes check ✅ Passed No obvious out-of-scope changes; edits are limited to the stdin fix, related docs, and tests.

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

@wyattjoh wyattjoh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor test-cleanup note inline. The fix itself is correct: stopping expandInputJson from implicitly draining stdin is the right call, since that stdin is shared with commands that read their own body (clerk api, clerk config push).

Comment thread packages/cli-core/src/lib/input-json.test.ts
Implicit stdin consumption (when stdin was not a TTY) parsed any piped data as
the --input-json options payload, breaking `while read` loops and commands
that read their own stdin (e.g. `cat body.json | clerk api`). Require the
explicit `--input-json -` marker instead.

Fixes #333
@rafa-thayto rafa-thayto force-pushed the fix/input-json-explicit-stdin branch from 7d4ac9d to 9662f59 Compare June 26, 2026 19:59
@rafa-thayto rafa-thayto requested a review from wyattjoh June 26, 2026 20:00
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.

Agent mode parses any piped stdin as --input-json, breaking shell loops and preempting explicit flags

2 participants