README.md

<p align="center">
  <img src="assets/jules_ex.svg" alt="JulesEx Logo" width="200" height="200">
</p>

# JulesEx

An Elixir client library for the [Jules](https://jules.google.com) [API](https://developers.google.com/jules/api). Jules is an AI-powered coding assistant that can automate software development tasks.

## Features

- Complete API client for Jules API (sources, sessions, activities)
- Support for GitHub repository operations
- Session management with plan approval
- Activity tracking and messaging
- Environment-based configuration
- Comprehensive error handling

## Installation

Add `jules_ex` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:jules_ex, "~> 0.1.0"}
  ]
end
```

## Configuration

Set your Jules API key as an environment variable:

```bash
export JULES_API_KEY="your-api-key-here"
```

Alternatively, configure it in your application config:

```elixir
config :jules_ex,
  api_key: "your-api-key-here"
```

## Usage

### List available sources (GitHub repositories)

```elixir
# List all sources
{:ok, %{"sources" => sources}} = JulesEx.list_sources()

# With pagination
{:ok, response} = JulesEx.list_sources(page_size: 10, page_token: "token")
```

### Create and manage sessions

```elixir
# Create a new session
{:ok, session} = JulesEx.create_session(
  prompt: "Fix the bug in the login function",
  source: "sources/github/owner/repo",
  title: "Bug Fix",
  starting_branch: "main"
)

session_id = session["id"]

# List all sessions
{:ok, %{"sessions" => sessions}} = JulesEx.list_sessions()

# Get a specific session
{:ok, session} = JulesEx.get_session(session_id)

# Approve a plan (if requirePlanApproval was set to true)
{:ok, _} = JulesEx.approve_plan(session_id)

# Send a message to the agent
{:ok, _} = JulesEx.send_message(session_id, "Make it corgi themed!")
```

### Work with activities

```elixir
# List activities in a session
{:ok, %{"activities" => activities}} = JulesEx.list_activities(session_id)

# With pagination
{:ok, response} = JulesEx.list_activities(session_id, page_size: 30)

# Get a specific activity
{:ok, activity} = JulesEx.get_activity(session_id, activity_id)
```

## API Structure

The Jules API is organized around three core resources:

- **Source**: An input source for the agent (e.g., a GitHub repository)
- **Session**: A continuous unit of work within a specific context
- **Activity**: A single unit of work within a session

## Modules

- `JulesEx` - Main module with convenience functions
- `JulesEx.Client` - Low-level HTTP client
- `JulesEx.Source` - Source management
- `JulesEx.Session` - Session management
- `JulesEx.Activity` - Activity tracking

## Example: Orchestrating Multiple Repos

```elixir
# Get all sources
{:ok, %{"sources" => sources}} = JulesEx.list_sources()

# Create sessions for multiple repos in parallel
tasks = Enum.map(sources, fn source ->
  Task.async(fn ->
    JulesEx.create_session(
      prompt: "Update dependencies and fix any compatibility issues",
      source: source["name"],
      title: "Dependency Update"
    )
  end)
end)

# Wait for all sessions to be created
sessions = Task.await_many(tasks, :infinity)
```

## Testing

Run the test suite:

```bash
mix test
```

## Documentation

Generate documentation:

```bash
mix docs
```

## License

Copyright (c) 2025 nshkrdotcom

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Resources

- [Jules API Documentation](https://docs.anthropic.com/claude/docs/jules-api)
- [Jules Web App](https://jules.googleapis.com)