Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
03264d6
Add Anthropic (Claude) API backend
bddap-bot May 29, 2026
65da913
Drop empty text blocks; live-tested against Anthropic
bddap-bot May 29, 2026
1e2fb8e
anthropic: log request via tracing::debug! instead of REFAC_DEBUG epr…
bddap-bot Jun 2, 2026
c9474ae
config: infer provider from available API keys when unset
bddap-bot Jun 2, 2026
51d6466
config: drop the max_tokens setting
bddap-bot Jun 2, 2026
678410a
config: error on invalid REFAC_PROVIDER; bump OpenAI default to gpt-5.5
bddap-bot Jun 2, 2026
8321e6b
login: take --provider flag, or pick interactively
bddap-bot Jun 2, 2026
0681b6e
anthropic: caller owns the cache-prefix boundary
bddap-bot Jun 2, 2026
7268ea8
Merge remote-tracking branch 'origin/main' into anthropic-backend
bddap-bot Jun 2, 2026
e970886
anthropic: drop the "no official Rust SDK" line from module docs
bddap-bot Jun 2, 2026
16b3dd5
anthropic: trim module docs, drop max_tokens comment, enum the type tags
bddap-bot Jun 2, 2026
538ae2b
anthropic: trim build_request doc to what readers need
bddap-bot Jun 2, 2026
a88238f
config: drop WHAT comment in resolve_provider
bddap-bot Jun 2, 2026
898239a
config: rename resolve_provider -> provider
bddap-bot Jun 2, 2026
f982110
login: derive provider labels from the choices list
bddap-bot Jun 2, 2026
f30572f
core: multi-field provider-agnostic Message; adapters do the converting
bddap-bot Jun 2, 2026
0f7cc71
openai: emit each field as its own message, don't concat
bddap-bot Jun 2, 2026
f10ab40
anthropic: raise MAX_TOKENS to 80000
bddap-bot Jun 2, 2026
a3c4be9
anthropic: represent type-tagged wire shapes as serde enums
bddap-bot Jun 2, 2026
f957cad
split provider wire code out of api.rs
bddap-bot Jun 2, 2026
2eeeffc
prompt: drop the cache-marking comment
bddap-bot Jun 2, 2026
b4f817b
README: sync with the provider changes
bddap-bot Jun 2, 2026
2804dea
README: trim the config blurb
bddap-bot Jun 2, 2026
eca0c21
secrets: write secrets.toml 0600; log provider as the enum
bddap-bot Jun 2, 2026
610e2db
README: regenerate the examples with Opus 4.8
bddap-bot Jun 2, 2026
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
96 changes: 94 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ reqwest = { version = "0.13", default-features = false, features = [
"json",
] }
rpassword = "7.5.0"
dialoguer = "0.11"
serde = { version = "1.0.154", features = ["derive"] }
serde_json = "1.0.94"
similar = "2.2.1"
Expand Down
86 changes: 38 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ The workflow:
- Run the command, write instructions on what you want changed.
- Enjoy the sassy comments.

This tool calls the openai api. You'll need your own api key to use it.
Use `refac login` to enter your api key. It will be saved in your home directory
for future use. See [your api usage](https://platform.openai.com/account) .
Calls Claude by default — bring your own key and run `refac login` (or set
`ANTHROPIC_API_KEY`). For OpenAI, set `REFAC_PROVIDER=openai` and `OPENAI_API_KEY`.
Optional `provider` / `model` config lives in `~/.config/refac/config.toml`.

## SETUP

Expand All @@ -30,31 +30,25 @@ THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
> refac tor '
def add(a: int, b: int):
return a + b
' 'turn this into a command line program that accepts a and b as arguments, printing the result'`
# I've transformed your `add` function into a command-line script that accepts two integer arguments and prints their sum.
# Based on the syntax of your code, I assume you're using Python. If this is incorrect, please let me know.
# Run the script with `python add.py <a> <b>` where `<a>` and `<b>` are the integers you want to add.
' 'turn this into a command line program that accepts a and b as arguments, printing the result'
# Another riveting addition machine for the ages. I'll spruce it up with type hints and argparse,
# because apparently I have standards even when you don't.
# Run it with `python add.py <a> <b>`.
# --refac

import sys
import argparse

def add(a: int, b: int):
return a + b

if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python add.py <a> <b>")
sys.exit(1)
def add(a: int, b: int) -> int:
return a + b

try:
a = int(sys.argv[1])
b = int(sys.argv[2])
except ValueError:
print("Both arguments must be integers.")
sys.exit(1)

result = add(a, b)
print(f"The result of {a} + {b} is {result}.")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Add two integers.")
parser.add_argument("a", type=int, help="The first integer.")
parser.add_argument("b", type=int, help="The second integer.")
args = parser.parse_args()
print(add(args.a, args.b))

> refac tor '
fn factorial(a: usize) -> usize {
Expand All @@ -65,42 +59,41 @@ fn factorial(a: usize) -> usize {
}
}
' 'switch to an iterative implementation'
// Recursion is elegant and all, but why summon the stack-overflow goblins when a loop will do?
// Here's your iterative factorial, served fresh.
// --refac
fn factorial(a: usize) -> usize {
// Switched to an iterative implementation using a loop.
// --refac
let mut result = 1;
for i in 1..=a {
for i in 2..=a {
result *= i;
}
result
}

> refac tor '
fn factorial(a: usize) -> usize {
let mut result = 1;
for i in 1..=a {
result *= i;
}
result
let mut result = 1;
for i in 1..=a {
result *= i;
}
result
}
' 'use an iterator and .fold()'
// Look at you, embracing the functional style! I'm getting all warm and fuzzy inside.
// --refac
fn factorial(a: usize) -> usize {
(1..=a).fold(1, |acc, x| acc * x)
(1..=a).fold(1, |result, i| result * i)
}

> refac tor '' 'implement hello world in rust'
// Here's a simple "Hello, World!" program in Rust.
// Compile it with `rustc hello_world.rs` and run it with `./hello_world`.
// Behold! A masterpiece of unparalleled complexity. Try not to strain yourself.
// --refac

fn main() {
println!("Hello, World!");
println!("Hello, world!");
}

> refac tor '' 'write fizzbuzz in rust'
// Oh, great. The ultimate test of awesomeness. *eyeroll*
// Fine. Here's a sparkling FizzBuzz implementation forged with pure Rustian might just for you.
// Run with `cargo run`.
// FizzBuzz, the eternal rite of passage. You've ascended to junior dev status, congrats.
// --refac
fn main() {
for i in 1..=100 {
Expand All @@ -116,32 +109,29 @@ fn main() {
> refac tor '
Hey [Name],

I\'m writing to ask if you can lend me $100. I promise I\'ll pay you back as soon as possible.
I'm writing to ask if you can lend me $100. I promise I'll pay you back as soon as possible.
Thanks,

[Your Name]
' 'make the email more formal and appropriate for a professional setting'
Subject: Request for Temporary Financial Assistance

Dear [Name],

I hope this email finds you well. I am reaching out to request a temporary financial loan of $100. Due to unforeseen circumstances, I find myself in a situation where I require immediate support. Please know that I do not take this request lightly, and I understand the responsibility that comes with borrowing money.
I hope this message finds you well. I am writing to respectfully request a short-term loan of $100. I would be most grateful for your assistance, and I assure you that I will repay the amount at the earliest possible opportunity.

I would like to emphasize my commitment to repaying the loan as promptly as possible. Your assistance during this challenging time would be greatly appreciated, and I assure you that I am doing everything in my power to improve my financial situation.
Please let me know if this is something you would be willing to consider. I am happy to discuss any terms or arrangements that would be convenient for you.

Should you have any concerns, questions, or require additional information, please do not hesitate to reach out to me. I am more than happy to discuss the matter further.
Thank you very much for your time and consideration.

Thank you very much for your time and consideration. I eagerly await your response.

Sincerely,
Best regards,

[Your Name]
```

## Using Refac From Your Favorite Text Editor

First, make sure you have:
- [ ] installed refac
- [ ] entered your [api key](https://platform.openai.com/account/api-keys) using `refac login`
- [ ] entered your [API key](https://console.anthropic.com/settings/keys) using `refac login`

### Emacs

Expand Down
Loading