Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ final report comes back. The main agent keeps design decisions and final review.
- **Default profile first:** new runs inherit `OFFLOAD_PROFILE`, the default for an
explicit `--caller`, or the configured default; explicit per-run overrides remain
available when requested or required.
- **Two backends:** Codex CLI and Claude Code, through Anthropic-compatible gateways
or Claude Code's own official login (`"auth_mode": "native"`).
- **Local backends:** Codex CLI, Claude Code (Anthropic-compatible gateway or native login),
and Antigravity CLI over ACP.
- **Named profiles:** a model, provider or managed Codex account, with an optional hint about which tasks it suits.
- **Persistent sessions:** resume related work and inspect previous reports.
- **macOS dashboard:** track tasks, switch profiles and manage accounts.
Expand All @@ -19,8 +19,7 @@ final report comes back. The main agent keeps design decisions and final review.

## Quick start

Requires Go 1.24+ and a signed-in `codex`, or `claude` configured with a supported
gateway. Both backend CLIs run locally.
Requires Go 1.24+ and at least one configured local backend CLI.

```sh
go install github.com/zhoushoujianwork/offload@latest
Expand All @@ -40,6 +39,25 @@ JSON
Creating a profile selects it as the default. New features may require building
from the current source with `go install .`.

### Antigravity CLI

Install `agy` on your PATH and sign in once with `agy acp --login` or an interactive
`agy` session. Offload uses the existing Antigravity credentials.
[Antigravity ACP setup](https://antigravity.google/docs/cli/acp/)

```sh
offload profile save --json <<'JSON'
{"name":"agy","create":true,"backend":"agy"}
JSON
offload -p agy "Inspect this project and summarize its entry points."
offload -r <session> "Continue the previous review."
```

Leave the model and reasoning effort empty to use Antigravity's defaults. Tool
permissions follow Antigravity's settings, and Offload denies requests that would
need interactive approval. This backend uses the default execution policy and does
not enforce Offload tool lists or report per-run token usage or cost.

## Everyday commands

```sh
Expand Down
10 changes: 7 additions & 3 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Run shell examples from the repository root.

## Install

