Skip to content

Commit 2b329fe

Browse files
committed
fix(cli): client detection for OpenCode, Hermes, Claude (DeusData#1167, DeusData#1180)
Three detection defects kept `codebase-memory-mcp install` from configuring agents people run, and made it configure one they never installed. OpenCode without a config file or a CLI on PATH (DeusData#1167, DeusData#1180). OpenCode was detected only from its global config file or directory, OPENCODE_CONFIG_DIR, or an `opencode` found on PATH. It now also counts as installed when its data directory exists: ~/.local/share/opencode on every OS, %USERPROFILE%\.local\share\opencode on Windows (opencode.ai/docs/troubleshooting, "Storage"; the same page names it as the global config location of older installs). The OpenCode CLI and the Desktop app both create it -- the Desktop's bundled opencode-cli server uses the same XDG paths (anomalyco/opencode packages/core/src/global.ts creates the config and data dirs at startup; packages/desktop/src/main/sidecar.ts only redirects XDG_STATE_HOME) -- so detection no longer depends on PATH. The install target ~/.config/opencode/opencode.json(c) -- %USERPROFILE%\.config\opencode on Windows per the same docs page -- is unchanged and right for CLI and Desktop alike. A PATH longer than 4 KB, which hides every CLI from find_in_path(), is handled separately by PR DeusData#2381. Hermes home on Windows (DeusData#1180). Native Windows Hermes -- the install.ps1 CLI, the MSIX package and the Desktop app -- defaults HERMES_HOME to %LOCALAPPDATA%\hermes and falls back to a legacy ~/.hermes only while that directory is absent (NousResearch/hermes-agent website/docs/user-guide/windows-native.md, "Data layout"; apps/desktop/electron/data-paths.mjs, resolveDesktopHermesHome). cbm probed and wrote ~/.hermes only, so a Desktop install was never detected and a Hermes found on PATH got its config.yaml and skill in a home it never reads. On Windows the home now resolves to <home>/AppData/Local/hermes unless only ~/.hermes exists, using the home-derived AppData convention of the existing Zed, goose, Kilo and VS Code probes; detection, install and uninstall all follow it. HERMES_HOME still wins, and macOS/Linux keep ~/.hermes. Claude Code from a bare ~/.claude (DeusData#1180). Any ~/.claude directory counted as a Claude Code install, so a user who only had the folder got hooks, skills and MCP entries for a client they never installed. Detection now needs what Claude Code itself leaves behind: settings.json in the config dir, .claude.json in the home (in CLAUDE_CONFIG_DIR when set), or the claude CLI. Proof on macOS against synthetic HOME/cache/runtime dirs with a minimal PATH (`install --dry-run --skip-binary`, then a config-only install): bare ~/.claude main: Claude-Code fix: none ~/.local/share/opencode only main: none fix: OpenCode In the OpenCode case the fixed install writes the codebase-memory-mcp entry to ~/.config/opencode/opencode.json; main writes nothing. Controls (a launched Desktop layout, a real Claude user) are detected by both. The Windows Hermes home is covered by a platform-parameterised resolver test that runs on every host plus a _WIN32-bound end-to-end detection and plan test. Tests (cli suite, 335 passed): seven new tests; five fail on main three times out of three (the _WIN32-bound Hermes test and the look-alike control are green on macOS by design). Reverting the Claude+Hermes half and the OpenCode data-dir probe separately turns exactly their own tests red. Nine existing Claude fixtures that used a bare ~/.claude as the install marker now write .claude.json; two Hermes tests and smoke-test 8x expect %LOCALAPPDATA%\hermes on Windows. Refs DeusData#1167 Fixes DeusData#1180 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 9d65f4c commit 2b329fe

4 files changed

Lines changed: 389 additions & 25 deletions

File tree

‎scripts/smoke-test.sh‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,19 +2126,25 @@ sys.exit(0 if ok else 1)
21262126
fi
21272127
echo "OK 8w-ii: Kiro MCP + steering + isolated exact-tool graph agent"
21282128

2129-
# 8x: Hermes Agent YAML MCP mapping
2129+
# 8x: Hermes Agent YAML MCP mapping. Native Windows Hermes keeps its home in
2130+
# %LOCALAPPDATA%\hermes (#1180); the stub-only FAKE_HOME has no legacy ~/.hermes.
2131+
if [[ "$BINARY" == *.exe ]]; then
2132+
HERMES_HOME_DIR="$FAKE_HOME/AppData/Local/hermes"
2133+
else
2134+
HERMES_HOME_DIR="$FAKE_HOME/.hermes"
2135+
fi
21302136
HERMES_CMD=$(sed -n '/^ codebase-memory-mcp:/{n;s/^ *command: *//p;}' \
2131-
"$FAKE_HOME/.hermes/config.yaml" 2>/dev/null | head -1)
2132-
if ! grep -q '^mcp_servers:' "$FAKE_HOME/.hermes/config.yaml" 2>/dev/null ||
2133-
! grep -q '^ codebase-memory-mcp:' "$FAKE_HOME/.hermes/config.yaml" 2>/dev/null ||
2137+
"$HERMES_HOME_DIR/config.yaml" 2>/dev/null | head -1)
2138+
if ! grep -q '^mcp_servers:' "$HERMES_HOME_DIR/config.yaml" 2>/dev/null ||
2139+
! grep -q '^ codebase-memory-mcp:' "$HERMES_HOME_DIR/config.yaml" 2>/dev/null ||
21342140
! quoted_path_value_matches "$HERMES_CMD" "$SELF_PATH"; then
21352141
echo "FAIL 8x: Hermes MCP mapping missing or malformed"
21362142
exit 1
21372143
fi
21382144
echo "OK 8x: Hermes Agent MCP"
2139-
if ! grep -q '^name: codebase-memory$' "$FAKE_HOME/.hermes/skills/codebase-memory/SKILL.md" 2>/dev/null ||
2140-
! grep -q 'delegate_task' "$FAKE_HOME/.hermes/skills/codebase-memory/SKILL.md" 2>/dev/null ||
2141-
! grep -q '`context`' "$FAKE_HOME/.hermes/skills/codebase-memory/SKILL.md" 2>/dev/null; then
2145+
if ! grep -q '^name: codebase-memory$' "$HERMES_HOME_DIR/skills/codebase-memory/SKILL.md" 2>/dev/null ||
2146+
! grep -q 'delegate_task' "$HERMES_HOME_DIR/skills/codebase-memory/SKILL.md" 2>/dev/null ||
2147+
! grep -q '`context`' "$HERMES_HOME_DIR/skills/codebase-memory/SKILL.md" 2>/dev/null; then
21422148
echo "FAIL 8x-i: Hermes delegation skill missing"
21432149
exit 1
21442150
fi

‎src/cli/cli.c‎

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,10 +2726,41 @@ static void cbm_kiro_home_dir(const char *home_dir, char *out, size_t out_sz) {
27262726
cbm_env_home_dir("KIRO_HOME", home_dir, ".kiro", out, out_sz);
27272727
}
27282728

2729+
/* #1180: native Windows Hermes -- the install.ps1 CLI, the MSIX package and
2730+
* the Desktop app -- defaults HERMES_HOME to %LOCALAPPDATA%\hermes and keeps a
2731+
* legacy ~/.hermes only while the new directory is absent (hermes-agent
2732+
* website/docs/user-guide/windows-native.md "Data layout";
2733+
* apps/desktop/electron/data-paths.mjs resolveDesktopHermesHome). Probing
2734+
* only ~/.hermes missed those installs and aimed config.yaml at a home Hermes
2735+
* never reads. Other platforms use ~/.hermes. */
2736+
static void cbm_hermes_home_dir_for(const char *home_dir, bool windows, char *out, size_t out_sz) {
2737+
const char *fallback = ".hermes";
2738+
if (windows) {
2739+
char native[CLI_BUF_1K];
2740+
char legacy[CLI_BUF_1K];
2741+
snprintf(native, sizeof(native), "%s/AppData/Local/hermes", home_dir);
2742+
snprintf(legacy, sizeof(legacy), "%s/.hermes", home_dir);
2743+
if (dir_exists(native) || !dir_exists(legacy)) {
2744+
fallback = "AppData/Local/hermes";
2745+
}
2746+
}
2747+
cbm_env_home_dir("HERMES_HOME", home_dir, fallback, out, out_sz);
2748+
}
2749+
27292750
static void cbm_hermes_home_dir(const char *home_dir, char *out, size_t out_sz) {
2730-
cbm_env_home_dir("HERMES_HOME", home_dir, ".hermes", out, out_sz);
2751+
#ifdef _WIN32
2752+
cbm_hermes_home_dir_for(home_dir, true, out, out_sz);
2753+
#else
2754+
cbm_hermes_home_dir_for(home_dir, false, out, out_sz);
2755+
#endif
27312756
}
27322757

2758+
#ifdef CBM_CLI_ENABLE_TEST_API
2759+
void cbm_hermes_home_dir_for_testing(const char *home_dir, bool windows, char *out, size_t out_sz) {
2760+
cbm_hermes_home_dir_for(home_dir, windows, out, out_sz);
2761+
}
2762+
#endif
2763+
27332764
static void cbm_qwen_home_dir(const char *home_dir, char *out, size_t out_sz) {
27342765
cbm_env_home_dir("QWEN_HOME", home_dir, ".qwen", out, out_sz);
27352766
}
@@ -3031,6 +3062,53 @@ static int cbm_resolve_released_hook_command(const char *script_name, char *out,
30313062
return written > 0 && (size_t)written < out_sz ? CLI_OK : CLI_ERR;
30323063
}
30333064

3065+
/* #1180: a bare ~/.claude directory is not a Claude Code install -- other
3066+
* tools create it -- and treating it as one wrote hooks, skills and MCP
3067+
* entries for a client the user never installed. Claude Code itself leaves
3068+
* its user config .claude.json (under CLAUDE_CONFIG_DIR when set), its
3069+
* settings.json, or the claude CLI. */
3070+
static bool cbm_claude_code_detected(const char *home_dir) {
3071+
char dir[CLI_BUF_1K];
3072+
char path[CLI_BUF_1K];
3073+
cbm_claude_config_dir(home_dir, dir, sizeof(dir));
3074+
int written = snprintf(path, sizeof(path), "%s/settings.json", dir);
3075+
if (dir[0] && written > 0 && (size_t)written < sizeof(path) && cbm_file_exists(path)) {
3076+
return true;
3077+
}
3078+
cbm_claude_user_root(home_dir, dir, sizeof(dir));
3079+
written = snprintf(path, sizeof(path), "%s/.claude.json", dir);
3080+
if (dir[0] && written > 0 && (size_t)written < sizeof(path) && cbm_file_exists(path)) {
3081+
return true;
3082+
}
3083+
return cbm_agent_cli_exists("claude", home_dir);
3084+
}
3085+
3086+
/* OpenCode keeps its data (auth, logs, sessions; the global config itself on
3087+
* older installs) in ~/.local/share/opencode on every OS --
3088+
* %USERPROFILE%\.local\share\opencode on Windows (opencode.ai/docs/
3089+
* troubleshooting, "Storage"). The CLI and the Desktop app's bundled
3090+
* opencode-cli server both create it, so it identifies an install that has
3091+
* no config file, no ~/.config/opencode and no `opencode` on PATH
3092+
* (#1167, #1180). */
3093+
static bool cbm_opencode_detected(const char *home_dir) {
3094+
char path[CLI_BUF_1K];
3095+
cbm_opencode_config_path(home_dir, path, sizeof(path));
3096+
if (cbm_file_exists(path) || cbm_agent_cli_exists("opencode", home_dir)) {
3097+
return true;
3098+
}
3099+
snprintf(path, sizeof(path), "%s/.config/opencode", home_dir);
3100+
if (dir_exists(path)) {
3101+
return true;
3102+
}
3103+
char env_buf[CLI_BUF_1K];
3104+
const char *config_dir = cbm_safe_getenv("OPENCODE_CONFIG_DIR", env_buf, sizeof(env_buf), NULL);
3105+
if (config_dir && config_dir[0] && dir_exists(config_dir)) {
3106+
return true;
3107+
}
3108+
snprintf(path, sizeof(path), "%s/.local/share/opencode", home_dir);
3109+
return dir_exists(path);
3110+
}
3111+
30343112
cbm_detected_agents_t cbm_detect_agents(const char *home_dir) {
30353113
cbm_detected_agents_t agents;
30363114
memset(&agents, 0, sizeof(agents));
@@ -3040,8 +3118,7 @@ cbm_detected_agents_t cbm_detect_agents(const char *home_dir) {
30403118

30413119
char path[CLI_BUF_1K];
30423120

3043-
cbm_claude_config_dir(home_dir, path, sizeof(path));
3044-
agents.claude_code = path[0] != '\0' && dir_exists(path);
3121+
agents.claude_code = cbm_claude_code_detected(home_dir);
30453122

30463123
cbm_codex_config_dir(home_dir, path, sizeof(path));
30473124
agents.codex = path[0] != '\0' && dir_exists(path);
@@ -3055,18 +3132,7 @@ cbm_detected_agents_t cbm_detect_agents(const char *home_dir) {
30553132
cbm_zed_config_dir(home_dir, path, sizeof(path));
30563133
agents.zed = dir_exists(path);
30573134

3058-
cbm_opencode_config_path(home_dir, path, sizeof(path));
3059-
agents.opencode = cbm_file_exists(path) || cbm_agent_cli_exists("opencode", home_dir);
3060-
if (!agents.opencode) {
3061-
snprintf(path, sizeof(path), "%s/.config/opencode", home_dir);
3062-
agents.opencode = dir_exists(path);
3063-
}
3064-
if (!agents.opencode) {
3065-
char env_buf[CLI_BUF_1K];
3066-
const char *config_dir =
3067-
cbm_safe_getenv("OPENCODE_CONFIG_DIR", env_buf, sizeof(env_buf), NULL);
3068-
agents.opencode = config_dir && config_dir[0] && dir_exists(config_dir);
3069-
}
3135+
agents.opencode = cbm_opencode_detected(home_dir);
30703136

30713137
agents.aider = cbm_agent_cli_exists("aider", home_dir);
30723138

‎src/cli/cli.h‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ int cbm_remove_zed_mcp_owned(const char *binary_path, const char *config_path);
182182

183183
/* Detected coding agents on the system. */
184184
typedef struct {
185-
bool claude_code; /* ~/.claude/ exists */
185+
bool claude_code; /* settings.json, .claude.json, or claude CLI exists */
186186
bool codex; /* $CODEX_HOME or ~/.codex exists */
187187
bool gemini; /* Gemini settings or executable exists */
188188
bool zed; /* platform-specific Zed config dir exists */
189-
bool opencode; /* opencode on PATH or config exists */
189+
bool opencode; /* opencode on PATH, config, or data dir exists */
190190
bool antigravity; /* Antigravity CLI config or executable exists */
191191
bool aider; /* aider on PATH */
192192
bool kilocode; /* KiloCode globalStorage dir exists */
@@ -197,7 +197,7 @@ typedef struct {
197197
bool openclaw; /* ~/.openclaw/ exists */
198198
bool kiro; /* ~/.kiro/ exists */
199199
bool junie; /* ~/.junie/ exists */
200-
bool hermes; /* ~/.hermes/ or hermes CLI exists */
200+
bool hermes; /* Hermes home (Windows: %LOCALAPPDATA%\hermes) or CLI */
201201
bool openhands; /* ~/.openhands/ or openhands CLI exists */
202202
bool cline; /* ~/.cline/ or cline CLI exists */
203203
bool warp; /* Warp footprint or oz/oz-preview/warp-cli exists */
@@ -217,6 +217,13 @@ cbm_detected_agents_t cbm_detect_agents(const char *home_dir);
217217
/* Install or refresh every detected agent integration below home. */
218218
int cbm_install_agent_configs(const char *home, const char *binary_path, bool force, bool dry_run);
219219

220+
#ifdef CBM_CLI_ENABLE_TEST_API
221+
/* #1180: the Hermes home as resolved on Windows (`windows`) or elsewhere, so
222+
* the %LOCALAPPDATA%\hermes default and its legacy ~/.hermes fallback are
223+
* exercised on every host. */
224+
void cbm_hermes_home_dir_for_testing(const char *home_dir, bool windows, char *out, size_t out_sz);
225+
#endif
226+
220227
#ifdef CBM_CLI_ENABLE_TEST_API
221228
/* #1558: client-selector vocabulary, exposed so a test can prove every token
222229
* resolves and an unknown one is rejected. */

0 commit comments

Comments
 (0)