MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_upsert_session_hooks

Function cbm_upsert_session_hooks

src/cli/cli.c:5925–5974  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5923}
5924
5925static int cbm_upsert_session_hooks(const char *settings_path, const char *binary_path) {
5926 static const char *matchers[] = {"startup", "resume", "clear", "compact"};
5927 char shell_command[CLI_BUF_8K];
5928 char previous_command[CLI_BUF_8K];
5929 char released_command[CLI_BUF_8K];
5930 char previous_legacy_command[CLI_BUF_8K];
5931 char released_legacy_command[CLI_BUF_8K];
5932 if (cbm_resolve_hook_command(CMM_SESSION_REMINDER_SCRIPT, shell_command,
5933 sizeof(shell_command)) != CLI_OK ||
5934 cbm_resolve_previous_hook_command(CMM_SESSION_REMINDER_SCRIPT, previous_command,
5935 sizeof(previous_command)) != CLI_OK ||
5936 cbm_resolve_released_hook_command(CMM_SESSION_REMINDER_SCRIPT, released_command,
5937 sizeof(released_command)) != CLI_OK ||
5938 cbm_resolve_previous_hook_command(CMM_SESSION_REMINDER_SCRIPT_LEGACY,
5939 previous_legacy_command,
5940 sizeof(previous_legacy_command)) != CLI_OK ||
5941 cbm_resolve_released_hook_command(CMM_SESSION_REMINDER_SCRIPT_LEGACY,
5942 released_legacy_command,
5943 sizeof(released_legacy_command)) != CLI_OK) {
5944 return CLI_ERR;
5945 }
5946 const char *command = binary_path && binary_path[0] ? binary_path : shell_command;
5947 const char *const *command_args = binary_path && binary_path[0] ? cmm_claude_exec_args : NULL;
5948 size_t command_arg_count = binary_path && binary_path[0]
5949 ? sizeof(cmm_claude_exec_args) / sizeof(cmm_claude_exec_args[0])
5950 : 0U;
5951 const char *const old_commands[] = {shell_command, released_command,
5952 previous_command, released_legacy_command,
5953 previous_legacy_command, NULL};
5954 int rc = 0;
5955 for (int i = 0; i < NUM_DIRS; i++) {
5956 if (cbm_remove_previous_claude_exec_hook(settings_path, "SessionStart", matchers[i], NULL,
5957 binary_path) != CLI_OK) {
5958 rc = CLI_ERR;
5959 continue;
5960 }
5961 if (upsert_hooks_json((hooks_upsert_args_t){.settings_path = settings_path,
5962 .hook_event = "SessionStart",
5963 .matcher_str = matchers[i],
5964 .command_str = command,
5965 .command_args = command_args,
5966 .command_arg_count = command_arg_count,
5967 .old_commands = old_commands,
5968 .timeout_value = CMM_HOOK_TIMEOUT_SEC,
5969 .match_command_exact = command}) != 0) {
5970 rc = CLI_ERR;
5971 }
5972 }
5973 return rc;
5974}
5975
5976static int cbm_remove_session_hooks(const char *settings_path, const char *binary_path) {
5977 static const char *matchers[] = {"startup", "resume", "clear", "compact"};

Callers 1

Tested by

no test coverage detected