fix: support bounded recursive glob across lessons

This commit is contained in:
Haoran
2026-08-23 11:28:14 +08:00
parent 1342a990a2
commit 61c3e64595
19 changed files with 189 additions and 83 deletions

View File

@@ -109,12 +109,15 @@ def run_edit(path: str, old_text: str, new_text: str) -> str:
def run_glob(pattern: str) -> str:
try:
matches = [
matches = sorted({
match
for match in glob.glob(pattern, root_dir=WORKDIR)
for match in glob.glob(pattern, root_dir=WORKDIR, recursive=True)
if (WORKDIR / match).resolve().is_relative_to(WORKDIR.resolve())
]
return "\n".join(matches[:200]) if matches else "(no matches)"
})
shown = matches[:200]
if len(matches) > 200:
shown.append("... (more matches omitted; narrow the pattern)")
return "\n".join(shown) if shown else "(no matches)"
except Exception as exc:
return f"Error: {exc}"
@@ -140,7 +143,7 @@ BASE_TOOLS = [
"old_text": {"type": "string"},
"new_text": {"type": "string"}},
"required": ["path", "old_text", "new_text"]}},
{"name": "glob", "description": "Find files by glob pattern.",
{"name": "glob", "description": "Find files by glob pattern; ** matches recursively.",
"input_schema": {"type": "object",
"properties": {"pattern": {"type": "string"}},
"required": ["pattern"]}},