Repository navigation
feat!: read piped input only with an explicit --stdin flag - #111
Conversation
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`.
doistbot
left a comment
There was a problem hiding this comment.
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.
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.
|
🎉 This PR is included in version 4.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Breaking change. Piped stdin is no longer read implicitly. Commands that take piped input now need an explicit
--stdinflag, usingreadStdinfrom@doist/cli-core1.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:
main,{ sleep 2; echo 'Slow body'; } | tdc msg update <ref> --dry-runfails withMISSING_CONTENT. On this branch, the same pipe with--stdinpostsSlow body.tdcwith stdin attached to a pipe, the command read that stream even when content was passed as an argument, and stdin won.What changes
thread create,thread reply,thread update,comment update,conversation reply,msg update$EDITOR--stdin, else$EDITORthread mark-read,thread mark-unread--stdin. With no refs and no--stdin, they show helpmigrate urls--stdin--stdinwith a content or URL argument is aCONFLICTING_OPTIONSerror.--stdinwith stdin on an interactive terminal fails at once withSTDIN_IS_TTYinstead of waiting for input.#comment lines in piped ref lists are still skipped.$EDITORfallback and--non-interactive/--interactiveare unchanged.Migration: add
--stdinwherever input is piped in, e.g.echo "Reply" | tdc thread reply <ref> --stdinorprintf "id:…\n" | tdc thread mark-read --stdin --yes.The help examples, the skill reference (
content.tsandSKILL.md),docs/SPEC.mdandCODEBASE.mdall use--stdin. The timeout-basedreadStdin/readStdinToEndinsrc/lib/input.tsare replaced byreadContentandreadStdinLines, which only read when asked.Testing
npm run verifypasses.process.stdinwithmockStdinfrom@doist/cli-core/testingand mock onlyopenEditor. Tests that pipe input now pass--stdin.thread replyposts its argument and ignores piped stdin without--stdin.--stdin, piped input is left unread.--stdintrims the piped content.--stdinwith an argument fails withCONFLICTING_OPTIONS.--stdinon a terminal fails withSTDIN_IS_TTY.mark-readwith no refs shows help instead of reading piped refs.migrate urlsignores piped URLs without--stdinand rejects an argument plus--stdin.msg updateandconversation replyread with--stdin.readContentand the mark-read help check, the fivethread --stdinbehaviour tests fail. The trim test passes either way, as it should.--dry-runonmsg update:--stdinpreviews it.--stdinpreviews the argument.MISSING_CONTENT.--stdingivesCONFLICTING_OPTIONS.--stdinpreviews the slow content.--stdingivesSTDIN_IS_TTY.thread mark-readwith piped refs and no--stdinprints its help.