Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(opencode): use [ \t]* instead of split to fix quoted paths with separators

Cursor Agent79d481723195
diff --git a/cli/beacon/internal/endpoint/hooks/assets/opencode/beacon.ts b/cli/beacon/internal/endpoint/hooks/assets/opencode/beacon.ts
index 3eebb0e1..05ff6f81 100644
--- a/cli/beacon/internal/endpoint/hooks/assets/opencode/beacon.ts
+++ b/cli/beacon/internal/endpoint/hooks/assets/opencode/beacon.ts
@@ -125,14 +125,9 @@ function shellMutationPaths(tool, args) {
if (name !== "bash" && !name.includes("shell")) return []
const command = String(args?.command || args?.cmd || "")
const paths = []
- // Split on command separators first so the delete-command pattern below stays
- // anchored and linear; a single regex spanning separators is open to
- // polynomial backtracking on adversarial tool input.
const pattern =
- /^(?:sudo\s+)?(?:command\s+)?(?:\/bin\/)?(?:rm|unlink)\s+(?:-[^\s]+\s+)*(?:"([^"]+)"|'([^']+)'|([^\s;&|]+))/
- for (const segment of command.split(/&&|\|\||;|\n/)) {
- const match = pattern.exec(segment.trimStart())
- if (!match) continue
+ /(?:^|(?:&&|\|\||;|\n)[ \t]*)(?:sudo\s+)?(?:command\s+)?(?:\/bin\/)?(?:rm|unlink)\s+(?:-[^\s]+\s+)*(?:"([^"]+)"|'([^']+)'|([^\s;&|]+))/g
+ for (const match of command.matchAll(pattern)) {
const path = match[1] || match[2] || match[3]
if (path) paths.push(path)
}
diff --git a/plugins/opencode-beacon/src/beacon.ts b/plugins/opencode-beacon/src/beacon.ts
index 3eebb0e1..05ff6f81 100644
--- a/plugins/opencode-beacon/src/beacon.ts
+++ b/plugins/opencode-beacon/src/beacon.ts
@@ -125,14 +125,9 @@ function shellMutationPaths(tool, args) {
if (name !== "bash" && !name.includes("shell")) return []
const command = String(args?.command || args?.cmd || "")
const paths = []
- // Split on command separators first so the delete-command pattern below stays
- // anchored and linear; a single regex spanning separators is open to
- // polynomial backtracking on adversarial tool input.
const pattern =
- /^(?:sudo\s+)?(?:command\s+)?(?:\/bin\/)?(?:rm|unlink)\s+(?:-[^\s]+\s+)*(?:"([^"]+)"|'([^']+)'|([^\s;&|]+))/
- for (const segment of command.split(/&&|\|\||;|\n/)) {
- const match = pattern.exec(segment.trimStart())
- if (!match) continue
+ /(?:^|(?:&&|\|\||;|\n)[ \t]*)(?:sudo\s+)?(?:command\s+)?(?:\/bin\/)?(?:rm|unlink)\s+(?:-[^\s]+\s+)*(?:"([^"]+)"|'([^']+)'|([^\s;&|]+))/g
+ for (const match of command.matchAll(pattern)) {
const path = match[1] || match[2] || match[3]
if (path) paths.push(path)
}