Implement glob tool for file pattern matching

t-241·WorkTask·
·
·
·Omni/Agent/Tools.hs
Created3 months ago·Updated1 month ago

Description

Edit

Add a glob tool to Omni/Agent/Tools.hs that finds files by glob pattern.

Data Types

data GlobArgs = GlobArgs
  { globPattern :: Text     -- Glob pattern, e.g., "**/*.hs", "src/**/*.py"
  , globPath :: Maybe Text  -- Optional: directory to search in (default: ".")
  , globLimit :: Maybe Int  -- Max results (default: 100)
  }
  deriving (Show, Eq, Generic)

Implementation

1. Add GlobArgs data type with FromJSON instance 2. Create globTool :: Engine.Tool with:

  • name: "glob"
  • description: "Find files matching a glob pattern. Returns paths sorted by modification time (most recent first). Respects .gitignore."

3. Implement executeGlob by shelling out to fd: bash fd --glob "<pattern>" --type f "<path>" | head -n <limit> 4. Add globTool to allTools list 5. Update the test that checks tool count (currently expects 6, will be 7) 6. Add globTool to the exports list in the module header

Tool Schema

{
  "type": "object",
  "properties": {
    "pattern": { "type": "string", "description": "Glob pattern like **/*.hs or src/**/*.py" },
    "path": { "type": "string", "description": "Directory to search in (default: current directory)" },
    "limit": { "type": "integer", "description": "Maximum number of results (default: 100)" }
  },
  "required": ["pattern"]
}

Testing

Add a unit test that runs glob with pattern "*.hs" and verifies it returns results.

Notes

  • fd is available in the NixOS environment
  • If fd is not found, fall back to find . -name "<pattern>"
  • Return paths relative to the search directory

Timeline (4)

🔄[human]Open → InProgress1 month ago
💬[human]1 month ago

CHANGES REQUESTED: ## Code Review: Implement glob tool for file pattern matching

Task Compliance

GlobArgs data type added with correct fields (globPattern, globPath, globLimit) ✅ FromJSON instance implemented correctly ✅ globTool :: Engine.Tool created with correct name, description, and schema ✅ executeGlob implemented using fd command ✅ Fallback to find when fd fails ✅ globTool added to allTools list ✅ Test count updated from 6 to 7 ✅ globTool and GlobArgs added to exports ✅ Unit tests added for schema validation, args parsing, and actual glob execution

Issues Found

1. Lint warning: There's a redundant bracket that hlint flagged: haskell (not (Text.null (toolResultOutput tr))) Test.@=? True Should be: haskell not (Text.null (toolResultOutput tr)) Test.@=? True

2. Description mismatch: The tool description says "sorted by modification time (most recent first)" but the fd command doesn't include --changed-within or sorting options. The default fd output is not sorted by modification time. Either the description should be updated or --exec-batch stat --printf '%Y %p\n' with sorting should be added.

3. Minor: The fallback find command uses -name which only matches the filename, not a full glob path like **/*.hs. This is noted in the task as acceptable fallback behavior, but worth noting the semantic difference.

Build & Test Status

✅ Build passes ✅ All 22 tests pass ⚠️ Lint has 1 warning (redundant bracket)

Code Quality

  • Code follows project conventions (using <|, <*>, Text.pack, etc.)
  • Proper error handling with mkSuccess and mkError
  • Clean separation between main execution and fallback

Summary

The implementation is functional and accomplishes the core task. However, there are two issues that should be addressed:

1. The lint warning about redundant brackets needs to be fixed 2. The description claims sorting by modification time which isn't implemented

🔄[human]InProgress → Done1 month ago