Dani Ariyanto on Discord (#feedback, 10-24): a custom provider's models (kenari/*:free) had no window, reply limit, vision or reasoning known, and there was no one place to say them. magpie model spec <provider/model> what it has, and whose each value is magpie model spec <provider/model> [--context <n>] [--output <n>] [--vision on|off|auto] [--reasoning <levels>|off|auto] magpie model spec '<provider>/*' --context <n> --output <n> magpie model spec <provider/model> --reset magpie model specs It writes the stores magpie model context/output/images/efforts write (providers.json contexts; settings.json modelOutputs, modelImages, modelEfforts, modelReasonless), so every reader that went by those goes by a spec: entryFor/EntryOf/Served, /v1/models, max_tokens, the GUI's /api/providers badges and chips, and the agents' model lists. Every part is checked before anything is written; a refused command writes nothing. Agents are told once. Readers that bypassed the stores and now honour them: - provider.Efforts returns the kept levels, so the gateway fits a request to them (fitEffort): xhigh asked of a model kept to low-high goes as high. This reverses #92 (47e12df41), which narrowed only the lists handed out; docs/subsystems/gateway-routing.md says so. - entryFor: levels given a model with none known make it Reasoning. - gateway AutoVision picks by the user's ModelImages (seesAt). - GUI gateway client: a reasonless model offers no level chips. Run at this tree (basea93190ae1): - go test -count=1 -timeout 45m ./internal/{provider,cli,gui,gateway, settings,tui,agent,catalog}: all ok (gateway 505s, agent 360s). - GUI: gateway-*.test.cjs, model-reasonless, plugin-gateway, i18n-keys (25 files, both engines, the new file at 1100 and 420 in en, zh, zh-TW, ja, de): 225/225 pass. app.js untouched. - gofmt -l empty; go vet darwin, linux -tags nogui, windows clean. - Sandbox HOME, built binary, `magpie web` on 47821/47820 and a fake Chat vendor on 47811: before, kenari/glm-5:free had no window or levels; after spec 128k/16k/on/low-high, /v1/models said 128000, 16000, image input, [low medium high]; max_tokens 100000 went as 16000, xhigh as high, low as low; qwen-x with --reasoning off was sent no reasoning field; /api/providers had context 128000, output 16000, images/imageSet, kept [low medium high], reasonless for qwen-x. A models.dev sync during the run (GLM-5 202752/131072) didn't move the spec; after --reset the vendor's values came back. Bad values, an unknown flag and --help wrote nothing (files hashed). Rebased ontoa6a3dbde8(the ZCode mover's min, one line): at the pushed head 5af093d8b's tree, ./internal/provider and ./internal/cli -timeout 45m ok, and the spec tests in gateway and gui ok. Broken by hand, each went red: AutoVision on raw sees; Efforts on the full list; the Reasoning line removed; output, vision or context not written; ParseLevels skipped; agents told twice; --context 0 taken; help printing modelUsage; old client.js; the GUI named() image and reasonless branches. Not tried / not changed: no full go test ./... (another session's full GUI suite was running). Codex's ChatGPT-model /models pass-through and the Codex effort dropdown read catalog.Codex(), not a spec. The TUI shows no spec badges. A Context-tab trace keeps the window it was recorded with. Pre-existing and the same on origin/maina6a3dbde8: a GLM-5 relay with no levels known has xhigh sent as high.
166 lines
4.7 KiB
Go
166 lines
4.7 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":
|
|
return " " + libraryUsage
|
|
case "plugin", "plugins":
|
|
return pluginUsage
|
|
case "quota", "quotas":
|
|
return quotaUsage
|
|
case "statusline":
|
|
return statuslineUsage
|
|
case "heap":
|
|
return heapUsage
|
|
case "cpu":
|
|
return cpuUsage
|
|
case "sessions":
|
|
return sessionsUsage
|
|
case "search":
|
|
return searchUsage
|
|
case "visible":
|
|
return visibleUsage
|
|
case "webdav", "dav":
|
|
return webdavUsage
|
|
case "s3":
|
|
return s3Usage
|
|
case "github":
|
|
return githubUsage
|
|
case "claude-code":
|
|
return claudeCodeUsage
|
|
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)
|
|
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 ""
|
|
}
|