Files
magpie/internal/agent/primeagent.go
T
yetone 64262a19f0 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 ./...
2026-10-11 03:11:33 +08:00

47 lines
1.8 KiB
Go

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")
}