Skip to content
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

feat: client github loads github info via messages #232

Merged
merged 14 commits into from
Jan 16, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: add github client guide to READEM
snobbee committed Jan 15, 2025

Partially verified

This commit is signed with the committer’s verified signature.
spydon’s contribution has been verified via GPG key.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
commit 75158d7ed994175931efb7e55d0dea96b31242a3
202 changes: 95 additions & 107 deletions packages/client-github/README.md
Original file line number Diff line number Diff line change
@@ -1,147 +1,135 @@
# Client-GitHub for Eliza Framework
# Guide to Using the GitHub Client 

## Overview
This guide provides detailed instructions for setting up and using the GitHub client with a specific pull request (PR) branch in the \`sa-eliza\` repository. Follow these steps to configure and test the system before the PR is merged into the `sif-dev` branch.

The `client-github` module is a component of the Eliza framework designed to interact with GitHub repositories. It provides functionalities to clone repositories, manage branches, create pull requests, and maintain file-based knowledge for Eliza agents.
## Prerequisites

This client leverages GitHub's REST API via the `@octokit/rest` library and includes robust error handling and configuration validation.
- Access to a terminal with `git`, `pnpm`, and a compatible Node.js version installed.
- Internet connection to clone the repository and install dependencies.

## Features
## Setup Instructions

- **Repository Management**: Clone, pull, and switch branches
- **File Processing**: Generate agent memories from repository files
- **Pull Request Management**: Create and manage pull requests programmatically
- **Commit Operations**: Stage, commit, and push files with ease
- **Knowledge Base Integration**: Convert repository content into agent memories
- **Branch Management**: Flexible branch switching and creation
### 1. Clone the Repository

## Installation
Clone the `sa-eliza` repository to your local machine:

Install the package as part of the Eliza framework:
bash
pnpm add @elizaos/client-github
```bash
git clone https://github.com/Sifchain/sa-eliza.git
```

### 2. Checkout the PR Branch

Navigate to the repository folder and checkout the PR branch:

## Configuration
```bash
cd sa-eliza
git checkout feat/client-github-load-github-info-via-messages
```

The GitHub client requires the following environment variables:
### 3. Ensure Secure Configuration

| Variable | Description | Required |
|-------------------|------------------------------------|----------|
| `GITHUB_OWNER` | Owner of the GitHub repository | Yes |
| `GITHUB_REPO` | Repository name | Yes |
| `GITHUB_BRANCH` | Target branch (default: `main`) | Yes |
| `GITHUB_PATH` | Path to focus on within the repo | Yes |
| `GITHUB_API_TOKEN`| GitHub API token for authentication| Yes |
Set the following environment variables within the `.env` file. See the next section to know how to create a new GitHub API token.

## Usage
- `GITHUB_API_TOKEN`: API key for GitHub API access.

### Initialization
typescript:packages/client-github/README.md
import { GitHubClientInterface } from "@elizaos/client-github";
// Initialize the client
const client = await GitHubClientInterface.start(runtime);
### 4. Creating a GitHub Classic Token with `public_repo` Scope

### Creating Memories
To generate a GitHub Classic token with the required `public_repo` scope, follow these steps:

```typescript
// Convert repository files to agent memories
await client.createMemoriesFromFiles();
- **Log in to GitHub**: Go to [GitHub](https://github.com/) and log in to your account.

typescript
// Convert repository files to agent memories
await client.createMemoriesFromFiles();
```
- **Access Personal Access Tokens**:

### Creating Pull Requests

```typescript
await client.createPullRequest(
"Feature: Add new functionality",
"feature/new-feature",
[
{
path: "src/feature.ts",
content: "// New feature implementation"
}
],
"Implements new functionality with tests"
);


typescript
await client.createPullRequest(
"Feature: Add new functionality",
"feature/new-feature",
[
{
path: "src/feature.ts",
content: "// New feature implementation"
}
],
"Implements new functionality with tests"
);
```
- Navigate to **Settings** by clicking on your profile picture in the top-right corner.
- Under **Developer settings**, select **Personal access tokens** > **Tokens (classic)**.
- Alternatively, you can go directly to [GitHub's token settings page](https://github.com/settings/tokens).

- **Generate New Token**:

- Click on **Generate new token**.
- Provide a note to identify the purpose of the token (e.g., "Plugin API Access").

- **Select the Scope**:

- Under **Select scopes**, check the box for `public_repo`. This grants access to public repositories.

- **Generate and Save the Token**:

- Scroll to the bottom and click **Generate token**.
- **Important**: Copy and save the token securely as it will not be shown again.

- **Set the Token as Environment Variable**:

### Direct Commits
- Add the generated token to your `.env` file:
- `GITHUB_API_TOKEN=<your_token>`bash
cd sa-eliza
git checkout feat/client-github-load-github-info-via-messages

```typescript
await client.createCommit(
"Update configuration",
[
{
path: "config.json",
content: JSON.stringify(config, null, 2)
}
]
);
### 5. Install Dependencies

Install all necessary dependencies:

```
pnpm install -r --no-frozen-lockfile
```

### 6. Build the Packages

## API Reference
Build the project packages:

```bash
pnpm build
```

### GitHubClientInterface
### 7. Start the Agent

- `start(runtime: IAgentRuntime)`: Initialize the client
- `stop(runtime: IAgentRuntime)`: Clean up resources
Start the agent along with the desired character configuration:

### GitHubClient
```bash
pnpm cleanstart --character=characters/staff-engineer.character.json
```

- `initialize()`: Set up repository and configuration
- `createMemoriesFromFiles()`: Generate agent memories
- `createPullRequest(title: string, branch: string, files: Array<{path: string, content: string}>, description?: string)`: Create PR
- `createCommit(message: string, files: Array<{path: string, content: string}>)`: Direct commit
### 8. Start the Eliza UI

## Scripts
Run the following command to start the Eliza user interface:

```bash
# Build the project
pnpm run build
pnpm start:client
```

# Development with watch mode
pnpm run dev
### 9. Open the Eliza UI in a Browser

# Lint the codebase
pnpm run lint
Open the Eliza UI in your web browser at the following URL:

```
http://localhost:5173/
```

### 10. Select the Staff Engineer Agent

From the UI, select the **Staff Engineer** agent. Send the following message to trigger the GitHub client process:

```
Configure the GitHub repository `snobbee/todo-list` on main branch
```

## Dependencies
You may use another repository if desired. The specified repository is public and contains a simple todo-list app written in Node.js. You can view it here:
[https://github.com/snobbee/todo-list](https://github.com/snobbee/todo-list)

- `@elizaos/core`: ^0.1.7-alpha.2
- `@octokit/rest`: ^20.1.1
- `@octokit/types`: ^12.6.0
- `glob`: ^10.4.5
- `simple-git`: ^3.27.0
### 11. Observe the Process and Validate

## Development Dependencies
You should see several messages added to the chat history:

- `@types/glob`: ^8.1.0
- `tsup`: ^8.3.5
- Configure repo settings
- Initialize repo
- Memorize repo
- Create issues

## Contribution
Visit the repository link to view the created issues:
[https://github.com/snobbee/todo-list/issues](https://github.com/snobbee/todo-list/issues)

Contributions are welcome! Please ensure all code adheres to the framework's standards and passes linting checks.
## Notes

## License
- Ensure that your environment meets all prerequisites to avoid errors.
- If you encounter issues during setup or usage, review the terminal output for debugging information.

This project is licensed under the MIT License. See the LICENSE file for details.