<!--
SPDX-FileCopyrightText: Amolith <amolith@secluded.site>

SPDX-License-Identifier: CC0-1.0
-->

# garble

[![Package Version](https://img.shields.io/hexpm/v/garble)](https://hex.pm/packages/garble)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/garble/)
[![REUSE status](https://api.reuse.software/badge/git.secluded.site/garble)](https://api.reuse.software/info/git.secluded.site/garble)
[![Liberapay donation status](https://img.shields.io/liberapay/receives/Amolith.svg?logo=liberapay)](https://liberapay.com/Amolith/)

Transform stdin with an LLM. Pipe text in, get transformed text out.

## tl;dr

```bash
# Fix typos and grammar
echo "teh quikc brown fox" | garble --directions "fix typos"

# Translate
cat letter.txt | garble --directions "translate to Pirate"

# Reformat
pbpaste | garble --directions "convert to markdown table" | pbcopy
```

## Installation

```bash
# Clone and install to ~/.local/bin
git clone https://git.secluded.site/garble
cd garble
make install

# Or install elsewhere
make install PREFIX=/usr/local
```

Requires Erlang/OTP and the Gleam toolchain.

## Usage

```bash
garble [--provider PROVIDER] [--model MODEL] [--directions "..."]
```

All flags are optional if configured in `~/.config/garble/config.toml`.

### Flags

| Flag           | Description                                 | Example values                              |
| -------------- | ------------------------------------------- | ------------------------------------------- |
| `--provider`   | Provider ID                                 | `openai`, `anthropic`, `google`             |
| `--model`      | Model ID                                    | `gpt-4o`, `claude-3-opus`, `gemini-1.5-pro` |
| `--directions` | Instructions for how to transform the input | `"fix grammar and spelling"`                |

### Configuration

Create `~/.config/garble/config.toml`:

```toml
provider = "anthropic"
model = "claude-sonnet-4-20250514"
directions = "fix grammar and spelling"

# API key options (in order of precedence):
# 1. Run a command to get the key
api_key_cmd = "op read 'op://Private/Anthropic/credential'"

# 2. Or set it directly (not recommended)
# api_key = "sk-..."
```

If neither `api_key_cmd` nor `api_key` is set, garble falls back to the
provider's environment variable (e.g. `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`).

CLI flags override config file values.

## Contributions

Patch requests are in [amolith/llm-projects] on [pr.pico.sh]. You don't
need a new account to contribute, you don't need to fork this repo, you
don't need to fiddle with `git send-email`, you don't need to faff with
your email client to get `git request-pull` working...

You just need:

- Git
- SSH
- An SSH key

```sh
# Clone this repo, make your changes, and commit them
# Create a new patch request with
git format-patch origin/main --stdout | ssh pr.pico.sh pr create amolith/llm-projects
# After potential feedback, submit a revision to an existing patch request with
git format-patch origin/main --stdout | ssh pr.pico.sh pr add {prID}
# List patch requests
ssh pr.pico.sh pr ls amolith/llm-projects
```

See "How do Patch Requests work?" on [pr.pico.sh]'s home page for a more
complete example workflow.

[amolith/llm-projects]: https://pr.pico.sh/r/amolith/llm-projects
[pr.pico.sh]: https://pr.pico.sh

## License

AGPL-3.0-or-later
