Skip to content

chore: add agent endpoint for querying file system #16736

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

Merged
merged 11 commits into from
Mar 7, 2025
Merged

Conversation

ethanndickson
Copy link
Member

@ethanndickson ethanndickson commented Feb 28, 2025

Closes coder/internal#382

The API differs slightly from the RFC, in the interest of making consumption of the API agnostic to the host operating system of the agent.

Queries supply the requested path as an array:

{
  "path": ["home", "coder"],
  "relativity": "root" 
}

Whilst the agent returns the requested path as an OS-specific path string but also as an array, both absolute. (relativity = root)

Linux:

{
    "absolute_path_string": "/home/coder",
    "absolute_path": ["home", "coder"],
    "contents": [
        {
            "absolute_path_string": "/home/coder/.bash_logout",
            "is_dir": false,
            "name": ".bash_logout"
        },
        ...
    ]
}

Windows:

{
    "absolute_path_string": "C:\\Users\\coder",
    "absolute_path": ["C:\\", "Users", "coder"],
    "contents": [
        {
            "absolute_path_string": "C:\\Users\\coder\\Documents",
            "is_dir": true,
            "name": "Documents"
        },
        ...
    ]
}

API consumers need only append the name of a contents to the existing path array in order to query a subdirectory.
To traverse backwards from path: [], relativity=home, the absolute_path array returned can be used, popping the last element off the array, and changing the relativity to root.
Once the consumer has a target, they can use the absolute_path_string - at no point do they need to know the workspace OS.

Example Usage:

$ http POST localhost:4/api/v0/list-directory path:='["home", "coder"]' relativity=root
HTTP/1.1 200 OK
Content-Length: 649
Content-Type: application/json; charset=utf-8
Date: Fri, 28 Feb 2025 05:53:40 GMT

{
    "absolute_path": [
        "home",
        "coder"
    ],
    "absolute_path_string": "/home/coder",
    "contents": [
        {
            "absolute_path_string": "/home/coder/.bash_logout",
            "is_dir": false,
            "name": ".bash_logout"
        },
        ...
    ]
}

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ethanndickson ethanndickson changed the title feat: add agent endpoint for querying file system chore: add agent endpoint for querying file system Feb 28, 2025
@ethanndickson ethanndickson marked this pull request as ready for review February 28, 2025 03:40
@ethanndickson ethanndickson force-pushed the ethan/agent-ls branch 3 times, most recently from 690da7c to 39aa907 Compare February 28, 2025 06:11
@ethanndickson ethanndickson force-pushed the ethan/agent-ls branch 2 times, most recently from 285ae7f to 4c37100 Compare February 28, 2025 07:37
@ethanndickson ethanndickson merged commit 17f8e93 into main Mar 7, 2025
31 checks passed
@ethanndickson ethanndickson deleted the ethan/agent-ls branch March 7, 2025 04:33
@github-actions github-actions bot locked and limited conversation to collaborators Mar 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement file 'ls' API on Agent
4 participants