agent: Prime Agent is an Agents-page row, wired like Pi into ~/.prime/agent, and Disconnect puts its files back (#1528, takltc)
What changed
- internal/agent/primeagent.go: Prime Agent (PrimeIntellect-ai/prime-agent,
CLI prime-agent) through the piLike path, as OmO was added. Its folder is
~/.prime/agent or PRIME_AGENT_CODING_AGENT_DIR (~ expands, as upstream's
agent_dir does; appdir now lets that variable carry ~). models.json and
settings.json were checked against upstream v0.10.0 (pa-core settings and
models registry): Pi's camelCase fields, the same thinking levels and
enabledModels rules. Connect writes providers.magpie, defaultProvider and
defaultModel and keeps the user's providers and settings. Only the global
settings.json is written; allowedModels and subagentDefaultModel are left
alone.
- Prime Agent sends no User-Agent, so its provider block carries the key
magpie-prime-agent and the usage log names it (piLikeKeyed). The block is
Pi's otherwise, compat.sendSessionAffinityHeaders included (Prime Agent's
openai_completions honours it), kept as the user set it (piBlockKept).
- Disconnect restores both files byte-for-byte: before magpie's first write
a copy is kept (*.before-magpie, or a note that the file was absent), and
Disconnect puts it back when nothing else changed since (Agent.Restore). A
file changed while connected is left with only magpie's part taken out.
- WSL kind, agentenv, the icon, PICKS_ITSELF in the GUI, docs and READMEs.
Run
- go test -tags nogui ./internal/agent ./internal/appdir ./internal/agentenv
./internal/library ./internal/usage; the new tests went red with the key,
the restore, the ~ expansion, PICKS_ITSELF and the icon each taken out.
- pi-default-note.test.cjs in chromium and webkit.
- Real use: prime-agent 0.10.0 installed into a sandbox HOME, a sandbox
gateway on 127.0.0.1:3651 and a fake upstream on 3652. The interactive
TUI with no flags started on magpie/fake/echo-1, the fake got the request
and usage.jsonl recorded agent "prime-agent". `magpie prime-agent default`
put models.json back byte-for-byte; settings.json got its values back, but
Prime Agent rewrites the whole file when it runs (every key, nulls), so
that file is equal in content, not bytes. Reconnecting over that
null-filled file and disconnecting again left it byte-identical. After
the rebase onto 7a5536793 (compat in Pi's block) the turn was run again:
same result, and both files byte-identical after Disconnect.
`prime-agent -p` ignores the saved default upstream (print mode picks a
featured model); with --provider magpie --model it goes through magpie.
- gofmt -l, GOOS=linux and GOOS=windows go vet, full go test ./...
This commit is contained in:
@@ -70,7 +70,7 @@ magpie tui # the whole thing, in a terminal
|
||||
<table>
|
||||
<tr><td>
|
||||
|
||||
Claude Code · Claude Desktop · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · Pi · oh-my-pi · Aside · OmO · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy
|
||||
Claude Code · Claude Desktop · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · Pi · oh-my-pi · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy
|
||||
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ magpie tui # 全部功能,在终端里
|
||||
<table>
|
||||
<tr><td>
|
||||
|
||||
Claude Code · Claude Desktop · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · Pi · oh-my-pi · Aside · OmO · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy
|
||||
Claude Code · Claude Desktop · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · Pi · oh-my-pi · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy
|
||||
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
@@ -94,6 +94,7 @@ line; agents connected to magpie lose it when it quits.
|
||||
| Pi | `~/.pi/agent/settings.json` | model |
|
||||
| Aside | `~/.aside/u/0/settings.json` (+ `models.json`; the first account, the only one magpie wires) | model, effort, fast, standard, deep, visual, image |
|
||||
| OmO (omo-ai) | `~/.omo/agent/settings.json` (+ `models.json`; `$OMO_CODING_AGENT_DIR`, `$SENPI_CODING_AGENT_DIR`) | model |
|
||||
| Prime Agent | `~/.prime/agent/settings.json` (+ `models.json`; `$PRIME_AGENT_CODING_AGENT_DIR`) | model, thinking (Pi's fields; its key `magpie-prime-agent` names it, since its requests carry no User-Agent; the global settings alone, `allowedModels` and `subagentDefaultModel` left as they are) |
|
||||
| Goose | `~/.config/goose/config.yaml` | model |
|
||||
| Cursor CLI | `~/.cursor/cli-config.json` | model |
|
||||
| Zed | `~/.config/zed/settings.json` (`$XDG_CONFIG_HOME` on Linux, `%APPDATA%\Zed` on Windows) | model (a `magpie` OpenAI-compatible provider; its catalog in Zed's picker) |
|
||||
|
||||
@@ -18,7 +18,7 @@ something else shows up as drift.
|
||||
| Connect | `ConnectHow` picks the model an agent starts on and reports how. `How` is one of: `kept`, `again`, `joined`, `magpie`, `same`, `alike`, `default` or `first` (#726). With no models to give, it returns `NoModelsError` (code `no_models`). | [`applied.go`](../../internal/agent/applied.go) |
|
||||
| What magpie set | `Apply` sets a field and records it in `applied.json`. `Wired` says whether magpie is in the config. `Drift` reports `unwired`, `replaced`, `unreachable` or `bypassed`. `Reapply` sets the record again. `Keep` accepts the config as it is now. | [`applied.go`](../../internal/agent/applied.go) |
|
||||
| What came before | The stash (`stash.json`) remembers what the config said before magpie pointed it at the gateway, so Disconnect restores it rather than guessing. | [`stash.go`](../../internal/agent/stash.go) |
|
||||
| Disconnect and preview | `Disconnect` runs `Unwire`, then returns each field still on magpie to its default. `DisconnectPreview` runs the real Disconnect on a copy under a temporary home, in a subprocess (`DryRunArg`), and diffs the files. The preview is never a second account of what Disconnect does. | [`applied.go`](../../internal/agent/applied.go), [`preview.go`](../../internal/agent/preview.go) |
|
||||
| Disconnect and preview | `Disconnect` runs `Unwire`, then returns each field still on magpie to its default. Last it runs `Restore`: Pi and its kin (`piLike`: Pi, OmO, Prime Agent) copy `settings.json` and `models.json` aside (`*.before-magpie`, `beforeMagpie`) before magpie's first write, and put that copy back byte for byte where what Disconnect left is the same JSON; a file that wasn't there goes again when only empty objects are left in it. `DisconnectPreview` runs the real Disconnect on a copy under a temporary home, in a subprocess (`DryRunArg`), and diffs the files. The preview is never a second account of what Disconnect does. | [`applied.go`](../../internal/agent/applied.go), [`preview.go`](../../internal/agent/preview.go) |
|
||||
| Keeping configs current | `Reseat` moves agents off a model magpie no longer serves (#200). `OnGateway` and `Rewire` write the new gateway address into every connected agent when the port changes. `Source` and `Stale` say what an unconnected agent runs on, and whether running copies still use the old list. | [`reseat.go`](../../internal/agent/reseat.go), [`rewire.go`](../../internal/agent/rewire.go), [`connectinfo.go`](../../internal/agent/connectinfo.go) |
|
||||
| Named omp profiles | omp keeps a profile's settings under `~/.omp/profiles/<name>` (or under `PI_CONFIG_DIR`), each with its own `config.yml` and `models.yml`. Every such profile is an agent of its own — `omp#<name>` on Windows, `omp#<name>@wsl:<distro>` in a distro — so each can be connected, drifted and disconnected on its own. They share omp's model lists (`ListsFor`), and the default `omp` row is the folder `ompDir`/`ompIn` already pick, so an `OMP_PROFILE` that row is already pointed at is not listed twice. A name omp refuses is not a row: `default`, a trailing dot, or a Windows reserved device name (`aux`, `nul`, `com1`, `lpt9.x`, `con.work`), on every platform (`ompProfileOK`). A distro's profile names come from its probe and are kept in `wsl.json`; a stopped distro is never started to list them, its profile rows showing what was last seen (`asleep`). | [`omp.go`](../../internal/agent/omp.go), [`wsl.go`](../../internal/agent/wsl.go) |
|
||||
| WSL twins | On Windows each running distro is probed once, without starting a stopped one. The `wslKinds` agents found there become agents of their own, `<id>@wsl:<distro>`, edited through `\\wsl.localhost\<distro>`. A kind is found by its folder under the distro's home or by its command there (not one on a Windows drive). Where another tool shares one of them, the kind leaves it out: Gemini CLI is found by its command alone, because Antigravity keeps `~/.gemini` too. Goose is found by its folder alone, because a `goose` command can be pressly's migration tool. Reasonix also needs the version its command gives (`accept`), because the old npm client is named `reasonix` too. The gateway address and key follow the distro's networking: mirrored or NAT (`place`, `keyAt`). `ListsFor` keeps a twin's model picks under the Windows twin's id (#927). | [`wsl.go`](../../internal/agent/wsl.go), [`gatewaykey.go`](../../internal/agent/gatewaykey.go) |
|
||||
|
||||
@@ -129,6 +129,10 @@ type Agent struct {
|
||||
// kept: the endpoint, provider and model the user had. Disconnect runs
|
||||
// it before the fields' defaults.
|
||||
Unwire func() error
|
||||
// Restore, for an agent whose files magpie copied aside before its
|
||||
// first write (beforeMagpie), puts them back as they were where what
|
||||
// Disconnect left says the same. Disconnect runs it last.
|
||||
Restore func() error
|
||||
// Join, for an agent that can have magpie's models in its own list
|
||||
// while it stays on the model it was on (Codex signed in with ChatGPT),
|
||||
// connects it so, its model left as its own last pick; false where it
|
||||
|
||||
+104
-2
@@ -1,6 +1,7 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -8,6 +9,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"slices"
|
||||
"sort"
|
||||
@@ -89,6 +91,7 @@ func builtins(home, cfg string) []*Agent {
|
||||
pi(home),
|
||||
aside(home),
|
||||
omo(home),
|
||||
primeAgent(home),
|
||||
goose(home, cfg),
|
||||
cursor(home),
|
||||
cursorLocal(),
|
||||
@@ -834,10 +837,96 @@ func homeDir(home, d string) string {
|
||||
return filepath.Clean(d)
|
||||
}
|
||||
|
||||
// beforeMagpie is a copy of an agent's own files taken before magpie first
|
||||
// writes them (file.before-magpie beside each), which Disconnect puts back
|
||||
// byte for byte when what it left says the same as the copy: the same
|
||||
// JSON, in the user's own order, spacing and comments-free layout. Where
|
||||
// they differ (the user changed something while connected), what
|
||||
// Disconnect left stands. A file that wasn't there (named in the stash
|
||||
// under absent) goes again when nothing but empty objects is left in it.
|
||||
type beforeMagpie struct {
|
||||
absent string
|
||||
files []string
|
||||
}
|
||||
|
||||
// take copies each file aside, or notes it absent; a file that can't be
|
||||
// read is neither, and isn't put back.
|
||||
func (b beforeMagpie) take() {
|
||||
var gone []string
|
||||
for _, f := range b.files {
|
||||
raw, err := os.ReadFile(f)
|
||||
switch {
|
||||
case err == nil:
|
||||
if edit.WriteAtomic(f+".before-magpie", raw) != nil {
|
||||
os.Remove(f + ".before-magpie")
|
||||
}
|
||||
case errors.Is(err, fs.ErrNotExist):
|
||||
os.Remove(f + ".before-magpie")
|
||||
gone = append(gone, filepath.Base(f))
|
||||
default:
|
||||
os.Remove(f + ".before-magpie")
|
||||
}
|
||||
}
|
||||
stash(map[string]string{b.absent: strings.Join(gone, "\n")})
|
||||
}
|
||||
|
||||
// restore puts back what take kept, where Disconnect left the same.
|
||||
func (b beforeMagpie) restore() error {
|
||||
gone := strings.Split(unstash(b.absent), "\n")
|
||||
for _, f := range b.files {
|
||||
cur, err := os.ReadFile(f)
|
||||
if err != nil {
|
||||
os.Remove(f + ".before-magpie")
|
||||
continue
|
||||
}
|
||||
var now any
|
||||
if json.Unmarshal(cur, &now) != nil {
|
||||
continue
|
||||
}
|
||||
if was, err := os.ReadFile(f + ".before-magpie"); err == nil {
|
||||
var then any
|
||||
if json.Unmarshal(was, &then) == nil && reflect.DeepEqual(now, then) && !bytes.Equal(cur, was) {
|
||||
if err := edit.WriteAtomic(f, was); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
os.Remove(f + ".before-magpie")
|
||||
continue
|
||||
}
|
||||
if slices.Contains(gone, filepath.Base(f)) && emptyJSON(now) {
|
||||
if err := os.Remove(f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// emptyJSON says v is an object holding nothing but empty objects.
|
||||
func emptyJSON(v any) bool {
|
||||
m, ok := v.(map[string]any)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
for _, x := range m {
|
||||
if !emptyJSON(x) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// piLike is Pi, or a fork of it that keeps Pi's settings.json and
|
||||
// models.json in an agent folder of its own (OmO, omo.go): id is its id,
|
||||
// icon and command, dir its agent folder.
|
||||
func piLike(at place, id, name, dir string) *Agent {
|
||||
return piLikeKeyed(at, id, name, dir, at.gwKey)
|
||||
}
|
||||
|
||||
// piLikeKeyed is piLike whose provider "magpie" carries key's key: one
|
||||
// that names the agent (agentKeyAt) for an agent whose requests carry
|
||||
// nothing else of it (Prime Agent, primeagent.go).
|
||||
func piLikeKeyed(at place, id, name, dir string, key func() string) *Agent {
|
||||
path := filepath.Join(dir, "settings.json")
|
||||
modelsPath := filepath.Join(dir, "models.json")
|
||||
auth := filepath.Join(dir, "auth.json")
|
||||
@@ -846,18 +935,26 @@ func piLike(at place, id, name, dir string) *Agent {
|
||||
pair := pairSet(set, "defaultProvider", "defaultModel")
|
||||
// the model a new session starts on, as the model field shows it
|
||||
startup := func() string { return piStartup(path, pairGet(get, "defaultProvider", "defaultModel")()) }
|
||||
block := piBlockKept(modelsPath, func() any { return magpieProviderJSONAt("pi", id, at.gw()) })
|
||||
block := piBlockKept(modelsPath, func() any {
|
||||
b := magpieProviderJSONAt("pi", id, at.gw()).(map[string]any)
|
||||
b["apiKey"] = key()
|
||||
return b
|
||||
})
|
||||
writeMagpie := func() error {
|
||||
return edit.SetJSON(modelsPath, edit.KV{Path: "providers." + magpieID, Value: block()})
|
||||
}
|
||||
// the user's two files as they were before magpie's first write, put
|
||||
// back byte for byte by Disconnect where it leaves them saying the same
|
||||
before := beforeMagpie{at.key(id + ".before.absent"), []string{path, modelsPath}}
|
||||
return &Agent{
|
||||
ID: id, Name: name, Icon: id, Bin: id, Dir: dir, Path: path, Spelled: prefixed,
|
||||
Restore: before.restore,
|
||||
Check: func() string {
|
||||
if p, _ := get("defaultProvider"); p != magpieID {
|
||||
return ""
|
||||
}
|
||||
return wiringOff(name, modelsPath, func(k string) (string, bool) { return edit.GetJSON(modelsPath, "providers."+magpieID+"."+k) },
|
||||
"baseUrl", at.v1(), "apiKey", at.gwKey())
|
||||
"baseUrl", at.v1(), "apiKey", key())
|
||||
},
|
||||
Sync: func() error {
|
||||
return syncJSON(modelsPath, "providers."+magpieID, block)
|
||||
@@ -878,6 +975,11 @@ func piLike(at place, id, name, dir string) *Agent {
|
||||
return piScopeWithout(path)
|
||||
}
|
||||
if ref, ok := strings.CutPrefix(v, magpieID+"/"); ok && isMagpie(ref) {
|
||||
if _, has := edit.GetJSON(modelsPath, "providers."+magpieID); !has {
|
||||
if p, _ := get("defaultProvider"); p != magpieID {
|
||||
before.take()
|
||||
}
|
||||
}
|
||||
if err := writeMagpie(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -695,6 +695,11 @@ func (a *Agent) Disconnect() error {
|
||||
}
|
||||
}
|
||||
}
|
||||
if a.Restore != nil {
|
||||
if err := a.Restore(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// what it was on through magpie, for switching it on again
|
||||
back := reconnection{Magpie: map[string]string{}, Left: a.Values()}
|
||||
for _, f := range a.Fields {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package agent
|
||||
|
||||
// Prime Agent (PrimeIntellect-ai/prime-agent, the prime-agent command) is
|
||||
// a Rust agent that keeps Pi's settings.json and models.json in an agent
|
||||
// folder of its own: $PRIME_AGENT_CODING_AGENT_DIR, "~" in it standing for
|
||||
// home, else ~/.prime/agent (pa-types platform/dirs.rs, agent_dir). It
|
||||
// reads both files with Pi's fields and types (pa-core models/custom.rs,
|
||||
// settings/types.rs), so magpie wires it as it does Pi:
|
||||
// defaultProvider/defaultModel/defaultThinkingLevel in settings.json and
|
||||
// magpie as the provider "magpie" in models.json.
|
||||
//
|
||||
// Its requests carry no User-Agent (its HTTP client sets none), so the key
|
||||
// magpie gives it names it (magpie-prime-agent): that is how the gateway
|
||||
// counts its requests as Prime Agent's.
|
||||
//
|
||||
// Its global settings.json alone is written, as Pi's is: a project's
|
||||
// .prime/agent/settings.json is the user's, and so are allowedModels (its
|
||||
// daemon's allow-list, which a model outside fails loudly) and
|
||||
// subagentDefaultModel.
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
)
|
||||
|
||||
func primeAgent(home string) *Agent { return primeAgentIn(here(home)) }
|
||||
|
||||
// primeAgentIn is Prime Agent at a place: this machine's home, where its
|
||||
// variable moves it, or a WSL distro's, whose variables magpie can't read.
|
||||
func primeAgentIn(at place) *Agent {
|
||||
return piLikeKeyed(at, "prime-agent", "Prime Agent", primeAgentDir(at),
|
||||
func() string { return agentKeyAt("prime-agent", at.gw()) })
|
||||
}
|
||||
|
||||
// primeAgentDir is Prime Agent's agent folder at a place. A relative
|
||||
// PRIME_AGENT_CODING_AGENT_DIR is its working directory's, which magpie
|
||||
// can't know, so it is not taken.
|
||||
func primeAgentDir(at place) string {
|
||||
if at.spell == nil {
|
||||
if d := homeDir(at.home, appdir.Getenv("PRIME_AGENT_CODING_AGENT_DIR")); d != "" {
|
||||
return d
|
||||
}
|
||||
}
|
||||
return filepath.Join(at.home, ".prime", "agent")
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/usage"
|
||||
)
|
||||
|
||||
// Prime Agent (#1528) is an agent of its own, wired as Pi is but in
|
||||
// ~/.prime/agent: a model through magpie sets settings.json's
|
||||
// defaultProvider/defaultModel and magpie's provider in models.json there,
|
||||
// beside the user's own providers and settings. The provider's key names
|
||||
// Prime Agent, whose requests carry no User-Agent; Disconnect puts both
|
||||
// files back as they were, byte for byte.
|
||||
func TestPrimeAgent(t *testing.T) {
|
||||
home := syncHome(t)
|
||||
var a *Agent
|
||||
for _, x := range All() {
|
||||
if x.ID == "prime-agent" {
|
||||
a = x
|
||||
}
|
||||
}
|
||||
if a == nil {
|
||||
t.Fatal("no prime-agent in All()")
|
||||
}
|
||||
dir := filepath.Join(home, ".prime", "agent")
|
||||
settings, models := filepath.Join(dir, "settings.json"), filepath.Join(dir, "models.json")
|
||||
if a.Name != "Prime Agent" || a.Icon != "prime-agent" || a.Bin != "prime-agent" || a.Dir != dir || a.Path != settings || a.Detected() {
|
||||
t.Fatalf("%+v", a)
|
||||
}
|
||||
os.MkdirAll(dir, 0o755)
|
||||
// the user's own, as they wrote them: comments aside, Prime Agent
|
||||
// takes Pi's JSON
|
||||
userSettings := "{\n \"theme\": \"dark\",\n \"defaultProvider\": \"xai\",\n \"defaultModel\": \"grok-4.6\",\n \"allowedModels\": [\"xai/grok-4.6\", \"magpie/relay/glm-4.6\"],\n \"subagentDefaultModel\": \"xai/grok-4.6\"\n}\n"
|
||||
userModels := "{\n \"providers\": {\n \"mine\": {\n \"baseUrl\": \"http://127.0.0.1:9/v1\",\n \"api\": \"openai-completions\",\n \"apiKey\": \"MINE_KEY\",\n \"models\": [{\"id\": \"m1\", \"contextWindow\": 64000}]\n }\n }\n}\n"
|
||||
writeFile(t, settings, userSettings)
|
||||
writeFile(t, models, userModels)
|
||||
if !a.Detected() || a.Field("model").Get() != "xai/grok-4.6" {
|
||||
t.Fatalf("detected %v, model %q", a.Detected(), a.Field("model").Get())
|
||||
}
|
||||
|
||||
if err := a.Connect(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for k, want := range map[string]string{"defaultProvider": "magpie", "defaultModel": "relay/glm-4.6",
|
||||
"theme": "dark", "subagentDefaultModel": "xai/grok-4.6", "allowedModels.0": "xai/grok-4.6"} {
|
||||
if v, _ := edit.GetJSON(settings, k); v != want {
|
||||
t.Fatalf("%s = %q:\n%s", k, v, readFile(settings))
|
||||
}
|
||||
}
|
||||
var file struct {
|
||||
Providers map[string]map[string]any `json:"providers"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(readFile(models)), &file); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if mine := file.Providers["mine"]; mine == nil || mine["apiKey"] != "MINE_KEY" {
|
||||
t.Fatalf("their provider:\n%s", readFile(models))
|
||||
}
|
||||
got := file.Providers["magpie"]
|
||||
if got["baseUrl"] != gateway.URL()+"/v1" || got["api"] != "openai-completions" || got["apiKey"] != "magpie-prime-agent" {
|
||||
t.Fatalf("models:\n%s", readFile(models))
|
||||
}
|
||||
// Pi's block, but for the key: the fields Prime Agent's models.json
|
||||
// takes, of the types it takes (pa-core models/custom.rs)
|
||||
want := magpieProviderJSON("pi").(map[string]any)
|
||||
want["apiKey"] = gateway.TokenFor("prime-agent")
|
||||
wb, _ := json.Marshal(want)
|
||||
if b, _ := json.Marshal(got); string(b) != string(wb) {
|
||||
t.Fatalf("not Pi's block:\n got %s\nwant %s", b, wb)
|
||||
}
|
||||
if c := a.Check(); c != "" {
|
||||
t.Fatal(c)
|
||||
}
|
||||
// a key magpie no longer gives it is off
|
||||
edit.SetJSON(models, edit.KV{Path: "providers.magpie.apiKey", Value: gateway.Token})
|
||||
if a.Check() == "" {
|
||||
t.Fatal("the shared key reads as Prime Agent's")
|
||||
}
|
||||
if err := a.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if k, _ := edit.GetJSON(models, "providers.magpie.apiKey"); k != "magpie-prime-agent" || a.Check() != "" {
|
||||
t.Fatalf("sync left %q: %s", k, a.Check())
|
||||
}
|
||||
for _, other := range []string{".pi", ".omo"} {
|
||||
if _, err := os.Stat(filepath.Join(home, other)); !os.IsNotExist(err) {
|
||||
t.Fatalf("~/%s was touched: %v", other, err)
|
||||
}
|
||||
}
|
||||
|
||||
// its requests, which say nothing of it but the key, are its: the
|
||||
// gateway reads the agent off magpie-<id> (gateway.agentOf)
|
||||
if got := usage.AgentOf("prime-agent"); got != "prime-agent" {
|
||||
t.Fatalf("usage: %q", got)
|
||||
}
|
||||
|
||||
if err := a.Disconnect(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a.Wired() {
|
||||
t.Fatal("still connected")
|
||||
}
|
||||
if b := readFile(settings); b != userSettings {
|
||||
t.Fatalf("settings.json not as it was:\n%s", b)
|
||||
}
|
||||
if b := readFile(models); b != userModels {
|
||||
t.Fatalf("models.json not as it was:\n%s", b)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect and Disconnect from the Agents page, with nothing of the user's
|
||||
// in models.json, leave it as it was too.
|
||||
func TestPrimeAgentRoundTrip(t *testing.T) {
|
||||
home := syncHome(t)
|
||||
a := primeAgent(home)
|
||||
dir := filepath.Join(home, ".prime", "agent")
|
||||
userSettings := []byte("{\n \"defaultProvider\": \"prime-inference\",\n \"defaultModel\": \"glm-5.3\",\n \"enabledModels\": [\"prime-inference/*\"]\n}\n")
|
||||
writeFile(t, filepath.Join(dir, "settings.json"), string(userSettings))
|
||||
for i := 0; i < 2; i++ {
|
||||
if err := a.Connect(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !a.Wired() || a.Check() != "" {
|
||||
t.Fatalf("not connected:\n%s", readFile(a.Path))
|
||||
}
|
||||
// a model outside enabledModels would never start
|
||||
if v, _ := edit.GetJSON(a.Path, "enabledModels"); !bytes.Contains([]byte(v), []byte("magpie/")) {
|
||||
t.Fatalf("enabledModels: %s", v)
|
||||
}
|
||||
if err := a.Disconnect(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b, _ := os.ReadFile(a.Path); !bytes.Equal(b, userSettings) {
|
||||
t.Fatalf("round %d:\n%s", i, b)
|
||||
}
|
||||
// models.json wasn't there, and isn't again; nor is a copy left
|
||||
for _, f := range []string{"models.json", "models.json.before-magpie", "settings.json.before-magpie"} {
|
||||
if _, err := os.Stat(filepath.Join(dir, f)); !os.IsNotExist(err) {
|
||||
t.Fatalf("round %d: %s left: %v", i, f, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// What the user changes while it is connected stands: Disconnect takes
|
||||
// magpie out of it and leaves their change, rather than putting back the
|
||||
// copy from before.
|
||||
func TestPrimeAgentKeepsWhatChangedWhileConnected(t *testing.T) {
|
||||
home := syncHome(t)
|
||||
a := primeAgent(home)
|
||||
settings := filepath.Join(home, ".prime", "agent", "settings.json")
|
||||
writeFile(t, settings, `{"defaultProvider": "prime-inference", "defaultModel": "glm-5.3"}`)
|
||||
if err := a.Connect(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := edit.SetJSON(settings, edit.KV{Path: "theme", Value: "light"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := a.Disconnect(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for k, want := range map[string]string{"theme": "light", "defaultProvider": "prime-inference", "defaultModel": "glm-5.3"} {
|
||||
if v, _ := edit.GetJSON(settings, k); v != want {
|
||||
t.Fatalf("%s = %q:\n%s", k, v, readFile(settings))
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat(settings + ".before-magpie"); !os.IsNotExist(err) {
|
||||
t.Fatalf("copy left: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// PRIME_AGENT_CODING_AGENT_DIR moves its folder, "~" in it standing for
|
||||
// home, as its own agent_dir does; a relative one is not taken, and a
|
||||
// distro's Prime Agent is at its home whatever this machine's says.
|
||||
func TestPrimeAgentDir(t *testing.T) {
|
||||
home := syncHome(t)
|
||||
own := filepath.Join(home, "own")
|
||||
def := filepath.Join(home, ".prime", "agent")
|
||||
for _, c := range []struct{ env, want string }{
|
||||
{"", def},
|
||||
{own, own},
|
||||
{"~", home},
|
||||
{"~/pa", filepath.Join(home, "pa")},
|
||||
{"rel/dir", def},
|
||||
} {
|
||||
t.Setenv("PRIME_AGENT_CODING_AGENT_DIR", c.env)
|
||||
if a := primeAgent(home); a.Dir != c.want || a.Path != filepath.Join(c.want, "settings.json") {
|
||||
t.Errorf("%+v: %s", c, a.Dir)
|
||||
}
|
||||
}
|
||||
t.Setenv("PRIME_AGENT_CODING_AGENT_DIR", own)
|
||||
root := t.TempDir()
|
||||
d := distro{Name: "Ubuntu", Root: root, Home: "/home/me", Has: map[string]bool{"dir:.prime/agent": true}, Mirrored: true, Running: true}
|
||||
a := wslAgent(wslKindOf("prime-agent"), d)
|
||||
if a.ID != "prime-agent@wsl:Ubuntu" || a.Name != "Prime Agent · WSL Ubuntu" || a.Dir != filepath.Join(root, "home", "me", ".prime", "agent") {
|
||||
t.Fatalf("%+v", a)
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// leaving the row connected on the model it went back to (#835, OpenHanako's
|
||||
// own deepseek/deepseek-v4-pro).
|
||||
func TestOwnProviderNamedAsMagpies(t *testing.T) {
|
||||
ids := []string{"agy", "opencode", "openchamber", "mimocode", "pi", "aside", "omo", "goose", "zed", "vscode",
|
||||
ids := []string{"agy", "opencode", "openchamber", "mimocode", "pi", "aside", "omo", "prime-agent", "goose", "zed", "vscode",
|
||||
"crush", "dsh", "commandcode", "fx", "omp", "hermes", "morph", "kimi", "empryo", "minimax-code", "droid",
|
||||
"qoder", "qoder-cn", "grok", "atomcode", "cline", "snow"}
|
||||
for _, id := range ids {
|
||||
|
||||
@@ -36,6 +36,7 @@ func syncHome(t *testing.T) string {
|
||||
t.Setenv("DSH_HOME", "")
|
||||
t.Setenv("OMO_CODING_AGENT_DIR", "")
|
||||
t.Setenv("SENPI_CODING_AGENT_DIR", "")
|
||||
t.Setenv("PRIME_AGENT_CODING_AGENT_DIR", "")
|
||||
t.Setenv("PI_CODING_AGENT_DIR", "")
|
||||
t.Setenv("PI_CONFIG_DIR", "")
|
||||
t.Setenv("OMP_PROFILE", "")
|
||||
|
||||
@@ -290,6 +290,17 @@ var wslKinds = []wslKind{
|
||||
}
|
||||
return nil
|
||||
}},
|
||||
// Prime Agent, Pi's files in a folder of its own, at its default
|
||||
// folder: the distro's variable that moves it isn't read
|
||||
{id: "prime-agent", name: "Prime Agent", dir: ".prime/agent", bin: "prime-agent", in: primeAgentIn,
|
||||
asleep: func(key string) func(map[string]string) []Option {
|
||||
if key == "model" {
|
||||
return func(cur map[string]string) []Option {
|
||||
return append(ownOptions("", cur["model"]), viaMagpie("prime-agent", magpieID+"/")...)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}},
|
||||
// only its settings.json: its sign-in, sessions and prompt history,
|
||||
// read on this machine for Claude Code here, aren't read in a distro
|
||||
{id: "claude", name: "Claude Code", dir: ".claude", bin: "claude", in: claudeIn,
|
||||
|
||||
@@ -43,6 +43,7 @@ var Vars = []string{
|
||||
// Pi and its forks (OmO, Senpi), whose profile and config are apart
|
||||
"PI_CODING_AGENT_DIR", "PI_CODING_AGENT_SESSION_DIR", "PI_CONFIG_DIR", "PI_PROFILE",
|
||||
"OMO_CODING_AGENT_DIR", "SENPI_CODING_AGENT_DIR",
|
||||
"PRIME_AGENT_CODING_AGENT_DIR",
|
||||
// omp
|
||||
"OMP_PROFILE",
|
||||
// Qoder's two builds, the global site's and China's
|
||||
|
||||
@@ -86,7 +86,7 @@ func usable(name, v string) bool {
|
||||
return true
|
||||
}
|
||||
switch name {
|
||||
case "PI_CODING_AGENT_DIR", "PI_CODING_AGENT_SESSION_DIR", "HANA_HOME", "T3CODE_HOME":
|
||||
case "PI_CODING_AGENT_DIR", "PI_CODING_AGENT_SESSION_DIR", "PRIME_AGENT_CODING_AGENT_DIR", "HANA_HOME", "T3CODE_HOME":
|
||||
return v == "~" || strings.HasPrefix(v, "~/") || (runtime.GOOS == "windows" && strings.HasPrefix(v, `~\`))
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -117,6 +117,10 @@ func TestTildeFolderVariables(t *testing.T) {
|
||||
{"HANA_HOME", "~other/hanako", false},
|
||||
{"PI_CODING_AGENT_DIR", "~other/pi", false},
|
||||
{"PI_CODING_AGENT_DIR", `~\pi`, runtime.GOOS == "windows"},
|
||||
{"PRIME_AGENT_CODING_AGENT_DIR", "~", true},
|
||||
{"PRIME_AGENT_CODING_AGENT_DIR", "~/pa", true},
|
||||
{"PRIME_AGENT_CODING_AGENT_DIR", "~other/pa", false},
|
||||
{"PRIME_AGENT_CODING_AGENT_DIR", `~\pa`, runtime.GOOS == "windows"},
|
||||
} {
|
||||
t.Run(tc.name+"="+tc.value, func(t *testing.T) {
|
||||
t.Setenv(tc.name, tc.value)
|
||||
|
||||
@@ -2961,7 +2961,7 @@ const grouped = (a, f) => menuRoles(a).includes(f.label) || roleLevel(f.label);
|
||||
const ROLE_MODELS = [...FOLLOWS_MODEL, ...OMP_OWN_PICK];
|
||||
// agents with no default model of their own, whose Default leaves the pick
|
||||
// to them (#709)
|
||||
const PICKS_ITSELF = ["pi", "omo"];
|
||||
const PICKS_ITSELF = ["pi", "omo", "prime-agent"];
|
||||
|
||||
// A field that follows the model unless set — Codex's subagents, Claude
|
||||
// Code's tiers, omp's roles — is a small square after the pickers rather
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" height="1em" style="flex:none;line-height:1" viewBox="1.5 -6 52 52" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Prime Agent</title><path d="M36.7084 18.2266C36.656 18.2284 36.5914 18.2306 36.5071 18.2306L36.5023 18.2239C36.2652 18.2777 35.9705 18.2583 35.6691 18.2385C34.7753 18.1798 33.822 18.1172 34.138 19.9454C34.2085 20.3481 33.7202 20.4471 33.3964 20.4638C32.477 20.5142 31.5544 20.5343 30.6331 20.5159C30.4587 20.513 30.2804 20.3662 30.1194 20.2336C30.0917 20.2107 30.0642 20.1882 30.0375 20.1669C30.0089 20.1434 30.1162 19.8397 30.1718 19.8363C31.0704 19.7839 31.3963 19.1745 31.7212 18.5669C31.8849 18.2612 32.0482 17.9559 32.284 17.7223C34.4183 15.6065 36.5978 13.5311 39.091 11.8264C39.3342 11.6603 39.6313 11.5076 39.8326 11.7962C39.9877 12.0192 39.8425 12.1455 39.6935 12.2751C39.6284 12.3319 39.5625 12.3892 39.5205 12.4556C39.37 12.6945 39.1028 12.8705 38.8374 13.0456C38.3157 13.3894 37.7997 13.7295 38.1833 14.5344C38.516 15.2313 38.2183 15.355 37.7607 15.545L37.742 15.5528C37.5464 15.6349 37.3459 15.7094 37.1459 15.7839C36.7198 15.9424 36.2946 16.1008 35.9133 16.3314C35.5308 16.5629 35.3479 17.0142 35.9737 17.281C37.3411 17.8632 40.8813 16.9337 41.5724 15.6518C42.2185 14.4524 43.1838 13.5628 44.1484 12.6738C44.6898 12.175 45.2309 11.6764 45.7152 11.1234C46.7595 9.93206 47.9822 8.89721 49.2054 7.86179C49.8136 7.34709 50.422 6.83225 51.0085 6.29797C51.4498 5.89531 51.6327 5.36512 51.2872 4.78627C50.9431 4.21077 50.3593 4.13359 49.8106 4.26278C46.1949 5.11343 42.7017 6.26108 39.5993 8.40365C34.6463 11.8247 29.6851 15.2341 24.6836 18.583C22.9789 19.7256 21.947 19.1669 21.3783 17.1887C20.1149 12.7962 18.2625 8.96571 12.9405 8.37009C10.9959 8.15198 9.56975 9.37008 9.85161 11.3029C9.99422 12.2828 9.86504 13.2056 9.39358 14.125C9.28963 14.328 9.18468 14.5311 9.07963 14.7344C8.35368 16.1392 7.62145 17.5561 7.16711 19.0511C7.12909 19.1761 7.08555 19.3077 7.04068 19.4434C6.63561 20.6674 6.12067 22.2233 8.57814 22.3094C8.67882 22.3128 8.87178 22.5661 8.84828 22.6601C8.7946 22.8833 8.68552 23.1483 8.51103 23.2775C6.15537 25.0141 4.21917 27.1163 3.38696 29.9603C2.96583 31.3965 3.24435 32.8881 4.47083 34.0005C5.34834 34.7958 6.46913 35.2571 7.45233 34.5878C8.34914 33.9773 9.33328 33.5677 10.3154 33.159C11.1799 32.7992 12.0428 32.4401 12.8432 31.9451C13.0361 31.8258 13.2705 31.7166 13.5076 31.6061C14.1634 31.301 14.8406 30.9854 14.7223 30.4149C14.5361 29.5208 13.5915 28.6919 12.8046 28.0408C12.0244 27.395 10.0362 23.0577 10.2727 22.0158C10.604 20.5567 11.3499 19.2935 12.0965 18.029C12.7338 16.9495 13.3716 15.8691 13.7526 14.6653C13.9103 14.1686 14.5143 13.8968 15.0965 14.0948C15.4916 14.2287 15.4244 14.5914 15.3617 14.9293C15.36 14.9386 15.3583 14.9479 15.3566 14.9572C15.1205 16.2559 14.889 17.5562 14.6574 18.8564C14.5416 19.5064 14.4259 20.1563 14.3096 20.8061C14.2358 21.2222 14.3649 21.5544 14.7961 21.6383C15.6267 21.801 15.6082 22.1752 15.2341 22.8178C14.8364 23.499 14.7811 24.3312 15.2257 24.9604C15.672 25.5929 16.4186 25.7255 17.177 25.3463C17.6501 25.1114 18.0176 25.3211 18.0125 25.7976C17.9823 28.343 19.0477 27.769 20.3447 26.6584C20.464 26.5561 20.6265 26.4995 20.7835 26.4449C20.812 26.435 20.8404 26.4251 20.8682 26.4151C20.9912 26.3712 21.1144 26.3275 21.2376 26.2838C23.6789 25.4175 26.1172 24.5524 27.4955 22.0527C27.602 21.8575 27.9514 21.7629 28.2235 21.6893C28.2389 21.6851 28.2542 21.681 28.2691 21.6769C29.8453 21.2486 31.4545 21.2422 33.0627 21.2358C34.2705 21.231 35.4774 21.2262 36.6699 21.0427C37.8462 20.8615 39.1278 20.1752 39.138 19.0394C39.1473 18.1236 38.4463 18.1805 37.746 18.2373C37.443 18.262 37.14 18.2865 36.8947 18.2323C36.845 18.222 36.7927 18.2238 36.7084 18.2266Z"/><path d="M18.1822 31.05C17.8903 32.9929 18.6319 34.6556 21.6671 34.634H21.6654C24.2576 34.5282 27.1906 32.9593 30.0561 30.9528C31.9486 29.6273 33.5846 28.2295 34.645 26.1642C35.4253 24.6458 35.0241 23.4277 33.8481 22.3623C33.3296 21.8925 32.8347 21.8405 32.2541 22.4076C30.1936 24.4243 27.6284 25.525 24.9942 26.6323C24.3229 26.9147 23.5584 27.0557 22.7884 27.1977C20.7369 27.576 18.647 27.9612 18.1822 31.05Z"/></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
@@ -2,7 +2,7 @@
|
||||
// #709: Pi has no default model of its own — Default in its model picker
|
||||
// clears the default it has, and Pi then takes the first provider signed in
|
||||
// (openai's gpt-5.5 before openai-codex's), so "what Pi ships with" read as
|
||||
// a model Pi would keep. Pi's and OmO's Default says it clears the default
|
||||
// a model Pi would keep. Pi's, OmO's and Prime Agent's (#1528) Default says it clears the default
|
||||
// and Pi picks one itself; other agents' says what it said. Pi's
|
||||
// openai-codex models are rows of their own beside openai's of the same
|
||||
// name. Both connected to magpie, so the pickers in their rows list every
|
||||
@@ -23,6 +23,9 @@ const piOptions = [
|
||||
const state = {
|
||||
agents: [
|
||||
{ id: "pi", name: "Pi", icon: "generic", path: "/fixture/pi", wired: true, fields: [{ key: "model", label: "model", value: "openai/gpt-6-astra", options: piOptions }] },
|
||||
// #1528: Prime Agent, Pi's files in ~/.prime/agent, with no default of
|
||||
// its own either (it starts on its featured model)
|
||||
{ id: "prime-agent", name: "Prime Agent", icon: "prime-agent", path: "/fixture/prime", wired: true, fields: [{ key: "model", label: "model", value: "magpie/relay/m1", options: piOptions.filter((o) => o.ref) }] },
|
||||
{ id: "claude", name: "Claude Code", icon: "generic", path: "/fixture/claude", wired: true, fields: [{ key: "model", label: "model", value: "opus", options: [{ value: "opus" }, { value: "sonnet" }, { value: "relay/m1", label: "m1", ref: "relay/m1", note: "Relay · via magpie" }] }] },
|
||||
],
|
||||
profiles: [],
|
||||
@@ -84,6 +87,15 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.ok(values.includes("openai/gpt-6-astra") && values.includes("openai-codex/gpt-6-astra"), "same-named models stay a row each: " + values);
|
||||
await close();
|
||||
|
||||
await open("prime-agent");
|
||||
assert.equal(await page.locator("#list li", { hasText: w.pi.replace("Pi", "Prime Agent") }).count(), 1, "Prime Agent's Default says it clears the default");
|
||||
await close();
|
||||
// its icon is its own, loaded, not the generic one a missing file falls to
|
||||
const ic = page.locator(`${row("prime-agent")} .ic[data-icon="prime-agent"]`).first();
|
||||
await ic.locator(".mask").waitFor();
|
||||
assert.equal(await ic.evaluate((e) => e.classList.contains("generic")), false);
|
||||
assert.ok(await page.evaluate(() => new Promise((ok) => { const i = new Image(); i.onload = () => ok(i.naturalWidth > 0); i.onerror = () => ok(false); i.src = "icons/prime-agent.svg"; })), "icons/prime-agent.svg loads");
|
||||
|
||||
await open("claude");
|
||||
assert.equal(await page.locator("#list li", { hasText: w.claude }).count(), 1, "other agents' Default is as it was");
|
||||
assert.equal(await page.locator("#list li", { hasText: w.pi.replace("Pi", "Claude Code") }).count(), 0);
|
||||
|
||||
Reference in New Issue
Block a user