The built-in agy agent (Antigravity CLI) is the first built-in agent a community agent plugin serves, as the retired subscriptions moved onto provider plugins. While @magpie-community/agent-agy is installed and on, magpie's agy is the plugin's: the built-in leaves the list (here and in WSL), its id and aliases are the plugin's, and what the built-in wired is handed over. Turned off or removed, the built-in is back. Nothing is forced yet; the forced install and the built-in's retirement come once the plugin is on npm and a real run with it is on record. The plugin (plugins ebcff866, 0.2.0) follows the built-in since0cc91af3d: its config is magpie's own magpie-settings.json, handed to agy with --settings, agy's settings.json is only read, and remote-control runs as agy is. What an agent plugin can say now (agentplug; docs/reference.md and the site's plugins pages, en/zh/ja, and llms-full.txt): - base: the agent's own settings file, read for the user's own model and passed to connect and own; needs launch.args with {config}, and stepping out removes magpie's config file whole; - launch {env, model, args, plain}: `magpie start <id>` and the shell functions (posix, fish, PowerShell, a WSL distro's) put args before the model flag, and run a plain word or flag as the agent is; - own({config, base, model}), effort, wsl, aliases. Moving over (plugged_moved.go): agentMovers names agy's package; agyHandover gives back a settings.json an older built-in wired (Sync), then makes magpie-settings.json the plugin's stash, so the plugin's agent reads as connected and stepping out removes the file. Run (mote, macOS 27, Go 1.26.8) atfe8c05e0c, the base before the last rebase: - go test internal/agent (507s), agentplug, sessions, edit, update, plugin: ok. - internal/cli and internal/gui: red only on main's own reds, the same at origin/main8fe720453: TestModelUsageAlignsEveryDescription and TestModelUsageLinesUpItsDescriptions (#6104), TestSettingsSaveKeepsWhatItDoesNotSend (#6103), TestCoreScriptBudget (#6116, filed now). - GUI, both engines, and site node --test: agy-effort, agy-launch, library-rtk-agy, gui-de, gui-zh-tw, i18n-en-no-cjk, i18n-keys, plugin-page-foreign-error, site/*.test.mjs: 114 pass. - vet: macOS, GOOS=windows, Linux in WSL (-tags gtk3); gofmt clean. - The shell functions with a config path holding a space: bash and zsh on mote, PowerShell on Windows (win-run), bash in WSL. - Broken by hand: TestAgyPlugin red with Args, Plain or the file's removal taken out. At 20d807d92 (rebased on8fe720453): vet (macOS, windows) ok, agentplug and internal/agent -run 'Agy|Plugged' ok, agy-launch and i18n-keys pass; plugin-page-foreign-error is red there and at plain origin/main8fe720453, from that commit (#6117), not this change. Plugins repo: bun test packages/agent-agy 4 pass. Not tried: fish (on none of the machines); a real agy run with the plugin at 0.2.0 (the 0.1.0 design ran for real in a sandbox HOME, the settings.json one this replaces); Windows and WSL agy with the plugin; an install from npm: @magpie-community/agent-agy isn't on npm yet, so until its first publish no user is moved.
124 lines
5.4 KiB
Go
124 lines
5.4 KiB
Go
package agentplug
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func compileSrc(t *testing.T, src string) (*Agent, error) {
|
|
t.Helper()
|
|
dir := t.TempDir()
|
|
file := filepath.Join(dir, "agent.js")
|
|
if err := os.WriteFile(file, []byte(src), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return Compile(dir, file)
|
|
}
|
|
|
|
// What agent.launch says goes into the user's shell profiles: the command,
|
|
// the variables' names and their values. A module can say only names a
|
|
// shell takes as they are, and values that are magpie's address or key,
|
|
// so no plugin puts a command of its own, or a value of its choosing
|
|
// (LD_PRELOAD, NODE_OPTIONS), into the user's shells.
|
|
func TestLaunchSaysOnlyWhatAShellTakesAsItIs(t *testing.T) {
|
|
desc := func(launch, bin string) string {
|
|
return `export const agent = { id: "lx", bin: "` + bin + `", config: "~/.lx.json", model: "model", prefix: "magpie/", launch: ` + launch + ` };`
|
|
}
|
|
ok := []string{
|
|
`{ env: { GEMINI_API_KEY: "{key}", GOOGLE_GEMINI_BASE_URL: "{url}" }, model: "--model" }`,
|
|
`{ env: { BASE: "{v1}" } }`,
|
|
`{ env: { BASE: "{url}/api/v2/" } }`,
|
|
`{ model: "-m" }`,
|
|
`{ model: "--model", args: { "--settings": "{config}" }, plain: ["remote-control", "--remote-control"] }`,
|
|
}
|
|
for _, l := range ok {
|
|
a, err := compileSrc(t, desc(l, "lx"))
|
|
if err != nil || a.Desc.Launch == nil {
|
|
t.Errorf("%s: %v", l, err)
|
|
}
|
|
}
|
|
bad := map[string]string{
|
|
desc(`{ env: { K: "{key}; rm -rf ~" } }`, "lx"): "agent.launch.env K",
|
|
desc(`{ env: { LD_PRELOAD: "/tmp/x.so" } }`, "lx"): "agent.launch.env LD_PRELOAD",
|
|
desc(`{ env: { NODE_OPTIONS: "--require=/x {key}" } }`, "lx"): "agent.launch.env NODE_OPTIONS",
|
|
desc(`{ env: { BASE: "{url}/$(id)" } }`, "lx"): "agent.launch.env BASE",
|
|
desc(`{ env: { BASE: "{url}/../x" } }`, "lx"): "",
|
|
desc(`{ env: { "A B": "{key}" } }`, "lx"): "a variable's name",
|
|
desc(`{ model: "--model; id" }`, "lx"): "a flag",
|
|
desc(`{ model: "--model" }`, "lx; id"): "agent.bin",
|
|
desc(`{}`, "lx"): "neither env nor a model flag",
|
|
desc(`{ model: "-m", args: { "--settings": "/tmp/x" } }`, "lx"): "agent.launch.args --settings",
|
|
desc(`{ model: "-m", args: { "--x; id": "{config}" } }`, "lx"): "agent.launch.args",
|
|
desc(`{ model: "-m", args: { "-m": "{config}" } }`, "lx"): "not the model's",
|
|
desc(`{ model: "-m", plain: ["a b"] }`, "lx"): "agent.launch.plain",
|
|
desc(`{ model: "-m", plain: ["x;id"] }`, "lx"): "agent.launch.plain",
|
|
}
|
|
for src, want := range bad {
|
|
_, err := compileSrc(t, src)
|
|
if want == "" {
|
|
// a dot path is still a path under the address: a shell takes it as it is
|
|
if err != nil {
|
|
t.Errorf("%s: %v", src, err)
|
|
}
|
|
continue
|
|
}
|
|
if err == nil || !strings.Contains(err.Error(), want) {
|
|
t.Errorf("%s: %v, want %q", src, err, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// own is given the agent's file as parsed and the model it is on, and
|
|
// what it lists without a value is left out.
|
|
func TestOwnModels(t *testing.T) {
|
|
a, err := compileSrc(t, `export const agent = { id: "lx", config: "~/.lx.json", model: "model" };
|
|
export function own({ config, base, model }) {
|
|
return [...Object.keys((base ?? config).models ?? {}).map((k) => ({ value: k, direct: "Google" })), { value: model, model: "m-" + model }, { value: "" }];
|
|
}`)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !a.HasOwn() {
|
|
t.Fatal("own not found")
|
|
}
|
|
got, err := a.OwnModels(map[string]any{"models": map[string]any{"mine": true}}, nil, "cur")
|
|
if err != nil || len(got) != 2 || got[0] != (Own{Value: "mine", Direct: "Google"}) || got[1] != (Own{Value: "cur", Model: "m-cur"}) {
|
|
t.Fatalf("own: %+v %v", got, err)
|
|
}
|
|
// the agent's own file, when it has one, is given as base
|
|
got, err = a.OwnModels(map[string]any{}, map[string]any{"models": map[string]any{"theirs": true}}, "cur")
|
|
if err != nil || len(got) != 2 || got[0].Value != "theirs" {
|
|
t.Fatalf("own with base: %+v %v", got, err)
|
|
}
|
|
b, err := compileSrc(t, `export const agent = { id: "lx", config: "~/.lx.json", model: "model" };`)
|
|
if err != nil || b.HasOwn() {
|
|
t.Fatalf("no own: %v", err)
|
|
}
|
|
if got, err := b.OwnModels(nil, nil, ""); got != nil || err != nil {
|
|
t.Fatalf("no own: %v %v", got, err)
|
|
}
|
|
}
|
|
|
|
// agent.base, the agent's own file beside magpie's, is only for a config
|
|
// the agent is handed by agent.launch.args, and is never the config.
|
|
func TestBaseIsForAHandedConfig(t *testing.T) {
|
|
src := func(base, launch string) string {
|
|
return `export const agent = { id: "lx", bin: "lx", config: "~/.lx/magpie.json", base: "` + base + `", model: "model", launch: ` + launch + ` };`
|
|
}
|
|
if a, err := compileSrc(t, src("~/.lx/settings.json", `{ model: "-m", args: { "--settings": "{config}" } }`)); err != nil || a.Desc.Base != "~/.lx/settings.json" {
|
|
t.Fatalf("base: %v", err)
|
|
}
|
|
bad := map[string]string{
|
|
src("~/.lx/settings.json", `{ model: "-m" }`): "agent.launch.args hands the agent",
|
|
src("~/.lx/magpie.json", `{ model: "-m", args: { "--settings": "{config}" } }`): "agent.base is agent.config",
|
|
src("~/.lx/settings.yaml", `{ model: "-m", args: { "--settings": "{config}" } }`): "a file of agent.format",
|
|
}
|
|
for s, want := range bad {
|
|
if _, err := compileSrc(t, s); err == nil || !strings.Contains(err.Error(), want) {
|
|
t.Errorf("%s: %v, want %q", s, err, want)
|
|
}
|
|
}
|
|
}
|