The goal of this project is to extend the existing AI Hub with an interactive coding assistant. This assistant will enable an AI to directly "work" on a user's local codebase, allowing it to understand, debug, and modify a project's files by communicating with a lightweight client running on the user's machine.
This is a significant step beyond a traditional RESTful API, as it allows for real-time, bi-directional communication, which is essential for the dynamic, back-and-forth nature of a coding session.
The project is built on two main components that communicate over a WebSocket (WSS) connection:
AI Hub (Server): The central brain of the operation. This is your existing FastAPI application, which will be extended to include WebSocket endpoints. The server's primary responsibilities are:
Local Client: A new, lightweight application that runs on the user's machine. Its sole purpose is to act as a secure, local intermediary. Its responsibilities are:
A clear, robust communication schema is the foundation of this project. All communication over the WebSocket will be a JSON object with a consistent structure, using a type
to identify the command and a request_id
to link a request to its response.
These are the commands the AI Hub sends to the local client.
type |
Description | Payload |
---|---|---|
list_files |
Requests a list of files and folders in a specified directory. | {"path": "./"} |
read_files |
Requests the content of one or more specific files. | {"files": ["src/main.py", "tests/test.py"]} |
execute_command |
Instructs the client to execute a shell command in the project root directory. | {"command": "npm test"} |
write_file |
Instructs the client to overwrite a specific file with new content. | {"path": "src/main.py", "content": "new code..."} |
These are the responses the local client sends back to the AI Hub. All responses must include the original request_id
.
type |
Description | Payload |
---|---|---|
list_files_response |
Returns a list of files and folders. | {"status": "success", "files": [{"name": "...", "is_dir": true}]} |
read_files_response |
Returns the content of the requested files. | {"status": "success", "files": {"path": "content"}} |
command_output |
Returns the stdout and stderr from the executed command. |
{"status": "success", "stdout": "...", "stderr": "..."} |
write_file_response |
Confirms if a file was successfully written or returns an error. | {"status": "success"} |
In the event of an error (e.g., a file not found), the client will always return a status: "error"
in the payload, along with a human-readable error_message
.
We can tackle this project in three phases to ensure a solid foundation.
workspace.py
route file and define a basic websocket
endpoint.command_output
, etc.) and for sending commands to the client.list_files
, read_files
, and execute_command
. This client must include robust file system checks to prevent access outside the designated directory.list_files
command to the client, receive a list of files, and then send a read_files
command for one of those files.rm
).