Skip to content

feat: add line range support to get_file_contents tool #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

aryasoni98
Copy link
Contributor

Closes: #350

@aryasoni98 aryasoni98 requested a review from a team as a code owner April 26, 2025 16:02
Copy link
Collaborator

@williammartin williammartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, added some notes. I haven't reviewed the line implementation because I'd rather see tests that pass first.

@@ -15,6 +15,66 @@ automation and interaction capabilities for developers and tools.
## Prerequisites

1. To run the server in a container, you will need to have [Docker](https://www.docker.com/) installed.

## Required Token Permissions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this section. I think it's interesting to have, but should have its own issue for discussion.

- `owner`: Repository owner (string, required)
- `repo`: Repository name (string, required)
- `sha`: Branch name, tag, or commit SHA (string, optional)
- `path`: Only commits containing this file path (string, optional)
- `page`: Page number (number, optional)
- `perPage`: Results per page (number, optional)

### Search
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is moved.

@@ -471,7 +488,39 @@ func GetFileContents(getClient GetClientFn, t translations.TranslationHelperFunc

var result interface{}
if fileContent != nil {
result = fileContent
if fileContent.Content != nil && (begin > 0 || end > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this implementation. Should it be possible for the LLM to only provide the beginning or the end? Whatever we choose should be documented so the LLM understands what is acceptable.

}
} else {
result = fileContent
}
} else {
result = dirContent
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should happen if the LLM provides begin and end but the contents returned are dirContent? How do we communicate what is acceptable to the LLM in the description?

@@ -471,7 +488,39 @@ func GetFileContents(getClient GetClientFn, t translations.TranslationHelperFunc

var result interface{}
if fileContent != nil {
result = fileContent
if fileContent.Content != nil && (begin > 0 || end > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this needs to be unit tested.

}
ranged := lines[startIdx:endIdx]
joined := strings.Join(ranged, "\n")
result = &github.RepositoryContent{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we should check the .Encoding of the file content before deciding that we need to base64 encode it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get_file_contents: Add ability to select line(s) ranges
2 participants