Skip to content

Commit 98e58ac

Browse files
committed
fix(install): keep foreign tables between the managed TOML markers (DeusData#2228)
cbm_toml_upsert_managed_block and cbm_toml_remove_managed_block treated everything between the "# >>> codebase-memory-mcp MCP >>>" markers as ours: install replaced the whole span with the fresh block, uninstall deleted it, and the conflict check skipped that same span. When our block ended ~/.codex/config.toml, Codex Desktop appended its own tables below it while the closing marker stayed the last line, so [mcp_servers.node_repl], [desktop] and the [marketplaces.*] tables sat inside the markers. The 0.10.4 -> 0.11.0 upgrade deleted all of them, together with the startup_timeout_sec the user had added to our own table. The span is now read as TOML sections, each classified against the tables the block declares: - owned: a declared table (the k-th [[element]] of a declared array). The keys the block writes are replaced; every other key, comment and blank line in it stays in the table. - attached: a sub-table of a declared table, such as [mcp_servers.codebase-memory-mcp.env]. It is part of our server entry and stays with it; outside the markers it would collide with the next install. - foreign: any other table, moved byte for byte and in order to just after the closing marker, so from then on the markers bracket only our entry and later appends land outside them. - lead: lines above the span's first table, moved above the opening marker, where they keep the table they belong to. Uninstall of the Codex, Grok and Kimi blocks goes through the new cbm_toml_remove_managed_block_owned with the header each block declares: it removes our table with its keys and sub-tables and leaves everything else in place. cbm_toml_remove_managed_block keeps the historical whole-span contract. Content whose ownership cannot be decided fails closed with the file untouched: a second copy of a declared table, an undeclared extra [[element]] of a declared array, a child of a declared array element, an unparsable line in an owned table, a user key colliding with one the block writes, a move that would hand the keys below the block to another table, and a rewritten file whose tables conflict with the block. Preserving was chosen over failing closed on every foreign table because Codex keeps appending below a closing marker that ends the file. A refusing installer would block every later install and uninstall until the user hand-edits the TOML, and a hand edit is itself the likeliest way to lose those tables. Moving whole sections keeps every byte and every key's table, and the shapes that cannot be attributed still refuse. Without foreign content the output is byte-identical to the old rewrite. Fixes DeusData#2228 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 9d65f4c commit 98e58ac

5 files changed

Lines changed: 751 additions & 26 deletions

File tree

‎src/cli/cli.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,8 +3793,11 @@ int cbm_upsert_codex_mcp(const char *binary_path, const char *config_path) {
37933793
}
37943794

37953795
int cbm_remove_codex_mcp(const char *config_path) {
3796+
/* #2228: only our table goes; foreign tables found between the markers
3797+
* (Codex Desktop appends below a block that ends the file) stay. */
37963798
if (!config_path ||
3797-
cbm_toml_remove_managed_block(config_path, CODEX_MCP_BEGIN, CODEX_MCP_END) != 0) {
3799+
cbm_toml_remove_managed_block_owned(config_path, CODEX_MCP_BEGIN, CODEX_MCP_END,
3800+
CODEX_CMM_SECTION "\n") != 0) {
37983801
return CLI_ERR;
37993802
}
38003803
return cbm_remove_codex_legacy_mcp(config_path) >= 0 ? CLI_OK : CLI_ERR;
@@ -4418,7 +4421,8 @@ static int cbm_upsert_grok_mcp(const char *binary_path, const char *config_path)
44184421
static int cbm_remove_grok_mcp_owned(const char *binary_path, const char *config_path) {
44194422
(void)binary_path;
44204423
if (!config_path ||
4421-
cbm_toml_remove_managed_block(config_path, GROK_MCP_BEGIN, GROK_MCP_END) != 0) {
4424+
cbm_toml_remove_managed_block_owned(config_path, GROK_MCP_BEGIN, GROK_MCP_END,
4425+
GROK_CMM_SECTION "\n") != 0) {
44224426
return CLI_ERR;
44234427
}
44244428
return cbm_remove_grok_legacy_mcp(config_path) >= 0 ? CLI_OK : CLI_ERR;
@@ -4984,7 +4988,8 @@ static int cbm_upsert_kimi_context_hook(const char *config_path, const char *bin
49844988
}
49854989

49864990
static int cbm_remove_kimi_context_hook(const char *config_path) {
4987-
return cbm_toml_remove_managed_block(config_path, KIMI_HOOK_BEGIN, KIMI_HOOK_END) == 0
4991+
return cbm_toml_remove_managed_block_owned(config_path, KIMI_HOOK_BEGIN, KIMI_HOOK_END,
4992+
"[[hooks]]\n") == 0
49884993
? CLI_OK
49894994
: CLI_ERR;
49904995
}

0 commit comments

Comments
 (0)