Add a native glob tool for agent file discovery #82
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The agent can search file contents with
searchand inspect one directory withlist, but it cannot recursively find files by name or path pattern. It therefore falls back to Bash commands such asfind,fd, orrg --filesfor a read-only operation that should be available as a native, permission-confined agent tool.Goal
Add a read-only
globtool that finds regular files by basename or relative path pattern without launching a shell or any external process.This is filename/path discovery only. Content matching remains the responsibility of
search, and single-directory inspection remains the responsibility oflist.Tool contract
Expose
globthrough the existing generated tool schema and validation path insrc/agent.rs.Parameters:
pattern(required string): non-empty filename or relative-path wildcard.path(optional string, default.): directory under an existing readable root from which to search.max_results(optional integer, default 100, range 1–500): maximum number of paths returned.Pattern behavior:
/matches basenames recursively, e.g.Cargo.tomlor*.rs./matches the path relative to the selected search root, e.g.src/*test*.rs.searchtool'sglobfilter (*and?) so the two tools do not develop incompatible matchers. Document that*follows the existing matcher and can span path separators./separators.Example calls:
Because the existing matcher treats consecutive
*characters like*, the last example remains valid without introducing separate**semantics.Required behavior
find,fd,rg, or another subprocess.Tools::existing_pathandinside_readable_root. The tool must have exactly the same readable-root policy asread,list, andsearch: project files, enabled skill roots, and visible managed Dev Brain content..git. Preserve the existing hidden-entry policy for project, skill, and Dev Brain traversal rather than inventing a second policy.max_results, so output is deterministic.No matchesresult.max_results, return the firstmax_resultsentries and an explicit truncation summary that tells the agent to narrow the pattern or raise the limit.globfor filename discovery before resorting to Bash.Implementation location
Keep the change focused in the existing agent tool implementation unless a small traversal-helper refactor is needed:
ToolHandler::Globvariant;globToolSpec;execute_validated;No UI or server API changes are required.
Tests
Add focused tests that prove:
globwith the required and optional fields and validation rejects missing/invalid arguments;*,?, and relative-path patterns find nested files;max_resultswith a visible truncation notice;.gitentries, symlinks,.., and out-of-root paths cannot escape confinement;Acceptance criteria
globand does not need Bash for that task.read,list, andsearchbehavior remains unchanged.cargo fmt --all -- --check,cargo clippy --all-targets --all-features -- -D warnings,make bundle, andcargo test --all-featurespass.Implemented and pushed as
5c74739.Verification covers required/optional schema fields and invalid arguments; exact, , ?, relative-path, repeated-star, spaces, Unicode, deterministic truncation, no-match, large/binary, .git, symlink and confinement cases; skill and Dev Brain visibility; and cancellation. Manual local-model verification selected glob with pattern=agent.rs and path=src, returned src/agent.rs, and did not use Bash. This is a new DS4Server agent feature with no corresponding DS4 functionality; existing DS4 transport plus read/list/search regressions remain green.
Commit gates passed: cargo fmt --all -- --check; cargo clippy --all-targets --all-features -- -D warnings; make bundle; cargo test --all-features (216 passed, 16 ignored).