Skip to content

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

fix(gitlink): respect wrapped directory changes in shell commands (#903)

Rudy Mizrahi Celeklia6723d7e282a
diff --git a/cli/beacon/internal/gitlink/shell.go b/cli/beacon/internal/gitlink/shell.go
index 8c65c16b..b884b2b7 100644
--- a/cli/beacon/internal/gitlink/shell.go
+++ b/cli/beacon/internal/gitlink/shell.go
@@ -21,14 +21,14 @@ func ShellWrittenPaths(command string) []string {
found = absoluteOnly(found)
}
paths = append(paths, found...)
- if len(words) > 0 && (words[0] == "cd" || words[0] == "pushd" || words[0] == "popd") {
+ if command := unwrappedCommand(words); len(command) > 0 && (command[0] == "cd" || command[0] == "pushd" || command[0] == "popd") {
moved = true
}
}
return dedupe(paths)
}
-func commandTargets(words []string) []string {
+func unwrappedCommand(words []string) []string {
// Skip environment assignments and the wrappers that run the real command.
for len(words) > 0 {
w := words[0]
@@ -36,12 +36,17 @@ func commandTargets(words []string) []string {
words = words[1:]
continue
}
- if w == "sudo" || w == "command" || w == "exec" || w == "nohup" || w == "time" {
+ if w == "sudo" || w == "command" || w == "builtin" || w == "exec" || w == "nohup" || w == "time" {
words = words[1:]
continue
}
break
}
+ return words
+}
+
+func commandTargets(words []string) []string {
+ words = unwrappedCommand(words)
if len(words) == 0 {
return nil
}
diff --git a/cli/beacon/internal/gitlink/shell_test.go b/cli/beacon/internal/gitlink/shell_test.go
index 1cd9b13b..15ce3655 100644
--- a/cli/beacon/internal/gitlink/shell_test.go
+++ b/cli/beacon/internal/gitlink/shell_test.go
@@ -38,6 +38,12 @@ func TestShellWrittenPaths(t *testing.T) {
{"(cd sub && rm x)", nil}, // x is sub/x, which this parser does not follow
{"cd /tmp && rm /abs/path.txt && rm rel.txt", []string{"/abs/path.txt"}},
{"rm before.txt; cd sub; rm after.txt", []string{"before.txt"}},
+ {"command cd sub && rm after.txt", nil},
+ {"ROOT=sub cd sub && touch after.txt", nil},
+ {"builtin cd sub && rm after.txt", nil},
+ {"command cd sub && rm /abs/path.txt", []string{"/abs/path.txt"}},
+ {"touch before.txt; command pushd sub; rm after.txt", []string{"before.txt"}},
+ {"command popd; rm after.txt", nil},
{"ls -la; go test ./...", nil},
{"cat <<EOF > gen.txt\nhello\nEOF", []string{"gen.txt"}},
} {