wavetermdev/waveterm · error
stdin (-) can only be used once
Error message
stdin (-) can only be used once
What it means
The `wsh ai` command allows the special `-` argument (stdin) at most once. A stdinUsed flag guards this; passing a second `-` returns this error before reading anything, because each `-` would require a second sequential read of os.Stdin which the command does not support.
Source
Thrown at cmd/wsh/cmd/wshcmd-ai.go:97
const maxFileCount = 15
const rpcTimeout = 30000
var allFiles []wshrpc.AIAttachedFile
var stdinUsed bool
if len(args) > maxFileCount {
return fmt.Errorf("too many files (maximum %d files allowed)", maxFileCount)
}
for _, filePath := range args {
var data []byte
var fileName string
var mimeType string
var err error
if filePath == "-" {
if stdinUsed {
return fmt.Errorf("stdin (-) can only be used once")
}
stdinUsed = true
data, err = io.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("reading from stdin: %w", err)
}
fileName = "stdin"
mimeType = "text/plain"
} else {
fileInfo, err := os.Stat(filePath)
if err != nil {
return fmt.Errorf("accessing file %s: %w", filePath, err)
}
absPath, err := filepath.Abs(filePath)
if err != nil {
return fmt.Errorf("getting absolute path for %s: %w", filePath, err)
}View on GitHub (pinned to a4447c1563)
Solutions
- Remove duplicate `-` arguments; keep exactly one `-`.
- Concatenate multiple stdin sources first: `cat a b | wsh ai -`.
- If second input is a file, pass its path instead of `-`.
- For scripting, deduplicate the args list before invoking wsh ai.
Example fix
// before $ echo x | wsh ai - - notes.txt // after $ echo x | wsh ai - notes.txt
Defensive patterns
Strategy: validation
Validate before calling
count=$(printf '%s\n' "$@" | grep -cx -- '-' || true) if [ "$count" -gt 1 ]; then echo "wsh ai accepts at most one '-' (stdin) argument" >&2 exit 1 fi
Prevention
- Treat `-` as a singleton placeholder in any command template that builds wsh ai invocations.
- Concatenate multiple streams into one pipe: `cat a b | wsh ai -`.
- Deduplicate args programmatically before calling wsh ai in scripts.
When it happens
Trigger: Running e.g. `wsh ai - - file.txt` or `cat a | wsh ai - -`, i.e. two or more literal `-` arguments in the same invocation.
Common situations: Users assuming `-` behaves like `cat` (repeatable), templated commands that inject `-` per input stream, copy-pasted command lines with duplicated placeholders.
Related errors
- no arguments. wsh %s requires a file or URL as an argument
- too many arguments. wsh %s requires exactly one argument
- no arguments. wsh wavepath requires a type argument (config,
- too many arguments. wsh wavepath requires exactly one argume
- invalid path type %q. must be one of: config, data, log
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/16cfd223092f7084.
Report an issue: GitHub.