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

Function codex_hook_strip

src/cli/cli.c:1599–1627  ·  view source on GitHub ↗

Splice out an existing [CODEX_HOOK_BEGIN .. CODEX_HOOK_END] block (inclusive, * plus a leading newline). Returns a newly-malloc'd string the caller frees, or * NULL if no block was present (content is left untouched). */

Source from the content-addressed store, hash-verified

1597 * plus a leading newline). Returns a newly-malloc'd string the caller frees, or
1598 * NULL if no block was present (content is left untouched). */
1599static char *codex_hook_strip(const char *content) {
1600 const char *begin = strstr(content, CODEX_HOOK_BEGIN);
1601 if (!begin) {
1602 return NULL;
1603 }
1604 const char *end = strstr(begin, CODEX_HOOK_END);
1605 if (!end) {
1606 return NULL;
1607 }
1608 end += strlen(CODEX_HOOK_END);
1609 if (*end == '\n') {
1610 end++;
1611 }
1612 /* Drop one leading newline before the block, if any. */
1613 const char *cut = begin;
1614 if (cut > content && *(cut - CLI_SKIP_ONE) == '\n') {
1615 cut--;
1616 }
1617 size_t prefix_len = (size_t)(cut - content);
1618 size_t suffix_len = strlen(end);
1619 char *out = malloc(prefix_len + suffix_len + CLI_SKIP_ONE);
1620 if (!out) {
1621 return NULL;
1622 }
1623 memcpy(out, content, prefix_len);
1624 memcpy(out + prefix_len, end, suffix_len);
1625 out[prefix_len + suffix_len] = '\0';
1626 return out;
1627}
1628
1629/* Install/update the Codex SessionStart reminder hook in config.toml. */
1630int cbm_upsert_codex_hooks(const char *config_path) {

Callers 2

cbm_upsert_codex_hooksFunction · 0.85
cbm_remove_codex_hooksFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected