MCPcopy Create free account
hub / github.com/Eversmile12/sharedcontext / updateCodexConfig

Function updateCodexConfig

src/cli/setup.ts:171–194  ·  view source on GitHub ↗
(configPath: string)

Source from the content-addressed store, hash-verified

169}
170
171function updateCodexConfig(configPath: string): void {
172 const command = process.execPath;
173 const args = [fileURLToPath(new URL("../index.js", import.meta.url)), "serve"];
174
175 const sharedcontextSection = [
176 "[mcp_servers.sharedcontext]",
177 `command = ${toTomlString(command)}`,
178 `args = [${args.map((arg) => toTomlString(arg)).join(", ")}]`,
179 ].join("\n");
180
181 mkdirSync(dirname(configPath), { recursive: true });
182
183 const existing = existsSync(configPath) ? readFileSync(configPath, "utf-8") : "";
184 const normalized = existing.replace(/\r\n/g, "\n").trimEnd();
185 const sectionRegex = /^\[mcp_servers\.sharedcontext\]\n[\s\S]*?(?=^\[[^\]]+\]\n?|$)/m;
186
187 const nextContent = sectionRegex.test(normalized)
188 ? normalized.replace(sectionRegex, sharedcontextSection)
189 : normalized === ""
190 ? sharedcontextSection
191 : `${normalized}\n\n${sharedcontextSection}`;
192
193 writeFileSync(configPath, `${nextContent}\n`, "utf-8");
194}
195
196function toTomlString(value: string): string {
197 const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');

Callers 1

setupTargetFunction · 0.85

Calls 1

toTomlStringFunction · 0.85

Tested by

no test coverage detected