agent: Air starts the OpenCode an IDE installed from the ACP registry (#2423)
whiteS18 installed OpenCode from IDEA's ACP registry. The IDE unpacks it into ~/Library/Caches/JetBrains/IntelliJIdea2026.2/acp-agents/opencode/ 1.19.0/opencode, on no PATH, so Air's Magpie agent said "OpenCode not installed". airOpenCode now also looks where JetBrains IDEs and Zed put registry installs (Caches/JetBrains/*/acp-agents/opencode/*, Zed's external_agents/registry/opencode/*; ~/.cache and ~/.local/share on Linux, %LOCALAPPDATA% on Windows), the newest by mtime. Run: - TestAirFindsACPRegistryOpenCode: darwin, linux and windows layouts (the reporter's literal macOS paths), none installed gives "", the newer of two wins. - XDG_CACHE_HOME listed in agentenv_test's notAnAgent (TestFolderVarsAreListed was red without it). - go test -tags nogui -count=1 ./internal/agent ok; gofmt clean; go vet -tags nogui darwin, linux, windows ok on agent. - Not tried: a real IDE registry install (none on this machine). Full suite: agent only here; the release head runs ./... before its tag.
This commit is contained in:
@@ -27,6 +27,7 @@ var notAnAgent = map[string]string{
|
||||
"USER": "the process' own",
|
||||
"XDG_CONFIG_HOME": "magpie's own folder's, which appdir decides",
|
||||
"XDG_DATA_HOME": "the same",
|
||||
"XDG_CACHE_HOME": "Go's build cache's too, which a sandbox keeps shared; Air's ACP OpenCode under it is found by path in a test's own home (#2423)",
|
||||
"MAGPIE_ADDR": "magpie's own",
|
||||
"MAGPIE_DEBUG": "magpie's own debug flag",
|
||||
"MAGPIE_PUBLIC_URL": "magpie's own public URL",
|
||||
|
||||
+54
-1
@@ -36,6 +36,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
@@ -78,7 +79,59 @@ var airOpenCode = func(home string) string {
|
||||
if p := filepath.Join(home, ".opencode", "bin", name); isFile(p) {
|
||||
return p
|
||||
}
|
||||
return ""
|
||||
return acpOpenCode(home, name, runtime.GOOS)
|
||||
}
|
||||
|
||||
// acpOpenCode is an OpenCode a JetBrains IDE or Zed installed from the ACP
|
||||
// registry, unpacked into the editor's own folder and on no PATH (#2423:
|
||||
// IDEA's at ~/Library/Caches/JetBrains/IntelliJIdea2026.2/acp-agents/
|
||||
// opencode/1.19.0/opencode); the newest when there are several, "" when
|
||||
// none.
|
||||
func acpOpenCode(home, name, goos string) string {
|
||||
var globs []string
|
||||
switch goos {
|
||||
case "darwin":
|
||||
globs = []string{
|
||||
filepath.Join(home, "Library", "Caches", "JetBrains", "*", "acp-agents", "opencode", "*", name),
|
||||
filepath.Join(home, "Library", "Application Support", "Zed", "external_agents", "registry", "opencode", "*", name),
|
||||
}
|
||||
case "windows":
|
||||
local := appdir.Getenv("LOCALAPPDATA")
|
||||
if local == "" {
|
||||
local = filepath.Join(home, "AppData", "Local")
|
||||
}
|
||||
globs = []string{
|
||||
filepath.Join(local, "JetBrains", "*", "acp-agents", "opencode", "*", name),
|
||||
filepath.Join(local, "Zed", "external_agents", "registry", "opencode", "*", name),
|
||||
}
|
||||
default:
|
||||
cache := appdir.Getenv("XDG_CACHE_HOME")
|
||||
if cache == "" {
|
||||
cache = filepath.Join(home, ".cache")
|
||||
}
|
||||
data := appdir.Getenv("XDG_DATA_HOME")
|
||||
if data == "" {
|
||||
data = filepath.Join(home, ".local", "share")
|
||||
}
|
||||
globs = []string{
|
||||
filepath.Join(cache, "JetBrains", "*", "acp-agents", "opencode", "*", name),
|
||||
filepath.Join(data, "zed", "external_agents", "registry", "opencode", "*", name),
|
||||
}
|
||||
}
|
||||
best, at := "", time.Time{}
|
||||
for _, g := range globs {
|
||||
ps, _ := filepath.Glob(g)
|
||||
for _, p := range ps {
|
||||
fi, err := os.Stat(p)
|
||||
if err != nil || !fi.Mode().IsRegular() {
|
||||
continue
|
||||
}
|
||||
if best == "" || fi.ModTime().After(at) {
|
||||
best, at = p, fi.ModTime()
|
||||
}
|
||||
}
|
||||
}
|
||||
return best
|
||||
}
|
||||
|
||||
func air(home, cfg string) *Agent {
|
||||
|
||||
@@ -277,3 +277,44 @@ func TestAirProviderWritesKeepCustomFields(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// An OpenCode a JetBrains IDE or Zed installed from the ACP registry, in
|
||||
// the editor's own folder and on no PATH, is the one Air starts (#2423,
|
||||
// whiteS18: IDEA 2026.2's on macOS); the newest of several.
|
||||
func TestAirFindsACPRegistryOpenCode(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local"))
|
||||
t.Setenv("XDG_CACHE_HOME", "")
|
||||
t.Setenv("XDG_DATA_HOME", "")
|
||||
put := func(p string, age time.Duration) string {
|
||||
writeFile(t, p, "#!/bin/sh\n")
|
||||
when := time.Now().Add(-age)
|
||||
if err := os.Chtimes(p, when, when); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return p
|
||||
}
|
||||
for _, c := range []struct {
|
||||
goos, name string
|
||||
older, want string
|
||||
}{
|
||||
{"darwin", "opencode",
|
||||
filepath.Join(home, "Library", "Application Support", "Zed", "external_agents", "registry", "opencode", "v_1.18.11_c8581a12e4e7afe7_fd7ca24743b4ae6b", "opencode"),
|
||||
filepath.Join(home, "Library", "Caches", "JetBrains", "IntelliJIdea2026.2", "acp-agents", "opencode", "1.19.0", "opencode")},
|
||||
{"linux", "opencode",
|
||||
filepath.Join(home, ".local", "share", "zed", "external_agents", "registry", "opencode", "v_1.18.11", "opencode"),
|
||||
filepath.Join(home, ".cache", "JetBrains", "IntelliJIdea2026.2", "acp-agents", "opencode", "1.19.0", "opencode")},
|
||||
{"windows", "opencode.exe",
|
||||
filepath.Join(home, "AppData", "Local", "JetBrains", "IntelliJIdea2026.2", "acp-agents", "opencode", "1.18.0", "opencode.exe"),
|
||||
filepath.Join(home, "AppData", "Local", "Zed", "external_agents", "registry", "opencode", "v_1.19.0", "opencode.exe")},
|
||||
} {
|
||||
if got := acpOpenCode(home, c.name, c.goos); got != "" {
|
||||
t.Fatalf("%s: none installed, got %q", c.goos, got)
|
||||
}
|
||||
put(c.older, time.Hour)
|
||||
put(c.want, time.Minute)
|
||||
if got := acpOpenCode(home, c.name, c.goos); got != c.want {
|
||||
t.Fatalf("%s: got %q, want %q", c.goos, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user