waveterm/pkg
Copilot fa19d7c287
Add read_dir AI tool for reading directory contents (#2414)
- [x] Explore repository structure and understand existing tools pattern
- [x] Create tools_readdir.go file with read_dir tool implementation
- [x] Add GetReadDirToolDefinition() function following the pattern of
read_text_file
- [x] Register the new tool in tools.go GenerateTabStateAndTools
function
- [x] Create comprehensive tests in tools_readdir_test.go
- [x] Test the implementation manually with various scenarios
- [x] Run Go tests to ensure no regressions
- [x] Run security check with CodeQL - No vulnerabilities found
- [x] Revert unintended changes to tsunami demo go.mod and go.sum files
- [x] Fix sorting to happen before truncation and preserve real total
count

## Summary

Successfully implemented a new `read_dir` AI tool that reads and lists
directory contents, following the same pattern as the existing
`read_text_file` tool.

**Key Features:**
- Supports path expansion (including ~)
- Sorts directories first, then files (sorting happens BEFORE
truncation)
- Truncates output to prevent overwhelming responses (default 1000
entries)
- Preserves the real total count even when truncated
- Requires user approval for security
- Provides detailed file/directory information (name, type, size,
permissions, modification time)
- Returns both structured data and formatted listing

**Files Changed:**
- `pkg/aiusechat/tools_readdir.go` - Main implementation (189 lines)
- `pkg/aiusechat/tools_readdir_test.go` - Comprehensive tests (211
lines)
- `pkg/aiusechat/tools.go` - Tool registration (1 line)

**Testing:**
-  All 6 unit tests passing (including new test for
sort-before-truncate)
-  Manual testing with real directories successful
-  CodeQL security scan passed with no vulnerabilities
-  Go build and vet successful

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>

> Right now we have AI tools in go at pkg/aichat ... see tools.go,
tools_readfile.go. i'd like to add a new tool to read directories in the
style of readfile.


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Co-authored-by: sawka <mike@commandline.dev>
2025-10-09 21:41:50 -07:00
..
aiusechat Add read_dir AI tool for reading directory contents (#2414) 2025-10-09 21:41:50 -07:00
authkey Happy new year! (#1684) 2025-01-04 20:56:57 -08:00
blockcontroller New AIPanel (#2370) 2025-10-07 13:32:10 -07:00
blocklogger conn updates 3 (#1711) 2025-01-10 14:09:32 -08:00
docsite Add license identifiers to missing files (#1806) 2025-01-22 20:06:36 -08:00
eventbus Happy new year! (#1684) 2025-01-04 20:56:57 -08:00
faviconcache web bookmarks (#1930) 2025-02-07 16:11:40 -08:00
filestore Fix windows path for wsh url (#1798) 2025-01-22 17:28:59 -08:00
genconn WSL Updates for New Architecture (#1756) 2025-01-16 15:54:58 -08:00
gogen Embedded Structs in Code Generation (#1909) 2025-02-07 13:13:47 -08:00
ijson Happy new year! (#1684) 2025-01-04 20:56:57 -08:00
panichandler new tevents analytics framework (#1894) 2025-02-03 15:32:44 -08:00
remote Not found paths in prefix fs always treated as dir (#2002) 2025-02-21 16:32:14 -08:00
schema settings schema.json (#1874) 2025-02-03 14:20:50 -08:00
service add tsunami view in wave (#2350) 2025-09-15 12:58:59 -07:00
shellexec implement cmd:jwt and fix remote execution of commands (#2292) 2025-08-26 16:23:48 -07:00
suggestion remove wsh s3 dependency (#1994) 2025-02-18 18:52:32 -08:00
telemetry openai native web search tool enabled (#2410) 2025-10-09 15:06:40 -07:00
trimquotes Add license identifiers to missing files (#1806) 2025-01-22 20:06:36 -08:00
tsgen New AIPanel (#2370) 2025-10-07 13:32:10 -07:00
userinput Known Hosts User Input Fix (#1778) 2025-01-20 14:38:40 -08:00
util New data-tooluse AI SDK packet and Tool Approvals Implemented (#2407) 2025-10-09 10:21:01 -07:00
utilds add tsunami view in wave (#2350) 2025-09-15 12:58:59 -07:00
vdom Happy new year! (#1684) 2025-01-04 20:56:57 -08:00
waveai New AIPanel (#2370) 2025-10-07 13:32:10 -07:00
waveapp fail any rpc call which blocks the runServer loop for more than 1s (#1861) 2025-01-27 22:38:19 -08:00
wavebase add tsunami view in wave (#2350) 2025-09-15 12:58:59 -07:00
waveobj New AIPanel (#2370) 2025-10-07 13:32:10 -07:00
wcloud new tevents analytics framework (#1894) 2025-02-03 15:32:44 -08:00
wconfig switch to using gpt-5-mini for free proxy (#2297) 2025-08-28 14:28:49 -07:00
wcore onboarding and polish for v0.12 (#2411) 2025-10-09 16:29:09 -07:00
web New data-tooluse AI SDK packet and Tool Approvals Implemented (#2407) 2025-10-09 10:21:01 -07:00
wps New AIPanel (#2370) 2025-10-07 13:32:10 -07:00
wshrpc New data-tooluse AI SDK packet and Tool Approvals Implemented (#2407) 2025-10-09 10:21:01 -07:00
wshutil s3 suggestions + widget cache (#1987) 2025-02-18 15:15:12 -08:00
wsl WSL Updates for New Architecture (#1756) 2025-01-16 15:54:58 -08:00
wslconn new tevents analytics framework (#1894) 2025-02-03 15:32:44 -08:00
wstore New AIPanel (#2370) 2025-10-07 13:32:10 -07:00