aws / aws/amazon-q-developer-cli

Feature request -- fs_read and fs_write should display the number of lines read/write

Open
#1,450 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2k
Forks
439
PR merge metrics
No merged PRs in 30d

Description

### Checks

- [x] I have searched [github.com/aws/amazon-q-developer-cli/issues](https://github.com/aws/amazon-q-developer-cli/issues?q=) and there are no duplicates of my issue
- [x] I have run `q doctor` in the affected terminal session
- [x] I have run `q restart` and replicated the issue again

### Operating system

Amazon Linux 2

### Expected behaviour

I would like `fs_read` and `fs_write` to display an absolute number of lines processed, rather than the word `all`. For example:

#### Reads lines from existing file:
```
I'll check the file at ~/workplace/AmazonQ.md for relevant instructions.

🛠️ Using tool: fs_read (trusted)

● Reading file: ~/workplace/AmazonQ.md, (121/121 lines)

● Completed in 0.0s
```

#### Reads existing empty file:
```
I'll check the file at /workplace/AmazonQ.md for relevant instructions.

🛠️ Using tool: fs_read (trusted)

● Reading file: /workplace/AmazonQ.md, (0/0 lines)

● Completed in 0.0s
```

#### Reads file that doesn't exist
```
I'll check the file at /dne/workplace/AmazonQ.md for relevant instructions.

🛠️ Using tool: fs_read (trusted)

● Reading file: /dne/workplace/AmazonQ.md, (no such file)

● Completed in 0.0s
```

### Actual behaviour

The `fs_read` and `fs_write` tools interact with the filesystem, but due to an unrelated issue (https://github.com/aws/amazon-q-developer-cli/issues/1449), Q often misunderstands my filesystem directory structure, and attempts to read a file from the wrong location. When it does this, it will say "Read file, all lines" regardless of whether the file exists and has legitimate content, or the file exists but has 0 content. In attempting to reproduce this, I did not get the identical behavior for the empty file, but have shown the transcripts below.

#### File exists:
```
I'll check the file at ~/workplace/AmazonQ.md for relevant instructions.

🛠️ Using tool: fs_read (trusted)

● Reading file: ~/workplace/AmazonQ.md, all lines

● Completed in 0.0s
```

#### File does not exist:
```
> Read the file at /dne/AmazonQ.md

I'll try to read the file at /dne/AmazonQ.md for you.

Tool validation failed:
Failed to validate tool parameters: '/dne/AmazonQ.md' does not exist

I'm unable to read the file at /dne/AmazonQ.md because the file does not exist. The path /dne/ likely stands for "does not exist" and indeed there is no such directory in your
filesystem.

If you're looking for your AmazonQ.md file, I previously accessed it at ~/workplace/AmazonQ.md (which resolves to /home/alopey/workplace/AmazonQ.md). Would you like me to read
that file again, or were you looking for a different file?
```

#### File exists with no printable content (initially created with `touch ~/zero_lines.md`, then modified with `echo "\n" >> ~/zero_lines.md`):
```
> Read ~/zero_lines.md

I'll try to read the file at ~/zero_lines.md for you.

🛠️ Using tool: fs_read (trusted)

● Reading file: ~/zero_lines.md, from line 1 to 1

● Execution failed after 0.0s:
starting index: 1 is outside of the allowed range: (0, 0)

I attempted to read the file at ~/zero_lines.md, but it appears to be an empty file (zero lines). The error message indicates that the starting index (1) is outside the allowed
range (0, 0), which confirms that the file exists but contains no content.

Would you like me to check if the file exists and get its properties, or would you like me to do something else with this empty file?

> Read ~/zero_lines.md again

I'll try to read the file at ~/zero_lines.md again, taking a different approach to handle the empty file.

🛠️ Using tool: execute_bash (trusted)

● I will run the following shell command: cat ~/zero_lines.md


● Completed in 0.2s

The file ~/zero_lines.md exists but contains only a single newline character. When I tried to read it using the cat command, it returned just a newline.

This explains the previous error - the file isn't completely empty (it has a newline), but it doesn't have any actual content lines to display.

> Read it using the fs_read tool

I'll read the file using the fs_read tool as requested.

🛠️ Using tool: fs_read (trusted)

● Reading file: ~/zero_lines.md, from line 3 to end of file

● Execution failed after 0.0s:
starting index: 0 is outside of the allowed range: (-2, 2)

I tried to read the file using the fs_read tool, but I received an error message: "starting index: 0 is outside of the allowed range: (-2, 2)".

This error suggests that there might be an issue with how the fs_read tool handles empty or nearly empty files. Let me try a different approach with the fs_read tool by specifying
different parameters:
● Completed in 0.0s

🛠️ Using tool: execute_bash (trusted)

● I will run the following shell command:
wc -l ~/zero_lines.md

2 /home/alopey/zero_lines.md


● Completed in 0.2s

🛠️ Using tool: fs_read (trusted)

● Reading file: ~/zero_lines.md, all lines

● Completed in 0.0s

I've tried several approaches to read the file ~/zero_lines.md:

1. First, I used the fs_read tool with default parameters, but received an error about the index being outside the allowed range.

2. Then I tried using fs_read with a negative start_line parameter, but that didn't produce any output.

3. I checked the file using the wc -l command, which shows that the file has 2 lines.

4. Finally, I tried fs_read again with explicit start_line=1 and end_line=2 parameters, but still received no content.

Based on these results, it appears that ~/zero_lines.md contains 2 empty lines (just newline characters) but no actual text content. The fs_read tool seems to have difficulty
handling files that contain only empty lines.

>
```

### Steps to reproduce

1. Open `q chat`
2. Ask to read a file that exists with content
3. See "all lines"

### Environment

```yaml
% q diagnostic

[q-details]
version = "1.9.1"
hash = "5d2c2807cab9bc6c9dc5fcd05f92c7a979e8a4f7"
date = "2025-04-29T06:21:28.508115Z (2d ago)"
version_id = "2"
version = "2"
variant = "internal"

[environment]
cwd = "/local/home/USER"
cli-path = "/local/home/USER"
os = "Linux"
shell-path = "/local/home/USER/.toolbox/tools/toolbox/1.1.1762.0/toolbox-exec"
shell-version = "5.8"
install-method = "toolbox"
in-ssh = true

[env-vars]
PATH = "/home/USER/.local/share/mise/installs/node/18.20.2/bin:/home/USER/.local/share/mise/installs/python/3.12/bin:/home/USER/.local/share/mise/installs/python/3.11/bin:/home/USER/.local/share/mise/installs/python/3.10/bin:/home/USER/.local/share/mise/installs/python/3.9/bin:/home/USER/.local/share/mise/installs/python/3.8/bin:/home/USER/.toolbox/bin:/home/USER/.toolbox/bin:/home/USER/.cargo/bin:/usr/local/bin:/usr/bin:/home/USER/bin:/usr/local/sbin:/usr/sbin:/home/USER/.local/bin"
Q_SET_PARENT_CHECK = "1"
SHELL = "/bin/zsh"
TERM = "screen"
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.