Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(init): keep a Codex pullboard server in any TOML form [A9,I1]

Corey Olsondbe895639bd3
diff --git a/src/init.js b/src/init.js
index 6bdfb9ba..f4c790c4 100644
--- a/src/init.js
+++ b/src/init.js
@@ -424,6 +424,75 @@ export const RESUME_HOOK =
export const MCP_COMMAND =
'm=$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)/..; for p in node_modules/.bin/pullboard "$m/node_modules/.bin/pullboard"; do [ -x "$p" ] && exec "$p" mcp; done; command -v pullboard >/dev/null && exec pullboard mcp; echo "pullboard is not installed; npm i -D pullboard" >&2; exit 1';
+/**
+ * Split a TOML key such as `mcp_servers.'pullboard'` into its parts: bare, "basic" or 'literal', dots between.
+ *
+ * @param {string} text
+ * @returns {string[]|null} null when the text is not a plain dotted key.
+ */
+function tomlKeyParts(text) {
+ const parts = [];
+ const pattern = /\s*(?:([A-Za-z0-9_-]+)|"((?:[^"\\]|\\.)*)"|'([^']*)')\s*(\.|$)/uy;
+ let match;
+ while (pattern.lastIndex < text.length && (match = pattern.exec(text))) {
+ parts.push(match[1] ?? (match[2] !== undefined ? JSON.parse(`"${match[2]}"`) : match[3]));
+ if (!match[4]) return pattern.lastIndex === text.length ? parts : null;
+ }
+ return null;
+}
+
+/**
+ * Drop a TOML line's comment: a # outside any quoted string.
+ *
+ * @param {string} line
+ * @returns {string}
+ */
+function withoutTomlComment(line) {
+ let quote = '';
+ for (let index = 0; index < line.length; index += 1) {
+ const char = line[index];
+ if (quote === '"' && char === '\\') index += 1;
+ else if (quote && char === quote) quote = '';
+ else if (!quote && (char === '"' || char === "'")) quote = char;
+ else if (!quote && char === '#') return line.slice(0, index);
+ }
+ return line;
+}
+
+/**
+ * Whether a Codex config.toml already defines an MCP server by this name, in any form TOML allows: a
+ * `[mcp_servers.name]` table with quoted keys or a trailing comment, its subtables, dotted keys under
+ * `[mcp_servers]` or the top level, or an inline table. Init must keep such a server and add no second
+ * one, since a duplicate makes the whole file invalid TOML (#961).
+ *
+ * @param {string} contents
+ * @param {string} name
+ * @returns {boolean}
+ */
+export function codexHasMcpServer(contents, name) {
+ const names = (path) => path.length >= 2 && path[0] === 'mcp_servers' && path[1] === name;
+ let table = [];
+ for (const raw of String(contents).split(/\r?\n/u)) {
+ const line = withoutTomlComment(raw).trim();
+ const header = /^\[\[?(.+?)\]\]?$/u.exec(line);
+ if (header) {
+ table = tomlKeyParts(header[1]) ?? [];
+ if (names(table)) return true;
+ continue;
+ }
+ const equals = line.indexOf('=');
+ if (equals < 1) continue;
+ const key = tomlKeyParts(line.slice(0, equals));
+ if (!key) continue;
+ const path = [...table, ...key];
+ if (names(path)) return true;
+ // An inline table: mcp_servers = { name = { ... } } names the server among its keys.
+ const value = line.slice(equals + 1);
+ if (path.length === 1 && path[0] === 'mcp_servers' && new RegExp(`[{,]\\s*(?:${name}|"${name}"|'${name}')\\s*[.=]`, 'u').test(value)) return true;
+ }
+ return false;
+}
+
/**
* Register pullboard mcp for Claude Code (.mcp.json) and Codex (.codex/config.toml), merging with any servers already
* there and never replacing a pullboard entry or a file it cannot read, so an agent can work the loop through MCP (#961).
@@ -452,7 +521,7 @@ function writeMcpConfig(root, onWrite) {
}
const codex = join(root, '.codex', 'config.toml');
const contents = existsSync(codex) ? readFileSync(codex, 'utf8') : '';
- if (/^\s*\[mcp_servers\.(?:pullboard|"pullboard")\]\s*$/mu.test(contents) || /^\s*\[mcp_servers\]\s*$(?:(?!^\s*\[)[\s\S])*?^\s*pullboard\s*=/mu.test(contents)) {
+ if (codexHasMcpServer(contents, 'pullboard')) {
notes.push('kept the Codex MCP server in .codex/config.toml');
} else {
// A new table at the end is valid TOML after any existing content, so nothing already there is rewritten.
diff --git a/test/init-permissions.test.js b/test/init-permissions.test.js
index 6f2a7a19..c32f27e9 100644
--- a/test/init-permissions.test.js
+++ b/test/init-permissions.test.js
@@ -195,3 +195,31 @@ test('init grants the agent the permissions the Pullboard loop needs [I1,I2]', t
assert.deepEqual(JSON.parse(readFileSync(skipSettingsPath, 'utf8')).sandbox, skipSandbox, '--no-permissions preserves existing sandbox scope');
assert.equal(readFileSync(skipCodexPath, 'utf8'), skipCodexBytes, '--no-permissions preserves existing Codex rules byte-for-byte');
});
+
+test('init keeps an existing Codex pullboard server in any TOML form and adds no second one [A9,I1]', (t) => {
+ const forms = {
+ 'a trailing comment': '[mcp_servers.pullboard] # the team runs it here\ncommand = "pullboard"\nargs = ["mcp"]\n',
+ 'a single-quoted key': "[mcp_servers.'pullboard']\ncommand = \"pullboard\"\nargs = [\"mcp\"]\n",
+ 'an inline table': 'mcp_servers = { pullboard = { command = "pullboard", args = ["mcp"] } }\n',
+ 'an inline table under [mcp_servers]': '[mcp_servers]\npullboard = { command = "pullboard", args = ["mcp"] }\n',
+ 'dotted keys': 'mcp_servers.pullboard.command = "pullboard"\nmcp_servers.pullboard.args = ["mcp"]\n',
+ };
+ for (const [form, existing] of Object.entries(forms)) {
+ const box = initFixture(t);
+ mkdirSync(join(box.root, '.codex'), { recursive: true });
+ writeFileSync(join(box.root, '.codex', 'config.toml'), existing);
+ const initialized = box.init();
+ assert.equal(initialized.code, 0, `${form}: ${initialized.stderr}`);
+ assert.equal(readFileSync(join(box.root, '.codex', 'config.toml'), 'utf8'), existing, `${form}: the config is byte for byte as it was, with no duplicate server`);
+ assert.ok(initialized.document.notes.includes('kept the Codex MCP server in .codex/config.toml'), `${form}: init says it kept the server`);
+ }
+ // A server by another name, or pullboard named only inside a string or a comment, still gets the pullboard table.
+ const box = initFixture(t);
+ const other = '# [mcp_servers.pullboard] was here once\n[mcp_servers.other]\ncommand = "pullboard"\n';
+ mkdirSync(join(box.root, '.codex'), { recursive: true });
+ writeFileSync(join(box.root, '.codex', 'config.toml'), other);
+ assert.equal(box.init().code, 0);
+ const after = readFileSync(join(box.root, '.codex', 'config.toml'), 'utf8');
+ assert.ok(after.startsWith(other), 'the existing config is kept');
+ assert.match(after.slice(other.length), /^\n\[mcp_servers\.pullboard\]\ncommand = "sh"\n/u, 'the pullboard server is appended once');
+});