Files
magpie/docs
yetone b9d1cd36f5 agent: Hermes's api_key as "${VAR}" with the key in its .env reaches magpie (PaulT on Discord)
PaulT (magpie 0.1.1291) keeps Hermes's key the way Hermes keeps keys:
providers.magpie.api_key: "${MAGPIE_API_KEY}" in config.yaml, the key in
~/.hermes/.env. Hermes expands ${VAR} and ${env:VAR} as it loads the
config (hermes_cli/config.py _ENV_REF_RE, _env_expand_match), from the
.env beside it, which load_hermes_dotenv loads over the environment.
magpie compared the literal "${MAGPIE_API_KEY}" with its key, so Check
marked Hermes as needing attention, and a sync (mergeKept) wrote the
literal key over the reference.

Now hermesKey expands the reference the way Hermes does: the .env
beside the config (main or a profile's), then this machine's
environment. Check reads that key through keyHolds, so magpie's key or a
Gateway key is not drift. A variable magpie can't see (only a shell
profile sets it) or another secret source (${vault:...}) is unknown:
not drift, and kept. A sync or pick keeps the reference
(hermesKeptKey). When it names a key the gateway doesn't take, magpie
keeps the reference and writes its key into that .env under the
variable (made 0600 when there was none). A value with more than the
one reference in it is replaced by magpie's key, as before.

Siblings not covered here: other agents whose configs take env
references in the key (Droid's "${VAR}", OpenCode's {env:VAR}) still
compare literally.

Test: TestHermesWithAKeyInItsEnvFile uses the reporter's provider block
as written: a Gateway key and magpie's own (quoted, export) in .env,
${env:VAR} from the environment, an unseen variable, a wrong key (.env
rewritten in place, other lines kept), and a composite value.
Broken by hand: with hermes.go at origin/main it fails "a gateway key in
.env is drift: Hermes's api_key (config.yaml) was changed"; with only
the sync half removed it fails "the user's reference was written over".

Run (worktree, sandbox HOME, GOCACHE pinned, macOS, load ~300):
- gofmt -l internal/agent: nothing. go vet ./..., GOOS=linux go vet
  -tags nogui ./..., GOOS=windows go vet ./...: ok (at b10788745 and
  again at 94df23926). go build, GOOS=linux -tags nogui and
  GOOS=windows builds: ok at b10788745.
- go test -timeout 45m ./... at b10788745 (none of these three files
  changed up to 94df23926): 63 packages ok, internal/agent ok in 2092s.
  One red: internal/gateway TestMaxRPMTooLongIs429WithRetryAfter
  ("second = 200 Retry-After"), the load red filed as #1791; this change
  doesn't reach the gateway.
- At 94df23926: go test -run 'TestHermes|TestKeyHolds|TestGatewayKey|
  TestFolderVars' ./internal/agent/: ok.
Not tried: a real Hermes reading the config (its binary rewrites the
live launcher under a temp HERMES_HOME); the expansion rules were read
from Hermes's source (hermes_cli/config.py, env_loader.py).
2026-10-19 22:49:49 +08:00
..