Requires Go 1.24+ and the CLI for your selected backend: [Claude Code](https://docs.anthropic.com/en/docs/claude-code) (`claude` on PATH or at `~/.claude/local/claude`) or [Codex](https://developers.openai.com/codex/cli/) (`codex` on PATH, already signed in).
Requires Go 1.24+ and the CLI for your selected backend. Use [Claude Code](https://docs.anthropic.com/en/docs/claude-code) (`claude` on PATH or at `~/.claude/local/claude`), [Codex](https://developers.openai.com/codex/cli/) (`codex` on PATH, already signed in), or [Antigravity CLI](https://antigravity.google/docs/cli/acp/) (`agy` on PATH, already signed in).

```bash
go install github.com/zhoushoujianwork/offload@latest
Expand Down Expand Up @@ -53,7 +53,7 @@ Run `offload config`, select **Profile**, then **Add profile** to save a bundle

`token_cmd` (preferred) prints the token on stdout, so secrets can live in the macOS Keychain, `pass`, 1Password CLI, etc. A literal `token` field also works.

Optional `endpoint` (`cc` for a Claude Code proxy, `llm` for a generic LLM gateway) applies to Claude profiles only. It is an informational label shown by `offload profiles` and in the settings wizard; it does not change requests. Unknown values and Codex profiles with an endpoint are rejected.
Optional `endpoint` (`cc` for a Claude Code proxy, `llm` for a generic LLM gateway) applies to Claude profiles only. It is an informational label shown by `offload profiles` and in the settings wizard.

### Official Claude (native login)

Expand All @@ -70,7 +70,7 @@ For a native run, offload still drops every caller `ANTHROPIC_*` variable and ke

### How switching works

Profiles select a `backend`: `claude` (the default for existing profiles) or `codex`. Claude profiles provide the three variables Claude Code reads. For each Claude run, offload drops every `ANTHROPIC_*` variable from the caller's environment and sets exactly:
Supported values for `backend` are `claude` (the default for existing profiles), `codex`, and `agy`. For each Claude gateway run, offload drops every `ANTHROPIC_*` variable from the caller's environment and sets the following values.

| profile field | worker env |
|---|---|
Expand All @@ -88,6 +88,10 @@ By default, Codex runs with `--dangerously-bypass-approvals-and-sandbox` for bot

Interrupted Codex runs retain progress and a resume command. Automatic tool-less salvage is supported only for Claude.

### Antigravity workers

An `agy` profile launches `agy acp` with the working directory and any `--add-dir` paths. An optional `model` or `-m` selects a model ID offered by Antigravity. An optional `reasoning_effort` or `-effort` selects a thinking level available for that model. Follow-up runs use `offload -r <session>`. See the [Antigravity CLI quick start](../README.md#antigravity-cli) for profile setup and permissions.

### Choosing a profile

Choose per run with `-p name`, per shell with `OFFLOAD_PROFILE=name`, per calling tool with a [caller default](#per-caller-default-profiles), otherwise through `default` in the config. `offload profiles` lists profiles (name, backend, endpoint or `-`, model, base URL), with `*` marking the selected default; it never prints tokens.
Expand Down
107 changes: 107 additions & 0 deletions internal/cli/agy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package cli

import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"

"github.com/zhoushoujianwork/offload/internal/history"
"github.com/zhoushoujianwork/offload/internal/transcript"
)

func TestAgyACPProfileRunAndResume(t *testing.T) {
work, _ := setup(t, okReply)
dir := t.TempDir()
agy := filepath.Join(dir, "agy")
const script = `#!/bin/sh
set -eu
[ "$1" = acp ] && [ "$2" = --add-dir ] && [ "$3" = "$AGY_TEST_MOUNT" ] || exit 10
read_frame() { IFS= read -r frame; }
read_frame
case "$frame" in *'"method":"initialize"'*'"protocolVersion":1'*) ;; *) exit 11 ;; esac
echo '{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":1,"agentCapabilities":{"sessionCapabilities":{"resume":{}}}}}'
read_frame
case "$frame" in
*'"method":"session/new"'*) report="new" ;;
*'"method":"session/resume"'*'"sessionId":"agy-session"'*) report="resumed" ;;
*) exit 12 ;;
esac
echo '{"jsonrpc":"2.0","id":2,"result":{"sessionId":"agy-session","configOptions":[{"id":"model","currentValue":"default-model"}]}}'
read_frame
case "$frame" in *'"method":"session/set_config_option"'*'"configId":"model"'*'"value":"chosen-model"'*) ;; *) exit 13 ;; esac
echo '{"jsonrpc":"2.0","id":3,"result":{"configOptions":[{"id":"model","currentValue":"chosen-model"}]}}'
read_frame
case "$frame" in *'"method":"session/set_config_option"'*'"configId":"thought_level"'*'"value":"low"'*) ;; *) exit 14 ;; esac
echo '{"jsonrpc":"2.0","id":4,"result":{"configOptions":[{"id":"model","currentValue":"chosen-model"}]}}'
read_frame
case "$frame" in *'"method":"session/prompt"'*'"type":"text"'*'"sessionId":"agy-session"'*) ;; *) exit 15 ;; esac
if [ "${AGY_TEST_HANG:-}" = 1 ]; then exec sleep 60; fi
echo '{"jsonrpc":"2.0","method":"session/update","params":{"sessionId":"agy-session","update":{"sessionUpdate":"tool_call","toolCallId":"tool","title":"Test","kind":"execute"}}}'
echo '{"jsonrpc":"2.0","id":"permission","method":"session/request_permission","params":{"sessionId":"agy-session","options":[{"kind":"allow_once","optionId":"allow"},{"kind":"reject_once","optionId":"deny"}]}}'
read_frame
case "$frame" in *'"id":"permission"'*'"optionId":"deny"'*'"outcome":"selected"'*) ;; *) exit 16 ;; esac
echo '{"jsonrpc":"2.0","method":"session/update","params":{"sessionId":"agy-session","update":{"sessionUpdate":"tool_call_update","toolCallId":"tool","status":"failed"}}}'
echo '{"jsonrpc":"2.0","method":"session/update","params":{"sessionId":"foreign","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"ignored"}}}}'
printf '{"jsonrpc":"2.0","method":"session/update","params":{"sessionId":"agy-session","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"%s "}}}}\n' "$report"
echo '{"jsonrpc":"2.0","method":"session/update","params":{"sessionId":"agy-session","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"report"}}}}'
echo '{"jsonrpc":"2.0","id":5,"result":{"stopReason":"end_turn"}}'
# Some servers exit immediately instead of waiting for the client to close stdin.
`
if err := os.WriteFile(agy, []byte(script), 0700); err != nil {
t.Fatal(err)
}
t.Setenv("PATH", dir+string(os.PathListSeparator)+os.Getenv("PATH"))
mount := t.TempDir()
t.Setenv("AGY_TEST_MOUNT", mount)
input := strings.NewReader(`{"name":"agy","create":true,"backend":"agy","model":"chosen-model","reasoning_effort":"low"}`)
var output, stderr strings.Builder
if code := cmdProfile([]string{"save", "--json"}, input, &output, &stderr); code != 0 {
t.Fatal(stderr.String())
}
if code, out, err := runCLI("-p", "agy", "-d", work, "--add-dir", mount, "first task"); code != 0 || !strings.Contains(out, "new report") {
t.Fatalf("fresh code=%d stdout=%q stderr=%q", code, out, err)
}
if code, out, err := runCLI("-r", "agy-session", "next task"); code != 0 || !strings.Contains(out, "resumed report") {
t.Fatalf("resume code=%d stdout=%q stderr=%q", code, out, err)
}
records, err := history.Read(history.Path())
if err != nil || len(records) != 2 {
t.Fatalf("history: %v %v", records, err)
}
for _, record := range records {
if record.Backend != "agy" || record.NativeProtocol != "acp" || record.ObservedModel != "chosen-model" ||
record.Session != "agy-session" || record.Turns != 1 || record.Denials != 1 ||
record.Usage != nil || record.CostUSD != nil || record.UsageUnavailable == "" || record.CostUnavailable == "" {
t.Fatalf("unexpected ACP history: %+v", record)
}
capture := transcript.Read(transcript.ReadOptions{RunID: record.RunID})
found := false
for _, raw := range capture.Events {
var event transcript.Event
if err := json.Unmarshal(raw, &event); err != nil {
t.Fatal(err)
}
if event.Type == transcript.TypeMessage && event.Role == "assistant" && event.Text == record.Result {
found = true
}
}
if capture.Availability != transcript.Available || !found {
t.Fatalf("missing ACP report in transcript: %+v", capture)
}
}

t.Setenv("AGY_TEST_HANG", "1")
if code, _, err := runCLI("-r", "agy-session", "-t", "2s", "time out"); code != 124 {
t.Fatalf("timeout code=%d stderr=%q", code, err)
}
records, err = history.Read(history.Path())
if err != nil || len(records) != 3 {
t.Fatalf("history after timeout: %v %v", records, err)
}
last := records[2]
if last.Status != "timeout" || last.Session != "agy-session" || last.Cleanup != "" {
t.Fatalf("ACP timeout lost its session or left an owned process: %+v", last)
}
}
2 changes: 1 addition & 1 deletion internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ func cmdProfiles(stdout, stderr io.Writer) int {
aliases += " — " + p.UseFor
}
gateway := p.BaseURL
if p.UsesNativeAuth() {
if p.UsesNativeAuth() || p.BackendName() == "agy" {
gateway = "native official login"
}
fmt.Fprintf(stdout, "%s %-12s %-8s %-5s %-15s %-24s %s%s\n", mark, n, p.BackendName(), firstNonEmpty(p.Endpoint, "-"), tools, p.Model, gateway, aliases)
Expand Down
12 changes: 11 additions & 1 deletion internal/cli/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func safeBaseURL(raw string) (string, bool) {

func authMode(p config.Profile) string {
switch {
case p.UsesNativeAuth():
case p.UsesNativeAuth() || p.BackendName() == "agy":
return "native"
case p.TokenCmd != "":
return "token_cmd"
Expand Down Expand Up @@ -230,6 +230,9 @@ var safeSaveErrors = map[string]bool{
"unknown backend": true,
"invalid Codex reasoning effort": true,
"invalid Codex service tier": true,
"invalid agy reasoning effort": true,
"agy uses native credentials and cannot use Offload gateway settings": true,
"agy cannot use Codex account or service tier settings": true,
"endpoint applies only to claude profiles": true,
"base URL must be http(s) with a host": true,
"model is required": true,
Expand Down Expand Up @@ -266,6 +269,10 @@ func applyProfileRequest(p config.Profile, req profileSaveRequest) (config.Profi
p.Backend = "claude"
}
if req.Backend != nil {
if p.BackendName() != "agy" && *req.Backend == "agy" {
p.BaseURL, p.Endpoint, p.AuthMode, p.Token, p.TokenCmd = "", "", "", "", ""
p.ServiceTier, p.ReasoningEffort = "", ""
}
p.Backend = *req.Backend
}
if req.BaseURL != nil {
Expand Down Expand Up @@ -318,6 +325,9 @@ func applyProfileRequest(p config.Profile, req profileSaveRequest) (config.Profi
if req.Secret != nil {
return p, errors.New("secret is only allowed with token or token_cmd")
}
if p.BackendName() == "agy" {
break // Native credentials are inherent to the agy backend.
}
if p.BackendName() != "claude" {
return p, errors.New("auth_mode applies only to claude profiles")
}
Expand Down
9 changes: 7 additions & 2 deletions internal/cli/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,11 @@ func settingsWizard(p settingsPrompt, cfg *config.Config, name string, add bool)
if _, exists := cfg.Profiles[name]; exists {
return errors.New("profile already exists")
}
index, err := settingsChoice(p, "Backend", []string{"Codex", "Claude gateway"}, 0)
index, err := settingsChoice(p, "Backend", []string{"Codex", "Claude gateway", "Antigravity (agy)"}, 0)
if err != nil {
return err
}
profile.Backend = []string{"codex", "claude"}[index]
profile.Backend = []string{"codex", "claude", "agy"}[index]
}
if profile.BackendName() == "codex" {
profile.Model, err = p.Ask("Model (empty inherits Codex default)", profile.Model)
Expand Down Expand Up @@ -372,6 +372,11 @@ func settingsWizard(p settingsPrompt, cfg *config.Config, name string, add bool)
if err != nil {
return err
}
} else if profile.BackendName() == "agy" {
profile.Model, err = p.Ask("Model (empty inherits Antigravity default)", profile.Model)
if err != nil {
return err
}
} else if profile.UsesNativeAuth() {
// A native profile has no gateway, token or endpoint; only the model is editable here.
profile.Model, err = p.Ask("Model (required, e.g. sonnet)", profile.Model)
Expand Down
20 changes: 16 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Profile struct {
CodexAccount string `json:"codex_account,omitempty"`
Aliases []string `json:"aliases,omitempty"`
IdleTimeout string `json:"idle_timeout,omitempty"`
Backend string `json:"backend,omitempty"` // claude (default) or codex
Backend string `json:"backend,omitempty"` // claude (default), codex, or agy
BaseURL string `json:"base_url"`
Model string `json:"model"`
ReasoningEffort string `json:"reasoning_effort,omitempty"`
Expand Down Expand Up @@ -145,9 +145,12 @@ func (c *Config) resolveNamed(name string) (string, Profile, error) {
}
name = match
}
if p.BackendName() != "claude" && p.BackendName() != "codex" {
if !p.ValidBackend() {
return name, p, fmt.Errorf("profile %q has unknown backend %q", name, p.Backend)
}
if err := p.ValidateAgySettings(); err != nil {
return name, p, err
}
if err := p.ValidateAuthMode(); err != nil {
return name, p, fmt.Errorf("profile %q: %w", name, err)
}
Expand All @@ -167,9 +170,9 @@ func (c *Config) resolveNamed(name string) (string, Profile, error) {
}

// SupportsToolRestrictions reports whether the backend can enforce explicit tool allow or deny
// lists. Claude forwards them to the CLI; Codex has no equivalent control.
// lists. Claude forwards them to the CLI.
func (p Profile) SupportsToolRestrictions() bool {
return p.BackendName() != "codex"
return p.BackendName() == "claude"
}

// AuthModeNative marks a Claude profile that uses the installed Claude Code's official login.
Expand Down Expand Up @@ -210,6 +213,15 @@ func (p Profile) BackendName() string {
return p.Backend
}

func (p Profile) ValidBackend() bool {
switch p.BackendName() {
case "claude", "codex", "agy":
return true
default:
return false
}
}

// SetDefault updates only the default field, preserving other configuration fields.
func SetDefault(path, name string) error {
c, err := Load(path)
Expand Down
23 changes: 22 additions & 1 deletion internal/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ func (p Profile) ValidateClaudeSettings() error {
}
}

func (p Profile) ValidateAgySettings() error {
if p.BackendName() != "agy" {
return nil
}
if p.BaseURL != "" || p.Token != "" || p.TokenCmd != "" || p.Endpoint != "" || p.AuthMode != "" {
return fmt.Errorf("agy uses native credentials and cannot use Offload gateway settings")
}
if p.CodexAccount != "" || p.ServiceTier != "" {
return fmt.Errorf("agy cannot use Codex account or service tier settings")
}
switch p.ReasoningEffort {
case "", "low", "medium", "high", "xhigh", "max":
return nil
default:
return fmt.Errorf("invalid agy reasoning effort")
}
}

// SaveProfile saves a complete bundle, preserving unknown JSON and unrelated profiles.
// Adding selects the new profile; editing preserves the saved default.
func SaveProfile(path, name string, p Profile, add bool) error {
Expand Down Expand Up @@ -140,9 +158,12 @@ func SaveProfile(path, name string, p Profile, add bool) error {
if !add && !exists {
return fmt.Errorf("unknown profile")
}
if p.BackendName() != "codex" && p.BackendName() != "claude" {
if !p.ValidBackend() {
return fmt.Errorf("unknown backend")
}
if err := p.ValidateAgySettings(); err != nil {
return err
}
if err := p.ValidateCodexSettings(); err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions internal/nativeusage/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func SamePromptOverlap(a, b history.Record) bool {
// It refuses to replace a conflicting measured value. Interrupted native records
// are retained as a lower bound (partial_run), never promoted to full-run totals.
func (rd *Reader) Recover(r history.Record) (history.Record, bool, string) {
if r.Backend == "agy" {
return r, false, "Antigravity ACP has no native log accounting adapter"
}
if !Needed(r) {
return r, false, "already covered"
}
Expand Down
Loading
Loading