You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support piped stdout in dictate: auto-start single utterance (#193)
Enable `assembly dictate` to work in pipelines by detecting when stdout
is not a TTY and automatically recording a single utterance without
requiring a toggle keystroke.
## Summary
When `assembly dictate` is piped to another command (e.g., `assembly
dictate | assembly llm "…"`), the downstream consumer blocks waiting for
input while dictate idles in its interactive loop. This change detects
piped stdout and switches to single-shot mode, which auto-starts
recording and exits after one utterance so the transcript flows to the
next stage.
## Key Changes
- **Extract `_capture_and_transcribe()` helper**: Consolidates the
record-and-transcribe logic previously duplicated in the session loop,
reducing code duplication and enabling reuse for both interactive and
single-shot modes.
- **Add `single` parameter to `_session()`**: Controls whether to
auto-start one utterance (piped or `--once`) or enter the interactive
idle-toggle loop. The docstring clarifies the two modes and their use
cases.
- **Detect piped stdout in `run_dictate()`**: Import `stdio` module and
call `stdio.stdout_is_tty()` to determine if stdout is a pipe. Set
`single = opts.once or not stdio.stdout_is_tty()` to enable single-shot
mode for both `--once` flag and piped scenarios.
- **Conditional start prompt**: Only show the interactive "Press Enter
to start recording…" prompt when in interactive mode (`not single`),
since single-shot mode announces "● Recording" when the mic opens.
- **Update help text and examples**:
- Clarify `--once` help: "Record one utterance immediately, then exit"
- Expand command docstring to document piped and `--once` behavior
- Add example: `assembly dictate | assembly llm "write a conventional
commit"`
- **Test coverage**: Add
`test_piped_stdout_auto_starts_one_utterance_then_exits()` to verify
that piped stdout triggers single-shot mode, auto-starts recording, and
exits after one utterance. Mock `stdio.stdout_is_tty()` to return
`False` and verify the session reads no blocking idle key (only the
zero-timeout in-recording poll).
## Implementation Details
- The `stdio` module is imported alongside `sync_stt` in `_exec.py` to
check TTY status.
- Test seams mock `stdio.stdout_is_tty()` to default to `True`
(interactive), preventing capsys from forcing single-utterance mode in
unrelated tests.
- The single-shot path calls `_capture_and_transcribe()` once and
returns, while the interactive path loops until a quit key or `--once`
flag.
https://claude.ai/code/session_01KchiKPHFyhKBpQf6QkeyfT
Co-authored-by: Claude <noreply@anthropic.com>
0 commit comments