Skip to content

Commit a1e55fe

Browse files
fix(opencode): skip env-var prefixes in shell permission pattern matching
The source() function returned the full node text including variable_assignment children (e.g. "GOFLAGS=-mod=vendor go test"). This caused permission rules like "go *": "allow" to never match commands with env-var prefixes. Now source() filters out variable_assignment children before constructing the pattern text, so "GOFLAGS=-mod=vendor go test ./..." correctly matches "go *". Closes anomalyco#14110
1 parent e5cf3ad commit a1e55fe

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎packages/opencode/src/tool/shell.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,15 @@ function parts(node: Node) {
120120
}
121121

122122
function source(node: Node) {
123-
return (node.parent?.type === "redirected_statement" ? node.parent.text : node.text).trim()
123+
const target = node.parent?.type === "redirected_statement" ? node.parent : node
124+
// Filter out variable_assignment children so env-var prefixes like
125+
// "GOFLAGS=-mod=vendor" don't leak into the permission pattern (#14110)
126+
const children = []
127+
for (let i = 0; i < target.childCount; i++) {
128+
const child = target.child(i)
129+
if (child && child.type !== "variable_assignment") children.push(child.text)
130+
}
131+
return (children.length > 0 ? children.join(" ") : target.text).trim()
124132
}
125133

126134
function commands(node: Node) {

0 commit comments

Comments
 (0)