This is a WIP (work-in-progress) project 🚧👷♂️
codypy
is a Python wrapper binding to Cody Agent through establishing a connection to the Cody-Agent server from Sourcegraph Cody using JSON-RPC (Remote Procedure Call) protocol over a TCP/stdio connection. It allows sending and receiving JSON-RPC messages asynchronously. 📨📥
Note 1: You need to register an account at Sourcegraph and create an API key.
Note 2: This project is currently in an experimental alpha stage. The API and functionality may change and break in future versions.
- Connects to a server using TCP sockets or via stdio
- Sends JSON-RPC messages to the server
- Receives and processes JSON-RPC messages from the server
- Handles connection errors and timeouts
- Extracts method and result from JSON-RPC responses
- Supports asynchronous communication using
asyncio
library - Show inferred context files if any with optional line ranges
- Python 3.7+
asyncio
library- The Cody Agent CLI binary will be downloaded automatically based on the OS and architecture from https://github.com/sourcegraph/cody/releases
-
Clone the repository:
git clone https://github.com/PriNova/codypy.git
-
Navigate to the project directory:
cd codypy
-
Ensure you have Python 3.7 or higher installed:
python --version
-
The
asyncio
library is included in the Python standard library, so no additional installation is required. -
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate
-
Install the dependencies from the
requirements.txt
file:pip install -r requirements.txt
-
Rename the provided
env.example
file to.env
and set theSRC_ACCESS_TOKEN
value to your API key and the pathBINARY_PATH
to where the cody agent binary should be downloaded and accessed. Use the following command in Linux to rename your file:mv env.example .env
-
Run the script using
python main.py
.
You are now ready to use codypy!
You can also install the package in dev mode via pip install -e .
- Required to set the 'BINARY_PATH' where to download or use the agent binary
- Required to set the 'SRC_ACCESS_TOKEN' env to the API Token from your Sourcegraph account.
- Set your workspace path in the 'workspaceRootUri' property to your local GitHub repository.
- Run the example script using
python main.py
. - The script will attempt to connect to the Cody Agent.
- If the connection is successful, it will send an initialization message to the server.
- The script will then receive and process JSON-RPC messages from the server.
- It will extract and display the method and result from the received messages if
is_debugging
is set toTrue
. - You will be in 'chat' mode, where you can have a conversation with the Cody Agent based on your input and enhanced context about your codebase.
- The script will continue to receive messages until you input
/quit
. The server closes then the connection.
If installed as a package like mentioned above, you can also use codypy as a CLI tool. Simply export SRC_ACCESS_TOKEN
and BINARY_PATH
to your environment and in the terminal execute codypy-cli --help
to see the available options and flags.
For an example of initializing and chatting, look at main.py file
This example demonstrates how to use a complete cycle to establish a connection to the server and process JSON-RPC messages.
- Improve the parsing and handling of JSON-RPC responses in
receive_jsonrpc_messages()
function. - Enhance the initialization message in
initializing_message()
function to include additional client information. - Implement reliable logging functionality to track client-server communication.
- Implement CLI tooling.
- Download the cody agent binary based on OS and arch.
- Develop unit tests for key functions in
codypy
. - Create documentation and examples for using the
codypy
client library. - Implement support for including additional context about files and folders.
- Configure repository context.
- Show inferred context files from the conversation.
Copyright notices for third-party code included are licensed under their respective licenses.
This project is licensed under the MIT License.