diff --git a/app/Roster/Data/ProviderInstallers.swift b/app/Roster/Data/ProviderInstallers.swift index 68fd493..0770a44 100644 --- a/app/Roster/Data/ProviderInstallers.swift +++ b/app/Roster/Data/ProviderInstallers.swift @@ -324,6 +324,27 @@ enum CodexInstaller { } } + /// Places `block` as a document-root TOML entry. A bare key written after a + /// `[table]` header belongs to that table, so appending at end-of-file would + /// scope our `notify` into the file's last table (commonly an + /// `[mcp_servers.*]` block) and Codex would never see it. The block is + /// inserted just above the first table header instead; a file with no tables + /// (or an empty file) simply gets the block appended. + static func insertingAtRoot(_ block: String, into text: String) -> String { + if text.isEmpty { return block + "\n" } + let lines = text.components(separatedBy: "\n") + guard let idx = lines.firstIndex(where: { + $0.trimmingCharacters(in: .whitespaces).hasPrefix("[") + }) else { + return text + "\n\n" + block + "\n" + } + var head = Array(lines[..