Autonomous AI sales agent powered by Claude Code or Codex. Finds prospects, writes cold emails, sends campaigns, handles replies, books meetings. No API keys needed — runs on your Claude or Codex subscriptions.
Windows review: old cp1252 files still load; shim target read from the shim
Ethan6b7cf03361e2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b5a0d9b..88d9acc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -28,8 +28,11 @@ minor versions can still change behaviour.dashboard's log of `harvey run` can't crash on "⚠". An npm install's`claude.cmd` shim is resolved to the native `claude.exe` it wraps and isnever run through cmd.exe, which would re-parse Harvey's isolation flags;- if the executable is missing, Harvey says how to fix it. Based on #18 by- Tariz Shahid.+ if the executable is missing, Harvey says how to fix it. Files an older+ Harvey saved in the Windows code page (trained skills, harvey.yaml) still+ load, with a warning to re-save them as UTF-8. `harvey export` CSVs are now+ UTF-8 on Windows too, which sequencers expect (Excel needs Data > From+ Text/CSV to show accents). Based on #18 by Tariz Shahid.- Replies are read without the email they quote. The model, the stored threadand the answer get the reply without the quoted email, and any line thatrepeats what Harvey sent that person is set aside, so Harvey's own wordsdiff --git a/harvey/brain.py b/harvey/brain.pyindex 18aad30..704b40e 100644--- a/harvey/brain.py+++ b/harvey/brain.py@@ -19,6 +19,7 @@ from harvey.state import StateManagerlogger = logging.getLogger("harvey.brain")from harvey.paths import PROJECT_ROOT+from harvey.textio import read_user_textPROMPTS_DIR = PROJECT_ROOT / "prompts"SKILLS_DIR = PROJECT_ROOT / "skills"@@ -387,7 +388,7 @@ class Brain:except FileNotFoundError:logger.error(- "Claude CLI not found. Install it: https://claude.com/download"+ "Claude CLI not found. Install it: https://code.claude.com/docs/en/setup")return "" # not retryableexcept asyncio.CancelledError:@@ -675,7 +676,7 @@ class Brain:"""Load a prompt template from the prompts/ directory and fill in variables."""prompt_file = PROMPTS_DIR / f"{prompt_name}.md"try:- template = prompt_file.read_text(encoding="utf-8")+ template = read_user_text(prompt_file)except FileNotFoundError:logger.warning(f"Prompt file not found: {prompt_file}")return ""@@ -696,7 +697,7 @@ class Brain:"""Load a skill knowledge file from the skills/ directory."""skill_file = SKILLS_DIR / f"{skill_name}.md"try:- return skill_file.read_text(encoding="utf-8")+ return read_user_text(skill_file)except FileNotFoundError:logger.warning(f"Skill file not found: {skill_file}")return ""diff --git a/harvey/claude_runtime.py b/harvey/claude_runtime.pyindex 197eb9e..f0fc768 100644--- a/harvey/claude_runtime.py+++ b/harvey/claude_runtime.py@@ -81,14 +81,39 @@ class ClaudeRuntimeError(Exception):_PLATFORM = sys.platform+# npm/yarn/pnpm shims name their target relative to the shim's folder:+# "%dp0%\node_modules\@anthropic-ai\claude-code\bin\claude.exe" %*+_SHIM_TARGET_RE = re.compile(r'"%~?dp0%?\\([^"%]+?\.exe)"', re.IGNORECASE)+# Before its install script runs, the package's bin/claude.exe is a small+# text placeholder, not the real binary.+_MIN_NATIVE_BYTES = 4096+INSTALL_HINT = (+ "Install Claude Code (https://code.claude.com/docs/en/setup): on Windows run "+ "'irm https://claude.ai/install.ps1 | iex' in PowerShell or "+ "'winget install Anthropic.ClaudeCode'; or 'npm install -g "+ "@anthropic-ai/claude-code@latest' (without --ignore-scripts)."+)+++def _shim_target(shim: Path) -> Path:+ """The native exe a .cmd shim launches (read from the shim, else npm's+ usual layout next to it)."""+ try:+ m = _SHIM_TARGET_RE.search(shim.read_text(encoding="utf-8", errors="replace"))+ except OSError:+ m = None+ if m:+ return shim.parent / Path(m.group(1).replace("\\", "/"))+ return shim.parent / "node_modules" / "@anthropic-ai" / "claude-code" / "bin" / "claude.exe"++def _locate(env: dict | None) -> tuple[str | None, Path | None]:- """(what PATH finds, the native exe an npm shim wraps or None)."""+ """(what PATH finds, the native exe a Windows shim wraps or None)."""path = (env if env is not None else os.environ).get("PATH")found = shutil.which("claude", path=path)if not found or _PLATFORM != "win32" or not found.lower().endswith((".cmd", ".bat")):return found, None- return found, (Path(found).parent / "node_modules" / "@anthropic-ai" / "claude-code"- / "bin" / "claude.exe")+ return found, _shim_target(Path(found))def find_claude(env: dict | None = None) -> str | None:@@ -103,13 +128,14 @@ def find_claude(env: dict | None = None) -> str | None:found, native = _locate(env)if native is None:return found- if native.is_file():+ if native.is_file() and native.stat().st_size >= _MIN_NATIVE_BYTES:return str(native)+ problem = ("is only a placeholder: the package's install script didn't run"+ if native.is_file() else "isn't there")raise ClaudeRuntimeError(- f"Found only npm's claude.cmd shim ({found}), which Harvey won't run: "- "cmd.exe would re-parse the flags that keep each call isolated. Install "- "the native Claude Code for Windows (https://claude.com/download), or "- "update the npm package so it includes claude.exe, then try again.")+ f"Found the claude.cmd shim ({found}), but the claude.exe it launches "+ f"({native}) {problem}. Harvey never runs Claude through cmd.exe, which "+ f"re-parses the flags that keep each call isolated. {INSTALL_HINT}")def runtime_env(cwd: str, base: dict | None = None) -> dict:@@ -177,8 +203,8 @@ def _fingerprint(executable: str) -> tuple:def fingerprint(env: dict | None = None) -> tuple:"""Changes when the installed CLI changes (used to re-check a pause)."""found, native = _locate(env)- # A refused npm shim is tracked by the exe it should wrap: installing it- # changes the fingerprint, so a pause is re-checked.+ # A Windows shim is tracked by the exe it wraps, so the fingerprint+ # changes when that's installed or updated.exe = str(native) if native is not None else foundreturn _fingerprint(exe) if exe else ("", None, None)@@ -210,7 +236,7 @@ def check_cli(env: dict | None = None) -> str:exe = find_claude(env)if not exe:raise ClaudeRuntimeError(- "Claude CLI not found on PATH. Install it (https://claude.com/download) "+ "Claude CLI not found on PATH. Install it (https://code.claude.com/docs/en/setup) ""and run 'claude login'.")key = _fingerprint(exe)with _capable_lock:diff --git a/harvey/cli.py b/harvey/cli.pyindex b7b6a58..ccd80ae 100644--- a/harvey/cli.py+++ b/harvey/cli.py@@ -712,19 +712,9 @@ def cmd_sending(args):asyncio.run(_run())-def _utf8_stdio(*streams):- """Write output as UTF-8. On Windows, output going to a file or pipe (the- dashboard's log of `harvey run`) uses the locale code page, where "⚠" or- "→" in a message would crash print()."""- for stream in streams or (sys.stdout, sys.stderr):- try:- stream.reconfigure(encoding="utf-8", errors="replace")- except (AttributeError, ValueError, OSError):- pass # not a reconfigurable text stream (tests, embedded use)--def main():- _utf8_stdio()+ from harvey.textio import utf8_stdio+ utf8_stdio()from harvey.paths import PROJECT_ROOTproject_root = str(PROJECT_ROOT)diff --git a/harvey/config.py b/harvey/config.pyindex b0bd74b..46a613c 100644--- a/harvey/config.py+++ b/harvey/config.py@@ -7,6 +7,8 @@ from datetime import time as _timefrom pathlib import Pathimport yaml++from harvey.textio import read_user_textfrom dotenv import load_dotenvfrom pydantic import BaseModel, ValidationError, field_validator, model_validator@@ -455,8 +457,7 @@ def load_config(config_path: str | None = None) -> HarveyConfig:config_path = _find_config_file()try:- with open(config_path, encoding="utf-8") as f:- data = yaml.safe_load(f)+ data = yaml.safe_load(read_user_text(config_path))except FileNotFoundError:raise ConfigFileNotFoundError(f"Config file not found: {config_path}. "@@ -502,8 +503,7 @@ def load_brain_config(config_path: str | None = None) -> BrainConfig:except ConfigFileNotFoundError:return BrainConfig()try:- with open(config_path, encoding="utf-8") as f:- data = yaml.safe_load(f)+ data = yaml.safe_load(read_user_text(config_path))except FileNotFoundError:return BrainConfig()except (yaml.YAMLError, OSError) as e:diff --git a/harvey/dashboard.py b/harvey/dashboard.pyindex 5984f73..adfec6c 100644--- a/harvey/dashboard.py+++ b/harvey/dashboard.py@@ -26,6 +26,7 @@ logger = logging.getLogger("harvey.dashboard")from harvey import dashboard_auth as auth # noqa: E402from harvey.paths import PROJECT_ROOT # noqa: E402+from harvey.textio import read_user_text # noqa: E402DB_PATH = PROJECT_ROOT / "data" / "harvey.db"ENV_FILE = PROJECT_ROOT / ".env"CONFIG_FILE = PROJECT_ROOT / "harvey.yaml"@@ -90,7 +91,7 @@ def _read_env_file() -> dict[str, str]:"""Read .env file and return as dict."""env_vars = {}if ENV_FILE.exists():- for line in ENV_FILE.read_text(encoding="utf-8").splitlines():+ for line in read_user_text(ENV_FILE).splitlines():line = line.strip()if line and not line.startswith("#") and "=" in line:key, _, value = line.partition("=")@@ -122,7 +123,7 @@ def _write_env_file(updates: dict[str, str]):raise OSError(f"{ENV_FILE} is a symbolic link; edit it by hand.")if ENV_FILE.exists() and not ENV_FILE.is_file():raise OSError(f"{ENV_FILE} is not a regular file.")- lines = (ENV_FILE.read_text(encoding="utf-8").splitlines()+ lines = (read_user_text(ENV_FILE).splitlines()if ENV_FILE.exists() else [])out, written = [], set()@@ -241,8 +242,7 @@ async def get_setup_status():config_path = _resolve_config_file()if config_path.exists():try:- with open(config_path, encoding="utf-8") as f:- cfg = yaml.safe_load(f)+ cfg = yaml.safe_load(read_user_text(config_path))company = cfg.get("persona", {}).get("company", "")product = cfg.get("product", {}).get("name", "")config_valid = company not in ("Your Company", "") and product not in ("Your Product", "")@@ -301,8 +301,7 @@ async def get_setup_status():def _current_provider() -> str:"""Read channels.email.provider from the active config (best-effort)."""try:- with open(_resolve_config_file(), encoding="utf-8") as f:- cfg = yaml.safe_load(f) or {}+ cfg = yaml.safe_load(read_user_text(_resolve_config_file())) or {}return ((cfg.get("channels") or {}).get("email") or {}).get("provider", "instantly")except Exception:return "instantly"diff --git a/harvey/humanize.py b/harvey/humanize.pyindex 92105b5..7852c79 100644--- a/harvey/humanize.py+++ b/harvey/humanize.py@@ -20,6 +20,8 @@ import osimport refrom pathlib import Path+from harvey.textio import read_user_text+logger = logging.getLogger("harvey.humanize")SKILL_PATH = Path(@@ -42,7 +44,7 @@ def humanizer_enabled(config) -> bool:def load_skill(path: Path | None = None) -> str:"""The skill's instructions without its YAML frontmatter, or ""."""try:- text = (path or SKILL_PATH).read_text(encoding="utf-8")+ text = read_user_text(path or SKILL_PATH)except OSError:return ""if text.startswith("---"):diff --git a/harvey/main.py b/harvey/main.pyindex f2bda25..f97ccee 100644--- a/harvey/main.py+++ b/harvey/main.py@@ -418,9 +418,9 @@ def _needs_setup() -> bool:return Truetry:- with open(config_file, encoding="utf-8") as f:- import yaml- config = yaml.safe_load(f)+ import yaml+ from harvey.textio import read_user_text+ config = yaml.safe_load(read_user_text(config_file))if not isinstance(config, dict):return Truecompany = (config.get("persona") or {}).get("company", "")@@ -470,4 +470,6 @@ def main():if __name__ == "__main__":+ from harvey.textio import utf8_stdio+ utf8_stdio()main()diff --git a/harvey/setup.py b/harvey/setup.pyindex 497b417..25f67e2 100644--- a/harvey/setup.py+++ b/harvey/setup.py@@ -17,6 +17,7 @@ from harvey.state import StateManagerlogger = logging.getLogger("harvey.setup")from harvey.paths import PROJECT_ROOT+from harvey.textio import read_user_textENV_FILE = PROJECT_ROOT / ".env"ENV_EXAMPLE = PROJECT_ROOT / ".env.example"CONFIG_FILE = PROJECT_ROOT / "harvey.yaml"@@ -596,7 +597,7 @@ class SetupWizard:"""Write the .env file, preserving any existing variables we didn't touch."""existing: dict[str, str] = {}if ENV_FILE.exists():- for line in ENV_FILE.read_text(encoding="utf-8").splitlines():+ for line in read_user_text(ENV_FILE).splitlines():line = line.strip()if line and not line.startswith("#") and "=" in line:key, _, value = line.partition("=")@@ -630,8 +631,7 @@ class SetupWizard:elif self.config:# Config already exists (from trainer), update behavior settings onlytry:- with open(CONFIG_FILE, encoding="utf-8") as f:- existing = yaml.safe_load(f) or {}+ existing = yaml.safe_load(read_user_text(CONFIG_FILE)) or {}existing["usage"] = self.config.get("usage", existing.get("usage", {}))existing["brain"] = self.config["brain"]if "LINKEDIN_EMAIL" in self.env_vars:@@ -711,4 +711,6 @@ def main():if __name__ == "__main__":+ from harvey.textio import utf8_stdio+ utf8_stdio()main()diff --git a/harvey/textio.py b/harvey/textio.pynew file mode 100644index 0000000..a373b0e--- /dev/null+++ b/harvey/textio.py@@ -0,0 +1,41 @@+"""Text files and console output, the same on every platform.++Harvey reads and writes its files as UTF-8. Windows' default is the locale+code page (cp1252), so files saved there by an older Harvey, or edited in a+Windows tool, may not be UTF-8: those are still read, with a warning.+"""++import locale+import logging+import sys+from pathlib import Path++logger = logging.getLogger("harvey.textio")+++def read_user_text(path) -> str:+ """A file a person or an older Harvey may have saved (harvey.yaml, .env,+ skills, prompts): UTF-8, with or without a BOM, else the locale's code+ page. Raises what reading the file raises (FileNotFoundError...)."""+ data = Path(path).read_bytes()+ try:+ return data.decode("utf-8-sig")+ except UnicodeDecodeError:+ encoding = locale.getpreferredencoding(False)+ logger.warning(+ f"{path} isn't saved as UTF-8; read it as {encoding}. Re-save it as "+ "UTF-8 to keep characters like ★ or — intact.")+ return data.decode(encoding, errors="replace")+++def utf8_stdio(*streams):+ """Write output as UTF-8. On Windows, output going to a file or pipe (the+ dashboard's log of `harvey run`) uses the locale code page, where "⚠" or+ "→" in a message would crash print(). stderr keeps backslash escapes, so+ odd bytes stay diagnosable."""+ for stream in streams or (sys.stdout, sys.stderr):+ errors = "backslashreplace" if stream is sys.stderr else "replace"+ try:+ stream.reconfigure(encoding="utf-8", errors=errors)+ except (AttributeError, ValueError, OSError):+ pass # not a reconfigurable text stream (tests, embedded use)diff --git a/harvey/trainer.py b/harvey/trainer.pyindex 890a920..675d0a1 100644--- a/harvey/trainer.py+++ b/harvey/trainer.py@@ -26,6 +26,7 @@ from harvey.state import StateManagerlogger = logging.getLogger("harvey.trainer")from harvey.paths import PROJECT_ROOT+from harvey.textio import read_user_textdef _normalize_start_url(url: str) -> str:@@ -400,7 +401,7 @@ def write_trained_config(learned: dict, path: Path) -> dict:source = path if path.exists() else path.with_name("harvey.yaml")existing = Noneif source.exists():- raw = source.read_text(encoding="utf-8")+ raw = read_user_text(source)try:existing = yaml.safe_load(raw)except yaml.YAMLError:@@ -933,4 +934,6 @@ def main():if __name__ == "__main__":+ from harvey.textio import utf8_stdio+ utf8_stdio()main()diff --git a/tests/test_windows_support.py b/tests/test_windows_support.pyindex 5207072..d9c5ef1 100644--- a/tests/test_windows_support.py+++ b/tests/test_windows_support.py@@ -76,7 +76,7 @@ def _npm_install(tmp_path, with_native=True):native = shim.parent / "node_modules" / "@anthropic-ai" / "claude-code" / "bin" / "claude.exe"if with_native:native.parent.mkdir(parents=True)- native.write_bytes(b"MZ")+ native.write_bytes(b"MZ" + bytes(8190))return shim, native@@ -95,7 +95,35 @@ def test_windows_npm_shim_without_the_executable_is_refused(tmp_path, monkeypatcmonkeypatch.setattr(claude_runtime.shutil, "which", lambda *a, **k: str(shim))with pytest.raises(claude_runtime.ClaudeRuntimeError) as err:real_find_claude()- assert "claude.cmd" in str(err.value).lower() and "install" in str(err.value).lower()+ message = str(err.value)+ assert "claude.cmd" in message.lower() and "isn't there" in message+ assert "install.ps1" in message and "winget" in message+++def test_a_placeholder_exe_from_a_skipped_install_script_is_refused(tmp_path, monkeypatch):+ shim, native = _npm_install(tmp_path, with_native=False)+ native.parent.mkdir(parents=True)+ native.write_text("placeholder until install.cjs runs", encoding="utf-8")+ monkeypatch.setattr(claude_runtime, "_PLATFORM", "win32")+ monkeypatch.setattr(claude_runtime.shutil, "which", lambda *a, **k: str(shim))+ with pytest.raises(claude_runtime.ClaudeRuntimeError) as err:+ real_find_claude()+ assert "install script" in str(err.value)+++def test_the_shim_is_read_for_where_it_points(tmp_path, monkeypatch):+ # pnpm/yarn keep the package somewhere else; the shim says where.+ shim = tmp_path / "pnpm" / "claude.CMD"+ shim.parent.mkdir()+ shim.write_text('@ECHO off\r\n"%~dp0\\global\\5\\node_modules\\@anthropic-ai\\'+ 'claude-code\\bin\\claude.exe" %*\r\n', encoding="utf-8")+ native = shim.parent / "global" / "5" / "node_modules" / "@anthropic-ai" / "claude-code" \+ / "bin" / "claude.exe"+ native.parent.mkdir(parents=True)+ native.write_bytes(b"MZ" + bytes(8190))+ monkeypatch.setattr(claude_runtime, "_PLATFORM", "win32")+ monkeypatch.setattr(claude_runtime.shutil, "which", lambda *a, **k: str(shim))+ assert Path(real_find_claude()) == native@pytest.mark.parametrize("platform, found", [@@ -120,21 +148,46 @@ def test_not_installed_is_still_none(monkeypatch):def test_cli_output_never_crashes_on_a_legacy_code_page():# The dashboard runs `harvey run` with output going to a log file, which# Windows opens in cp1252: "⚠" or "→" in a message would crash print().- from harvey.cli import _utf8_stdio+ from harvey.textio import utf8_stdioraw = io.BytesIO()stream = io.TextIOWrapper(raw, encoding="cp1252")- _utf8_stdio(stream)+ utf8_stdio(stream)print("⚠ sending paused → resume", file=stream)stream.flush()assert raw.getvalue().decode("utf-8").startswith("⚠ sending paused → resume")def test_installing_the_missing_executable_changes_the_fingerprint(tmp_path, monkeypatch):- # A paused brain re-checks the CLI only when this changes.+ # The fingerprint follows the exe a shim wraps, not the shim itself.shim, native = _npm_install(tmp_path, with_native=False)monkeypatch.setattr(claude_runtime, "_PLATFORM", "win32")monkeypatch.setattr(claude_runtime.shutil, "which", lambda *a, **k: str(shim))before = claude_runtime.fingerprint()native.parent.mkdir(parents=True)- native.write_bytes(b"MZ")+ native.write_bytes(b"MZ" + bytes(8190))assert claude_runtime.fingerprint() != before+++def test_files_saved_in_the_old_windows_code_page_still_load(tmp_path, caplog):+ # Before this fix, Harvey on Windows saved trained skills as cp1252.+ from harvey.textio import read_user_text+ old = tmp_path / "product_knowledge.md"+ old.write_bytes("We\u2019re a caf\u00e9 \u2014 fast.".encode("cp1252"))+ text = read_user_text(old)+ assert "caf" in text and "fast" in text+ assert "isn't saved as UTF-8" in caplog.text+ bom = tmp_path / ".env"+ bom.write_bytes("\ufeffGMAIL_CLIENT_ID=x\n".encode("utf-8"))+ assert read_user_text(bom).startswith("GMAIL_CLIENT_ID=") # Notepad's BOM dropped+++def test_a_cp1252_config_loads(tmp_path):+ import yaml+ from harvey.config import load_config+ data = yaml.safe_load((HARVEY.parent / "harvey.yaml").read_text(encoding="utf-8"))+ data["persona"]["company"] = "Caf\u00e9 \u2014 Studio"+ config = tmp_path / "harvey.yaml"+ config.write_bytes(yaml.safe_dump(data, allow_unicode=True).encode("cp1252"))+ company = load_config(str(config)).persona.company+ # Exact under a cp1252 locale (Windows CI); readable, not a crash, elsewhere.+ assert company.startswith("Caf") and company.endswith("Studio")