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

Function cbm_upsert_session_hooks

src/cli/cli.c:5793–5842  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5791}
5792
5793static int cbm_upsert_session_hooks(const char *settings_path, const char *binary_path) {
5794 static const char *matchers[] = {"startup", "resume", "clear", "compact"};
5795 char shell_command[CLI_BUF_8K];
5796 char previous_command[CLI_BUF_8K];
5797 char released_command[CLI_BUF_8K];
5798 char previous_legacy_command[CLI_BUF_8K];
5799 char released_legacy_command[CLI_BUF_8K];
5800 if (cbm_resolve_hook_command(CMM_SESSION_REMINDER_SCRIPT, shell_command,
5801 sizeof(shell_command)) != CLI_OK ||
5802 cbm_resolve_previous_hook_command(CMM_SESSION_REMINDER_SCRIPT, previous_command,
5803 sizeof(previous_command)) != CLI_OK ||
5804 cbm_resolve_released_hook_command(CMM_SESSION_REMINDER_SCRIPT, released_command,
5805 sizeof(released_command)) != CLI_OK ||
5806 cbm_resolve_previous_hook_command(CMM_SESSION_REMINDER_SCRIPT_LEGACY,
5807 previous_legacy_command,
5808 sizeof(previous_legacy_command)) != CLI_OK ||
5809 cbm_resolve_released_hook_command(CMM_SESSION_REMINDER_SCRIPT_LEGACY,
5810 released_legacy_command,
5811 sizeof(released_legacy_command)) != CLI_OK) {
5812 return CLI_ERR;
5813 }
5814 const char *command = binary_path && binary_path[0] ? binary_path : shell_command;
5815 const char *const *command_args = binary_path && binary_path[0] ? cmm_claude_exec_args : NULL;
5816 size_t command_arg_count = binary_path && binary_path[0]
5817 ? sizeof(cmm_claude_exec_args) / sizeof(cmm_claude_exec_args[0])
5818 : 0U;
5819 const char *const old_commands[] = {shell_command, released_command,
5820 previous_command, released_legacy_command,
5821 previous_legacy_command, NULL};
5822 int rc = 0;
5823 for (int i = 0; i < NUM_DIRS; i++) {
5824 if (cbm_remove_previous_claude_exec_hook(settings_path, "SessionStart", matchers[i], NULL,
5825 binary_path) != CLI_OK) {
5826 rc = CLI_ERR;
5827 continue;
5828 }
5829 if (upsert_hooks_json((hooks_upsert_args_t){.settings_path = settings_path,
5830 .hook_event = "SessionStart",
5831 .matcher_str = matchers[i],
5832 .command_str = command,
5833 .command_args = command_args,
5834 .command_arg_count = command_arg_count,
5835 .old_commands = old_commands,
5836 .timeout_value = CMM_HOOK_TIMEOUT_SEC,
5837 .match_command_exact = command}) != 0) {
5838 rc = CLI_ERR;
5839 }
5840 }
5841 return rc;
5842}
5843
5844static int cbm_remove_session_hooks(const char *settings_path, const char *binary_path) {
5845 static const char *matchers[] = {"startup", "resume", "clear", "compact"};

Callers 1

Tested by

no test coverage detected