Repository navigation
fix(tools): expand ~ in the data, file-info, browse and grep tools - #4642
Conversation
amd#4576 expanded a leading ~ in the read/write/edit and indexing tools, but analyze_data_file, get_file_info, browse_directory and search_file_content still treated "~/sales.csv" as a relative path. "What's the total in ~/data/sales.csv?" answered "File not found: ~/data/sales.csv", or the agent went searching and analysed a different file with a similar name. Each now expands at its entry, before the sandbox check, the same way the amd#4576 tools do.
|
Verdict: Approve Four more file tools (data analysis, file info, folder browsing, and text search) now understand One thing is still open: the eval categories in the test plan haven't been re-scored. Running Real-world evidenceN/A: the evidence stage didn't run for this PR (no evidence bundle). The PR description includes before-state evidence from eval run 37110051697 ( 🔍 Technical detailsIssues found
Checked and fine
Strengths
|
File tools now all check the same allowed-folders rule. Before, `read_file` and `write_file` checked a path against the session's allowed folders (asking the user when it was outside), but several neighbouring tools did not: folder browsing and directory search, recent files, document and code indexing, folder watching, `list_files`, and the paths screenshots, transcripts, speech and exports are saved to. Now every one goes through the same check and the same approval prompt, so a chat scoped to its documents behaves the same whichever tool the model picks. - **One rule, not a second one.** Tools call the existing `PathValidator.validate_read` / `validate_write` through a thin helper. The validator now expands `~` before resolving symlinks and `..`, so it judges the path the tool actually opens. - **Approving a folder now covers document indexing too.** The chat agent's RAG SDK kept a separate validator, so a folder approved in the chat was still refused at indexing time. It now shares the agent's. - **Wider on purpose, and documented:** name search over the common document folders (it returns paths only, and opening one is checked), GAIA's own output folders, and `capture_skill`, which asks the user on every call. <details> <summary>🔍 Technical details</summary> - Helper: `gaia.agents.tools.path_access` (`read_access_error`, `write_access_error`, `readable_entry`). Folder walks call `readable_entry` per file, which never prompts. - Model-visible changes: refusal text from these tools is now the validator's standard message, `list_recent_files` reports `locations_not_searched`, and `search_directory` with no root searches the allowed folders instead of the whole home folder. No tool docstrings changed. - Overlap with amd#4642: both PRs add the same `~` expansion to `browse_directory`, `get_file_info`, `analyze_data_file` and `search_file_content`, with identical lines, so either merge order applies cleanly. Merging amd#4642 first is the simplest order. - Nearby open PRs: amd#4613 and amd#4648 (`rag_tools.py`), amd#4644 (`code_index_tools.py`), amd#4626 (`filesystem_tools.py`), and amd#4647 (flagship CHANGELOG). Their hunks don't overlap these, but whichever lands second may need a trivial rebase. </details> ## Test plan - [x] `pytest tests/unit/test_file_tools_allowed_folders.py hub/agents/chat/python/tests/test_chat_file_tools_allowed_folders.py`: 66 tests. For each tool, a path outside the allowed folders (direct, through `..`, and through a symlink) goes through the approval prompt and is refused, and a path inside still works. 41 of them fail on main. The ChatAgent tests live in the chat package, so the chat-agent lane runs them; the core unit lane has no `gaia_agent_chat`. - [x] Existing file, RAG, audio, screenshot, code-index, security and chat-agent unit tests pass. The two local failures (`test_persisted_grants_are_not_unioned_into_a_host_scope`, `test_backups_directory_is_owner_only`) also fail on main on this machine. - [x] black, isort, flake8 and pylint are clean on the changed files. - [ ] Follow-up after the core release that ships `path_access`: raise the chat and flagship `amd-gaia` floors to it, as the chat CHANGELOG records. - [ ] CI eval re-run, since refusal text and the default search scope are model-visible: `gaia_files`, `gaia_core`, `gaia_data`, `tool_selection`. --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
Asking "what's the total revenue in ~/data/sales.csv?" returned "File not found: ~/data/sales.csv". The agent then either gave up or searched for a similarly named file and analysed that one instead. #4576 fixed
~for read/write/edit and indexing, but four read-side tools still treated~/xas a relative path:analyze_data_file,get_file_info,browse_directoryandsearch_file_content. All four now expand~before their sandbox check, the same way the #4576 tools do.Evidence from run 37110051697:
data_total_revenue:analyze_data_file("~/gaia-eval/csv/sales.csv")→File not found(backend log). The agent then pickedsales_data_2025.csvand answered $340,000 instead of $18,600.data_top_product,data_followup_compound,mcp_builtin_fits_better: the sameFile not foundon the first call, followed by afind_filesdetour.🔍 Technical details
Path(file_path)or ranresolve()on the raw string.Path("~/x").resolve()is<cwd>/~/x, so the sandbox check also judged the wrong path.browse_directorydoesn't call_read_access_errorat all. It is left as it was here and will be raised separately.Test plan
pytest tests/unit/test_tool_tilde_expansion.py: four new tests, run inside a sandbox scoped to the fake home. They fail on main and pass with this change.gaia_data,gaia_tool_selection,gaia_mcp,gaia_skills_tasks,gaia_code.