| 2095 | #define CMM_SESSION_REMINDER_SCRIPT "cbm-session-reminder" |
| 2096 | |
| 2097 | static void cbm_install_session_reminder_script(const char *home) { |
| 2098 | if (!home) { |
| 2099 | return; |
| 2100 | } |
| 2101 | char config_dir[CLI_BUF_1K]; |
| 2102 | cbm_claude_config_dir(home, config_dir, sizeof(config_dir)); |
| 2103 | if (!config_dir[0]) { |
| 2104 | return; |
| 2105 | } |
| 2106 | char hooks_dir[CLI_BUF_1K]; |
| 2107 | snprintf(hooks_dir, sizeof(hooks_dir), "%s/hooks", config_dir); |
| 2108 | cbm_mkdir_p(hooks_dir, CLI_OCTAL_PERM); |
| 2109 | |
| 2110 | char script_path[CLI_BUF_1K]; |
| 2111 | snprintf(script_path, sizeof(script_path), "%s/" CMM_SESSION_REMINDER_SCRIPT, hooks_dir); |
| 2112 | |
| 2113 | FILE *f = fopen(script_path, "w"); |
| 2114 | if (!f) { |
| 2115 | return; |
| 2116 | } |
| 2117 | (void)fprintf( |
| 2118 | f, "#!/usr/bin/env bash\n" |
| 2119 | "# SessionStart hook: remind agent to use codebase-memory-mcp tools.\n" |
| 2120 | "# Installed by codebase-memory-mcp. Fires on startup/resume/clear/compact.\n" |
| 2121 | "cat << 'REMINDER'\n" |
| 2122 | "CRITICAL - Code Discovery Protocol:\n" |
| 2123 | "1. ALWAYS use codebase-memory-mcp tools FIRST for ANY code exploration:\n" |
| 2124 | " - search_graph(name_pattern/label/qn_pattern) to find functions/classes/routes\n" |
| 2125 | " - trace_path(function_name, mode=calls|data_flow|cross_service) for call chains\n" |
| 2126 | " - get_code_snippet(qualified_name) for exact symbol source (precise ranges)\n" |
| 2127 | " - query_graph(query) for complex Cypher patterns\n" |
| 2128 | " - get_architecture(aspects) for project structure\n" |
| 2129 | " - search_code(pattern) for text search (graph-augmented grep)\n" |
| 2130 | "2. Use Grep/Glob/Read freely for text, configs, non-code files, and\n" |
| 2131 | " always Read a file before editing it.\n" |
| 2132 | "3. If a project is not indexed yet, run index_repository FIRST.\n" |
| 2133 | "REMINDER\n"); |
| 2134 | #ifndef _WIN32 |
| 2135 | fchmod(fileno(f), CLI_OCTAL_PERM); |
| 2136 | #endif |
| 2137 | (void)fclose(f); |
| 2138 | #ifdef _WIN32 |
| 2139 | chmod(script_path, CLI_OCTAL_PERM); |
| 2140 | #endif |
| 2141 | } |
| 2142 | |
| 2143 | static int cbm_upsert_session_hooks(const char *settings_path) { |
| 2144 | static const char *matchers[] = {"startup", "resume", "clear", "compact"}; |
no test coverage detected