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. */
| 9122 | * OS-reported identity (safe ownership evidence) from the ~/.local/bin fallback |
| 9123 | * used only as an install copy source. */ |
| 9124 | static bool cbm_detect_self_path(char *buf, size_t buf_sz, const char *home) { |
| 9125 | buf[0] = '\0'; |
| 9126 | bool exact = false; |
| 9127 | #ifdef _WIN32 |
| 9128 | /* GetModuleFileNameA renders the module path through the ANSI code page, |
| 9129 | * which mangles non-ASCII install paths (café_日本語 -> caf?_???). Resolve |
| 9130 | * wide and convert to UTF-8 so the returned path survives verbatim. */ |
| 9131 | char *module_path = cbm_module_path_utf8(); |
| 9132 | size_t length = module_path ? strlen(module_path) : 0U; |
| 9133 | exact = module_path && length > 0U && length < buf_sz; |
| 9134 | if (exact) { |
| 9135 | memcpy(buf, module_path, length + 1U); |
| 9136 | cbm_normalize_path_sep(buf); |
| 9137 | } else { |
| 9138 | buf[0] = '\0'; |
| 9139 | } |
| 9140 | free(module_path); |
| 9141 | #elif defined(__APPLE__) |
| 9142 | uint32_t sp_sz = (uint32_t)buf_sz; |
| 9143 | exact = _NSGetExecutablePath(buf, &sp_sz) == 0; |
| 9144 | if (!exact) { |
| 9145 | buf[0] = '\0'; |
| 9146 | } |
| 9147 | #else |
| 9148 | ssize_t sp_len = readlink("/proc/self/exe", buf, buf_sz - SKIP_ONE); |
| 9149 | exact = sp_len > 0 && (size_t)sp_len < buf_sz - SKIP_ONE; |
| 9150 | if (exact) { |
| 9151 | buf[sp_len] = '\0'; |
| 9152 | } else { |
| 9153 | buf[0] = '\0'; |
| 9154 | } |
| 9155 | #endif |
| 9156 | if (!buf[0]) { |
| 9157 | #ifdef _WIN32 |
| 9158 | snprintf(buf, buf_sz, "%s/.local/bin/codebase-memory-mcp.exe", home); |
| 9159 | #else |
| 9160 | snprintf(buf, buf_sz, "%s/.local/bin/codebase-memory-mcp", home); |
| 9161 | #endif |
| 9162 | } |
| 9163 | return exact; |
| 9164 | } |
| 9165 | |
| 9166 | /* Build the agent.install.plan.v1 receipt (#388): a machine-readable list of |
| 9167 | * the config / instruction / skill / agent / hook files `install` WOULD write, produced by |
no test coverage detected