The activation flow (self-path detection, simple-copy activate) is the same * on every platform: Windows ships ONE binary, exactly like Linux and macOS. */ Detect the running binary's path at runtime. The return value distinguishes * OS-reported identity (safe ownership evidence) from the ~/.local/bin fallback * used only as an install copy source. */
| 9078 | * OS-reported identity (safe ownership evidence) from the ~/.local/bin fallback |
| 9079 | * used only as an install copy source. */ |
| 9080 | static bool cbm_detect_self_path(char *buf, size_t buf_sz, const char *home) { |
| 9081 | buf[0] = '\0'; |
| 9082 | bool exact = false; |
| 9083 | #ifdef _WIN32 |
| 9084 | /* GetModuleFileNameA renders the module path through the ANSI code page, |
| 9085 | * which mangles non-ASCII install paths (café_日本語 -> caf?_???). Resolve |
| 9086 | * wide and convert to UTF-8 so the returned path survives verbatim. */ |
| 9087 | char *module_path = cbm_module_path_utf8(); |
| 9088 | size_t length = module_path ? strlen(module_path) : 0U; |
| 9089 | exact = module_path && length > 0U && length < buf_sz; |
| 9090 | if (exact) { |
| 9091 | memcpy(buf, module_path, length + 1U); |
| 9092 | cbm_normalize_path_sep(buf); |
| 9093 | } else { |
| 9094 | buf[0] = '\0'; |
| 9095 | } |
| 9096 | free(module_path); |
| 9097 | #elif defined(__APPLE__) |
| 9098 | uint32_t sp_sz = (uint32_t)buf_sz; |
| 9099 | exact = _NSGetExecutablePath(buf, &sp_sz) == 0; |
| 9100 | if (!exact) { |
| 9101 | buf[0] = '\0'; |
| 9102 | } |
| 9103 | #else |
| 9104 | ssize_t sp_len = readlink("/proc/self/exe", buf, buf_sz - SKIP_ONE); |
| 9105 | exact = sp_len > 0 && (size_t)sp_len < buf_sz - SKIP_ONE; |
| 9106 | if (exact) { |
| 9107 | buf[sp_len] = '\0'; |
| 9108 | } else { |
| 9109 | buf[0] = '\0'; |
| 9110 | } |
| 9111 | #endif |
| 9112 | if (!buf[0]) { |
| 9113 | #ifdef _WIN32 |
| 9114 | snprintf(buf, buf_sz, "%s/.local/bin/codebase-memory-mcp.exe", home); |
| 9115 | #else |
| 9116 | snprintf(buf, buf_sz, "%s/.local/bin/codebase-memory-mcp", home); |
| 9117 | #endif |
| 9118 | } |
| 9119 | return exact; |
| 9120 | } |
| 9121 | |
| 9122 | /* Build the agent.install.plan.v1 receipt (#388): a machine-readable list of |
| 9123 | * the config / instruction / skill / agent / hook files `install` WOULD write, produced by |
no test coverage detected