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
{{ message }}
Repository navigation
[FEATURE]: PowerShell scanner refuses any command containing en/em dash or curly quotes - normalize them like PowerShell does, and name the character in the error #61704
I understand why: PowerShell's tokenizer treats en/em dash and horizontal bar as -, and U+2018..U+201E as quote characters, so a scanner that does not know this could be fooled about what the command runs. Refusing is the safe default. But in practice this hits ordinary text, not evasion:
CJK prose uses these characters all the time. Chinese typography uses — and “ ” as normal punctuation, so any command that writes a Chinese message, comment, or report line is refused.
Models (and users pasting from editors) produce curly quotes in comments and strings.
Because the message says nothing about the cause, the agent keeps rewriting the quoting style. In one of my sessions it tried four different quoting forms for the same ~6 KB python -c script before falling back to writing a temp file. None of the retries could work, since the character was inside a Python comment string.
Requested enhancement (either part helps):
Normalize instead of refusing in the PowerShell scanner: before scanning, map U+2013/U+2014/U+2015 to - and U+2018..U+201B to ', U+201C..U+201E to ". That is exactly how PowerShell itself reads them, so the scanner then sees the same command PowerShell will run, and permission rules apply as usual. Keep refusing U+0000/U+0085/U+FEFF if they are considered risky.
Make the error actionable: say which character and where, and that requoting will not help, e.g. Portable shell scanner cannot analyze command: unsupported character U+2014 at line 3, col 18 (PowerShell reads it as '-'); write the text to a file or escape it.
The same applies to the length limit, which currently reports the same invalid-structure reason for commands over 65,536 characters.
Measured on my machine over one evening: 8 shell calls were refused by the scanner; 7 of them were caused only by these characters inside string literals or comments, 1 by an unrelated construct.
Workaround I use now: a plugin tool.execute.before hook that detects these characters and returns a message naming the character and line, so the agent fixes it on the first try. A built-in fix would help every user writing non-English text.
Thanks for the detailed write-up and measurements. You're asking for two things:
The PowerShell scanner should normalize en/em dashes, horizontal bars and curly quotes the way PowerShell's tokenizer reads them, instead of refusing the command.
When it does refuse, the error should name the character and its position, and the length limit should have its own reason instead of invalid-structure.
Right now these characters are refused on purpose, as a fail-closed safety check in the scanner. So this is a change to that design rather than a bug, and the maintainers will consider it.
Confirming this on v2.2.6 (Windows 11, Store pwsh 7.6.9 via a junction). Same invalid-structure refusal, real-world trigger: a gh CLI jq filter whose format string starts with an em dash —
refused twice, unchanged. The em dash (U+2014) is only inside a string literal used to build output text — exactly your "ordinary text, not evasion" case: agents commonly use bullet separators like this in report/filter commands. Second call without the em dash ran fine. Supporting normalization (or at least naming the character) as requested; for now we avoid typographic dashes/quotes in shell commands.
The shell tool returns only Portable shell scanner cannot analyze command: invalid-structure.
PowerShell's parser identifies EmptyPipeElement at line 1, column 42. Assigning the loop output to an array before piping succeeds.
This rejection is correct; this is a diagnostics request, not a request to execute invalid or opaque commands. Please distinguish syntax errors, unsupported constructs and scanner limits, and include a safe reason and location when available. Do not echo command contents or secrets, execute commands for diagnosis, or relax permission checks. This improvement would be useful independently of Unicode normalization.
Measured the same refusal on 2.2.5 (Windows 11, pwsh 7.6.5). One correction to the premise: the dash half and the quote half are not the same problem.
PowerShell honors smart quotes as delimiters, even inside an ASCII-quoted string:
Write-Output'safe’; Write-Output SECOND; ‘tail'
prints three lines (safe, SECOND, tail). The ’ closes the ASCII string, so Write-Output SECOND runs. A scanner that normalized smart quotes and treated that span as literal would never record that command, which is the case fails closed for PowerShell smart quotes guards. I don't think that half can be relaxed without teaching the tokenizer PowerShell's quote pairing.
Dashes are different. Inside a literal they are inert:
So the change that stays fail-closed: accept U+2013–U+2015 only where the tokenizer is already inside a quoted literal, keep refusing them outside (where PowerShell reads them as parameter prefixes), and keep refusing U+2018–U+201E everywhere. It is six lines:
--- a/packages/core/src/shell/scan.ts+++ b/packages/core/src/shell/scan.ts@@ -1819,6 +1819,6 @@ export function scanPowerShell(input: string): Result {
if (input.length > MAX_INPUT_LENGTH) return { kind: "opaque", reason: "invalid-structure" }
// PowerShell's Unicode quotes, dashes, and whitespace differ from JavaScript's token rules.
- if (/[\0\u0085\u2013-\u2015\u2018-\u201e\ufeff]/.test(input)) return { kind: "opaque", reason: "invalid-structure" }+ if (/[\0\u0085\u2018-\u201e\ufeff]/.test(input)) return { kind: "opaque", reason: "invalid-structure" }
const result = scanPowerShellList(input, 0, 0, { remaining: MAX_INPUT_LENGTH * MAX_SUBSTITUTION_DEPTH })
if (result.kind === "opaque") return result
return { kind: "scanned", commands: result.commands }
@@ -1983,6 +1983,11 @@
} else word += char
continue
}
+ // Outside a literal these dashes are parameter prefixes; inside one they are text.+ // Smart quotes stay refused everywhere: PowerShell honors them as delimiters even inside an+ // ASCII-quoted string, so they can close it and hand the rest to the parser.+ const code = char.charCodeAt(0)+ if (code >= 0x2013 && code <= 0x2015) return { kind: "opaque", reason: "invalid-structure" }
if (char === "'" || char === '"') {
if (!started && words.length === 0 && !invocation) expression = true
quote = char
Tests cover: the three dash characters inside a literal scan and stay in the permission resource; a dash outside a literal stays opaque; the smart-quote bypass above stays opaque; a dash inside a $(...) subexpression stays opaque.
On this machine the change would have unblocked 7 of the 11 shell commands the scanner refused in one day. All 7 were prose with —— or – inside an argument. The other 4 were genuinely malformed, so the scanner was right about those.
Verification: test/shell-scan/powershell-safety.test.ts 248 pass, test/shell-parse 219 pass, typecheck:tsc clean, oxlint clean on both files.
Since v2.4.0 (#65269) this limitation has a second life as a recurring permission dialog that cannot be permanently approved. Adding our measurements in case it helps prioritize.
What changed in v2.4.x: an opaque command no longer fails the shell call — ShellPermissions.requests (packages/core/src/shell/permissions.ts) now returns { action: "external_directory", resources: ["*"], save: undefined } alongside the shell request. The code comment there states: "An unanalyzed command may reach any directory, so only rules allowing every directory settle it, and approval is never saved as a pattern."
Consequence for non-English users with an ask policy: with any external_directory ask rule matching * (e.g. "*": "ask" — a common tripwire setup), every affected command raises an "Access external directory / Patterns: *" dialog. Approving with "always allow" persists nothing (save: undefined), and no zone-scoped grant can match the literal * resource — so the dialog repeats for every command containing these characters, indefinitely. Before v2.4.0 the same commands failed with the scanner error, which agents could at least see and rework.
Repro (v2.4.1, Windows, official channel, pwsh): ask the agent to run Write-Output "test — with em dash" (U+2014 inside a plain string literal) → the external_directory dialog appears; the ASCII-hyphen version runs without it.
Measured on one machine (Russian-language workflows, 3 days, 1465 agent shell calls): 47 calls (3.2%) were made opaque solely by these characters inside string literals — em/en dashes in prose passed to report comments, journal appends, notification text. 17 of them show multi-second approval waits in the recorded session data, and scheduled report sessions accumulate several per run. The dialog's pattern (*) names neither the offending character nor the command, so an agent cannot self-correct from the prompt itself.
Workaround we adopted: a standing instruction that shell commands use ASCII punctuation only (en/em dash → -, curly quotes → straight quotes; Cyrillic letters are fine) and that long non-ASCII text is passed through files rather than command arguments.
The patch proposed by @zklhp above (dashes allowed inside literals, smart quotes still refused) would eliminate most of this class on our data. Independently of it, the un-saveable * ask introduced by #65269 may deserve its own look — e.g. making that request saveable as a scoped approval, or surfacing the scanner's reason in the dialog so users (and agents) can see what to fix.
Activity
opencodejr commentedon Nov 4, 2026
Thanks for the detailed write-up and measurements. You're asking for two things:
invalid-structure.Right now these characters are refused on purpose, as a fail-closed safety check in the scanner. So this is a change to that design rather than a bug, and the maintainers will consider it.
Related:
Your
tool.execute.beforeplugin workaround is a good stopgap for the error-message part in the meantime.facebey commentedon Nov 7, 2026
Confirming this on v2.2.6 (Windows 11, Store pwsh 7.6.9 via a junction). Same
invalid-structurerefusal, real-world trigger: a gh CLI jq filter whose format string starts with an em dash —refused twice, unchanged. The em dash (U+2014) is only inside a string literal used to build output text — exactly your "ordinary text, not evasion" case: agents commonly use bullet separators like this in report/filter commands. Second call without the em dash ran fine. Supporting normalization (or at least naming the character) as requested; for now we avoid typographic dashes/quotes in shell commands.
ko-hamstar commentedon Nov 9, 2026
Additional reproduction: actionable diagnostics for genuine syntax errors
Reproduced with official OpenCode 2.2.6 on Windows, using PowerShell 7.6.9:
The shell tool returns only
Portable shell scanner cannot analyze command: invalid-structure.PowerShell's parser identifies
EmptyPipeElementat line 1, column 42. Assigning the loop output to an array before piping succeeds.This rejection is correct; this is a diagnostics request, not a request to execute invalid or opaque commands. Please distinguish syntax errors, unsupported constructs and scanner limits, and include a safe reason and location when available. Do not echo command contents or secrets, execute commands for diagnosis, or relax permission checks. This improvement would be useful independently of Unicode normalization.
zklhp commentedon Nov 9, 2026
Measured the same refusal on 2.2.5 (Windows 11, pwsh 7.6.5). One correction to the premise: the dash half and the quote half are not the same problem.
PowerShell honors smart quotes as delimiters, even inside an ASCII-quoted string:
prints three lines (
safe,SECOND,tail). The’closes the ASCII string, soWrite-Output SECONDruns. A scanner that normalized smart quotes and treated that span as literal would never record that command, which is the casefails closed for PowerShell smart quotesguards. I don't think that half can be relaxed without teaching the tokenizer PowerShell's quote pairing.Dashes are different. Inside a literal they are inert:
So the change that stays fail-closed: accept U+2013–U+2015 only where the tokenizer is already inside a quoted literal, keep refusing them outside (where PowerShell reads them as parameter prefixes), and keep refusing U+2018–U+201E everywhere. It is six lines:
Tests cover: the three dash characters inside a literal scan and stay in the permission resource; a dash outside a literal stays opaque; the smart-quote bypass above stays opaque; a dash inside a
$(...)subexpression stays opaque.On this machine the change would have unblocked 7 of the 11 shell commands the scanner refused in one day. All 7 were prose with
——or–inside an argument. The other 4 were genuinely malformed, so the scanner was right about those.Verification:
test/shell-scan/powershell-safety.test.ts248 pass,test/shell-parse219 pass,typecheck:tscclean, oxlint clean on both files.Petr28 commentedon Nov 27, 2026
Since v2.4.0 (#65269) this limitation has a second life as a recurring permission dialog that cannot be permanently approved. Adding our measurements in case it helps prioritize.
What changed in v2.4.x: an opaque command no longer fails the shell call —
ShellPermissions.requests(packages/core/src/shell/permissions.ts) now returns{ action: "external_directory", resources: ["*"], save: undefined }alongside theshellrequest. The code comment there states: "An unanalyzed command may reach any directory, so only rules allowing every directory settle it, and approval is never saved as a pattern."Consequence for non-English users with an ask policy: with any
external_directoryask rule matching*(e.g."*": "ask"— a common tripwire setup), every affected command raises an "Access external directory / Patterns: *" dialog. Approving with "always allow" persists nothing (save: undefined), and no zone-scoped grant can match the literal*resource — so the dialog repeats for every command containing these characters, indefinitely. Before v2.4.0 the same commands failed with the scanner error, which agents could at least see and rework.Repro (v2.4.1, Windows, official channel, pwsh): ask the agent to run
Write-Output "test — with em dash"(U+2014 inside a plain string literal) → the external_directory dialog appears; the ASCII-hyphen version runs without it.Measured on one machine (Russian-language workflows, 3 days, 1465 agent shell calls): 47 calls (3.2%) were made opaque solely by these characters inside string literals — em/en dashes in prose passed to report comments, journal appends, notification text. 17 of them show multi-second approval waits in the recorded session data, and scheduled report sessions accumulate several per run. The dialog's pattern (
*) names neither the offending character nor the command, so an agent cannot self-correct from the prompt itself.Workaround we adopted: a standing instruction that shell commands use ASCII punctuation only (en/em dash →
-, curly quotes → straight quotes; Cyrillic letters are fine) and that long non-ASCII text is passed through files rather than command arguments.The patch proposed by @zklhp above (dashes allowed inside literals, smart quotes still refused) would eliminate most of this class on our data. Independently of it, the un-saveable
*ask introduced by #65269 may deserve its own look — e.g. making that request saveable as a scoped approval, or surfacing the scanner's reason in the dialog so users (and agents) can see what to fix.