GetEnvFile returned the first line for a key and SetEnvFile replaced the first one. Gemini CLI reads ~/.gemini/.env with dotenv.parse, where a later line overrides an earlier one, so in a file with GEMINI_API_KEY twice the Gemini CLI uses the last, while magpie read and wrote the first. Wiring Gemini CLI to the gateway then changed a line the CLI ignored, and the check for whether it was wired read a value the CLI did not use.
GetEnvFile now returns the last line for the key and setLine replaces the last matching line (setLine is only used by SetEnvFile). A key that is set once behaves as before.
TestGetEnvFileLastDuplicateWins and TestSetEnvFileReplacesLastDuplicate fail on the old code. go vet and go test ./internal/edit ./internal/agent pass.
SetEnvFile, the TOML setters and the top-level YAML setters build the lines they add with \n, then join the whole file. In a file saved with \r\n (the usual case for a config edited on Windows) that left the new or replaced lines with a bare \n among \r\n ones. SetEnvFile turned "A=1\r\nB=2\r\n" with A set to 9 into "A=9\nB=2\r\n", and SetTOMLTop, a new TOML key or table, and SetYAMLTop did the same.
The files are written back through joinLinesLike, which turns every line break into \r\n when the original used \r\n for all of them. Untouched lines already carry their \r, so only the lines the edit added change; a file that mixed endings is written as before.
TestSetEnvFileKeepsCRLF, TestSetTOMLKeepsCRLF and TestSetYAMLTopKeepsCRLF fail on the old code; TestSetEnvFileKeepsMixedEndings pins that a mixed file is left alone. go vet and go test ./internal/edit pass on this branch and on current main with it merged; the full go test -tags nogui ./... run (under a temp HOME) passes except internal/sessions TestCodexArchivedSameSizeRewriteInvalidatesDiscovery, which fails the same way on unmodified main here.
Changing Goose's model or effort could insert a key inside a multiline flow
collection or append a duplicate when the existing key was quoted. Locate
entries through parsed keys, keep complete values together, and validate the
result before writing it. Read and delete use decoded key names too.
Keep other entries, document markers, comments and block-scalar blank lines
in place. Reject invalid input, multiple documents and layouts that cannot
be edited safely as whole lines, with the file path in the error.
Regression tests reproduce the flow-value and quoted-key failures and cover
multiline values, unchanged surrounding content and failed writes.
Setting a field to nothing now means the agent's own default: dial's
wiring (gateway provider, model catalog, env) comes out and the key is
removed, so Codex is back on OpenAI's catalog and Claude Code on
Anthropic's. The picker lists it first; the CLI takes `dial <agent>
default`. Also the vendor icon inside a field pill was 22px, not 14px:
the row icon rule outranked it.
Wails v3 tray panel and window, TUI and CLI. Switches model, effort and
provider for Claude Code, Codex, Gemini CLI, OpenCode, Pi, Goose, Cursor,
Copilot CLI and Crush with format-preserving config edits. Providers page
and registry, stored keys, live vendor model lists, profiles.
Co-Authored-By: Claude <noreply@anthropic.com>