opencode
opencode copied to clipboard
fix: preserve argument boundaries in run command
Summary
Fixes argument parsing for opencode run --command when arguments contain spaces.
Problem
When running a command like:
opencode run --command testcommand val1 "val 2" val3
With a command template configured as:
Arg1: $1
Arg2: $2
Arg3: $3
The arguments were incorrectly parsed as:
Arg1: val1
Arg2: val
Arg3: 2
Instead of the expected:
Arg1: val1
Arg2: val 2
Arg3: val3
Cause
The issue was a double-parsing problem:
- The shell correctly parses the command line, treating
"val 2"as a single argument -
run.tsjoins all positional arguments with spaces:args.message.join(" ")→val1 val 2 val3 - The command handler in
prompt.tsre-parses this string using a regex that splits on whitespace
At step 2, the original quoting information is lost, so step 3 splits val 2 into two separate arguments.
Fix
Quote any argument containing spaces before joining, so the command handler can correctly identify the original argument boundaries. Also escapes any existing double quotes within arguments.