@yawlabs/mcp 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -891,6 +891,7 @@ function resolveAppDataDir(opts) {
891
891
  }
892
892
 
893
893
  // src/client-config.ts
894
+ var CONFIG_FORMATS = ["json", "jsonc", "toml"];
894
895
  function syntaxNameFor(format) {
895
896
  switch (format) {
896
897
  case "json":
@@ -978,16 +979,17 @@ function composeEntry(opts) {
978
979
  if (out.env === void 0 && opts.env !== void 0 && Object.keys(opts.env).length > 0) out.env = opts.env;
979
980
  return out;
980
981
  }
981
- function reloadDoneClause(reload, label) {
982
+ function reloadDoneClause(reload, label, what = "server") {
983
+ const server = what === "server";
982
984
  switch (reload) {
983
985
  case "live":
984
- return `${label} starts the server when the file is saved -- no restart needed.`;
986
+ return server ? `${label} starts the server when the file is saved -- no restart needed.` : `${label} picks the change up when the file is saved -- no restart needed.`;
985
987
  case "reload-window":
986
- return "Reload the IDE window to pick up the new MCP server.";
988
+ return `Reload the IDE window to pick up the ${server ? "new MCP server" : "change"}.`;
987
989
  case "next-session":
988
- return `${label} picks the entry up in its next session.`;
990
+ return `${label} picks the ${server ? "entry" : "change"} up in its next session.`;
989
991
  default:
990
- return "Restart it to pick up the new MCP server.";
992
+ return `Restart it to pick up the ${server ? "new MCP server" : "change"}.`;
991
993
  }
992
994
  }
993
995
  function reloadRemovalClause(reload, label) {
@@ -1016,6 +1018,9 @@ function registerConfigAdapter(format, adapter) {
1016
1018
  }
1017
1019
  REGISTERED.set(format, adapter);
1018
1020
  }
1021
+ function hasConfigAdapter(format) {
1022
+ return builtInAdapter(format) !== void 0 || REGISTERED.has(format);
1023
+ }
1019
1024
  function adapterFor(format) {
1020
1025
  const adapter = builtInAdapter(format) ?? REGISTERED.get(format);
1021
1026
  if (adapter === void 0) throw new MissingConfigAdapterError(format);
@@ -1034,9 +1039,16 @@ function describeValueShape(value) {
1034
1039
  if (Array.isArray(value)) return value.length === 0 ? "an empty array" : `an array of ${value.length}`;
1035
1040
  return `a ${typeof value}`;
1036
1041
  }
1042
+ function detectLineEnding(text) {
1043
+ const match = /\r\n|\n|\r/.exec(text);
1044
+ return match === null ? "\n" : match[0];
1045
+ }
1037
1046
  function terminateWithNewline(text) {
1038
- return text.endsWith("\n") ? text : `${text}
1047
+ if (text.endsWith("\n")) return text;
1048
+ const eol = detectLineEnding(text);
1049
+ if (text.endsWith("\r")) return eol === "\r" ? text : `${text}
1039
1050
  `;
1051
+ return text + eol;
1040
1052
  }
1041
1053
  function findLegacyKey(keys) {
1042
1054
  return LEGACY_ENTRY_NAMES.find((name) => keys.includes(name)) ?? null;
@@ -1104,11 +1116,82 @@ function containerKeysAt(raw, site, prefix) {
1104
1116
  function siteAt(site, containerPath) {
1105
1117
  return { ...site, resolved: { ...site.resolved, containerPath: [...containerPath] } };
1106
1118
  }
1119
+ function firstInvalidUtf8Offset(bytes) {
1120
+ let i = 0;
1121
+ while (i < bytes.length) {
1122
+ const lead = bytes[i];
1123
+ if (lead < 128) {
1124
+ i++;
1125
+ continue;
1126
+ }
1127
+ let follow;
1128
+ let low = 128;
1129
+ let high = 191;
1130
+ if (lead >= 194 && lead <= 223) follow = 1;
1131
+ else if (lead === 224) {
1132
+ follow = 2;
1133
+ low = 160;
1134
+ } else if (lead === 237) {
1135
+ follow = 2;
1136
+ high = 159;
1137
+ } else if (lead >= 225 && lead <= 239) follow = 2;
1138
+ else if (lead === 240) {
1139
+ follow = 3;
1140
+ low = 144;
1141
+ } else if (lead === 244) {
1142
+ follow = 3;
1143
+ high = 143;
1144
+ } else if (lead >= 241 && lead <= 243) follow = 3;
1145
+ else return i;
1146
+ if (i + follow >= bytes.length) return i;
1147
+ if (bytes[i + 1] < low || bytes[i + 1] > high) return i;
1148
+ for (let k = 2; k <= follow; k++) {
1149
+ if (bytes[i + k] < 128 || bytes[i + k] > 191) return i;
1150
+ }
1151
+ i += follow + 1;
1152
+ }
1153
+ return -1;
1154
+ }
1155
+ function mustBeUtf8(format) {
1156
+ switch (format) {
1157
+ case "toml":
1158
+ return true;
1159
+ case "json":
1160
+ case "jsonc":
1161
+ return false;
1162
+ default: {
1163
+ const _exhaustive = format;
1164
+ return _exhaustive;
1165
+ }
1166
+ }
1167
+ }
1168
+ function decodeClientConfigBytes(bytes, format) {
1169
+ const buffer = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
1170
+ const text = buffer.toString("utf8");
1171
+ if (!mustBeUtf8(format)) return { text, malformed: null };
1172
+ const bad = firstInvalidUtf8Offset(bytes);
1173
+ if (bad === -1) return { text, malformed: null };
1174
+ const syntax = syntaxNameFor(format);
1175
+ const valid = buffer.subarray(0, bad).toString("utf8");
1176
+ return {
1177
+ text,
1178
+ malformed: {
1179
+ kind: "malformed",
1180
+ syntax,
1181
+ reason: "encoding",
1182
+ // The BYTE offset belongs in the detail and the position does not: the
1183
+ // facade's refusal adds " at line L column C" from `position` itself,
1184
+ // while install, uninstall, import and try print the detail alone.
1185
+ detail: `invalid UTF-8 at byte offset ${bad}, and a ${syntax} file must be UTF-8 -- re-save the file as UTF-8`,
1186
+ position: positionAt(text, valid.length)
1187
+ }
1188
+ };
1189
+ }
1107
1190
  async function readClientConfigFile(site, opts = {}) {
1108
- const load = opts.readFile ?? ((path3) => readFile(path3, "utf8"));
1109
- let raw;
1191
+ const load = opts.readFile ?? ((path3) => readFile(path3));
1192
+ let loaded;
1110
1193
  try {
1111
- raw = await load(site.resolved.absolute);
1194
+ loaded = await load(site.resolved.absolute);
1112
1195
  } catch (err) {
1113
1196
  const code = err?.code;
1114
1197
  if (code === "ENOENT") return classifyClientConfig(null, site, opts);
@@ -1119,7 +1202,14 @@ async function readClientConfigFile(site, opts = {}) {
1119
1202
  };
1120
1203
  return makeView(read, null, addressOf(site), 0, adapterFor(site.format), opts);
1121
1204
  }
1122
- return classifyClientConfig(raw, site, opts);
1205
+ if (typeof loaded === "string") return classifyClientConfig(loaded, site, opts);
1206
+ const decoded = decodeClientConfigBytes(loaded, site.format);
1207
+ if (decoded.malformed === null) return classifyClientConfig(decoded.text, site, opts);
1208
+ const address = {
1209
+ format: site.format,
1210
+ containerPath: opts.containerPaths?.[0] ?? site.resolved.containerPath
1211
+ };
1212
+ return makeView(decoded.malformed, decoded.text, address, 0, adapterFor(site.format), opts);
1123
1213
  }
1124
1214
  var ClientConfigWriteError = class extends Error {
1125
1215
  constructor(message) {
@@ -1132,21 +1222,41 @@ function applyClientConfigEdits(view, edits, site) {
1132
1222
  const where = site === void 0 ? "the config file" : site.resolved.absolute;
1133
1223
  const { adapter, address, read } = view;
1134
1224
  const writes = edits.some((edit) => edit.op !== "remove");
1225
+ for (const edit of edits) {
1226
+ if (edit.op !== "rootDefault") continue;
1227
+ rootKeySupport(adapter, `a "${edit.key}" rootDefault edit`, ClientConfigWriteError);
1228
+ if (edit.key === address.containerPath[0]) {
1229
+ throw new ClientConfigWriteError(
1230
+ `a rootDefault edit cannot set "${edit.key}": that key holds the server map in ${where}`
1231
+ );
1232
+ }
1233
+ }
1135
1234
  if (read.kind === "absent") {
1136
- const only = edits[0];
1137
- if (edits.length !== 1 || only.op !== "upsert") {
1235
+ const state = view.raw === null ? "does not exist" : "holds only whitespace";
1236
+ const refused = edits.find((edit) => edit.op === "remove" || edit.op === "repair");
1237
+ if (refused !== void 0) {
1238
+ throw new ClientConfigWriteError(
1239
+ `${where} ${state}, so there is nothing in it to ${refused.op === "remove" ? "remove" : "repair"}`
1240
+ );
1241
+ }
1242
+ const upserts = edits.filter((edit) => edit.op === "upsert").length;
1243
+ if (upserts > 1) {
1138
1244
  throw new ClientConfigWriteError(
1139
- `${where} does not exist, so there is nothing in it to ${only.op === "remove" ? "remove" : "repair"}`
1245
+ `${where} ${state}, and a write that creates it adds at most one entry -- ${upserts} upserts were asked for`
1140
1246
  );
1141
1247
  }
1142
- let fresh;
1248
+ let fresh = view.raw !== null && detectLineEnding(view.raw) === "\r\n" ? view.raw : null;
1143
1249
  try {
1144
- fresh = adapter.upsert(null, address, only.key, only.entry);
1250
+ for (const edit of edits) {
1251
+ if (edit.op === "upsert") fresh = adapter.upsert(fresh, address, edit.key, edit.entry);
1252
+ else if (edit.op === "rootDefault") fresh = insertRootKeyWith(adapter, fresh, edit.key, edit.value);
1253
+ }
1145
1254
  } catch (err) {
1146
1255
  throw new ClientConfigWriteError(
1147
1256
  `${where} could not be created (${err instanceof Error ? err.message : String(err)})`
1148
1257
  );
1149
1258
  }
1259
+ if (fresh === null) throw new ClientConfigWriteError(`${where} could not be created (no edit produced text)`);
1150
1260
  verifyEdits(adapter, address, null, fresh, edits, where, view);
1151
1261
  return fresh;
1152
1262
  }
@@ -1171,6 +1281,7 @@ function applyClientConfigEdits(view, edits, site) {
1171
1281
  for (const edit of edits) {
1172
1282
  if (edit.op === "upsert") text = adapter.upsert(text, address, edit.key, edit.entry);
1173
1283
  else if (edit.op === "remove") text = adapter.remove(text, address, edit.key);
1284
+ else if (edit.op === "rootDefault") text = insertRootKeyWith(adapter, text, edit.key, edit.value);
1174
1285
  else text = adapter.repairContainer(text, address, edit.path);
1175
1286
  }
1176
1287
  } catch (err) {
@@ -1206,8 +1317,10 @@ function sameSegments(a, b) {
1206
1317
  }
1207
1318
  function verifyEdits(adapter, address, before, after, edits, where, view) {
1208
1319
  const touched = /* @__PURE__ */ new Set();
1320
+ const rootKeys = [];
1209
1321
  for (const edit of edits) {
1210
- if (edit.op !== "repair") touched.add(edit.key);
1322
+ if (edit.op === "upsert" || edit.op === "remove") touched.add(edit.key);
1323
+ else if (edit.op === "rootDefault") rootKeys.push(edit.key);
1211
1324
  }
1212
1325
  let reread = adapter.classify(after, address, void 0);
1213
1326
  if (reread.kind === "absent" && edits.every((edit) => edit.op === "remove")) {
@@ -1251,9 +1364,31 @@ function verifyEdits(adapter, address, before, after, edits, where, view) {
1251
1364
  );
1252
1365
  }
1253
1366
  }
1367
+ for (const edit of edits) {
1368
+ if (edit.op !== "rootDefault") continue;
1369
+ const readRoot = rootKeySupport(adapter, `a "${edit.key}" rootDefault edit`, ClientConfigWriteError).read;
1370
+ if (before !== null && readRoot(before, edit.key).present) {
1371
+ throw new ClientConfigWriteError(
1372
+ `"${edit.key}" is already set in ${where}, and a rootDefault never changes a value that is there -- nothing was written`
1373
+ );
1374
+ }
1375
+ const back = readRoot(after, edit.key);
1376
+ if (!back.present || canonicalJson(back.value) !== canonicalJson(edit.value)) {
1377
+ throw new ClientConfigWriteError(
1378
+ `"${edit.key}" did not read back from ${where} as ${canonicalJson(edit.value)} -- nothing was written`
1379
+ );
1380
+ }
1381
+ const integerDefault = typeof edit.value === "number" && Number.isInteger(edit.value);
1382
+ if (integerDefault && back.float !== void 0) {
1383
+ throw new ClientConfigWriteError(
1384
+ `"${edit.key}" read back from ${where} as the float ${back.float}, not the integer ${canonicalJson(edit.value)} -- nothing was written`
1385
+ );
1386
+ }
1387
+ }
1254
1388
  if (before !== null) {
1255
1389
  const containerChanged = edits.some((edit) => edit.op === "repair") || view.read.kind === "ok" && !view.read.containerPresent;
1256
- const opts = containerChanged ? { dropContainer: true } : { drop: [...touched] };
1390
+ const dropRoot = rootKeys.length > 0 ? { dropRoot: rootKeys } : {};
1391
+ const opts = containerChanged ? { dropContainer: true, ...dropRoot } : { drop: [...touched], ...dropRoot };
1257
1392
  if (adapter.canon(before, address, opts) !== adapter.canon(after, address, opts)) {
1258
1393
  throw new ClientConfigWriteError(
1259
1394
  `writing to ${where} would have changed other settings in the file -- nothing was written`
@@ -1261,6 +1396,99 @@ function verifyEdits(adapter, address, before, after, edits, where, view) {
1261
1396
  }
1262
1397
  }
1263
1398
  }
1399
+ function rootKeySupport(adapter, what, ErrorType = Error) {
1400
+ const read = adapter.readRootKey;
1401
+ const insert = adapter.insertRootKey;
1402
+ if (read === void 0 || insert === void 0) {
1403
+ throw new ErrorType(
1404
+ `${what} needs a config adapter that can read and add a top-level key, and the ${adapter.syntax} adapter does not implement both readRootKey and insertRootKey -- a target may declare rootDefaults only on a format whose adapter does (a programming error, not a problem with the file)`
1405
+ );
1406
+ }
1407
+ return { read: read.bind(adapter), insert: insert.bind(adapter) };
1408
+ }
1409
+ function insertRootKeyWith(adapter, raw, key, value) {
1410
+ return rootKeySupport(adapter, `a "${key}" rootDefault edit`, ClientConfigWriteError).insert(raw, key, value);
1411
+ }
1412
+ var ROOT_INTEGER_CEILING = 9223372036854775807n;
1413
+ var ROOT_INTEGER_FLOOR = -9223372036854775808n;
1414
+ function refusalOf(type, value, float) {
1415
+ switch (type) {
1416
+ case "unsigned-integer": {
1417
+ const needs = "a non-negative integer";
1418
+ if (float !== void 0 || typeof value === "number" && !Number.isInteger(value)) {
1419
+ return { kind: "a float", needs: "an integer" };
1420
+ }
1421
+ if (typeof value === "number" || typeof value === "bigint") {
1422
+ if (BigInt(value) < ROOT_INTEGER_FLOOR) {
1423
+ return { kind: "a negative integer", needs, everyRelease: "smaller than a TOML integer holds" };
1424
+ }
1425
+ if (value < 0) return { kind: "a negative integer", needs };
1426
+ if (BigInt(value) > ROOT_INTEGER_CEILING) {
1427
+ return {
1428
+ // The whole range the type takes, not only the bound this value
1429
+ // broke: a negative integer meets "no larger than" and is refused
1430
+ // too.
1431
+ needs: `a non-negative integer no larger than ${ROOT_INTEGER_CEILING}`,
1432
+ everyRelease: "larger than a TOML integer holds"
1433
+ };
1434
+ }
1435
+ return void 0;
1436
+ }
1437
+ if (typeof value === "string") return { kind: "a string", needs };
1438
+ if (typeof value === "boolean") return { kind: "a boolean", needs };
1439
+ if (value instanceof Date) return { kind: "a date or time", needs };
1440
+ return { needs };
1441
+ }
1442
+ }
1443
+ }
1444
+ function planRootDefaults(view, defaults) {
1445
+ if (defaults === void 0 || defaults.length === 0) return { set: [], kept: [] };
1446
+ const { read } = rootKeySupport(view.adapter, `a target's rootDefaults (${defaults.map((d) => d.key).join(", ")})`);
1447
+ if (view.read.kind === "absent") return { set: [...defaults], kept: [] };
1448
+ if (view.read.kind !== "ok" || view.raw === null) return { set: [], kept: [] };
1449
+ const set = [];
1450
+ const kept = [];
1451
+ for (const rootDefault of defaults) {
1452
+ const current = read(view.raw, rootDefault.key);
1453
+ if (!current.present) {
1454
+ set.push(rootDefault);
1455
+ continue;
1456
+ }
1457
+ const integerDefault = typeof rootDefault.value === "number" && Number.isInteger(rootDefault.value);
1458
+ const float = integerDefault ? current.float : void 0;
1459
+ const refused = rootDefault.accepts === void 0 ? void 0 : refusalOf(rootDefault.accepts, current.value, current.float);
1460
+ if (float === void 0 && refused === void 0) {
1461
+ if (canonicalJson(current.value) !== canonicalJson(rootDefault.value)) {
1462
+ kept.push({ rootDefault, value: current.value });
1463
+ }
1464
+ continue;
1465
+ }
1466
+ kept.push({
1467
+ rootDefault,
1468
+ value: current.value,
1469
+ ...float === void 0 ? {} : { float },
1470
+ ...refused === void 0 ? {} : { refused }
1471
+ });
1472
+ }
1473
+ return { set, kept };
1474
+ }
1475
+ function previewRootDefaults(view, defaults) {
1476
+ if (defaults.length === 0) return "";
1477
+ const { insert } = rootKeySupport(view.adapter, "a rootDefault preview");
1478
+ return defaults.map((d) => insert(null, d.key, d.value)).join("");
1479
+ }
1480
+ var CLIENT_ENV_VARS = [
1481
+ "APPDATA",
1482
+ "CLAUDE_CONFIG_DIR",
1483
+ "CLINE_DATA_DIR",
1484
+ "CLINE_DIR",
1485
+ "CLINE_MCP_SETTINGS_PATH",
1486
+ "CODEX_HOME",
1487
+ "CONTINUE_GLOBAL_DIR",
1488
+ "TYPED_CLI_BUNDLE",
1489
+ "XDG_CONFIG_HOME",
1490
+ "YAW_MODE"
1491
+ ];
1264
1492
  function readClientEnv(env = process.env) {
1265
1493
  const value = (name) => {
1266
1494
  const raw = env[name];
@@ -1512,8 +1740,7 @@ function describeTomlShape(value) {
1512
1740
  var isHorizontalSpace2 = (c) => c === " " || c === " ";
1513
1741
  var isBareKeyChar = (c) => c !== void 0 && /^[A-Za-z0-9_-]$/.test(c);
1514
1742
  function detectTomlEol(text) {
1515
- const match = /\r\n|\n|\r/.exec(text);
1516
- return match ? match[0] : "\n";
1743
+ return detectLineEnding(text);
1517
1744
  }
1518
1745
  function lineEnd(text, from) {
1519
1746
  let i = from;
@@ -1707,7 +1934,8 @@ function scanTomlSections(text) {
1707
1934
  section,
1708
1935
  keyPath: read.path,
1709
1936
  inlineTable: text[v] === "{",
1710
- start: lineStart
1937
+ start: lineStart,
1938
+ valueStart: v
1711
1939
  });
1712
1940
  pos = eq + 1;
1713
1941
  }
@@ -2237,10 +2465,11 @@ function canonValue(value) {
2237
2465
  }
2238
2466
  return value;
2239
2467
  }
2240
- function canonTomlConfig(raw, containerPath, drop = []) {
2468
+ function canonTomlConfig(raw, containerPath, drop = [], dropRoot = []) {
2241
2469
  const parsed = parseTomlConfig(raw);
2242
2470
  const value = canonValue(parsed);
2243
2471
  if (!isTomlTable(value)) return JSON.stringify(value);
2472
+ for (const key of dropRoot) delete value[key];
2244
2473
  let cursor = value;
2245
2474
  for (let i = 0; i < containerPath.length; i++) {
2246
2475
  const key = containerPath[i];
@@ -2302,6 +2531,91 @@ function verifyTomlSplice(before, after, containerPath, expectation = {}) {
2302
2531
  }
2303
2532
  }
2304
2533
  }
2534
+ function readTomlRootKey(raw, key) {
2535
+ if (raw === null || raw.trim() === "") return { present: false };
2536
+ const parsed = parseTomlConfig(raw);
2537
+ if (!isTomlTable(parsed) || !Object.hasOwn(parsed, key)) return { present: false };
2538
+ const value = parsed[key];
2539
+ if (typeof value !== "number") return { present: true, value };
2540
+ const typed = parseTomlText(stripBom2(raw), { integersAsBigInt: true });
2541
+ if (typeof typed[key] === "bigint") return { present: true, value };
2542
+ return { present: true, value, float: rootValueSpelling(raw, key) ?? String(value) };
2543
+ }
2544
+ function rootValueSpelling(raw, key) {
2545
+ const assignment = scanTomlSections(raw).assignments.find(
2546
+ (a) => a.section.length === 0 && a.keyPath.length === 1 && a.keyPath[0] === key
2547
+ );
2548
+ if (assignment === void 0) return null;
2549
+ const token = /^[+-]?(?:inf|nan|[0-9][0-9_]*(?:\.[0-9][0-9_]*)?(?:[eE][+-]?[0-9][0-9_]*)?)/.exec(
2550
+ raw.slice(assignment.valueStart)
2551
+ );
2552
+ return token === null ? null : token[0];
2553
+ }
2554
+ function insertTomlRootKey(raw, key, value) {
2555
+ const line = rootKeyLine(key, value);
2556
+ if (raw === null || raw.trim() === "") {
2557
+ const fresh = line + (raw === null ? "\n" : detectTomlEol(raw));
2558
+ verifyTomlRootInsert("", fresh, key, value);
2559
+ return fresh;
2560
+ }
2561
+ const parsed = parseTomlConfig(raw);
2562
+ if (!isTomlTable(parsed)) {
2563
+ throw new TomlSpliceRefusal("the document root", "not a TOML table", "fix the file by hand, then re-run");
2564
+ }
2565
+ if (Object.hasOwn(parsed, key)) {
2566
+ throw new TomlSpliceRefusal(
2567
+ `the top-level "${key}" key`,
2568
+ "already set in this file",
2569
+ "yaw-mcp only adds it and never changes a value that is there; edit it by hand to change it"
2570
+ );
2571
+ }
2572
+ const scan = scanTomlSections(raw);
2573
+ const next = applyEdits2(raw, rootInsertEdits(raw, scan, line));
2574
+ verifyTomlRootInsert(raw, next, key, value);
2575
+ return next;
2576
+ }
2577
+ function rootInsertEdits(text, scan, line) {
2578
+ const eol = scan.eol;
2579
+ const unterminated = !/[\r\n]/.test(text[text.length - 1] ?? "");
2580
+ const terminated = (edit) => unterminated ? [edit, { start: text.length, end: text.length, text: eol }] : [edit];
2581
+ const roots = scan.assignments.filter((a) => a.section.length === 0);
2582
+ const last = roots[roots.length - 1];
2583
+ if (last === void 0) {
2584
+ const at2 = bomOffset(text);
2585
+ const opensOnBlank = isBlankLine(text, at2, lineEnd(text, at2));
2586
+ return terminated({ start: at2, end: at2, text: line + eol + (opensOnBlank ? "" : eol) });
2587
+ }
2588
+ let at = lineEnd(text, last.start);
2589
+ while (at < text.length && scan.continuedLines.has(at)) at = lineEnd(text, at);
2590
+ if (at >= text.length) return [{ start: at, end: at, text: (unterminated ? eol : "") + line + eol }];
2591
+ return terminated({ start: at, end: at, text: line + eol });
2592
+ }
2593
+ function rootKeyLine(key, value) {
2594
+ return `${tomlKey(key)} = ${tomlValue(value, key)}`;
2595
+ }
2596
+ function verifyTomlRootInsert(before, after, key, value) {
2597
+ if (readTomlRootKey(before, key).present) {
2598
+ throw new TomlVerifyError(`the top-level "${key}" was already set before the edit`);
2599
+ }
2600
+ let read;
2601
+ try {
2602
+ read = readTomlRootKey(after, key);
2603
+ } catch (e) {
2604
+ throw new TomlVerifyError(`the edited text does not parse as TOML (${e.message})`);
2605
+ }
2606
+ if (!read.present) throw new TomlVerifyError(`the edit did not leave a top-level "${key}" behind`);
2607
+ if (JSON.stringify(canonValue(read.value)) !== JSON.stringify(canonValue(value))) {
2608
+ throw new TomlVerifyError(`the top-level "${key}" did not read back as the value written`);
2609
+ }
2610
+ if (typeof value === "number" && Number.isInteger(value) && read.float !== void 0) {
2611
+ throw new TomlVerifyError(
2612
+ `the top-level "${key}" read back as the float ${read.float}, where the value written is an integer`
2613
+ );
2614
+ }
2615
+ if (canonTomlConfig(before.trim() === "" ? "" : before, [], [], [key]) !== canonTomlConfig(after, [], [], [key])) {
2616
+ throw new TomlVerifyError(`the edit changed settings other than the top-level "${key}" it was asked to add`);
2617
+ }
2618
+ }
2305
2619
 
2306
2620
  // src/target-codex-cli.ts
2307
2621
  var CONTAINER_KEY = "mcp_servers";
@@ -2372,7 +2686,13 @@ function describeTomlLocation(absolute, _addr) {
2372
2686
  }
2373
2687
  function canonToml(raw, addr, opts = {}) {
2374
2688
  const drop = opts.dropContainer === true ? tomlEntryNames(readTomlConfig(raw, addr.containerPath)) : opts.drop ?? [];
2375
- return canonTomlConfig(raw, addr.containerPath, drop);
2689
+ return canonTomlConfig(raw, addr.containerPath, drop, opts.dropRoot ?? []);
2690
+ }
2691
+ function readTomlRoot(raw, key) {
2692
+ return readTomlRootKey(raw, key);
2693
+ }
2694
+ function insertTomlRoot(raw, key, value) {
2695
+ return insertTomlRootKey(raw, key, value);
2376
2696
  }
2377
2697
  var TOML_ADAPTER = {
2378
2698
  syntax: TOML_SYNTAX,
@@ -2382,7 +2702,11 @@ var TOML_ADAPTER = {
2382
2702
  repairContainer: repairTomlContainer,
2383
2703
  renderPreview: previewToml,
2384
2704
  describeLocation: describeTomlLocation,
2385
- canon: canonToml
2705
+ canon: canonToml,
2706
+ // The two root-key methods: what lets a TOML row declare a top-level
2707
+ // default (`ConfigShape.rootDefaults`). The JSON family implements neither.
2708
+ readRootKey: readTomlRoot,
2709
+ insertRootKey: insertTomlRoot
2386
2710
  };
2387
2711
  registerConfigAdapter("toml", TOML_ADAPTER);
2388
2712
  function resolveCodexPath(base) {
@@ -2468,10 +2792,16 @@ function codexImportView(stored) {
2468
2792
  if (discarded.length > 0) view.discardedKeys = discarded;
2469
2793
  return view;
2470
2794
  }
2795
+ var STARTUP_GRACE_DEFAULT = {
2796
+ key: "mcp_optional_startup_grace_ms",
2797
+ value: 0,
2798
+ why: "Codex 0.151 and later otherwise give optional MCP servers one shared grace (1000 ms unless set) to start and leave a slower yaw-mcp out of the whole session; at 0 each server gets its own startup_timeout_sec (60 s on the entry install writes)",
2799
+ accepts: "unsigned-integer"
2800
+ };
2471
2801
  var CODEX_CLI_TARGET = defineTarget({
2472
2802
  clientId: "codex-cli",
2473
2803
  label: "Codex CLI",
2474
- config: { format: "toml", root: CONTAINER_KEY },
2804
+ config: { format: "toml", root: CONTAINER_KEY, rootDefaults: [STARTUP_GRACE_DEFAULT] },
2475
2805
  availableOn: ["macos", "linux", "windows"],
2476
2806
  entry: {
2477
2807
  normalize: normalizeCodexEntry,
@@ -2485,6 +2815,13 @@ var CODEX_CLI_TARGET = defineTarget({
2485
2815
  // magnitude for that launch and 60 is not. A genuinely COLD fetch (a fresh
2486
2816
  // machine, or the first spawn after a new release) can still exceed it --
2487
2817
  // the remedy there is to re-run the spawn, not a timeout we could pick.
2818
+ //
2819
+ // On Codex 0.151 and later this timeout is only half of it: the shared
2820
+ // `mcp_optional_startup_grace_ms` (1000 ms by default) decides whether a
2821
+ // server's tools make the session at all, and it is the root key in
2822
+ // `config.rootDefaults` above, set to 0, that makes Codex wait these 60
2823
+ // seconds instead (S6). Codex 0.147 to 0.150 already wait a fixed 1 s
2824
+ // that the key cannot change.
2488
2825
  extraFields: () => ({ startup_timeout_sec: 60 }),
2489
2826
  // Bare `npx` on Windows: Codex resolves the `.cmd` shim itself (S2), which
2490
2827
  // is also what `codex mcp add` writes, so a `cmd /c` entry of ours would
@@ -2497,7 +2834,7 @@ var CODEX_CLI_TARGET = defineTarget({
2497
2834
  windowsLaunch: { broker: "bare", upstream: "cmd-wrap" },
2498
2835
  forImport: codexImportView
2499
2836
  },
2500
- notes: "Codex CLI reads MCP servers from config.toml ([mcp_servers.<name>] tables) under CODEX_HOME, which defaults to ~/.codex. A project's .codex/config.toml is read only once Codex trusts the project. Codex starts a server with a cleared environment and forwards an allowlist, so put yaw-mcp settings in the entry's [mcp_servers.mcp.env] table or name them in env_vars. On Windows the entry is bare npx, not cmd /c npx, and needs Codex 0.59.0 or newer, which resolves npx's .cmd shim itself. Restart Codex after editing; `codex mcp list` shows the entry.",
2837
+ notes: "Codex CLI reads MCP servers from config.toml ([mcp_servers.<name>] tables) under CODEX_HOME, which defaults to ~/.codex. A project's .codex/config.toml is read only once Codex trusts the project. Codex starts a server with a cleared environment and forwards an allowlist, so put yaw-mcp settings in the entry's [mcp_servers.mcp.env] table or name them in env_vars. On Windows the entry is bare npx, not cmd /c npx, and needs Codex 0.59.0 or newer, which resolves npx's .cmd shim itself. Install also sets mcp_optional_startup_grace_ms = 0 at the top of config.toml: Codex 0.151 and later otherwise give MCP servers a shared 1 s grace to start and leave a slower yaw-mcp out of the whole session. With 0, Codex waits up to each server's startup_timeout_sec, which the entry sets to 60. Codex 0.147 to 0.150 already wait a fixed 1 s that this key cannot change, so the fix needs Codex 0.151 or newer. A value already in the file is left alone, and uninstall leaves the key in place (it only changes how long Codex waits for servers to start). Restart Codex after editing; `codex mcp list` shows the entry.",
2501
2838
  resolvePath: resolveCodexPath,
2502
2839
  scopes: [
2503
2840
  // User FIRST, like every other multi-scope row: the probe walks this array
@@ -2846,8 +3183,7 @@ async function prepareClaudeCodeSettingsPatch(opts) {
2846
3183
  }
2847
3184
  try {
2848
3185
  const next = patchPermissionsAllowText(rawSettings, [CLAUDE_CODE_ALLOW_PATTERN], op);
2849
- return { path: path3, nextJson: next.endsWith("\n") ? next : `${next}
2850
- `, changed: true, added, removed, fingerprint };
3186
+ return { path: path3, nextJson: terminateWithNewline(next), changed: true, added, removed, fingerprint };
2851
3187
  } catch (e) {
2852
3188
  return {
2853
3189
  path: path3,
@@ -4569,7 +4905,7 @@ async function oamFloorLines(probe) {
4569
4905
  }
4570
4906
  async function defaultRunningPrefix(argvPath) {
4571
4907
  if (process.env.VITEST) return null;
4572
- const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-ECOUS4F4.js");
4908
+ const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-FMCVLIO7.js");
4573
4909
  return detectRunningInstallPrefix2(argvPath);
4574
4910
  }
4575
4911
  async function defaultSpawn(cmd, args, cwd) {
@@ -4630,7 +4966,7 @@ async function runUpgrade(opts = {}) {
4630
4966
  if (method === "global-npm") {
4631
4967
  const rawPrefix = await (opts.runningPrefix ?? defaultRunningPrefix)(argvPath);
4632
4968
  if (rawPrefix !== null) {
4633
- const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-ECOUS4F4.js");
4969
+ const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-FMCVLIO7.js");
4634
4970
  const spawnForm = quoteShellArgIfNeeded2(rawPrefix, opts.platform);
4635
4971
  const displayForm = quoteArgForDisplay2(rawPrefix, opts.platform);
4636
4972
  if (spawnForm !== null && displayForm !== null) {
@@ -4747,7 +5083,7 @@ async function runUpgrade(opts = {}) {
4747
5083
  return { exitCode: 3, lines };
4748
5084
  }
4749
5085
  function readCurrentVersion() {
4750
- return true ? "1.0.15" : "dev";
5086
+ return true ? "1.0.16" : "dev";
4751
5087
  }
4752
5088
 
4753
5089
  // src/auto-upgrade.ts
@@ -5028,7 +5364,7 @@ function defaultSpawn2(cmd, args, onDone = () => {
5028
5364
  }
5029
5365
  async function maybeAutoUpgrade(deps = {}) {
5030
5366
  if (isFeatureDisabled("YAW_MCP_AUTO_UPGRADE")) return;
5031
- const current = deps.currentVersion ?? (true ? "1.0.15" : "dev");
5367
+ const current = deps.currentVersion ?? (true ? "1.0.16" : "dev");
5032
5368
  if (current === "dev") return;
5033
5369
  const argvPath = deps.argvPath ?? process.argv[1];
5034
5370
  const method = (deps.isSeaImpl ? await deps.isSeaImpl() : await detectSea()) ? "binary" : detectInstallMethod(argvPath, realpathSync3, ["unknown", "local-node-modules"]);
@@ -5163,6 +5499,7 @@ export {
5163
5499
  ENTRY_NAME,
5164
5500
  LEGACY_ENTRY_NAMES,
5165
5501
  resolveAppDataDir,
5502
+ CONFIG_FORMATS,
5166
5503
  syntaxNameFor,
5167
5504
  containerNounFor,
5168
5505
  effectiveConfigFormat,
@@ -5177,13 +5514,18 @@ export {
5177
5514
  composeEntry,
5178
5515
  reloadDoneClause,
5179
5516
  reloadRemovalClause,
5517
+ hasConfigAdapter,
5180
5518
  describeValueShape,
5181
5519
  terminateWithNewline,
5182
5520
  classifyClientConfig,
5183
5521
  containerKeysAt,
5184
5522
  siteAt,
5523
+ decodeClientConfigBytes,
5185
5524
  readClientConfigFile,
5186
5525
  applyClientConfigEdits,
5526
+ planRootDefaults,
5527
+ previewRootDefaults,
5528
+ CLIENT_ENV_VARS,
5187
5529
  readClientEnv,
5188
5530
  CLAUDE_CODE_ALLOW_PATTERN,
5189
5531
  resolveClaudeCodeSettingsPath,