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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(init): no table is read inside a TOML multi-line string [A9,I1]
Corey Olson39747d444609
diff --git a/src/init.js b/src/init.jsindex a4838aea..968a39bc 100644--- a/src/init.js+++ b/src/init.js@@ -424,6 +424,62 @@ 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';+/**+ * Decode the body of a TOML basic string: \\b \\t \\n \\f \\r \\e \\" \\\\, \\uXXXX and \\UXXXXXXXX. Null for an escape+ * TOML does not define, so a key that cannot be read names nothing rather than crashing init (#961).+ *+ * @param {string} body+ * @returns {string | null}+ */+function tomlBasicString(body) {+ const simple = { b: '\b', t: '\t', n: '\n', f: '\f', r: '\r', e: '\u001b', '"': '"', '\\': '\\' };+ let out = '';+ for (let at = 0; at < body.length; at += 1) {+ if (body[at] !== '\\') { out += body[at]; continue; }+ const kind = body[at + 1];+ if (kind in simple) { out += simple[kind]; at += 1; continue; }+ const width = kind === 'u' ? 4 : kind === 'U' ? 8 : 0;+ const hex = body.slice(at + 2, at + 2 + width);+ if (!width || !/^[0-9A-Fa-f]+$/u.test(hex) || hex.length !== width) return null;+ const code = Number.parseInt(hex, 16);+ if (code > 0x10ffff || (code >= 0xd800 && code <= 0xdfff)) return null;+ out += String.fromCodePoint(code);+ at += 1 + width;+ }+ return out;+}++/**+ * A Codex config.toml's lines, each with whether it begins inside a multi-line string ("""…""" or \'\'\'…\'\'\'). Such a+ * line is text, never a table header or a key, however it looks (#961).+ *+ * @param {string} contents+ * @returns {{ text: string, inString: boolean }[]}+ */+function tomlLines(contents) {+ const lines = String(contents).split(/\r?\n/u);+ const result = [];+ let multi = '';+ for (const text of lines) {+ result.push({ text, inString: Boolean(multi) });+ let quote = '';+ for (let at = 0; at < text.length; at += 1) {+ if (multi) {+ if (multi === '"""' && text[at] === '\\') { at += 1; continue; }+ if (text.startsWith(multi, at)) { at += multi.length - 1; multi = ''; }+ continue;+ }+ const char = text[at];+ if (quote === '"' && char === '\\') { at += 1; continue; }+ if (quote) { if (char === quote) quote = ''; continue; }+ if (text.startsWith('"""', at) || text.startsWith("\'\'\'", at)) { multi = text.slice(at, at + 3); at += 2; continue; }+ if (char === '"' || char === "'") quote = char;+ else if (char === '#') break;+ }+ }+ return result;+}+/*** Split a TOML key such as `mcp_servers.'pullboard'` into its parts: bare, "basic" or 'literal', dots between.*@@ -435,7 +491,9 @@ function tomlKeyParts(text) {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]));+ const part = match[1] ?? (match[2] !== undefined ? tomlBasicString(match[2]) : match[3]);+ if (part === null) return null;+ parts.push(part);if (!match[4]) return pattern.lastIndex === text.length ? parts : null;}return null;@@ -472,7 +530,8 @@ function withoutTomlComment(line) {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)) {+ for (const { text: raw, inString } of tomlLines(contents)) {+ if (inString) continue;const line = withoutTomlComment(raw).trim();const header = /^\[\[?(.+?)\]\]?$/u.exec(line);if (header) {@@ -502,7 +561,8 @@ export function codexHasMcpServer(contents, name) {*/export function codexMcpServersInline(contents) {let table = [];- for (const raw of String(contents).split(/\r?\n/u)) {+ for (const { text: raw, inString } of tomlLines(contents)) {+ if (inString) continue;const line = withoutTomlComment(raw).trim();const header = /^\[\[?(.+?)\]\]?$/u.exec(line);if (header) { table = tomlKeyParts(header[1]) ?? []; continue; }diff --git a/test/init-permissions.test.js b/test/init-permissions.test.jsindex 37d8f58f..eb08ebaf 100644--- a/test/init-permissions.test.js+++ b/test/init-permissions.test.js@@ -250,3 +250,22 @@ test('init leaves an inline mcp_servers table as written, prints the exact blockconst ordinary = initFixture(t);assert.equal(ordinary.init().document.mcp.codex, 'added');});++test('init reads no table inside a multi-line string and reads every TOML escape in a key [A9,I1]', (t) => {+ // A header written inside a multi-line string is text, so the pullboard server is still added; a \U escape never crashes.+ for (const existing of [+ 'note = """\n[mcp_servers.pullboard]\n"""\n[mcp_servers.other]\ncommand = "other"\n',+ "note = '''\n[mcp_servers.pullboard]\n'''\n",+ '[mcp_servers."\\U0001F600"]\ncommand = "smile"\n',+ ]) {+ 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, `${existing}\n${initialized.stderr}`);+ assert.equal(initialized.document.mcp.codex, 'added', existing);+ const after = readFileSync(join(box.root, '.codex', 'config.toml'), 'utf8');+ assert.ok(after.startsWith(existing), 'everything already there is kept');+ assert.match(after.slice(existing.length), /^\n\[mcp_servers\.pullboard\]\ncommand = "sh"\n/u, 'the pullboard table is appended once');+ }+});