Skip to content

feat!: read piped input only with an explicit --stdin flag - #111

Merged
scottlovegrove merged 2 commits into
mainfrom
feat/explicit-stdin
Nov 7, 2026
Merged

scottlovegrove merged 2 commits into
mainfrom
feat/explicit-stdin

Conversation

@scottlovegrove

Copy link
Copy Markdown
Collaborator

Breaking change. Piped stdin is no longer read implicitly. Commands that take piped input now need an explicit --stdin flag, using readStdin from @doist/cli-core 1.8.0 (todoist/cli-core#172), the same way todoist-cli and outline-cli take piped input.

Why

These commands read stdin whenever it wasn't a terminal, and in non-interactive mode gave up if no byte arrived within 100ms. That caused two problems:

  • A slow producer lost its input. On main, { sleep 2; echo 'Slow body'; } | tdc msg update <ref> --dry-run fails with MISSING_CONTENT. On this branch, the same pipe with --stdin posts Slow body.
  • An open stdin got read without anyone asking. When a script or agent runs tdc with stdin attached to a pipe, the command read that stream even when content was passed as an argument, and stdin won.

What changes

Command Before After
thread create, thread reply, thread update, comment update, conversation reply, msg update Piped stdin, else the content argument, else $EDITOR The content argument, or piped stdin with --stdin, else $EDITOR
thread mark-read, thread mark-unread Refs piped one per line were added to the positional refs The same, but only with --stdin. With no refs and no --stdin, they show help
migrate urls The URL argument, else piped stdin The URL argument, or piped stdin with --stdin
  • --stdin with a content or URL argument is a CONFLICTING_OPTIONS error.
  • --stdin with stdin on an interactive terminal fails at once with STDIN_IS_TTY instead of waiting for input.
  • Piped content is still trimmed, and # comment lines in piped ref lists are still skipped.
  • The $EDITOR fallback and --non-interactive / --interactive are unchanged.

Migration: add --stdin wherever input is piped in, e.g. echo "Reply" | tdc thread reply <ref> --stdin or printf "id:…\n" | tdc thread mark-read --stdin --yes.

The help examples, the skill reference (content.ts and SKILL.md), docs/SPEC.md and CODEBASE.md all use --stdin. The timeout-based readStdin / readStdinToEnd in src/lib/input.ts are replaced by readContent and readStdinLines, which only read when asked.

Testing

  • npm run verify passes.
  • The tests now stand in for process.stdin with mockStdin from @doist/cli-core/testing and mock only openEditor. Tests that pipe input now pass --stdin.
  • New tests:
    • thread reply posts its argument and ignores piped stdin without --stdin.
    • With no content and no --stdin, piped input is left unread.
    • --stdin trims the piped content.
    • --stdin with an argument fails with CONFLICTING_OPTIONS.
    • --stdin on a terminal fails with STDIN_IS_TTY.
    • mark-read with no refs shows help instead of reading piped refs.
    • migrate urls ignores piped URLs without --stdin and rejects an argument plus --stdin.
    • msg update and conversation reply read with --stdin.
  • With implicit reading temporarily put back into readContent and the mark-read help check, the five thread --stdin behaviour tests fail. The trim test passes either way, as it should.
  • Built CLI with a dummy token and --dry-run on msg update:
    • Piped input with --stdin previews it.
    • Piped input plus an argument without --stdin previews the argument.
    • Piped input with neither gives MISSING_CONTENT.
    • An argument plus --stdin gives CONFLICTING_OPTIONS.
    • A 2s-slow pipe with --stdin previews the slow content.
    • Under a real pty, --stdin gives STDIN_IS_TTY.
    • thread mark-read with piped refs and no --stdin prints its help.
  • Not run against a live Comms workspace.

Content commands (thread create/reply/update, comment update,
conversation reply, msg update), thread mark-read/mark-unread and
migrate urls used to read stdin whenever it was not a terminal, and in
non-interactive mode gave up after 100ms with no first byte. A slow
producer lost its input, and a script or agent with an open stdin got
it read when it had passed content as an argument.

Each of these commands now takes --stdin and only reads stdin when it
is passed, through readStdin from @doist/cli-core 1.8.0. --stdin with a
content or URL argument is a CONFLICTING_OPTIONS error, and --stdin on
an interactive terminal fails at once with STDIN_IS_TTY. Without
content or --stdin the editor fallback is unchanged. mark-read and
mark-unread with no refs and no --stdin show help, as they did on a
terminal before.

BREAKING CHANGE: piped stdin is no longer read implicitly. Add --stdin
to thread create, thread reply, thread update, comment update,
conversation reply, msg update, thread mark-read, thread mark-unread
and migrate urls when piping input in, e.g.
`echo "Reply" | tdc thread reply <ref> --stdin`.
@scottlovegrove scottlovegrove self-assigned this Nov 7, 2026

@doistbot doistbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR adds an explicit --stdin flag so piped input is only read on request, replacing the implicit non-interactive stdin read with a clear, opt-in contract across all affected commands. The implementation is coherent and consistent — the flag wiring, conflict and TTY guards, error codes, help text, and skill/docs updates all land together, and tests cover both the new behavior and regressions for the old implicit reads. One small thing worth tightening: migrate urls re-implements the --stdin conflict check and input-selection branch that readContent in src/lib/input.ts now centralizes — reusing readContent (optionally parameterized with a label to keep the URL-specific error wording) would avoid maintaining a second copy of that logic.

Share Feedback • Review Logs

Comment thread src/commands/migrate/urls.ts Resolved
migrate urls had its own copy of the --stdin conflict check and input
selection. Give readContent an optional label for the conflicting-options
message and use it there, so the URL wording stays the same.
@scottlovegrove scottlovegrove added the 🚢 Ship PR requires passing checks before merge, but no independent human review. label Nov 7, 2026
@scottlovegrove
scottlovegrove merged commit e797a63 into main Nov 7, 2026
6 checks passed
@scottlovegrove
scottlovegrove deleted the feat/explicit-stdin branch November 7, 2026 14:10
doist-release-bot Bot added a commit that referenced this pull request Nov 7, 2026
## [4.0.0](v3.10.0...v4.0.0) (2026-11-07)

### ⚠ BREAKING CHANGES

* read piped input only with an explicit --stdin flag (#111)

### Features

* read piped input only with an explicit --stdin flag ([#111](#111)) ([e797a63](e797a63))
doist-release-bot Bot added a commit that referenced this pull request Nov 7, 2026
## [4.0.0](v3.10.0...v4.0.0) (2026-11-07)

### ⚠ BREAKING CHANGES

* read piped input only with an explicit --stdin flag (#111)

### Features

* read piped input only with an explicit --stdin flag ([#111](#111)) ([e797a63](e797a63))
@doist-release-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released 🚢 Ship PR requires passing checks before merge, but no independent human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants