The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
fix(hooks): keep the arguments after env -S whole
L4XB64e004a9625c
diff --git a/scripts/hooks/gateguard-fact-force.js b/scripts/hooks/gateguard-fact-force.jsindex 587e48739..48a9d466d 100644--- a/scripts/hooks/gateguard-fact-force.js+++ b/scripts/hooks/gateguard-fact-force.js@@ -533,6 +533,13 @@ function unwrapLeadWrappers(tokens) {* @param {string[]} tokens dequoted tokens for one segment* @returns {string[]} the command lines, possibly none*/+// `env -S` splits only its own argument; later arguments reach the command+// whole. Escaping every character makes the classifier read each one back as a+// single literal word, so a `;` inside one cannot become a separator.+function asLiteralWord(token) {+ return token === '' ? "''" : token.replace(/[\s\S]/gu, ch => `\\${ch}`);+}+function envSplitStrings(tokens) {const payloads = [];for (let i = 0; i < tokens.length; i += 1) {@@ -540,15 +547,15 @@ function envSplitStrings(tokens) {for (let j = i + 1; j < tokens.length; j += 1) {const arg = tokens[j];if (arg === '-S' || arg === '--split-string') {- if (j + 1 < tokens.length) payloads.push(tokens.slice(j + 1).join(' '));+ if (j + 1 < tokens.length) payloads.push([tokens[j + 1], ...tokens.slice(j + 2).map(asLiteralWord)].join(' '));break;}if (arg.startsWith('--split-string=')) {- payloads.push([arg.slice('--split-string='.length), ...tokens.slice(j + 1)].join(' '));+ payloads.push([arg.slice('--split-string='.length), ...tokens.slice(j + 1).map(asLiteralWord)].join(' '));break;}if (/^-S./.test(arg)) {- payloads.push([arg.slice(2), ...tokens.slice(j + 1)].join(' '));+ payloads.push([arg.slice(2), ...tokens.slice(j + 1).map(asLiteralWord)].join(' '));break;}if (arg === '-u' || arg === '--unset' || arg === '-C' || arg === '--chdir') {diff --git a/tests/hooks/gateguard-fact-force.test.js b/tests/hooks/gateguard-fact-force.test.jsindex 2496182ff..dd8488085 100644--- a/tests/hooks/gateguard-fact-force.test.js+++ b/tests/hooks/gateguard-fact-force.test.js@@ -1545,6 +1545,7 @@ function runTests() {expectDestructiveDeny('sh -ec "psql -c \'drop table users\'"', 'sh -ec psql');expectDestructiveDeny('env -S \'psql -c "drop table users"\'', 'env -S psql');expectDestructiveDeny('env --split-string=\'psql -c "drop table users"\'', 'env --split-string psql');+ expectDestructiveDeny('env -S \'psql -c\' \'drop table users\'', 'env -S psql with the SQL as a later argument');expectDestructiveDeny('env time -f "%E" psql -c "drop table users"', 'env time -f psql');expectDestructiveDeny('nice -n 10 psql -c "drop table users"', 'nice psql');expectDestructiveDeny('timeout 30 psql -c "drop table users"', 'timeout psql');@@ -1573,6 +1574,7 @@ function runTests() {expectAllow('nice -n 10 psql -c "select 1"', 'nice select');expectAllow('timeout 30 git status', 'timeout git status');expectAllow('env -S \'psql -c "select 1"\'', 'env -S select');+ expectAllow('env -S \'echo\' \'; psql -c "drop table users"\'', 'env -S echo with a literal argument');}))passed++;