@yawlabs/mcp 1.0.13 → 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.
@@ -117,15 +117,18 @@ var INTERNAL_SECRET_ENV_KEYS = /* @__PURE__ */ new Set([
117
117
  "YAW_MCP_VAULT_PASSPHRASE",
118
118
  "YAW_MCP_VAULT_PASSPHRASE_NEW"
119
119
  ]);
120
+ function isInternalSecretEnvKey(key) {
121
+ return INTERNAL_SECRET_ENV_KEYS.has(key.toUpperCase());
122
+ }
120
123
  function scrubInternalSecretsFromProcessEnv() {
121
124
  for (const key of Object.keys(process.env)) {
122
- if (INTERNAL_SECRET_ENV_KEYS.has(key.toUpperCase())) delete process.env[key];
125
+ if (isInternalSecretEnvKey(key)) delete process.env[key];
123
126
  }
124
127
  }
125
128
  function stripInternalSecretsFromEnv(env) {
126
129
  const out = {};
127
130
  for (const [key, value] of Object.entries(env)) {
128
- if (INTERNAL_SECRET_ENV_KEYS.has(key.toUpperCase())) continue;
131
+ if (isInternalSecretEnvKey(key)) continue;
129
132
  out[key] = value;
130
133
  }
131
134
  return out;
@@ -888,6 +891,7 @@ function resolveAppDataDir(opts) {
888
891
  }
889
892
 
890
893
  // src/client-config.ts
894
+ var CONFIG_FORMATS = ["json", "jsonc", "toml"];
891
895
  function syntaxNameFor(format) {
892
896
  switch (format) {
893
897
  case "json":
@@ -975,16 +979,17 @@ function composeEntry(opts) {
975
979
  if (out.env === void 0 && opts.env !== void 0 && Object.keys(opts.env).length > 0) out.env = opts.env;
976
980
  return out;
977
981
  }
978
- function reloadDoneClause(reload, label) {
982
+ function reloadDoneClause(reload, label, what = "server") {
983
+ const server = what === "server";
979
984
  switch (reload) {
980
985
  case "live":
981
- 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.`;
982
987
  case "reload-window":
983
- 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"}.`;
984
989
  case "next-session":
985
- return `${label} picks the entry up in its next session.`;
990
+ return `${label} picks the ${server ? "entry" : "change"} up in its next session.`;
986
991
  default:
987
- return "Restart it to pick up the new MCP server.";
992
+ return `Restart it to pick up the ${server ? "new MCP server" : "change"}.`;
988
993
  }
989
994
  }
990
995
  function reloadRemovalClause(reload, label) {
@@ -1013,6 +1018,9 @@ function registerConfigAdapter(format, adapter) {
1013
1018
  }
1014
1019
  REGISTERED.set(format, adapter);
1015
1020
  }
1021
+ function hasConfigAdapter(format) {
1022
+ return builtInAdapter(format) !== void 0 || REGISTERED.has(format);
1023
+ }
1016
1024
  function adapterFor(format) {
1017
1025
  const adapter = builtInAdapter(format) ?? REGISTERED.get(format);
1018
1026
  if (adapter === void 0) throw new MissingConfigAdapterError(format);
@@ -1031,9 +1039,16 @@ function describeValueShape(value) {
1031
1039
  if (Array.isArray(value)) return value.length === 0 ? "an empty array" : `an array of ${value.length}`;
1032
1040
  return `a ${typeof value}`;
1033
1041
  }
1042
+ function detectLineEnding(text) {
1043
+ const match = /\r\n|\n|\r/.exec(text);
1044
+ return match === null ? "\n" : match[0];
1045
+ }
1034
1046
  function terminateWithNewline(text) {
1035
- 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}
1036
1050
  `;
1051
+ return text + eol;
1037
1052
  }
1038
1053
  function findLegacyKey(keys) {
1039
1054
  return LEGACY_ENTRY_NAMES.find((name) => keys.includes(name)) ?? null;
@@ -1101,11 +1116,82 @@ function containerKeysAt(raw, site, prefix) {
1101
1116
  function siteAt(site, containerPath) {
1102
1117
  return { ...site, resolved: { ...site.resolved, containerPath: [...containerPath] } };
1103
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
+ }
1104
1190
  async function readClientConfigFile(site, opts = {}) {
1105
- const load = opts.readFile ?? ((path3) => readFile(path3, "utf8"));
1106
- let raw;
1191
+ const load = opts.readFile ?? ((path3) => readFile(path3));
1192
+ let loaded;
1107
1193
  try {
1108
- raw = await load(site.resolved.absolute);
1194
+ loaded = await load(site.resolved.absolute);
1109
1195
  } catch (err) {
1110
1196
  const code = err?.code;
1111
1197
  if (code === "ENOENT") return classifyClientConfig(null, site, opts);
@@ -1116,7 +1202,14 @@ async function readClientConfigFile(site, opts = {}) {
1116
1202
  };
1117
1203
  return makeView(read, null, addressOf(site), 0, adapterFor(site.format), opts);
1118
1204
  }
1119
- 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);
1120
1213
  }
1121
1214
  var ClientConfigWriteError = class extends Error {
1122
1215
  constructor(message) {
@@ -1129,21 +1222,41 @@ function applyClientConfigEdits(view, edits, site) {
1129
1222
  const where = site === void 0 ? "the config file" : site.resolved.absolute;
1130
1223
  const { adapter, address, read } = view;
1131
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
+ }
1132
1234
  if (read.kind === "absent") {
1133
- const only = edits[0];
1134
- 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) {
1135
1244
  throw new ClientConfigWriteError(
1136
- `${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`
1137
1246
  );
1138
1247
  }
1139
- let fresh;
1248
+ let fresh = view.raw !== null && detectLineEnding(view.raw) === "\r\n" ? view.raw : null;
1140
1249
  try {
1141
- 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
+ }
1142
1254
  } catch (err) {
1143
1255
  throw new ClientConfigWriteError(
1144
1256
  `${where} could not be created (${err instanceof Error ? err.message : String(err)})`
1145
1257
  );
1146
1258
  }
1259
+ if (fresh === null) throw new ClientConfigWriteError(`${where} could not be created (no edit produced text)`);
1147
1260
  verifyEdits(adapter, address, null, fresh, edits, where, view);
1148
1261
  return fresh;
1149
1262
  }
@@ -1168,6 +1281,7 @@ function applyClientConfigEdits(view, edits, site) {
1168
1281
  for (const edit of edits) {
1169
1282
  if (edit.op === "upsert") text = adapter.upsert(text, address, edit.key, edit.entry);
1170
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);
1171
1285
  else text = adapter.repairContainer(text, address, edit.path);
1172
1286
  }
1173
1287
  } catch (err) {
@@ -1203,8 +1317,10 @@ function sameSegments(a, b) {
1203
1317
  }
1204
1318
  function verifyEdits(adapter, address, before, after, edits, where, view) {
1205
1319
  const touched = /* @__PURE__ */ new Set();
1320
+ const rootKeys = [];
1206
1321
  for (const edit of edits) {
1207
- 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);
1208
1324
  }
1209
1325
  let reread = adapter.classify(after, address, void 0);
1210
1326
  if (reread.kind === "absent" && edits.every((edit) => edit.op === "remove")) {
@@ -1248,9 +1364,31 @@ function verifyEdits(adapter, address, before, after, edits, where, view) {
1248
1364
  );
1249
1365
  }
1250
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
+ }
1251
1388
  if (before !== null) {
1252
1389
  const containerChanged = edits.some((edit) => edit.op === "repair") || view.read.kind === "ok" && !view.read.containerPresent;
1253
- 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 };
1254
1392
  if (adapter.canon(before, address, opts) !== adapter.canon(after, address, opts)) {
1255
1393
  throw new ClientConfigWriteError(
1256
1394
  `writing to ${where} would have changed other settings in the file -- nothing was written`
@@ -1258,6 +1396,99 @@ function verifyEdits(adapter, address, before, after, edits, where, view) {
1258
1396
  }
1259
1397
  }
1260
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
+ ];
1261
1492
  function readClientEnv(env = process.env) {
1262
1493
  const value = (name) => {
1263
1494
  const raw = env[name];
@@ -1509,8 +1740,7 @@ function describeTomlShape(value) {
1509
1740
  var isHorizontalSpace2 = (c) => c === " " || c === " ";
1510
1741
  var isBareKeyChar = (c) => c !== void 0 && /^[A-Za-z0-9_-]$/.test(c);
1511
1742
  function detectTomlEol(text) {
1512
- const match = /\r\n|\n|\r/.exec(text);
1513
- return match ? match[0] : "\n";
1743
+ return detectLineEnding(text);
1514
1744
  }
1515
1745
  function lineEnd(text, from) {
1516
1746
  let i = from;
@@ -1704,7 +1934,8 @@ function scanTomlSections(text) {
1704
1934
  section,
1705
1935
  keyPath: read.path,
1706
1936
  inlineTable: text[v] === "{",
1707
- start: lineStart
1937
+ start: lineStart,
1938
+ valueStart: v
1708
1939
  });
1709
1940
  pos = eq + 1;
1710
1941
  }
@@ -2234,10 +2465,11 @@ function canonValue(value) {
2234
2465
  }
2235
2466
  return value;
2236
2467
  }
2237
- function canonTomlConfig(raw, containerPath, drop = []) {
2468
+ function canonTomlConfig(raw, containerPath, drop = [], dropRoot = []) {
2238
2469
  const parsed = parseTomlConfig(raw);
2239
2470
  const value = canonValue(parsed);
2240
2471
  if (!isTomlTable(value)) return JSON.stringify(value);
2472
+ for (const key of dropRoot) delete value[key];
2241
2473
  let cursor = value;
2242
2474
  for (let i = 0; i < containerPath.length; i++) {
2243
2475
  const key = containerPath[i];
@@ -2299,6 +2531,91 @@ function verifyTomlSplice(before, after, containerPath, expectation = {}) {
2299
2531
  }
2300
2532
  }
2301
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
+ }
2302
2619
 
2303
2620
  // src/target-codex-cli.ts
2304
2621
  var CONTAINER_KEY = "mcp_servers";
@@ -2369,7 +2686,13 @@ function describeTomlLocation(absolute, _addr) {
2369
2686
  }
2370
2687
  function canonToml(raw, addr, opts = {}) {
2371
2688
  const drop = opts.dropContainer === true ? tomlEntryNames(readTomlConfig(raw, addr.containerPath)) : opts.drop ?? [];
2372
- 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);
2373
2696
  }
2374
2697
  var TOML_ADAPTER = {
2375
2698
  syntax: TOML_SYNTAX,
@@ -2379,7 +2702,11 @@ var TOML_ADAPTER = {
2379
2702
  repairContainer: repairTomlContainer,
2380
2703
  renderPreview: previewToml,
2381
2704
  describeLocation: describeTomlLocation,
2382
- 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
2383
2710
  };
2384
2711
  registerConfigAdapter("toml", TOML_ADAPTER);
2385
2712
  function resolveCodexPath(base) {
@@ -2465,10 +2792,16 @@ function codexImportView(stored) {
2465
2792
  if (discarded.length > 0) view.discardedKeys = discarded;
2466
2793
  return view;
2467
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
+ };
2468
2801
  var CODEX_CLI_TARGET = defineTarget({
2469
2802
  clientId: "codex-cli",
2470
2803
  label: "Codex CLI",
2471
- config: { format: "toml", root: CONTAINER_KEY },
2804
+ config: { format: "toml", root: CONTAINER_KEY, rootDefaults: [STARTUP_GRACE_DEFAULT] },
2472
2805
  availableOn: ["macos", "linux", "windows"],
2473
2806
  entry: {
2474
2807
  normalize: normalizeCodexEntry,
@@ -2482,6 +2815,13 @@ var CODEX_CLI_TARGET = defineTarget({
2482
2815
  // magnitude for that launch and 60 is not. A genuinely COLD fetch (a fresh
2483
2816
  // machine, or the first spawn after a new release) can still exceed it --
2484
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.
2485
2825
  extraFields: () => ({ startup_timeout_sec: 60 }),
2486
2826
  // Bare `npx` on Windows: Codex resolves the `.cmd` shim itself (S2), which
2487
2827
  // is also what `codex mcp add` writes, so a `cmd /c` entry of ours would
@@ -2494,7 +2834,7 @@ var CODEX_CLI_TARGET = defineTarget({
2494
2834
  windowsLaunch: { broker: "bare", upstream: "cmd-wrap" },
2495
2835
  forImport: codexImportView
2496
2836
  },
2497
- 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.",
2498
2838
  resolvePath: resolveCodexPath,
2499
2839
  scopes: [
2500
2840
  // User FIRST, like every other multi-scope row: the probe walks this array
@@ -2843,8 +3183,7 @@ async function prepareClaudeCodeSettingsPatch(opts) {
2843
3183
  }
2844
3184
  try {
2845
3185
  const next = patchPermissionsAllowText(rawSettings, [CLAUDE_CODE_ALLOW_PATTERN], op);
2846
- return { path: path3, nextJson: next.endsWith("\n") ? next : `${next}
2847
- `, changed: true, added, removed, fingerprint };
3186
+ return { path: path3, nextJson: terminateWithNewline(next), changed: true, added, removed, fingerprint };
2848
3187
  } catch (e) {
2849
3188
  return {
2850
3189
  path: path3,
@@ -4391,7 +4730,10 @@ function defaultInstalledVersion(pkgDir) {
4391
4730
  function killProcessTree(child, platform = process.platform, spawnImpl = spawn2) {
4392
4731
  if (platform === "win32" && child.pid !== void 0) {
4393
4732
  try {
4394
- spawnImpl("taskkill", ["/pid", String(child.pid), "/T", "/F"], { stdio: "ignore" }).on("error", () => {
4733
+ spawnImpl("taskkill", ["/pid", String(child.pid), "/T", "/F"], {
4734
+ stdio: "ignore",
4735
+ env: stripInternalSecretsFromEnv(process.env)
4736
+ }).on("error", () => {
4395
4737
  });
4396
4738
  } catch {
4397
4739
  }
@@ -4563,7 +4905,7 @@ async function oamFloorLines(probe) {
4563
4905
  }
4564
4906
  async function defaultRunningPrefix(argvPath) {
4565
4907
  if (process.env.VITEST) return null;
4566
- const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-H5NMT5BV.js");
4908
+ const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-FMCVLIO7.js");
4567
4909
  return detectRunningInstallPrefix2(argvPath);
4568
4910
  }
4569
4911
  async function defaultSpawn(cmd, args, cwd) {
@@ -4624,7 +4966,7 @@ async function runUpgrade(opts = {}) {
4624
4966
  if (method === "global-npm") {
4625
4967
  const rawPrefix = await (opts.runningPrefix ?? defaultRunningPrefix)(argvPath);
4626
4968
  if (rawPrefix !== null) {
4627
- const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-H5NMT5BV.js");
4969
+ const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-FMCVLIO7.js");
4628
4970
  const spawnForm = quoteShellArgIfNeeded2(rawPrefix, opts.platform);
4629
4971
  const displayForm = quoteArgForDisplay2(rawPrefix, opts.platform);
4630
4972
  if (spawnForm !== null && displayForm !== null) {
@@ -4741,7 +5083,7 @@ async function runUpgrade(opts = {}) {
4741
5083
  return { exitCode: 3, lines };
4742
5084
  }
4743
5085
  function readCurrentVersion() {
4744
- return true ? "1.0.13" : "dev";
5086
+ return true ? "1.0.16" : "dev";
4745
5087
  }
4746
5088
 
4747
5089
  // src/auto-upgrade.ts
@@ -5022,7 +5364,7 @@ function defaultSpawn2(cmd, args, onDone = () => {
5022
5364
  }
5023
5365
  async function maybeAutoUpgrade(deps = {}) {
5024
5366
  if (isFeatureDisabled("YAW_MCP_AUTO_UPGRADE")) return;
5025
- const current = deps.currentVersion ?? (true ? "1.0.13" : "dev");
5367
+ const current = deps.currentVersion ?? (true ? "1.0.16" : "dev");
5026
5368
  if (current === "dev") return;
5027
5369
  const argvPath = deps.argvPath ?? process.argv[1];
5028
5370
  const method = (deps.isSeaImpl ? await deps.isSeaImpl() : await detectSea()) ? "binary" : detectInstallMethod(argvPath, realpathSync3, ["unknown", "local-node-modules"]);
@@ -5129,7 +5471,7 @@ async function maybeAutoUpgrade(deps = {}) {
5129
5471
  }
5130
5472
 
5131
5473
  export {
5132
- INTERNAL_SECRET_ENV_KEYS,
5474
+ isInternalSecretEnvKey,
5133
5475
  scrubInternalSecretsFromProcessEnv,
5134
5476
  stripInternalSecretsFromEnv,
5135
5477
  setLogSurface,
@@ -5157,6 +5499,7 @@ export {
5157
5499
  ENTRY_NAME,
5158
5500
  LEGACY_ENTRY_NAMES,
5159
5501
  resolveAppDataDir,
5502
+ CONFIG_FORMATS,
5160
5503
  syntaxNameFor,
5161
5504
  containerNounFor,
5162
5505
  effectiveConfigFormat,
@@ -5171,13 +5514,18 @@ export {
5171
5514
  composeEntry,
5172
5515
  reloadDoneClause,
5173
5516
  reloadRemovalClause,
5517
+ hasConfigAdapter,
5174
5518
  describeValueShape,
5175
5519
  terminateWithNewline,
5176
5520
  classifyClientConfig,
5177
5521
  containerKeysAt,
5178
5522
  siteAt,
5523
+ decodeClientConfigBytes,
5179
5524
  readClientConfigFile,
5180
5525
  applyClientConfigEdits,
5526
+ planRootDefaults,
5527
+ previewRootDefaults,
5528
+ CLIENT_ENV_VARS,
5181
5529
  readClientEnv,
5182
5530
  CLAUDE_CODE_ALLOW_PATTERN,
5183
5531
  resolveClaudeCodeSettingsPath,