From 3c59a3c698addc969f00249ab6f5dc41b8ba78f9 Mon Sep 17 00:00:00 2001 From: Tym Rabchuk Date: Wed, 20 May 2026 19:45:09 -0400 Subject: [PATCH 1/2] feat: add AgyRunner for Google Antigravity CLI Wraps `agy --print` from Google's Antigravity CLI (announced 2026-05-19 at I/O 2026), the official successor to Gemini CLI. - `agy --print --dangerously-skip-permissions` with stdin pipe returns the model response on stdout, mirroring the gemini.go shape. - Inserted before GeminiRunner in DetectRunners() so agy wins detection when both binaries are installed. - Treats stdout starting with "Error:" as failure since `agy --print` exits 0 even on internal errors (e.g. print-timeout). Verified against the installed agy v1.0.0: stdin is the prompt input channel; argv after --print is ignored. Build + full test suite pass. --- src/runners/agy.go | 61 +++++++++++++++++++++++++++++++++++++++++++ src/runners/runner.go | 1 + 2 files changed, 62 insertions(+) create mode 100644 src/runners/agy.go diff --git a/src/runners/agy.go b/src/runners/agy.go new file mode 100644 index 0000000..e0b69f8 --- /dev/null +++ b/src/runners/agy.go @@ -0,0 +1,61 @@ +package runners + +import ( + "bytes" + "context" + "fmt" + "os/exec" + "strings" +) + +type AgyRunner struct{} + +func (r *AgyRunner) Name() string { return "agy" } + +func (r *AgyRunner) Available() bool { + _, err := exec.LookPath("agy") + return err == nil +} + +func (r *AgyRunner) Run(ctx context.Context, prompt string, opts RunOpts) (RunResult, error) { + // agy reads the prompt from stdin in --print mode; passing the prompt as + // argv after --print is not used and causes a print-timeout error. + args := []string{"--print", "--dangerously-skip-permissions"} + + cmd := exec.CommandContext(ctx, "agy", args...) + if opts.WorkDir != "" { + cmd.Dir = opts.WorkDir + } + cmd.Stdin = strings.NewReader(prompt) + + var stdout, stderr bytes.Buffer + cmd.Stdout = &stdout + cmd.Stderr = &stderr + + err := cmd.Run() + exitCode := 0 + if err != nil { + if exitErr, ok := err.(*exec.ExitError); ok { + exitCode = exitErr.ExitCode() + } else { + return RunResult{ExitCode: 1}, fmt.Errorf("agy failed to run: %w", err) + } + } + + output := stdout.String() + result := RunResult{Output: output, ExitCode: exitCode} + // agy exits 0 on internal errors (e.g. print timeout) and prints + // "Error: ..." on stdout — surface those as failures rather than + // returning the error string as a successful response. + if exitCode == 0 && strings.HasPrefix(strings.TrimSpace(output), "Error:") { + return result, fmt.Errorf("agy reported error: %s", TruncStr(strings.TrimSpace(output), 200)) + } + if exitCode != 0 { + errMsg := stderr.String() + if errMsg == "" { + errMsg = output + } + return result, fmt.Errorf("agy exited %d: %s", exitCode, TruncStr(errMsg, 200)) + } + return result, nil +} diff --git a/src/runners/runner.go b/src/runners/runner.go index 74b7ac3..cc7e0a4 100644 --- a/src/runners/runner.go +++ b/src/runners/runner.go @@ -29,6 +29,7 @@ func DetectRunners() []Runner { all := []Runner{ &ClaudeRunner{}, &CodexRunner{}, + &AgyRunner{}, &GeminiRunner{}, &LocalRunner{}, } From fdb0e2b2071428e16fb1c0a8b9bffbcb5d57ea1a Mon Sep 17 00:00:00 2001 From: Tym Rabchuk Date: Thu, 21 May 2026 19:59:48 -0400 Subject: [PATCH 2/2] fix(agy): narrow Error: heuristic + extract testable helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review surfaced that the previous HasPrefix(TrimSpace, "Error:") would swallow legitimate model output starting with "Error:" — tri-review routinely asks models to discuss error handling, so a review beginning with "Error: NullPointerException..." would be silently discarded. - Extract detection into pure helper agyOutputIsError(output) so the predicate has one home and can be tested in isolation. - Narrow the heuristic: still requires "Error:" prefix on the trimmed output, but additionally requires it to be SHORT (< 300 chars) and SINGLE-PARAGRAPH (no blank line). Real agy print-mode errors are short single-line messages; model responses discussing errors are longer or multi-paragraph. - Tighten the two existing comments per comment-analyzer feedback — the stdin-vs-argv quirk now reads cleanly, and the exit-0-on-error comment is anchored to agy v1.0.0 and points at the helper. - Add agy_test.go with table-driven coverage of the helper (12 cases: observed errors, hypothetical errors, false-positive shapes, edge cases) and a TestAgyRunnerName matching the sibling pattern. Full test suite passes. --- src/runners/agy.go | 35 ++++++++++++++++++++++++----- src/runners/agy_test.go | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 src/runners/agy_test.go diff --git a/src/runners/agy.go b/src/runners/agy.go index e0b69f8..ce603ba 100644 --- a/src/runners/agy.go +++ b/src/runners/agy.go @@ -18,8 +18,9 @@ func (r *AgyRunner) Available() bool { } func (r *AgyRunner) Run(ctx context.Context, prompt string, opts RunOpts) (RunResult, error) { - // agy reads the prompt from stdin in --print mode; passing the prompt as - // argv after --print is not used and causes a print-timeout error. + // agy --print reads the prompt from stdin; supplying it as a trailing + // argv leaves stdin empty and the process hangs until --print-timeout + // (5m default) fires. args := []string{"--print", "--dangerously-skip-permissions"} cmd := exec.CommandContext(ctx, "agy", args...) @@ -44,10 +45,11 @@ func (r *AgyRunner) Run(ctx context.Context, prompt string, opts RunOpts) (RunRe output := stdout.String() result := RunResult{Output: output, ExitCode: exitCode} - // agy exits 0 on internal errors (e.g. print timeout) and prints - // "Error: ..." on stdout — surface those as failures rather than - // returning the error string as a successful response. - if exitCode == 0 && strings.HasPrefix(strings.TrimSpace(output), "Error:") { + // Observed against agy v1.0.0: print-timeout and similar failures exit + // 0 with a short single-line "Error: ..." on stdout. Treat that as + // failure; see agyOutputIsError for the heuristic and its bounds (model + // responses that discuss errors are longer/multi-paragraph and pass). + if exitCode == 0 && agyOutputIsError(output) { return result, fmt.Errorf("agy reported error: %s", TruncStr(strings.TrimSpace(output), 200)) } if exitCode != 0 { @@ -59,3 +61,24 @@ func (r *AgyRunner) Run(ctx context.Context, prompt string, opts RunOpts) (RunRe } return result, nil } + +// agyOutputIsError decides whether an exit-0 stdout payload from `agy --print` +// is actually an agy-emitted error rather than a model response. +// +// Genuine agy errors are short, single-line, case-sensitive "Error: ..." +// strings. Model outputs that legitimately discuss errors are typically +// multi-paragraph (contain a blank line) or substantially longer, so those +// pass through. +func agyOutputIsError(output string) bool { + trimmed := strings.TrimSpace(output) + if !strings.HasPrefix(trimmed, "Error:") { + return false + } + if len(trimmed) > 300 { + return false + } + if strings.Contains(trimmed, "\n\n") { + return false + } + return true +} diff --git a/src/runners/agy_test.go b/src/runners/agy_test.go new file mode 100644 index 0000000..b6f4a16 --- /dev/null +++ b/src/runners/agy_test.go @@ -0,0 +1,49 @@ +package runners + +import "testing" + +func TestAgyRunnerName(t *testing.T) { + r := &AgyRunner{} + if r.Name() != "agy" { + t.Errorf("Name() = %q, want %q", r.Name(), "agy") + } +} + +func TestAgyOutputIsError(t *testing.T) { + tests := []struct { + name string + output string + want bool + }{ + {"observed print-timeout", "Error: timed out waiting for response", true}, + {"hypothetical print timeout", "Error: print timeout", true}, + {"leading and trailing whitespace", " Error: rate limited\n", true}, + + {"model discussing errors (multi-paragraph)", "Error: NullPointerException at line 42\n\nThe root cause is the nil dereference in handleRequest()...", false}, + {"long model response starting with Error:", "Error: " + longString(400), false}, + {"Error: mid-body, not at prefix", "Here's a review.\n\nError: this is a discussion of error handling.", false}, + {"empty output", "", false}, + {"whitespace only", " \n \t ", false}, + {"lowercase error: is not an agy error", "error: lowercase from a model response", false}, + {"uppercase ERROR: is not matched (case-sensitive)", "ERROR: yelling", false}, + {"Error- with dash, not colon", "Error- not the right delimiter", false}, + {"plain success output", "ok", false}, + {"multi-line model output", "Here is my review:\n- point 1\n- point 2", false}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := agyOutputIsError(tt.output); got != tt.want { + t.Errorf("agyOutputIsError(%q) = %v, want %v", tt.output, got, tt.want) + } + }) + } +} + +func longString(n int) string { + b := make([]byte, n) + for i := range b { + b[i] = 'x' + } + return string(b) +}