Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/setup/assets/hermes/nudge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from pathlib import Path
import sys

try:
payload = json.loads(Path(sys.argv[1]).read_text() or "{}")
payload = json.loads(Path(sys.argv[1]).read_text(encoding="utf-8") or "{}")
except Exception:
payload = {}

Expand All @@ -33,7 +33,8 @@ if "mnemon" not in response.lower() and "durable memory" not in response.lower()
state_dir.mkdir(parents=True, exist_ok=True)
(state_dir / "pending-nudge.txt").write_text(
"[mnemon] Consider whether the previous exchange warrants durable memory. "
"Use mnemon remember only for stable decisions, preferences, facts, or insights.\n"
"Use mnemon remember only for stable decisions, preferences, facts, or insights.\n",
encoding="utf-8",
)
except Exception:
pass
Expand Down
6 changes: 4 additions & 2 deletions internal/setup/assets/hermes/remind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from pathlib import Path

payload_path = Path(sys.argv[1])
try:
payload = json.loads(payload_path.read_text() or "{}")
payload = json.loads(payload_path.read_text(encoding="utf-8") or "{}")
except Exception:
payload = {}

Expand Down Expand Up @@ -60,7 +60,7 @@ def read_state_file(name):
hermes_home = Path(os.environ.get("HERMES_HOME") or Path.home() / ".hermes")
path = hermes_home / "mnemon" / name
try:
text = path.read_text().strip()
text = path.read_text(encoding="utf-8").strip()
path.unlink(missing_ok=True)
return text
except Exception:
Expand All @@ -75,6 +75,8 @@ def recall(query):
["mnemon", "recall", query, "--limit", "5"],
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
timeout=8,
check=False,
)
Expand Down
37 changes: 37 additions & 0 deletions internal/setup/hermes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,43 @@ func TestHermesWriteSkillAndHooks(t *testing.T) {
}
}

func TestHermesPythonHooksUseExplicitUTF8(t *testing.T) {
tests := []struct {
name string
hook string
want []string
}{
{
name: "remind",
hook: string(assets.HermesRemindHook),
want: []string{
`payload_path.read_text(encoding="utf-8")`,
`path.read_text(encoding="utf-8").strip()`,
`encoding="utf-8",`,
`errors="replace",`,
},
},
{
name: "nudge",
hook: string(assets.HermesNudgeHook),
want: []string{
`Path(sys.argv[1]).read_text(encoding="utf-8")`,
`encoding="utf-8",`,
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for _, want := range tt.want {
if !strings.Contains(tt.hook, want) {
t.Fatalf("Hermes %s hook is missing %q", tt.name, want)
}
}
})
}
}

func TestHermesRegisterHooksPreservesUnrelatedConfig(t *testing.T) {
dir := t.TempDir()
configPath := filepath.Join(dir, "config.yaml")
Expand Down
Loading