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.
195 lines
5.8 KiB
Go
195 lines
5.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/agent"
|
|
)
|
|
|
|
// helpAsked is whether args ask for help rather than for the command to
|
|
// run: -h or --help anywhere, or help as the word after the command. It
|
|
// is looked at before run does anything, since a command that took
|
|
// --help for a value acted on it: `magpie snow --help` set Snow's model
|
|
// to "--help", which took magpie out of it (#1457), and `magpie serve
|
|
// --help` started a gateway.
|
|
func helpAsked(args []string) bool {
|
|
// what magpie is started with by others (Claude Code's MCP helper, the
|
|
// Agents page's dry run, a link, Windows' -Embedding) never carries
|
|
// an exact -h, --help or help
|
|
for _, a := range args {
|
|
if a == "-h" || a == "--help" {
|
|
return true
|
|
}
|
|
}
|
|
return len(args) > 1 && args[1] == "help"
|
|
}
|
|
|
|
// helpFor is what `magpie <command> --help` prints: the command's own
|
|
// usage where it has one, its lines of magpie's usage otherwise, an
|
|
// agent's forms and fields for an agent, and the whole usage for
|
|
// anything else.
|
|
func helpFor(args []string) string {
|
|
cmd := args[0]
|
|
switch cmd {
|
|
case "-h", "--help", "help":
|
|
return usage
|
|
case "model":
|
|
if len(args) > 1 && (args[1] == "spec" || args[1] == "specs") {
|
|
return specUsage
|
|
}
|
|
return modelUsage
|
|
case "group", "groups":
|
|
if len(args) > 1 && (args[1] == "rule" || args[1] == "rules") {
|
|
return ruleUsage
|
|
}
|
|
return groupUsage
|
|
case "library", "lib":
|
|
if len(args) > 1 && (args[1] == "project" || args[1] == "projects") {
|
|
return " " + libraryProjectUsage
|
|
}
|
|
return " " + libraryUsage
|
|
case "plugin", "plugins":
|
|
return pluginUsage
|
|
case "quota", "quotas":
|
|
return quotaUsage
|
|
case "statusline":
|
|
return statuslineUsage
|
|
case "status":
|
|
return statusUsage
|
|
case "mtls":
|
|
return mtlsUsage
|
|
case "https":
|
|
return httpsUsage
|
|
case "heap":
|
|
return heapUsage
|
|
case "cpu":
|
|
return cpuUsage
|
|
case "goroutines":
|
|
return goroutinesUsage
|
|
case "log", "logs":
|
|
return logUsage
|
|
case "sessions":
|
|
return sessionsUsage
|
|
case "search":
|
|
return searchUsage
|
|
case "tool", "tools":
|
|
return toolUsage
|
|
case "visible":
|
|
return visibleUsage
|
|
case "webdav", "dav":
|
|
return webdavUsage
|
|
case "s3":
|
|
return s3Usage
|
|
case "github":
|
|
return githubUsage
|
|
case "claude-code":
|
|
return claudeCodeUsage
|
|
case "settings":
|
|
return settingsUsage
|
|
case "list":
|
|
cmd = "ls"
|
|
case "account":
|
|
cmd = "accounts"
|
|
case "app", "gui":
|
|
cmd = ""
|
|
}
|
|
if cmd != "" && !strings.HasPrefix(cmd, "-") {
|
|
if lines := usageLines(cmd); lines != "" {
|
|
return lines
|
|
}
|
|
}
|
|
if a, err := agent.Find(cmd); err == nil && cmd != "" {
|
|
return agentHelp(a)
|
|
}
|
|
return usage
|
|
}
|
|
|
|
// usageLines are the lines of magpie's usage for `magpie <cmd>`, with the
|
|
// lines that carry on from them.
|
|
func usageLines(cmd string) string {
|
|
var b strings.Builder
|
|
in := false
|
|
for _, l := range strings.Split(usage, "\n") {
|
|
if rest, ok := strings.CutPrefix(l, " magpie "); ok {
|
|
in = rest == cmd || strings.HasPrefix(rest, cmd+" ")
|
|
} else if !strings.HasPrefix(l, " ") {
|
|
in = false
|
|
}
|
|
if in {
|
|
b.WriteString(l + "\n")
|
|
}
|
|
}
|
|
return b.String()
|
|
}
|
|
|
|
// agentHelp is `magpie <agent> --help`: the forms that set it, and its
|
|
// fields.
|
|
func agentHelp(a *agent.Agent) string {
|
|
var b strings.Builder
|
|
id := a.ID
|
|
fmt.Fprintf(&b, "%s\n\n", a.Name)
|
|
fmt.Fprintf(&b, " magpie %s show it\n", id)
|
|
if len(a.Fields) == 0 {
|
|
return b.String()
|
|
}
|
|
fmt.Fprintf(&b, " magpie %s <model> set its model (magpie models %s lists them)\n", id, id)
|
|
fmt.Fprintf(&b, " magpie %s <field> show one field\n", id)
|
|
fmt.Fprintf(&b, " magpie %s <field> <value> set another field\n", id)
|
|
fmt.Fprintf(&b, " magpie %s default take magpie out: back on what it had before\n", id)
|
|
fmt.Fprintf(&b, " magpie %s <field> default that field back to its own default\n", id)
|
|
if a.Start != nil {
|
|
bin := a.Start().Bin
|
|
fmt.Fprintf(&b, " magpie %s run [args…] start %s, on magpie while its model is magpie's (what your shell's %s runs)\n", id, bin, bin)
|
|
fmt.Fprintf(&b, " magpie %s env the variables and model it is started with\n", id)
|
|
}
|
|
if a.ID == "claude" {
|
|
fmt.Fprintf(&b, " magpie %s run [args…] start Claude Code through magpie, a plain claude left as it is (what claude-magpie runs)\n", id)
|
|
fmt.Fprintf(&b, " magpie %s launcher [add|remove] the claude-magpie command\n", id)
|
|
}
|
|
if a.ID == "claude-desktop" {
|
|
fmt.Fprintf(&b, " magpie %s launcher [add|remove] Claude Magpie.app (macOS): Desktop on magpie in a folder of its own, your own Claude Desktop left signed in\n", id)
|
|
}
|
|
var keys []string
|
|
for _, f := range a.Fields {
|
|
keys = append(keys, f.Key)
|
|
}
|
|
fmt.Fprintf(&b, "\nfields: %s\n", strings.Join(keys, ", "))
|
|
// Claude Code's tiers are named as its model's aliases are
|
|
var both []string
|
|
for _, f := range a.Fields {
|
|
if slices.Contains(a.ModelAliases, f.Key) {
|
|
both = append(both, f.Key)
|
|
}
|
|
}
|
|
if n := len(both); n > 0 {
|
|
names := both[0]
|
|
if n > 1 {
|
|
names = strings.Join(both[:n-1], ", ") + " and " + both[n-1]
|
|
}
|
|
fmt.Fprintf(&b, " %s alone name the %s: magpie %s %s sets its %s to %s\n", names, a.Fields[0].Label, id, both[0], a.Fields[0].Label, both[0])
|
|
// they are the agent's own models, not magpie's: setting one takes
|
|
// magpie out (#2000, read as a query of the tier)
|
|
fmt.Fprintf(&b, " they are %s's own models, not magpie's: setting one takes magpie out; magpie %s alone shows each\n", a.Name, id)
|
|
}
|
|
return b.String()
|
|
}
|
|
|
|
// flagArg is an argument to `magpie <agent> …` that is a flag, which no
|
|
// agent form takes: it is said to be one, rather than set as a model or a
|
|
// field's value. A negative number is a value.
|
|
func flagArg(args []string) string {
|
|
for _, a := range args {
|
|
if !strings.HasPrefix(a, "-") {
|
|
continue
|
|
}
|
|
if _, err := strconv.ParseFloat(a, 64); err == nil {
|
|
continue
|
|
}
|
|
return a
|
|
}
|
|
return ""
|
|
}
|