fix(setup): keep comments around REA's table in Grok Build TOML (#6261)
The shared TOML server-table editor kept comment lines immediately only for the Codex dialect. For Grok Build it queued them with blank lines, then discarded the queue when an REA table header followed or while it skipped REA's table, so a comment introducing the stale REA table and a trailing file note after it were lost on setup and uninstall. Every comment line is now kept in place for both TOML dialects; only blank lines that separated a removed REA table go with it. The Codex wrapper's terminal line-break restoration moves into the shared editor, so removing a final REA table keeps the file's last line break for Grok Build too. Fixes #6207 Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
1639189f26
commit
86357bad54
3 files changed
+193
-13
No files matched your search
@@ -978,10 +978,11 @@ const withoutTrailingLineFeeds = (text: string): string => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Replace REA's TOML server tables and assignments. Comments that introduce a
|
||||
* following table stay. Codex also retains comments around REA's own table.
|
||||
* Text inside strings is not treated as a header. Only Grok Build reads the
|
||||
* root `disabled_mcp_servers` list that registration also edits.
|
||||
* Replace REA's TOML server tables and assignments. Every comment line stays
|
||||
* where it was, including comments before, inside, and after REA's own table;
|
||||
* only blank lines that separated a removed table go with it. Text inside
|
||||
* strings is not treated as a header. Only Grok Build reads the root
|
||||
* `disabled_mcp_servers` list that registration also edits.
|
||||
*/
|
||||
const upsertTomlServerSection = (
|
||||
originalText: string,
|
||||
@@ -1005,6 +1006,8 @@ const upsertTomlServerSection = (
|
||||
cursor += line.length + 1;
|
||||
}
|
||||
const kept: string[] = [];
|
||||
// Blank lines held until the next statement shows whether they belong to a
|
||||
// removed REA table. Comments are user text and are never held.
|
||||
const pending: string[] = [];
|
||||
let skipping = false;
|
||||
let inlineServerTable = false;
|
||||
@@ -1128,7 +1131,7 @@ const upsertTomlServerSection = (
|
||||
continue;
|
||||
}
|
||||
if (isBlankOrComment(line)) {
|
||||
if (format === "toml" && line.trimStart().startsWith("#")) {
|
||||
if (line.trimStart().startsWith("#")) {
|
||||
flushPending();
|
||||
kept.push(physical);
|
||||
} else pending.push(physical);
|
||||
@@ -1168,6 +1171,9 @@ const upsertTomlServerSection = (
|
||||
? `${fragment}${nl}`
|
||||
: `${trimmed}${nl}${nl}${fragment}${nl}`;
|
||||
}
|
||||
// Removing a final table also drops the file's last line break.
|
||||
if (originalText.endsWith("\n") && !body.endsWith("\n"))
|
||||
body += originalText.endsWith("\r\n") ? "\r\n" : "\n";
|
||||
return bom ? `\uFEFF${body}` : body;
|
||||
};
|
||||
|
||||
@@ -1270,17 +1276,12 @@ const serializeCodexConfiguration = (
|
||||
isEmptyClientConfigurationText(originalText)
|
||||
)
|
||||
return stringifyToml(document);
|
||||
const upserted = upsertTomlServerSection(
|
||||
const edited = upsertTomlServerSection(
|
||||
originalText,
|
||||
PRODUCT_IDENTITY.mcpServerKey,
|
||||
tomlServerEntry(document, PRODUCT_IDENTITY.mcpServerKey),
|
||||
"toml",
|
||||
);
|
||||
// Removing a final table also drops the file's last line break.
|
||||
const edited =
|
||||
originalText.endsWith("\n") && !upserted.endsWith("\n")
|
||||
? `${upserted}${originalText.endsWith("\r\n") ? "\r\n" : "\n"}`
|
||||
: upserted;
|
||||
return tomlTextHolds(edited, document) ? edited : stringifyToml(document);
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user