[Bug]: sed -i with a separated dotted backup suffix is misparsed as the sed script
Prerequisites
- I have searched the existing issues and discussions, and this is not a duplicate.
- This is a bug, not a usage question. (For questions, please use Discussions instead.)
Background / Description
BashCommandParser.check_sed_constraints only consumes a separated -i /
--in-place backup suffix when the next argument contains no dot. The
standard BSD/macOS spelling therefore breaks:
sed -i .bak 's/x/y/' notes.txt.bak is analyzed as the sed script and the command is rejected with
sed expression '.bak' not in allowlist, while the real substitution and
file arguments are never checked. Legitimate commands can never be
auto-allowed by the Bash permission system.
A token starting with a dot can never begin a sed script (scripts start
with s, an address, $, /, {, etc.), so consuming a leading-dot
token as the backup suffix is safe. A dot elsewhere can still belong to a
script such as /example.com/d and must stay unconsumed — the current
behavior for that case is preserved.
The attached forms (-i.bak, --in-place=.bak) and the dotless separated
form (-i bak) already work; #2795 and #2824 covered the inline-value
cases and missed this separated dotted form.
Steps to Reproduce
- Enable the Bash tool with the default permission checks
- Ask an agent to run
sed -i .bak 's/x/y/' notes.txt(no API key or external service needed; the rejection happens incheck_sed_constraintsbefore execution) - The command is blocked with:
sed expression '.bak' not in allowlist
Expected Behavior
sed -i .bak 's/x/y/' notes.txt passes the constraint check (None),
and sed -i .bak 's/x/y/' .env is still rejected as a dangerous-file
modification.
I have a small fix plus a regression test verified locally and would like to submit a PR for this issue.
Source: agentscope-ai/agentscope