From e3ccb85b6d0b6ed7e2bcffbcd8a16cb9022a0c4c Mon Sep 17 00:00:00 2001 From: gaoxiaolei-s59 <2995484417@qq.com> Date: Wed, 10 Jun 2026 09:33:48 +0800 Subject: [PATCH 1/3] fix(harness): support recursive glob_files patterns in sandbox --- .../sandbox/BaseSandboxFilesystem.java | 4 +- .../sandbox/BaseSandboxFilesystemTest.java | 82 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystemTest.java diff --git a/agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystem.java b/agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystem.java index 139dae8c80..2448208baf 100644 --- a/agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystem.java +++ b/agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystem.java @@ -319,7 +319,9 @@ public GrepResult grep( @Override public GlobResult glob(RuntimeContext runtimeContext, String pattern, String path) { String escapedPath = FilesystemUtils.shellQuote(path != null ? path : "/"); - String escapedPattern = FilesystemUtils.shellQuote(pattern); + String findNamePattern = + pattern != null && pattern.startsWith("**/") ? pattern.substring(3) : pattern; + String escapedPattern = FilesystemUtils.shellQuote(findNamePattern); String cmd = "find " + escapedPath + " -type f -name " + escapedPattern + " 2>/dev/null | sort"; diff --git a/agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystemTest.java b/agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystemTest.java new file mode 100644 index 0000000000..21312c3b9b --- /dev/null +++ b/agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystemTest.java @@ -0,0 +1,82 @@ +/* + * Copyright 2024-2026 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.agentscope.harness.agent.filesystem.sandbox; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import io.agentscope.core.agent.RuntimeContext; +import io.agentscope.harness.agent.filesystem.model.ExecuteResponse; +import io.agentscope.harness.agent.filesystem.model.FileDownloadResponse; +import io.agentscope.harness.agent.filesystem.model.FileUploadResponse; +import io.agentscope.harness.agent.filesystem.model.GlobResult; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; + +class BaseSandboxFilesystemTest { + + private static final RuntimeContext RT = RuntimeContext.empty(); + + @Test + void glob_recursivePattern_stripsDoubleStarPrefixBeforeFindName() { + FakeSandboxFilesystem filesystem = new FakeSandboxFilesystem(); + + GlobResult result = filesystem.glob(RT, "**/*.md", "/workspace"); + + assertTrue(result.isSuccess()); + assertEquals( + "find '/workspace' -type f -name '*.md' 2>/dev/null | sort", + filesystem.lastCommand); + assertEquals( + List.of("/workspace/README.md", "/workspace/docs/guide.md"), + result.matches().stream().map(match -> match.path()).collect(Collectors.toList())); + } + + private static final class FakeSandboxFilesystem extends BaseSandboxFilesystem { + + private String lastCommand; + + @Override + public String id() { + return "fake"; + } + + @Override + public ExecuteResponse execute( + RuntimeContext runtimeContext, String command, Integer timeoutSeconds) { + lastCommand = command; + if ("find '/workspace' -type f -name '*.md' 2>/dev/null | sort".equals(command)) { + return new ExecuteResponse( + "/workspace/README.md\n/workspace/docs/guide.md\n", 0, false); + } + return new ExecuteResponse("", 0, false); + } + + @Override + public List uploadFiles( + RuntimeContext runtimeContext, List> files) { + return List.of(); + } + + @Override + public List downloadFiles( + RuntimeContext runtimeContext, List paths) { + return List.of(); + } + } +} From d972fff5558a0c4cfb9a429d05d0b856d89acde2 Mon Sep 17 00:00:00 2001 From: gaoxiaolei-s59 <2995484417@qq.com> Date: Wed, 10 Jun 2026 09:47:30 +0800 Subject: [PATCH 2/3] test(harness): cover sandbox glob false branch --- .../sandbox/BaseSandboxFilesystemTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystemTest.java b/agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystemTest.java index 21312c3b9b..39c2d9417f 100644 --- a/agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystemTest.java +++ b/agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystemTest.java @@ -47,6 +47,21 @@ void glob_recursivePattern_stripsDoubleStarPrefixBeforeFindName() { result.matches().stream().map(match -> match.path()).collect(Collectors.toList())); } + @Test + void glob_plainPattern_keepsFindNamePatternUnchanged() { + FakeSandboxFilesystem filesystem = new FakeSandboxFilesystem(); + + GlobResult result = filesystem.glob(RT, "*.md", "/workspace"); + + assertTrue(result.isSuccess()); + assertEquals( + "find '/workspace' -type f -name '*.md' 2>/dev/null | sort", + filesystem.lastCommand); + assertEquals( + List.of("/workspace/README.md", "/workspace/docs/guide.md"), + result.matches().stream().map(match -> match.path()).collect(Collectors.toList())); + } + private static final class FakeSandboxFilesystem extends BaseSandboxFilesystem { private String lastCommand; From 56036886844ac44fdb585194dd64902937511411 Mon Sep 17 00:00:00 2001 From: Chickenlj Date: Thu, 11 Jun 2026 11:11:58 +0800 Subject: [PATCH 3/3] fix(harness): strip **/ prefix in grep glob param and extract shared helper grep --include= matches only the filename portion (like find -name), so passing **/*.java would silently return no matches. Apply the same stripRecursivePrefix() normalization that glob() already used, and extract it into a shared private helper to avoid duplication. --- .../sandbox/BaseSandboxFilesystem.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystem.java b/agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystem.java index 2448208baf..f0d0a794dd 100644 --- a/agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystem.java +++ b/agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/sandbox/BaseSandboxFilesystem.java @@ -279,7 +279,7 @@ public GrepResult grep( String grepOpts = "-rHnF"; String globPattern = ""; if (glob != null && !glob.isBlank()) { - globPattern = "--include=" + FilesystemUtils.shellQuote(glob); + globPattern = "--include=" + FilesystemUtils.shellQuote(stripRecursivePrefix(glob)); } String patternEscaped = FilesystemUtils.shellQuote(pattern); @@ -319,9 +319,7 @@ public GrepResult grep( @Override public GlobResult glob(RuntimeContext runtimeContext, String pattern, String path) { String escapedPath = FilesystemUtils.shellQuote(path != null ? path : "/"); - String findNamePattern = - pattern != null && pattern.startsWith("**/") ? pattern.substring(3) : pattern; - String escapedPattern = FilesystemUtils.shellQuote(findNamePattern); + String escapedPattern = FilesystemUtils.shellQuote(stripRecursivePrefix(pattern)); String cmd = "find " + escapedPath + " -type f -name " + escapedPattern + " 2>/dev/null | sort"; @@ -381,6 +379,21 @@ public boolean exists(RuntimeContext runtimeContext, String path) { return result.output() != null && result.output().strip().startsWith("yes"); } + /** + * Strips the recursive glob prefix {@code **/} from a pattern so it can be passed to + * tools like {@code find -name} or {@code grep --include=} that match only the filename + * portion. For example, {@code **/*.java} becomes {@code *.java}. + * + * @param pattern the glob pattern, may be {@code null} + * @return the pattern with any leading {@code **/} removed, or the original value if absent + */ + private static String stripRecursivePrefix(String pattern) { + if (pattern != null && pattern.startsWith("**/")) { + return pattern.substring(3); + } + return pattern; + } + private static String jsonEscape(String s) { if (s == null) { return "";