Every agent row keeps its 接入 switch and now has its model picker beside it. Picking a magpie model on an agent that isn't connected connects it first (agent.Pick, used by /api/set), so one pick sets the agent up; disconnecting still puts back what the agent had. The intro line says both ways. An opened row shook: the connected row centred its lines in its 56px min-height, and the 3px row-gap couldn't be folded away, so opening moved the name and the switch and changed the space under them. The first line now has its own height and isn't centred, the row-gap is 0 with the spacing in margins, and the opened part starts where the shut row ended (56/56 at 980px, 90/90 at 560px; the name at 8px and the switch at 19px open and shut). Opening and closing animate the part's height, padding, margin and border on iOS's sheet curve cubic-bezier(.32,.72,0,1), 460 ms open and 340 ms shut, and what's in it fades in from 6px above; a row already open slides shut before another opens. With reduced motion it opens at once. Gemini CLI's .env made by magpie for its key was left holding a newline after a disconnect (main too): DelEnvFile now removes a dotenv file once the deleted keys were all it held. TestPickConnectsFirst, the only.env case in TestEnvFile, agent-start-pick and agent-expand-steady (name and switch unmoved, the opened part's top at the shut row's end, at least 3 heights between on the way open and shut, growing/shrinking only, chromium and webkit at 980 and 560px) fail on the old code and pass. Tests that open rows wait for the slide. In a sandbox HOME with real accounts: Claude Code and Gemini CLI picked while not connected answer PONG and disconnect back to what they had; Goose's pick → disconnect round trip is byte-identical (goose itself stops at a Linear MCP OAuth, so no request). go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui for edit, agent and gui under a temp HOME pass; GUI tests that fail here fail the same on 82340f41 (account-arrange, cli-update, mobile-web, provider-levels-scroll, provider-proxy, redact-rule-row, routing-compact, provider-detect-models, plugin-move).
89 lines
2.2 KiB
Go
89 lines
2.2 KiB
Go
package edit
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// dotenv files (KEY=value per line) as Gemini CLI reads from ~/.gemini/.env.
|
|
|
|
var envLine = regexp.MustCompile(`^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$`)
|
|
|
|
// GetEnvFile reads one key from a dotenv file.
|
|
func GetEnvFile(path, key string) (string, bool) {
|
|
raw, err := Read(path)
|
|
if err != nil {
|
|
return "", false
|
|
}
|
|
for _, l := range splitLines(string(raw)) {
|
|
if m := envLine.FindStringSubmatch(l); m != nil && m[1] == key {
|
|
if v, ok := unquote(m[2]); ok {
|
|
return v, true
|
|
}
|
|
v := m[2]
|
|
if i := strings.IndexByte(v, '#'); i >= 0 {
|
|
v = strings.TrimSpace(v[:i])
|
|
}
|
|
return v, true
|
|
}
|
|
}
|
|
return "", false
|
|
}
|
|
|
|
// SetEnvFile sets keys in a dotenv file, replacing lines in place and
|
|
// appending new ones. Other lines are kept byte for byte.
|
|
func SetEnvFile(path string, kvs ...KV) error {
|
|
raw, err := Read(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
lines := splitLines(string(raw))
|
|
for _, kv := range kvs {
|
|
v := toString(kv.Value)
|
|
if strings.ContainsAny(v, " #\"'$\r\n") {
|
|
// Gemini CLI's dotenv keeps backslashes literal inside single quotes.
|
|
if !strings.ContainsAny(v, "'\r\n") {
|
|
v = "'" + v + "'"
|
|
} else {
|
|
v = `"` + strings.ReplaceAll(strings.ReplaceAll(v, `\`, `\\`), `"`, `\"`) + `"`
|
|
}
|
|
}
|
|
lines = setLine(lines, kv.Path, kv.Path+"="+v, nil, func(l string) (string, bool) {
|
|
if m := envLine.FindStringSubmatch(l); m != nil {
|
|
return m[1], true
|
|
}
|
|
return "", false
|
|
})
|
|
}
|
|
return WriteAtomic(path, []byte(joinLines(lines)))
|
|
}
|
|
|
|
// DelEnvFile removes keys from a dotenv file, and the file when they were
|
|
// all it held (Gemini CLI's .env, made by magpie for its key).
|
|
func DelEnvFile(path string, keys ...string) error {
|
|
raw, err := Read(path)
|
|
if err != nil || len(raw) == 0 {
|
|
return err
|
|
}
|
|
drop := map[string]bool{}
|
|
for _, k := range keys {
|
|
drop[k] = true
|
|
}
|
|
var out []string
|
|
changed := false
|
|
for _, l := range splitLines(string(raw)) {
|
|
if m := envLine.FindStringSubmatch(l); m != nil && drop[m[1]] {
|
|
changed = true
|
|
continue
|
|
}
|
|
out = append(out, l)
|
|
}
|
|
if !changed {
|
|
return nil
|
|
}
|
|
if strings.TrimSpace(strings.Join(out, "")) == "" {
|
|
return Remove(path)
|
|
}
|
|
return WriteAtomic(path, []byte(joinLines(out)))
|
|
}
|