Files
magpie/internal/appdir/hermes.go
T
yetone e08902e79d agent, library: Hermes Agent's folder is %LOCALAPPDATA%\hermes on Windows, and rtk's installer is told it (新v学员 on Discord)
新v学员 runs magpie on native Windows. Library -> RTK -> Hermes Agent
failed with "rtk's installer didn't add its hook to Hermes Agent:
Config: C:\Users\admin\AppData\Local\hermes\config.yaml ...". magpie
hard-coded ~/.hermes. Hermes' own default
(hermes_constants._get_platform_default_hermes_home) is
$LOCALAPPDATA\hermes on win32 (~/AppData/Local/hermes when LOCALAPPDATA
is empty) and ~/.hermes elsewhere, with $HERMES_HOME overriding it.
rtk 0.51's resolve_hermes_home knows only $HERMES_HOME and ~/.hermes,
on every OS.

What changed:
- appdir.HermesHome / HermesHomeIn / HermesDefaultIn: $HERMES_HOME,
  else Hermes' per-OS default. This is the one place that resolves it.
- agent: hermesIn (Agents-page model wiring) and hermesProfiles use it
  through place.hermesHome / hermesDefault. A WSL distro keeps
  ~/.hermes (Linux paths, Windows env not read). The Agents-page wiring
  was wrong on native Windows too: without HERMES_HOME it wrote
  %USERPROFILE%\.hermes\config.yaml, which Hermes never reads.
- sessions.HermesDir uses it, so Windows sessions are found.
- library/rtk: the hermes spec reads and writes the agent's own folder
  (a.Dir), and rtkSpec.env passes HERMES_HOME=<that folder> to
  `rtk init -g --agent hermes --auto-patch`.
- Tests resolve the folder through appdir instead of home/.hermes. New
  TestHermesDefault/TestHermesHome (appdir), TestHermesFolder (agent:
  Windows default, profiles under it, WSL unchanged), and
  TestRTKHermesHome (library, a fake rtk that behaves like 0.51).
- docs/reference.md and docs/subsystems/library.md describe the
  Windows folder and the env.

Run:
- gofmt -l clean. go vet ./... on darwin, GOOS=linux -tags nogui and
  GOOS=windows.
- darwin: go test ./internal/appdir ./internal/library
  ./internal/sessions ./internal/agent ./internal/tui.
- TestRTKHermesHome against the old rtk.go fails with the reporter's
  exact message ("didn't add its hook ... AppData/Local/hermes/
  config.yaml"), and its default subtest fails with HERMES_HOME="".
- Windows box (cross-compiled test binaries, testenv sandbox
  USERPROFILE/LOCALAPPDATA): appdir Hermes tests, agent
  Hermes|Reseat|Effort (incl. TestHermesFolder) and library Hermes|RTK
  pass. TestRTKHermesHome skips there (shell fake). The sessions binary
  failed only TestHermesMessageVisibility, because its testdata wasn't
  copied to the box.
- Real rtk.exe 0.51.0 on the Windows box: with
  HERMES_HOME=<sandbox>\AppData\Local\hermes it wrote the plugin there
  and patched that config.yaml. Without HERMES_HOME it wrote
  C:\Users\<user>\.hermes, ignoring a sandbox USERPROFILE (rtk asks
  Windows for the home folder). That confirms the cause and the fix.
  The stray folder it made on the test box was removed.

Not run: real Hermes on Windows (no install, and running hermes under
a temp HERMES_HOME rewrites the live launcher); the GUI suite; the full
go test ./... ; the reporter's own machine.
2026-10-13 00:01:46 +08:00

47 lines
1.5 KiB
Go

package appdir
import (
"os"
"path/filepath"
"runtime"
)
// HermesHome is the folder Hermes Agent (Nous Research) keeps its files in:
// config.yaml, .env, plugins, skills, profiles and state.db. It is
// $HERMES_HOME when that is set, else the platform's default, as
// hermes_constants.get_hermes_home reads them: %LOCALAPPDATA%\hermes on
// Windows (AppData\Local\hermes under the home folder without
// LOCALAPPDATA), ~/.hermes everywhere else. Every place magpie reads or
// writes Hermes's files goes through here (新v学员 on Discord: on native
// Windows Hermes and rtk's hook were in %LOCALAPPDATA%\hermes, and magpie
// looked for them in ~/.hermes).
func HermesHome() string {
home, _ := os.UserHomeDir()
return HermesHomeIn(home)
}
// HermesHomeIn is HermesHome with home as the user's home folder.
func HermesHomeIn(home string) string {
if d := Getenv("HERMES_HOME"); d != "" {
return d
}
return HermesDefaultIn(home)
}
// HermesDefaultIn is Hermes's own default home on this machine, whatever
// HERMES_HOME says (hermes_constants._get_platform_default_hermes_home):
// the root a HERMES_HOME under it is a profile of.
func HermesDefaultIn(home string) string {
return hermesDefault(runtime.GOOS, home, Getenv("LOCALAPPDATA"))
}
func hermesDefault(goos, home, localAppData string) string {
if goos != "windows" {
return filepath.Join(home, ".hermes")
}
if localAppData == "" {
localAppData = filepath.Join(home, "AppData", "Local")
}
return filepath.Join(localAppData, "hermes")
}