@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.
- package/CHANGELOG.md +215 -2
- package/README.md +9 -7
- package/dist/{auto-upgrade-H5NMT5BV.js → auto-upgrade-FMCVLIO7.js} +1 -1
- package/dist/{chunk-JSNVFUDY.js → chunk-IHHY6MVU.js} +383 -35
- package/dist/index.js +1515 -763
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,11 +3,12 @@ import {
|
|
|
3
3
|
ALLOW_UNOWNED_ENV,
|
|
4
4
|
BINARY_RETIRED_HINT,
|
|
5
5
|
CLAUDE_CODE_ALLOW_PATTERN,
|
|
6
|
+
CLIENT_ENV_VARS,
|
|
6
7
|
CONFIG_DIRNAME,
|
|
8
|
+
CONFIG_FORMATS,
|
|
7
9
|
CURRENT_OS,
|
|
8
10
|
ENTRY_NAME,
|
|
9
11
|
INSTALL_TARGETS,
|
|
10
|
-
INTERNAL_SECRET_ENV_KEYS,
|
|
11
12
|
LEGACY_ENTRY_NAMES,
|
|
12
13
|
MIN_OAM_VERSION,
|
|
13
14
|
POSIX_SHELL,
|
|
@@ -30,6 +31,7 @@ import {
|
|
|
30
31
|
containerKeysAt,
|
|
31
32
|
containerNounFor,
|
|
32
33
|
createStreamWriter,
|
|
34
|
+
decodeClientConfigBytes,
|
|
33
35
|
describeJsonShape,
|
|
34
36
|
describeValueShape,
|
|
35
37
|
detectInstallMethod,
|
|
@@ -41,8 +43,10 @@ import {
|
|
|
41
43
|
findLegacyEntry,
|
|
42
44
|
findProjectConfigDir,
|
|
43
45
|
guidePath,
|
|
46
|
+
hasConfigAdapter,
|
|
44
47
|
importViewOf,
|
|
45
48
|
isFeatureDisabled,
|
|
49
|
+
isInternalSecretEnvKey,
|
|
46
50
|
isOamCommand,
|
|
47
51
|
isOamLaunch,
|
|
48
52
|
isProjectLocalEntry,
|
|
@@ -65,8 +69,10 @@ import {
|
|
|
65
69
|
packageName,
|
|
66
70
|
parseJsonc,
|
|
67
71
|
parseUpgradeArgs,
|
|
72
|
+
planRootDefaults,
|
|
68
73
|
powershellPayload,
|
|
69
74
|
prepareClaudeCodeSettingsPatch,
|
|
75
|
+
previewRootDefaults,
|
|
70
76
|
probeOam,
|
|
71
77
|
quoteArgForDisplay,
|
|
72
78
|
readClientConfigFile,
|
|
@@ -101,7 +107,7 @@ import {
|
|
|
101
107
|
unparseableConfigFix,
|
|
102
108
|
userConfigDir,
|
|
103
109
|
yawModeOverlay
|
|
104
|
-
} from "./chunk-
|
|
110
|
+
} from "./chunk-IHHY6MVU.js";
|
|
105
111
|
|
|
106
112
|
// src/audit-cmd.ts
|
|
107
113
|
import { homedir as homedir6 } from "os";
|
|
@@ -261,7 +267,10 @@ function killTree(child) {
|
|
|
261
267
|
if (pid !== void 0) {
|
|
262
268
|
if (process.platform === "win32") {
|
|
263
269
|
try {
|
|
264
|
-
const killer = spawn("taskkill", ["/pid", String(pid), "/T", "/F"], {
|
|
270
|
+
const killer = spawn("taskkill", ["/pid", String(pid), "/T", "/F"], {
|
|
271
|
+
stdio: "ignore",
|
|
272
|
+
env: stripInternalSecretsFromEnv(process.env)
|
|
273
|
+
});
|
|
265
274
|
killer.on("error", () => {
|
|
266
275
|
});
|
|
267
276
|
return;
|
|
@@ -1631,6 +1640,7 @@ function isValidKdfParams(v) {
|
|
|
1631
1640
|
if (r < 1 || r > MAX_KDF_R) return false;
|
|
1632
1641
|
if (p < 1 || p > MAX_KDF_P) return false;
|
|
1633
1642
|
if (kdfMemoryBytes(N, r) > MAX_KDF_MEMORY_BYTES) return false;
|
|
1643
|
+
if (r < 4 && N >= 2 ** (16 * r)) return false;
|
|
1634
1644
|
return true;
|
|
1635
1645
|
}
|
|
1636
1646
|
function generateSalt() {
|
|
@@ -1687,21 +1697,11 @@ var SECRETS_SCHEMA_VERSION = 2;
|
|
|
1687
1697
|
var LEGACY_SCHEMA_VERSION = 1;
|
|
1688
1698
|
var VAULT_CHECK_AAD = "yaw-mcp:vault-check";
|
|
1689
1699
|
var VAULT_CHECK_PLAINTEXT = "yaw-mcp-vault-v1";
|
|
1690
|
-
var VAULT_CHECK_CORRUPT_ERROR = 'vault verification token ("check") is corrupt -- the passphrase is correct, but the check marker does not
|
|
1700
|
+
var VAULT_CHECK_CORRUPT_ERROR = 'vault verification token ("check") is corrupt -- the passphrase is correct, but the check marker does not verify';
|
|
1691
1701
|
var VAULT_WRONG_PASSPHRASE_ERROR = "wrong passphrase for this vault (decryption failed)";
|
|
1692
1702
|
function vaultPath(home = homedir4()) {
|
|
1693
1703
|
return join5(home, CONFIG_DIRNAME, SECRETS_FILENAME);
|
|
1694
1704
|
}
|
|
1695
|
-
function emptyVault() {
|
|
1696
|
-
return {
|
|
1697
|
-
version: SECRETS_SCHEMA_VERSION,
|
|
1698
|
-
salt: generateSalt().toString("base64"),
|
|
1699
|
-
// Recorded, never assumed: see KdfParams. A vault that carries its own
|
|
1700
|
-
// cost factor keeps opening after the default is raised.
|
|
1701
|
-
kdf: { ...DEFAULT_KDF },
|
|
1702
|
-
entries: {}
|
|
1703
|
-
};
|
|
1704
|
-
}
|
|
1705
1705
|
var VaultEntryCorruptError = class extends Error {
|
|
1706
1706
|
entryName;
|
|
1707
1707
|
constructor(entryName) {
|
|
@@ -1710,28 +1710,33 @@ var VaultEntryCorruptError = class extends Error {
|
|
|
1710
1710
|
this.entryName = entryName;
|
|
1711
1711
|
}
|
|
1712
1712
|
};
|
|
1713
|
-
async function loadVault(path5) {
|
|
1713
|
+
async function loadVault(path5, opts) {
|
|
1714
|
+
const onWarning = opts?.onWarning;
|
|
1714
1715
|
let raw;
|
|
1715
1716
|
try {
|
|
1716
1717
|
raw = await readFile5(path5, "utf8");
|
|
1717
1718
|
} catch (err) {
|
|
1718
1719
|
const code = err.code;
|
|
1719
1720
|
if (code === "ENOENT") return null;
|
|
1720
|
-
|
|
1721
|
+
if (!onWarning) {
|
|
1722
|
+
log("warn", "Failed to read vault", { path: path5, error: err instanceof Error ? err.message : String(err), code });
|
|
1723
|
+
}
|
|
1721
1724
|
throw err;
|
|
1722
1725
|
}
|
|
1723
1726
|
let parsed;
|
|
1724
1727
|
try {
|
|
1725
1728
|
parsed = JSON.parse(raw);
|
|
1726
1729
|
} catch (err) {
|
|
1727
|
-
|
|
1730
|
+
if (!onWarning) {
|
|
1731
|
+
log("warn", "Vault file is not valid JSON", { path: path5, error: err instanceof Error ? err.message : String(err) });
|
|
1732
|
+
}
|
|
1728
1733
|
throw new Error(`vault at ${path5} is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
1729
1734
|
}
|
|
1730
1735
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1731
1736
|
throw new Error(`vault at ${path5} is corrupt: root must be a JSON object`);
|
|
1732
1737
|
}
|
|
1733
1738
|
const obj = parsed;
|
|
1734
|
-
if (typeof obj.salt !== "string" || !obj.entries || typeof obj.entries !== "object") {
|
|
1739
|
+
if (typeof obj.salt !== "string" || !obj.entries || typeof obj.entries !== "object" || Array.isArray(obj.entries)) {
|
|
1735
1740
|
throw new Error(`vault at ${path5} is corrupt: missing or invalid salt/entries`);
|
|
1736
1741
|
}
|
|
1737
1742
|
if (Buffer.from(obj.salt, "base64").length !== SALT_LEN) {
|
|
@@ -1755,7 +1760,9 @@ async function loadVault(path5) {
|
|
|
1755
1760
|
}
|
|
1756
1761
|
}
|
|
1757
1762
|
if (obj.check !== void 0 && !isEncryptedEntry(obj.check)) {
|
|
1758
|
-
|
|
1763
|
+
const message = "Vault verification token is malformed; ignoring it (the next `yaw-mcp secrets set` re-stamps it)";
|
|
1764
|
+
if (onWarning) onWarning({ kind: "check-malformed", path: path5, message });
|
|
1765
|
+
else log("warn", message, { path: path5 });
|
|
1759
1766
|
}
|
|
1760
1767
|
const check = isEncryptedEntry(obj.check) ? obj.check : void 0;
|
|
1761
1768
|
return {
|
|
@@ -1876,14 +1883,17 @@ async function checkVaultPassphrase(vault, passphrase) {
|
|
|
1876
1883
|
(await unlock(vault, passphrase)).fill(0);
|
|
1877
1884
|
return "opens";
|
|
1878
1885
|
} catch (err) {
|
|
1879
|
-
|
|
1886
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1887
|
+
if (msg === VAULT_CHECK_CORRUPT_ERROR) return "marker-corrupt";
|
|
1888
|
+
if (msg === VAULT_WRONG_PASSPHRASE_ERROR) return "wrong";
|
|
1889
|
+
throw err;
|
|
1880
1890
|
}
|
|
1881
1891
|
}
|
|
1882
1892
|
function vaultCheckCorruptHint(path5) {
|
|
1883
1893
|
return `Your entries are intact: delete the "check" key from ${path5} by hand and re-run -- the next \`yaw-mcp secrets set\` re-stamps it.`;
|
|
1884
1894
|
}
|
|
1885
1895
|
async function createEmptyVault(passphrase) {
|
|
1886
|
-
const vault =
|
|
1896
|
+
const vault = newVault();
|
|
1887
1897
|
const key = await deriveKey(passphrase, Buffer.from(vault.salt, "base64"), DEFAULT_KDF);
|
|
1888
1898
|
try {
|
|
1889
1899
|
return ensureCheck(vault, key);
|
|
@@ -1901,6 +1911,11 @@ async function rotateVault(vault, oldKey, newPassphrase) {
|
|
|
1901
1911
|
plaintext.set(name, decryptBound(vault, entry, oldKey, name));
|
|
1902
1912
|
} catch {
|
|
1903
1913
|
plaintext.clear();
|
|
1914
|
+
if (vault.check) {
|
|
1915
|
+
throw new Error(
|
|
1916
|
+
`rotate aborted: entry "${name}" failed to decrypt, but the passphrase is right (the vault's check marker verifies under it) -- the entry is corrupt, or was written under a different passphrase than the rest of the vault. Remove it (\`yaw-mcp secrets remove ${name}\`), set it again, and re-run rotate.`
|
|
1917
|
+
);
|
|
1918
|
+
}
|
|
1904
1919
|
throw new Error(`rotate aborted: entry "${name}" failed to decrypt under the current passphrase`);
|
|
1905
1920
|
}
|
|
1906
1921
|
}
|
|
@@ -1959,7 +1974,14 @@ function getSecret(vault, key, name) {
|
|
|
1959
1974
|
return decryptBound(vault, entry, key, name);
|
|
1960
1975
|
}
|
|
1961
1976
|
function newVault() {
|
|
1962
|
-
return
|
|
1977
|
+
return {
|
|
1978
|
+
version: SECRETS_SCHEMA_VERSION,
|
|
1979
|
+
salt: generateSalt().toString("base64"),
|
|
1980
|
+
// Recorded, never assumed: see KdfParams. A vault that carries its own
|
|
1981
|
+
// cost factor keeps opening after the default is raised.
|
|
1982
|
+
kdf: { ...DEFAULT_KDF },
|
|
1983
|
+
entries: {}
|
|
1984
|
+
};
|
|
1963
1985
|
}
|
|
1964
1986
|
var SECRET_REF_RE = new RegExp(`\\$\\{secret:(${SECRET_NAME_CLASS})\\}`, "g");
|
|
1965
1987
|
function resolveSecretRefs(env, vault, key) {
|
|
@@ -2081,12 +2103,28 @@ import {
|
|
|
2081
2103
|
ToolListChangedNotificationSchema
|
|
2082
2104
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
2083
2105
|
|
|
2106
|
+
// src/bundles-hint.ts
|
|
2107
|
+
function bundlesFileHint(which) {
|
|
2108
|
+
const file = which === "defines-it" ? "the bundles.json that defines it" : "the bundles.json in effect";
|
|
2109
|
+
return `${file} (~/.yaw-mcp/bundles.json, or a trusted project-local .yaw-mcp/bundles.json)`;
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2084
2112
|
// src/credentials.ts
|
|
2113
|
+
var NAME = "[A-Z_][A-Z0-9_]{2,}";
|
|
2114
|
+
var GAP = "[^\\S\\r\\n]+";
|
|
2115
|
+
var SEP = "(?:[^\\S\\r\\n]*:\\s+|[^\\S\\r\\n]+)";
|
|
2116
|
+
var QUOTE = "[\"'`]?";
|
|
2117
|
+
var ENV_WORDS = `(?:(?:env|environment)${GAP})?(?:(?:variable|var)${GAP})?`;
|
|
2118
|
+
var LEADING_ENV_WORDS = `(?:(?:env|environment)${SEP})?(?:(?:variables?|vars?)${SEP})?`;
|
|
2085
2119
|
var MISSING_PATTERNS = [
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2120
|
+
new RegExp(`\\bmissing${SEP}(?:required${GAP})?${LEADING_ENV_WORDS}${QUOTE}(${NAME})\\b`, "gi"),
|
|
2121
|
+
new RegExp(
|
|
2122
|
+
`\\b(${NAME})${QUOTE}${GAP}${ENV_WORDS}(?:is${GAP}(?:required|missing|empty|undefined)|(?:is${GAP})?(?:not${GAP}set|unset|not${GAP}provided))\\b`,
|
|
2123
|
+
"gi"
|
|
2124
|
+
),
|
|
2125
|
+
new RegExp(`\\b(${NAME})${QUOTE}${GAP}${ENV_WORDS}must${GAP}be${GAP}set\\b`, "gi"),
|
|
2126
|
+
new RegExp(`\\bplease${GAP}set${GAP}(?:the${GAP})?${LEADING_ENV_WORDS}${QUOTE}(${NAME})\\b`, "gi"),
|
|
2127
|
+
new RegExp(`\\bno${GAP}${QUOTE}(${NAME})${QUOTE}${GAP}${ENV_WORDS}(?:provided|set)\\b`, "gi")
|
|
2090
2128
|
];
|
|
2091
2129
|
var CREDENTIAL_SEGMENTS = /* @__PURE__ */ new Set([
|
|
2092
2130
|
"TOKEN",
|
|
@@ -2122,6 +2160,7 @@ var CREDENTIAL_SEGMENTS = /* @__PURE__ */ new Set([
|
|
|
2122
2160
|
]);
|
|
2123
2161
|
var CREDENTIAL_NOUN_SUFFIXES = ["TOKEN", "SECRET", "PASSWORD", "PASSPHRASE", "CREDENTIAL"];
|
|
2124
2162
|
var CREDENTIAL_SUBSTRINGS = ["TOKEN", "SECRET", "PASSWORD", "PASSPHRASE", "APIKEY", "CREDENTIAL"];
|
|
2163
|
+
var LOCATOR_SEGMENTS = /* @__PURE__ */ new Set(["PATH", "FILE", "DIR", "HOST", "PORT", "PREFIX", "SIZE"]);
|
|
2125
2164
|
var IGNORED = /* @__PURE__ */ new Set([
|
|
2126
2165
|
"PATH",
|
|
2127
2166
|
"HOME",
|
|
@@ -2158,11 +2197,14 @@ var IGNORED = /* @__PURE__ */ new Set([
|
|
|
2158
2197
|
"VALUE",
|
|
2159
2198
|
"VAR"
|
|
2160
2199
|
]);
|
|
2200
|
+
var ALL_CAPS_NAME = new RegExp(`^${NAME}$`);
|
|
2161
2201
|
function isAllCaps(name) {
|
|
2162
|
-
return
|
|
2202
|
+
return ALL_CAPS_NAME.test(name);
|
|
2163
2203
|
}
|
|
2164
2204
|
function isCredentialShaped(name) {
|
|
2165
|
-
|
|
2205
|
+
const segments = name.split("_");
|
|
2206
|
+
if (LOCATOR_SEGMENTS.has(segments[segments.length - 1] ?? "")) return false;
|
|
2207
|
+
for (const segment of segments) {
|
|
2166
2208
|
if (CREDENTIAL_SEGMENTS.has(segment)) return true;
|
|
2167
2209
|
if (CREDENTIAL_NOUN_SUFFIXES.some((noun) => segment.length > noun.length && segment.endsWith(noun))) {
|
|
2168
2210
|
return true;
|
|
@@ -2939,10 +2981,9 @@ async function verifyVaultPassphrase(passphrase) {
|
|
|
2939
2981
|
}
|
|
2940
2982
|
if (!vault) return true;
|
|
2941
2983
|
try {
|
|
2942
|
-
await
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
return (err instanceof Error ? err.message : String(err)) === VAULT_CHECK_CORRUPT_ERROR;
|
|
2984
|
+
return await checkVaultPassphrase(vault, passphrase) !== "wrong";
|
|
2985
|
+
} catch {
|
|
2986
|
+
return false;
|
|
2946
2987
|
}
|
|
2947
2988
|
}
|
|
2948
2989
|
function vaultPassphrase() {
|
|
@@ -3137,7 +3178,7 @@ function redactSecretsInOutput(text, env) {
|
|
|
3137
3178
|
}
|
|
3138
3179
|
function withConfigPointer(message, config) {
|
|
3139
3180
|
if (!config.namespace) return message;
|
|
3140
|
-
return `${message} -> Fix
|
|
3181
|
+
return `${message} -> Fix "${config.namespace}" in ${bundlesFileHint("defines-it")}, then activate it again -- the edit is picked up on the next mcp_connect_* call, with no client restart.`;
|
|
3141
3182
|
}
|
|
3142
3183
|
function categorizeSpawnError(err) {
|
|
3143
3184
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -3230,7 +3271,7 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
3230
3271
|
if (downstreamCaps?.sampling) capabilities.sampling = downstreamCaps.sampling;
|
|
3231
3272
|
if (downstreamCaps?.roots) capabilities.roots = {};
|
|
3232
3273
|
const client = new Client(
|
|
3233
|
-
{ name: "yaw-mcp", version: true ? "1.0.
|
|
3274
|
+
{ name: "yaw-mcp", version: true ? "1.0.16" : "dev" },
|
|
3234
3275
|
{ capabilities }
|
|
3235
3276
|
);
|
|
3236
3277
|
if (bridge && capabilities.elicitation) {
|
|
@@ -4810,6 +4851,47 @@ import { readFile as readFile9, stat as stat4 } from "fs/promises";
|
|
|
4810
4851
|
import { homedir as homedir9 } from "os";
|
|
4811
4852
|
import { basename as basename2, isAbsolute, join as join9, resolve as resolve4 } from "path";
|
|
4812
4853
|
|
|
4854
|
+
// src/readline-question.ts
|
|
4855
|
+
import { createInterface } from "readline/promises";
|
|
4856
|
+
var QUESTION_CANCELLED = /* @__PURE__ */ Symbol("yaw-mcp:question-cancelled");
|
|
4857
|
+
async function questionOrEmpty(rl, prompt) {
|
|
4858
|
+
if (rl.closed === true) return "";
|
|
4859
|
+
const ac = new AbortController();
|
|
4860
|
+
let cancelled = false;
|
|
4861
|
+
const onClose = () => ac.abort();
|
|
4862
|
+
const onSigint = () => {
|
|
4863
|
+
cancelled = true;
|
|
4864
|
+
ac.abort();
|
|
4865
|
+
};
|
|
4866
|
+
rl.once("close", onClose);
|
|
4867
|
+
rl.once("SIGINT", onSigint);
|
|
4868
|
+
try {
|
|
4869
|
+
return await rl.question(prompt, { signal: ac.signal });
|
|
4870
|
+
} catch (err) {
|
|
4871
|
+
if (cancelled) return QUESTION_CANCELLED;
|
|
4872
|
+
if (ac.signal.aborted) return "";
|
|
4873
|
+
throw err;
|
|
4874
|
+
} finally {
|
|
4875
|
+
rl.off("close", onClose);
|
|
4876
|
+
rl.off("SIGINT", onSigint);
|
|
4877
|
+
}
|
|
4878
|
+
}
|
|
4879
|
+
async function readlineAnswer(input, output, question, terminal) {
|
|
4880
|
+
const rl = createInterface({ input, output, terminal });
|
|
4881
|
+
try {
|
|
4882
|
+
return await questionOrEmpty(rl, question);
|
|
4883
|
+
} finally {
|
|
4884
|
+
rl.close();
|
|
4885
|
+
}
|
|
4886
|
+
}
|
|
4887
|
+
async function askYesNo(opts, question, read = readlineAnswer) {
|
|
4888
|
+
if (opts.promptAnswer !== void 0) return opts.promptAnswer.trim().toLowerCase();
|
|
4889
|
+
const input = opts.io?.stdin ?? process.stdin;
|
|
4890
|
+
const output = opts.io?.stdout ?? process.stdout;
|
|
4891
|
+
const raw = await read(input, output, question, opts.io?.terminal);
|
|
4892
|
+
return raw === QUESTION_CANCELLED ? raw : raw.trim().toLowerCase();
|
|
4893
|
+
}
|
|
4894
|
+
|
|
4813
4895
|
// src/secrets-cmd.ts
|
|
4814
4896
|
import { createHash as createHash4 } from "crypto";
|
|
4815
4897
|
import { chmod as chmod5, copyFile, constants as fsConstants, readFile as readFile8, unlink } from "fs/promises";
|
|
@@ -4819,12 +4901,13 @@ var SECRETS_USAGE = `Usage: yaw-mcp secrets <action> [args]
|
|
|
4819
4901
|
Manage your encrypted secret vault at ~/.yaw-mcp/secrets.json.
|
|
4820
4902
|
|
|
4821
4903
|
Actions:
|
|
4822
|
-
set <name> Store a secret.
|
|
4823
|
-
line, no echo
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4904
|
+
set <name> Store a secret. At a terminal, prompts for the
|
|
4905
|
+
value (one line, no echo; a bare Enter asks
|
|
4906
|
+
again). A piped stdin is read whole instead,
|
|
4907
|
+
minus one trailing newline. Or pass --value <v>.
|
|
4908
|
+
Setting a name that already exists REPLACES it
|
|
4909
|
+
(confirmed first on a TTY; scripted runs proceed
|
|
4910
|
+
and say "Replaced" instead of "Stored").
|
|
4828
4911
|
get <name> Decrypt and print one secret value to stdout.
|
|
4829
4912
|
NOTE: this prints the secret in CLEARTEXT (with
|
|
4830
4913
|
or without --json). Redirect to a file or pipe
|
|
@@ -4882,22 +4965,27 @@ Actions:
|
|
|
4882
4965
|
string, not the bare name.
|
|
4883
4966
|
|
|
4884
4967
|
Flags:
|
|
4885
|
-
--json Machine-readable output
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
schema-behind file, a
|
|
4889
|
-
just created or reset
|
|
4890
|
-
|
|
4891
|
-
|
|
4968
|
+
--json Machine-readable output. stdout carries the result
|
|
4969
|
+
envelope, one JSON line; stderr carries one JSON
|
|
4970
|
+
object per line: {"warning":...} lines (a
|
|
4971
|
+
schema-behind file, a malformed check marker, a
|
|
4972
|
+
short passphrase, a vault just created or reset,
|
|
4973
|
+
a value printed in cleartext to a terminal) and,
|
|
4974
|
+
on failure, the {"ok":false,"error":...} envelope
|
|
4975
|
+
last -- an argument error too (exit 2, no usage
|
|
4976
|
+
text). Key on "warning" vs "ok", never on line
|
|
4977
|
+
position.
|
|
4892
4978
|
--value <v> Inline secret value (set only). The value sits in
|
|
4893
4979
|
this process's argv, so it is visible to every
|
|
4894
4980
|
other local user via ps / /proc/<pid>/cmdline for
|
|
4895
4981
|
the whole run (which includes the ~100ms key
|
|
4896
4982
|
derivation), and it lands in your shell history.
|
|
4897
|
-
For scripting
|
|
4898
|
-
default no-echo prompt.
|
|
4899
|
-
--stdin Read the
|
|
4900
|
-
|
|
4983
|
+
For scripting pipe the value in on stdin;
|
|
4984
|
+
interactively use the default no-echo prompt.
|
|
4985
|
+
--stdin Read the value from stdin even when stdin is a
|
|
4986
|
+
terminal (set only): raw, multi-line, until EOF,
|
|
4987
|
+
and the terminal echoes it. A piped stdin is read
|
|
4988
|
+
that way without the flag. Either way the value
|
|
4901
4989
|
never appears in argv.
|
|
4902
4990
|
--force Skip the destructive-action confirmation
|
|
4903
4991
|
(remove, reset, and a set that overwrites an
|
|
@@ -4922,8 +5010,19 @@ Forgot the passphrase?
|
|
|
4922
5010
|
moves the old file aside (kept, in case the passphrase turns up), lists
|
|
4923
5011
|
the entry names you have to set again, and starts an empty vault under a
|
|
4924
5012
|
new passphrase.`;
|
|
5013
|
+
var SECRETS_ACTIONS = ["set", "get", "list", "remove", "lock", "rotate", "reset", "audit"];
|
|
5014
|
+
function isSecretsAction(a) {
|
|
5015
|
+
return typeof a === "string" && SECRETS_ACTIONS.includes(a);
|
|
5016
|
+
}
|
|
4925
5017
|
function parseSecretsArgs(argv) {
|
|
5018
|
+
const json = argv.includes("--json");
|
|
4926
5019
|
const opts = {};
|
|
5020
|
+
const refuse = (msg) => ({
|
|
5021
|
+
ok: false,
|
|
5022
|
+
error: json ? JSON.stringify({ ok: false, error: msg }) : `yaw-mcp secrets${opts.action ? ` ${opts.action}` : ""}: ${msg}
|
|
5023
|
+
|
|
5024
|
+
${SECRETS_USAGE}`
|
|
5025
|
+
});
|
|
4927
5026
|
for (let i = 0; i < argv.length; i++) {
|
|
4928
5027
|
const a = argv[i];
|
|
4929
5028
|
if (a === "--help" || a === "-h") return { ok: false, error: SECRETS_USAGE, help: true };
|
|
@@ -4942,12 +5041,7 @@ function parseSecretsArgs(argv) {
|
|
|
4942
5041
|
if (a === "--value") {
|
|
4943
5042
|
const v = argv[++i];
|
|
4944
5043
|
if (v === void 0 || v.startsWith("-")) {
|
|
4945
|
-
return
|
|
4946
|
-
ok: false,
|
|
4947
|
-
error: `yaw-mcp secrets: --value requires a value (for a dash-leading value use --stdin)
|
|
4948
|
-
|
|
4949
|
-
${SECRETS_USAGE}`
|
|
4950
|
-
};
|
|
5044
|
+
return refuse("--value requires a value (for a dash-leading value use --stdin)");
|
|
4951
5045
|
}
|
|
4952
5046
|
opts.value = v;
|
|
4953
5047
|
continue;
|
|
@@ -4955,25 +5049,17 @@ ${SECRETS_USAGE}`
|
|
|
4955
5049
|
if (a === "--secret" || a === "--server") {
|
|
4956
5050
|
const v = argv[++i];
|
|
4957
5051
|
if (v === void 0 || v.startsWith("-")) {
|
|
4958
|
-
return {
|
|
4959
|
-
|
|
4960
|
-
${SECRETS_USAGE}` };
|
|
5052
|
+
return refuse(`${a} requires a value`);
|
|
4961
5053
|
}
|
|
4962
5054
|
if (a === "--secret") opts.secretFilter = v;
|
|
4963
5055
|
else opts.serverFilter = v;
|
|
4964
5056
|
continue;
|
|
4965
5057
|
}
|
|
4966
5058
|
if (a.startsWith("-")) {
|
|
4967
|
-
return
|
|
4968
|
-
|
|
4969
|
-
${SECRETS_USAGE}` };
|
|
5059
|
+
return refuse(`unknown flag "${a}"`);
|
|
4970
5060
|
}
|
|
4971
5061
|
if (!opts.action) {
|
|
4972
|
-
if (a
|
|
4973
|
-
return { ok: false, error: `yaw-mcp secrets: unknown action "${a}"
|
|
4974
|
-
|
|
4975
|
-
${SECRETS_USAGE}` };
|
|
4976
|
-
}
|
|
5062
|
+
if (!isSecretsAction(a)) return refuse(`unknown action "${a}"`);
|
|
4977
5063
|
opts.action = a;
|
|
4978
5064
|
continue;
|
|
4979
5065
|
}
|
|
@@ -4981,69 +5067,69 @@ ${SECRETS_USAGE}` };
|
|
|
4981
5067
|
opts.name = a;
|
|
4982
5068
|
continue;
|
|
4983
5069
|
}
|
|
4984
|
-
return
|
|
4985
|
-
|
|
4986
|
-
${SECRETS_USAGE}` };
|
|
5070
|
+
return refuse(`unexpected positional argument "${a}"`);
|
|
4987
5071
|
}
|
|
4988
|
-
if (!opts.action) return
|
|
4989
|
-
|
|
4990
|
-
${SECRETS_USAGE}` };
|
|
5072
|
+
if (!opts.action) return refuse("missing action");
|
|
4991
5073
|
if (opts.name !== void 0 && opts.action !== "set" && opts.action !== "get" && opts.action !== "remove") {
|
|
4992
5074
|
const hint = opts.action === "audit" ? ` -- audit takes no <name>; filter with \`--secret ${opts.name}\` or \`--server ${opts.name}\`` : ` -- ${opts.action} takes no <name>`;
|
|
4993
|
-
return {
|
|
4994
|
-
ok: false,
|
|
4995
|
-
error: `yaw-mcp secrets ${opts.action}: unexpected argument "${opts.name}"${hint}
|
|
4996
|
-
|
|
4997
|
-
${SECRETS_USAGE}`
|
|
4998
|
-
};
|
|
5075
|
+
return refuse(`unexpected argument "${opts.name}"${hint}`);
|
|
4999
5076
|
}
|
|
5000
5077
|
if (opts.action !== "set" && (opts.value !== void 0 || opts.fromStdin)) {
|
|
5001
5078
|
const flag = opts.value !== void 0 ? "--value" : "--stdin";
|
|
5002
|
-
return {
|
|
5003
|
-
|
|
5004
|
-
${SECRETS_USAGE}` };
|
|
5079
|
+
return refuse(`${flag} applies to \`set\` only`);
|
|
5005
5080
|
}
|
|
5006
5081
|
if (opts.value !== void 0 && opts.value.length === 0) {
|
|
5007
|
-
return
|
|
5008
|
-
|
|
5009
|
-
${SECRETS_USAGE}` };
|
|
5082
|
+
return refuse("Secret value cannot be empty.");
|
|
5010
5083
|
}
|
|
5011
5084
|
if (opts.action !== "audit" && (opts.secretFilter !== void 0 || opts.serverFilter !== void 0)) {
|
|
5012
5085
|
const flag = opts.secretFilter !== void 0 ? "--secret" : "--server";
|
|
5013
|
-
return {
|
|
5014
|
-
ok: false,
|
|
5015
|
-
error: `yaw-mcp secrets ${opts.action}: ${flag} applies to \`audit\` only
|
|
5016
|
-
|
|
5017
|
-
${SECRETS_USAGE}`
|
|
5018
|
-
};
|
|
5086
|
+
return refuse(`${flag} applies to \`audit\` only`);
|
|
5019
5087
|
}
|
|
5020
5088
|
if ((opts.action === "set" || opts.action === "get" || opts.action === "remove") && !opts.name) {
|
|
5021
|
-
return
|
|
5022
|
-
|
|
5023
|
-
${SECRETS_USAGE}` };
|
|
5089
|
+
return refuse("<name> is required");
|
|
5024
5090
|
}
|
|
5025
5091
|
if (opts.action === "set" && opts.name !== void 0 && !SECRET_NAME_RE.test(opts.name)) {
|
|
5026
|
-
return
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
${SECRETS_USAGE}`
|
|
5031
|
-
};
|
|
5092
|
+
return refuse(
|
|
5093
|
+
`invalid secret name "${opts.name}" -- use letters, digits, "_", "." or "-" only; other characters can never be referenced as \${secret:NAME}`
|
|
5094
|
+
);
|
|
5032
5095
|
}
|
|
5033
5096
|
return { ok: true, options: opts };
|
|
5034
5097
|
}
|
|
5098
|
+
function failResult(io, json, action, msg, opts = {}) {
|
|
5099
|
+
const { exitCode = 1, detail, detailAsHint = false, fields } = opts;
|
|
5100
|
+
if (json) {
|
|
5101
|
+
const error = detail !== void 0 && !detailAsHint ? `${msg} ${detail}` : msg;
|
|
5102
|
+
const hint = detail !== void 0 && detailAsHint ? { hint: detail } : {};
|
|
5103
|
+
io.err(`${JSON.stringify({ ok: false, error, ...hint, ...fields })}
|
|
5104
|
+
`);
|
|
5105
|
+
} else {
|
|
5106
|
+
io.err(`yaw-mcp secrets${action ? ` ${action}` : ""}: ${msg}
|
|
5107
|
+
${detail !== void 0 ? ` ${detail}
|
|
5108
|
+
` : ""}`);
|
|
5109
|
+
}
|
|
5110
|
+
return { exitCode };
|
|
5111
|
+
}
|
|
5112
|
+
function vaultLoadWarningNotice(io, warning, json) {
|
|
5113
|
+
if (json) {
|
|
5114
|
+
io.err(`${JSON.stringify({ warning: warning.kind, path: warning.path, message: warning.message })}
|
|
5115
|
+
`);
|
|
5116
|
+
return;
|
|
5117
|
+
}
|
|
5118
|
+
io.err(`yaw-mcp secrets: warning -- ${warning.path}: ${warning.message}.
|
|
5119
|
+
`);
|
|
5120
|
+
}
|
|
5121
|
+
function vaultUnreadableMessage(path5, error) {
|
|
5122
|
+
return `could not read the vault file at ${path5} (${error.code ?? error.message}) -- fix that and re-run.`;
|
|
5123
|
+
}
|
|
5035
5124
|
async function safeLoadVault(path5, io, json, action) {
|
|
5036
5125
|
try {
|
|
5037
|
-
return { ok: true, vault: await loadVault(path5) };
|
|
5126
|
+
return { ok: true, vault: await loadVault(path5, { onWarning: (w) => vaultLoadWarningNotice(io, w, json) }) };
|
|
5038
5127
|
} catch (err) {
|
|
5039
5128
|
const raw = err instanceof Error ? err.message : String(err);
|
|
5040
5129
|
const name = err instanceof VaultEntryCorruptError ? err.entryName : void 0;
|
|
5041
|
-
const
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
else io.err(`yaw-mcp secrets${action ? ` ${action}` : ""}: ${msg}
|
|
5045
|
-
`);
|
|
5046
|
-
return { ok: false, result: { exitCode: 1 } };
|
|
5130
|
+
const readError = err instanceof Error && typeof err.code === "string" ? err : void 0;
|
|
5131
|
+
const msg = name ? `secret entry ${name} is corrupt, and every secrets command fails until it is gone. Delete the "${name}" key from ${path5} by hand (or run \`yaw-mcp secrets reset\` to start the vault over -- it keeps the old file), then re-add it with \`yaw-mcp secrets set ${name}\`.` : readError ? vaultUnreadableMessage(path5, readError) : raw;
|
|
5132
|
+
return { ok: false, result: failResult(io, json, action, msg) };
|
|
5047
5133
|
}
|
|
5048
5134
|
}
|
|
5049
5135
|
function isVaultUnreadable(fp) {
|
|
@@ -5063,13 +5149,7 @@ async function vaultChangedSinceLoad(path5, baseline) {
|
|
|
5063
5149
|
return now !== baseline;
|
|
5064
5150
|
}
|
|
5065
5151
|
function vaultUnreadableResult(io, json, action, path5, fp) {
|
|
5066
|
-
|
|
5067
|
-
const msg = `could not read the vault file at ${path5} (${cause}) -- fix that and re-run. Nothing was written.`;
|
|
5068
|
-
if (json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5069
|
-
`);
|
|
5070
|
-
else io.err(`yaw-mcp secrets${action ? ` ${action}` : ""}: ${msg}
|
|
5071
|
-
`);
|
|
5072
|
-
return { exitCode: 1 };
|
|
5152
|
+
return failResult(io, json, action, `${vaultUnreadableMessage(path5, fp.error)} Nothing was written.`);
|
|
5073
5153
|
}
|
|
5074
5154
|
async function trySaveVault(path5, vault) {
|
|
5075
5155
|
try {
|
|
@@ -5083,20 +5163,15 @@ async function trySaveVault(path5, vault) {
|
|
|
5083
5163
|
async function saveVaultOrReport(path5, vault, io, json, action) {
|
|
5084
5164
|
const cause = await trySaveVault(path5, vault);
|
|
5085
5165
|
if (cause === null) return null;
|
|
5086
|
-
|
|
5087
|
-
if (json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5088
|
-
`);
|
|
5089
|
-
else io.err(`yaw-mcp secrets${action ? ` ${action}` : ""}: ${msg}
|
|
5090
|
-
`);
|
|
5091
|
-
return { exitCode: 1 };
|
|
5166
|
+
return failResult(io, json, action, `could not write the vault file at ${path5} (${cause}) -- nothing was saved.`);
|
|
5092
5167
|
}
|
|
5093
5168
|
function vaultChangedResult(io, json, action) {
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5169
|
+
return failResult(
|
|
5170
|
+
io,
|
|
5171
|
+
json,
|
|
5172
|
+
action,
|
|
5173
|
+
"the vault changed on disk while this command was waiting for input -- nothing was written. Re-run to work from the current vault."
|
|
5174
|
+
);
|
|
5100
5175
|
}
|
|
5101
5176
|
function unlockErrorMessage(err, path5) {
|
|
5102
5177
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -5109,21 +5184,11 @@ function unlockErrorMessage(err, path5) {
|
|
|
5109
5184
|
return msg;
|
|
5110
5185
|
}
|
|
5111
5186
|
var CANCELLED = /* @__PURE__ */ Symbol("yaw-mcp:passphrase-cancelled");
|
|
5112
|
-
function cancelledResult(io, json) {
|
|
5113
|
-
|
|
5114
|
-
if (json) io.err(`${JSON.stringify({ ok: false, error: msg, cancelled: true })}
|
|
5115
|
-
`);
|
|
5116
|
-
else io.err(`yaw-mcp secrets: ${msg}
|
|
5117
|
-
`);
|
|
5118
|
-
return { exitCode: 130 };
|
|
5187
|
+
function cancelledResult(io, json, action) {
|
|
5188
|
+
return failResult(io, json, action, "Cancelled.", { exitCode: 130, fields: { cancelled: true } });
|
|
5119
5189
|
}
|
|
5120
5190
|
function abortedResult(io, json, action) {
|
|
5121
|
-
|
|
5122
|
-
if (json) io.err(`${JSON.stringify({ ok: false, error: msg, aborted: true })}
|
|
5123
|
-
`);
|
|
5124
|
-
else io.err(`yaw-mcp secrets ${action}: ${msg}
|
|
5125
|
-
`);
|
|
5126
|
-
return { exitCode: 1 };
|
|
5191
|
+
return failResult(io, json, action, "Aborted.", { fields: { aborted: true } });
|
|
5127
5192
|
}
|
|
5128
5193
|
function ttyEnds(opts) {
|
|
5129
5194
|
const stdin = opts.io?.stdin ?? process.stdin;
|
|
@@ -5296,13 +5361,14 @@ var MAX_PASSPHRASE_PROMPTS = 3;
|
|
|
5296
5361
|
var MIN_PASSPHRASE_WARN_LEN = 12;
|
|
5297
5362
|
var CTRL_C = "";
|
|
5298
5363
|
var CTRL_D = "";
|
|
5364
|
+
var TAB = " ";
|
|
5299
5365
|
var DEL = "\x7F";
|
|
5300
5366
|
var ESC = "\x1B";
|
|
5301
5367
|
var NO_ECHO = /* @__PURE__ */ Symbol("yaw-mcp:no-echo-unavailable");
|
|
5302
5368
|
function noEchoRefusal(required, remedy) {
|
|
5303
5369
|
return `${required} Refusing to prompt: this terminal would not turn echo off, so what you type would be shown on screen. ${remedy}`;
|
|
5304
5370
|
}
|
|
5305
|
-
function readLineFromTTY(stdin, stdout, prompt = "Vault passphrase: ", echo = false) {
|
|
5371
|
+
function readLineFromTTY(stdin, stdout, prompt = "Vault passphrase: ", echo = false, keepTab = false) {
|
|
5306
5372
|
return new Promise((resolve8) => {
|
|
5307
5373
|
const chunks = [];
|
|
5308
5374
|
const wasRaw = stdin.isRaw === true;
|
|
@@ -5378,7 +5444,7 @@ function readLineFromTTY(stdin, stdout, prompt = "Vault passphrase: ", echo = fa
|
|
|
5378
5444
|
}
|
|
5379
5445
|
continue;
|
|
5380
5446
|
}
|
|
5381
|
-
if (ch < " ") continue;
|
|
5447
|
+
if (ch < " " && !(keepTab && ch === TAB)) continue;
|
|
5382
5448
|
chunks.push(ch);
|
|
5383
5449
|
if (echo) stdout.write(ch);
|
|
5384
5450
|
}
|
|
@@ -5398,7 +5464,12 @@ async function readStdinValue(io, forceRaw) {
|
|
|
5398
5464
|
const stdoutIsTTY = stdout.isTTY === true;
|
|
5399
5465
|
if (stdinIsTTY && !forceRaw) {
|
|
5400
5466
|
if (!stdoutIsTTY) return PROMPT_IMPOSSIBLE;
|
|
5401
|
-
|
|
5467
|
+
for (let attempt = 0; attempt < MAX_PASSPHRASE_PROMPTS; attempt++) {
|
|
5468
|
+
const entered = await readLineFromTTY(stdin, stdout, "Secret value: ", false, true);
|
|
5469
|
+
if (entered === CANCELLED || entered === NO_ECHO || entered.length > 0) return entered;
|
|
5470
|
+
stdout.write("Secret value cannot be empty.\n");
|
|
5471
|
+
}
|
|
5472
|
+
return "";
|
|
5402
5473
|
}
|
|
5403
5474
|
const chunks = [];
|
|
5404
5475
|
stdin.setEncoding("utf8");
|
|
@@ -5411,6 +5482,9 @@ async function runSecrets(opts, io = {
|
|
|
5411
5482
|
}) {
|
|
5412
5483
|
const home = opts.home ?? homedir8();
|
|
5413
5484
|
const path5 = vaultPath(home);
|
|
5485
|
+
if (!isSecretsAction(opts.action)) {
|
|
5486
|
+
return failResult(io, opts.json, "", `unknown action ${String(opts.action)}`, { exitCode: 2 });
|
|
5487
|
+
}
|
|
5414
5488
|
if (opts.action === "lock") {
|
|
5415
5489
|
lock();
|
|
5416
5490
|
if (opts.json) {
|
|
@@ -5440,7 +5514,7 @@ async function runSecrets(opts, io = {
|
|
|
5440
5514
|
const vault2 = loaded2.vault;
|
|
5441
5515
|
if (vault2) schemaBehindNotice(io, vault2, path5, opts.json);
|
|
5442
5516
|
const keys = vault2 ? listKeys(vault2) : [];
|
|
5443
|
-
if (opts.json) io.out(`${JSON.stringify({ ok: true, vault: vault2 !== null, keys }
|
|
5517
|
+
if (opts.json) io.out(`${JSON.stringify({ ok: true, vault: vault2 !== null, keys })}
|
|
5444
5518
|
`);
|
|
5445
5519
|
else if (!vault2) io.out(`No vault at ${path5}. Run \`yaw-mcp secrets set <name>\` to create one.
|
|
5446
5520
|
`);
|
|
@@ -5455,36 +5529,30 @@ async function runSecrets(opts, io = {
|
|
|
5455
5529
|
return { exitCode: 0 };
|
|
5456
5530
|
}
|
|
5457
5531
|
const baseline = opts.action === "get" ? null : await vaultFingerprint(path5);
|
|
5458
|
-
if (isVaultUnreadable(baseline)) return vaultUnreadableResult(io, opts.json, opts.action
|
|
5459
|
-
const loaded = await safeLoadVault(path5, io, opts.json, opts.action
|
|
5532
|
+
if (isVaultUnreadable(baseline)) return vaultUnreadableResult(io, opts.json, opts.action, path5, baseline);
|
|
5533
|
+
const loaded = await safeLoadVault(path5, io, opts.json, opts.action);
|
|
5460
5534
|
if (!loaded.ok) return loaded.result;
|
|
5461
5535
|
if (loaded.vault) schemaBehindNotice(io, loaded.vault, path5, opts.json);
|
|
5462
5536
|
if (opts.action === "get" || opts.action === "remove") {
|
|
5463
5537
|
const name = opts.name;
|
|
5464
5538
|
if (!loaded.vault || !Object.hasOwn(loaded.vault.entries, name)) {
|
|
5465
|
-
|
|
5466
|
-
if (opts.json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5467
|
-
`);
|
|
5468
|
-
else io.err(`yaw-mcp secrets: ${msg}
|
|
5469
|
-
`);
|
|
5470
|
-
return { exitCode: 1 };
|
|
5539
|
+
return failResult(io, opts.json, opts.action, `No secret named "${name}" in the vault.`);
|
|
5471
5540
|
}
|
|
5472
5541
|
}
|
|
5473
5542
|
const replacing = opts.action === "set" && loaded.vault !== null && Object.hasOwn(loaded.vault.entries, opts.name);
|
|
5474
5543
|
if (opts.action === "remove" && !opts.force) {
|
|
5475
5544
|
if (isInteractiveTTY(opts)) {
|
|
5476
5545
|
const confirmed = await promptYesNo(opts, `Permanently delete secret "${opts.name}"? This cannot be undone.`);
|
|
5477
|
-
if (confirmed === CANCELLED) return cancelledResult(io, opts.json);
|
|
5546
|
+
if (confirmed === CANCELLED) return cancelledResult(io, opts.json, "remove");
|
|
5478
5547
|
if (!confirmed) return abortedResult(io, opts.json, "remove");
|
|
5479
5548
|
} else {
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
return { exitCode: 2 };
|
|
5549
|
+
return failResult(
|
|
5550
|
+
io,
|
|
5551
|
+
opts.json,
|
|
5552
|
+
"remove",
|
|
5553
|
+
`refusing to delete "${opts.name}" without confirmation and ${nonTTYEnds(opts)}.`,
|
|
5554
|
+
{ exitCode: 2, detail: "Re-run with --force to delete it. This cannot be undone." }
|
|
5555
|
+
);
|
|
5488
5556
|
}
|
|
5489
5557
|
}
|
|
5490
5558
|
if (replacing && !opts.force && isInteractiveTTY(opts)) {
|
|
@@ -5492,40 +5560,35 @@ async function runSecrets(opts, io = {
|
|
|
5492
5560
|
opts,
|
|
5493
5561
|
`Secret "${opts.name}" already exists. Replace it? The stored value is overwritten.`
|
|
5494
5562
|
);
|
|
5495
|
-
if (confirmed === CANCELLED) return cancelledResult(io, opts.json);
|
|
5563
|
+
if (confirmed === CANCELLED) return cancelledResult(io, opts.json, "set");
|
|
5496
5564
|
if (!confirmed) return abortedResult(io, opts.json, "set");
|
|
5497
5565
|
}
|
|
5498
5566
|
let vault = loaded.vault ?? newVault();
|
|
5499
5567
|
const isFresh = loaded.vault === null;
|
|
5500
5568
|
const creatingVault = opts.action === "set" && !vault.check && Object.keys(vault.entries).length === 0;
|
|
5501
5569
|
const passphrase = await resolvePassphrase(opts, io, creatingVault);
|
|
5502
|
-
if (passphrase === CANCELLED) return cancelledResult(io, opts.json);
|
|
5570
|
+
if (passphrase === CANCELLED) return cancelledResult(io, opts.json, opts.action);
|
|
5503
5571
|
if (passphrase === NO_ECHO) {
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5572
|
+
return failResult(
|
|
5573
|
+
io,
|
|
5574
|
+
opts.json,
|
|
5575
|
+
opts.action,
|
|
5576
|
+
noEchoRefusal("Passphrase required.", "Set YAW_MCP_VAULT_PASSPHRASE instead.")
|
|
5577
|
+
);
|
|
5510
5578
|
}
|
|
5511
5579
|
if (passphrase === null) {
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5580
|
+
return failResult(
|
|
5581
|
+
io,
|
|
5582
|
+
opts.json,
|
|
5583
|
+
opts.action,
|
|
5584
|
+
promptUnavailableMessage(opts, "Passphrase required.", "YAW_MCP_VAULT_PASSPHRASE")
|
|
5585
|
+
);
|
|
5518
5586
|
}
|
|
5519
5587
|
let key;
|
|
5520
5588
|
try {
|
|
5521
5589
|
key = await unlock(vault, passphrase);
|
|
5522
5590
|
} catch (err) {
|
|
5523
|
-
|
|
5524
|
-
if (opts.json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5525
|
-
`);
|
|
5526
|
-
else io.err(`yaw-mcp secrets: ${msg}
|
|
5527
|
-
`);
|
|
5528
|
-
return { exitCode: 1 };
|
|
5591
|
+
return failResult(io, opts.json, opts.action, unlockErrorMessage(err, path5));
|
|
5529
5592
|
}
|
|
5530
5593
|
if (opts.action === "set") {
|
|
5531
5594
|
const name = opts.name;
|
|
@@ -5533,42 +5596,30 @@ async function runSecrets(opts, io = {
|
|
|
5533
5596
|
if (opts.value !== void 0) value = opts.value;
|
|
5534
5597
|
else {
|
|
5535
5598
|
const entered = await readStdinValue(opts.io, opts.fromStdin);
|
|
5536
|
-
if (entered === CANCELLED) return cancelledResult(io, opts.json);
|
|
5599
|
+
if (entered === CANCELLED) return cancelledResult(io, opts.json, "set");
|
|
5537
5600
|
if (entered === NO_ECHO) {
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5601
|
+
return failResult(
|
|
5602
|
+
io,
|
|
5603
|
+
opts.json,
|
|
5604
|
+
"set",
|
|
5605
|
+
noEchoRefusal("Secret value required.", "Pipe the value in with --stdin instead.")
|
|
5606
|
+
);
|
|
5544
5607
|
}
|
|
5545
5608
|
if (entered === PROMPT_IMPOSSIBLE) {
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5609
|
+
return failResult(
|
|
5610
|
+
io,
|
|
5611
|
+
opts.json,
|
|
5612
|
+
"set",
|
|
5613
|
+
"cannot prompt for the value: stdin is a TTY but stdout is not, so the prompt would be written into the redirect instead of shown. Pass --value <v>, or pipe the value in with --stdin."
|
|
5614
|
+
);
|
|
5552
5615
|
}
|
|
5553
5616
|
value = entered;
|
|
5554
5617
|
}
|
|
5555
|
-
if (!value)
|
|
5556
|
-
const msg = "Secret value cannot be empty.";
|
|
5557
|
-
if (opts.json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5558
|
-
`);
|
|
5559
|
-
else io.err(`yaw-mcp secrets: ${msg}
|
|
5560
|
-
`);
|
|
5561
|
-
return { exitCode: 1 };
|
|
5562
|
-
}
|
|
5618
|
+
if (!value) return failResult(io, opts.json, "set", "Secret value cannot be empty.");
|
|
5563
5619
|
try {
|
|
5564
5620
|
vault = setSecret(vault, key, name, value);
|
|
5565
5621
|
} catch (err) {
|
|
5566
|
-
|
|
5567
|
-
if (opts.json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5568
|
-
`);
|
|
5569
|
-
else io.err(`yaw-mcp secrets set: ${msg}
|
|
5570
|
-
`);
|
|
5571
|
-
return { exitCode: 1 };
|
|
5622
|
+
return failResult(io, opts.json, "set", err instanceof Error ? err.message : String(err));
|
|
5572
5623
|
}
|
|
5573
5624
|
if (await vaultChangedSinceLoad(path5, baseline)) return vaultChangedResult(io, opts.json, "set");
|
|
5574
5625
|
const failed = await saveVaultOrReport(path5, vault, io, opts.json, "set");
|
|
@@ -5588,10 +5639,14 @@ async function runSecrets(opts, io = {
|
|
|
5588
5639
|
const value = getSecret(vault, key, name);
|
|
5589
5640
|
const outStream = opts.io?.stdout ?? process.stdout;
|
|
5590
5641
|
if (outStream.isTTY === true) {
|
|
5591
|
-
io.err(
|
|
5592
|
-
|
|
5642
|
+
if (opts.json) io.err(`${JSON.stringify({ warning: "cleartext-on-tty", name })}
|
|
5643
|
+
`);
|
|
5644
|
+
else {
|
|
5645
|
+
io.err(
|
|
5646
|
+
`yaw-mcp secrets: warning -- printing "${name}" in cleartext to your terminal; it will remain in scrollback.
|
|
5593
5647
|
`
|
|
5594
|
-
|
|
5648
|
+
);
|
|
5649
|
+
}
|
|
5595
5650
|
}
|
|
5596
5651
|
if (opts.json) io.out(`${JSON.stringify({ ok: true, name, value })}
|
|
5597
5652
|
`);
|
|
@@ -5599,14 +5654,10 @@ async function runSecrets(opts, io = {
|
|
|
5599
5654
|
`);
|
|
5600
5655
|
return { exitCode: 0 };
|
|
5601
5656
|
} catch (err) {
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
else io.err(`yaw-mcp secrets: ${msg}
|
|
5607
|
-
${hint}
|
|
5608
|
-
`);
|
|
5609
|
-
return { exitCode: 1 };
|
|
5657
|
+
return failResult(io, opts.json, "get", err instanceof Error ? err.message : String(err), {
|
|
5658
|
+
detail: `Entry "${name}" failed to decrypt: it is corrupt, or it was written under a different passphrase than the rest of the vault. Remove it and set it again.`,
|
|
5659
|
+
detailAsHint: true
|
|
5660
|
+
});
|
|
5610
5661
|
}
|
|
5611
5662
|
}
|
|
5612
5663
|
if (opts.action === "remove") {
|
|
@@ -5621,9 +5672,8 @@ async function runSecrets(opts, io = {
|
|
|
5621
5672
|
`);
|
|
5622
5673
|
return { exitCode: 0 };
|
|
5623
5674
|
}
|
|
5624
|
-
|
|
5625
|
-
`);
|
|
5626
|
-
return { exitCode: 2 };
|
|
5675
|
+
const unhandled = opts.action;
|
|
5676
|
+
return failResult(io, opts.json, "", `unknown action ${String(unhandled)}`, { exitCode: 2 });
|
|
5627
5677
|
}
|
|
5628
5678
|
async function runSecretsRotate(opts, io) {
|
|
5629
5679
|
const home = opts.home ?? homedir8();
|
|
@@ -5634,75 +5684,65 @@ async function runSecretsRotate(opts, io) {
|
|
|
5634
5684
|
if (!loaded.ok) return loaded.result;
|
|
5635
5685
|
const vault = loaded.vault;
|
|
5636
5686
|
if (!vault) {
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
|
|
5641
|
-
`
|
|
5642
|
-
|
|
5687
|
+
return failResult(
|
|
5688
|
+
io,
|
|
5689
|
+
opts.json,
|
|
5690
|
+
"rotate",
|
|
5691
|
+
`No vault at ${path5} to rotate. Run \`yaw-mcp secrets set <name>\` first.`
|
|
5692
|
+
);
|
|
5643
5693
|
}
|
|
5644
5694
|
const currentPassphrase = await resolvePassphrase(opts, io);
|
|
5645
|
-
if (currentPassphrase === CANCELLED) return cancelledResult(io, opts.json);
|
|
5695
|
+
if (currentPassphrase === CANCELLED) return cancelledResult(io, opts.json, "rotate");
|
|
5646
5696
|
if (currentPassphrase === NO_ECHO) {
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5697
|
+
return failResult(
|
|
5698
|
+
io,
|
|
5699
|
+
opts.json,
|
|
5700
|
+
"rotate",
|
|
5701
|
+
noEchoRefusal("Current passphrase required.", "Set YAW_MCP_VAULT_PASSPHRASE instead.")
|
|
5702
|
+
);
|
|
5653
5703
|
}
|
|
5654
5704
|
if (currentPassphrase === null) {
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5705
|
+
return failResult(
|
|
5706
|
+
io,
|
|
5707
|
+
opts.json,
|
|
5708
|
+
"rotate",
|
|
5709
|
+
promptUnavailableMessage(opts, "Current passphrase required.", "YAW_MCP_VAULT_PASSPHRASE")
|
|
5710
|
+
);
|
|
5661
5711
|
}
|
|
5662
5712
|
let oldKey;
|
|
5663
5713
|
try {
|
|
5664
5714
|
oldKey = await unlock(vault, currentPassphrase);
|
|
5665
5715
|
} catch (err) {
|
|
5666
|
-
|
|
5667
|
-
if (opts.json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5668
|
-
`);
|
|
5669
|
-
else io.err(`yaw-mcp secrets rotate: ${msg}
|
|
5670
|
-
`);
|
|
5671
|
-
return { exitCode: 1 };
|
|
5716
|
+
return failResult(io, opts.json, "rotate", unlockErrorMessage(err, path5));
|
|
5672
5717
|
}
|
|
5673
5718
|
const newPassphrase = await resolveNewPassphrase(opts, io);
|
|
5674
|
-
if (newPassphrase === CANCELLED) return cancelledResult(io, opts.json);
|
|
5719
|
+
if (newPassphrase === CANCELLED) return cancelledResult(io, opts.json, "rotate");
|
|
5675
5720
|
if (newPassphrase === NO_ECHO) {
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5721
|
+
return failResult(
|
|
5722
|
+
io,
|
|
5723
|
+
opts.json,
|
|
5724
|
+
"rotate",
|
|
5725
|
+
noEchoRefusal("New passphrase required.", "Set YAW_MCP_VAULT_PASSPHRASE_NEW instead.")
|
|
5726
|
+
);
|
|
5682
5727
|
}
|
|
5683
5728
|
if (newPassphrase === null) {
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
"
|
|
5729
|
+
return failResult(
|
|
5730
|
+
io,
|
|
5731
|
+
opts.json,
|
|
5732
|
+
"rotate",
|
|
5733
|
+
promptUnavailableMessage(
|
|
5734
|
+
opts,
|
|
5735
|
+
"New passphrase required (and must be confirmed).",
|
|
5736
|
+
"YAW_MCP_VAULT_PASSPHRASE_NEW"
|
|
5737
|
+
)
|
|
5688
5738
|
);
|
|
5689
|
-
if (opts.json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5690
|
-
`);
|
|
5691
|
-
else io.err(`yaw-mcp secrets rotate: ${msg}
|
|
5692
|
-
`);
|
|
5693
|
-
return { exitCode: 1 };
|
|
5694
5739
|
}
|
|
5695
5740
|
let rotated;
|
|
5696
5741
|
try {
|
|
5697
5742
|
rotated = await rotateVault(vault, oldKey, newPassphrase);
|
|
5698
5743
|
} catch (err) {
|
|
5699
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
5700
|
-
if (opts.json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5701
|
-
`);
|
|
5702
|
-
else io.err(`yaw-mcp secrets rotate: ${msg}
|
|
5703
|
-
`);
|
|
5704
5744
|
lock();
|
|
5705
|
-
return
|
|
5745
|
+
return failResult(io, opts.json, "rotate", err instanceof Error ? err.message : String(err));
|
|
5706
5746
|
}
|
|
5707
5747
|
if (await vaultChangedSinceLoad(path5, baseline)) {
|
|
5708
5748
|
lock();
|
|
@@ -5773,6 +5813,18 @@ function alreadyOpensMessage(verdict, subject, path5) {
|
|
|
5773
5813
|
}
|
|
5774
5814
|
return `${subject} already opens the vault at ${path5} -- nothing to reset, and the vault was not touched. ${RESET_ALTERNATIVES}`;
|
|
5775
5815
|
}
|
|
5816
|
+
async function resetGuardVerdict(vault, candidate) {
|
|
5817
|
+
try {
|
|
5818
|
+
return await checkVaultPassphrase(vault, candidate);
|
|
5819
|
+
} catch (err) {
|
|
5820
|
+
return { failed: err instanceof Error ? err.message : String(err) };
|
|
5821
|
+
} finally {
|
|
5822
|
+
lock();
|
|
5823
|
+
}
|
|
5824
|
+
}
|
|
5825
|
+
function guardFailedMessage(subject, path5, cause) {
|
|
5826
|
+
return `could not check ${subject} against the vault at ${path5} (${cause}) -- nothing was changed.`;
|
|
5827
|
+
}
|
|
5776
5828
|
function resetPreamble(path5, backup, names, envKeyed) {
|
|
5777
5829
|
const lines = [];
|
|
5778
5830
|
if ("names" in names) {
|
|
@@ -5820,13 +5872,7 @@ async function runSecretsReset(opts, io) {
|
|
|
5820
5872
|
const home = opts.home ?? homedir8();
|
|
5821
5873
|
const path5 = vaultPath(home);
|
|
5822
5874
|
const json = opts.json;
|
|
5823
|
-
const fail = (msg,
|
|
5824
|
-
if (json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5825
|
-
`);
|
|
5826
|
-
else io.err(`yaw-mcp secrets reset: ${msg}
|
|
5827
|
-
`);
|
|
5828
|
-
return { exitCode };
|
|
5829
|
-
};
|
|
5875
|
+
const fail = (msg) => failResult(io, json, "reset", msg);
|
|
5830
5876
|
const baseline = await vaultFingerprint(path5);
|
|
5831
5877
|
if (isVaultUnreadable(baseline)) return vaultUnreadableResult(io, json, "reset", path5, baseline);
|
|
5832
5878
|
if (baseline === null) {
|
|
@@ -5836,7 +5882,7 @@ async function runSecretsReset(opts, io) {
|
|
|
5836
5882
|
let vault = null;
|
|
5837
5883
|
if ("names" in names) {
|
|
5838
5884
|
try {
|
|
5839
|
-
vault = await loadVault(path5);
|
|
5885
|
+
vault = await loadVault(path5, { onWarning: (w) => vaultLoadWarningNotice(io, w, json) });
|
|
5840
5886
|
} catch {
|
|
5841
5887
|
vault = null;
|
|
5842
5888
|
}
|
|
@@ -5844,8 +5890,8 @@ async function runSecretsReset(opts, io) {
|
|
|
5844
5890
|
const guardable = vault !== null && vaultVerifiesPassphrases(vault);
|
|
5845
5891
|
const scripted = opts.passphrase ?? process.env.YAW_MCP_VAULT_PASSPHRASE ?? "";
|
|
5846
5892
|
if (guardable && vault !== null && scripted.length > 0) {
|
|
5847
|
-
const verdict = await
|
|
5848
|
-
|
|
5893
|
+
const verdict = await resetGuardVerdict(vault, scripted);
|
|
5894
|
+
if (typeof verdict === "object") return fail(guardFailedMessage("YAW_MCP_VAULT_PASSPHRASE", path5, verdict.failed));
|
|
5849
5895
|
if (verdict !== "wrong") return fail(alreadyOpensMessage(verdict, "YAW_MCP_VAULT_PASSPHRASE", path5));
|
|
5850
5896
|
}
|
|
5851
5897
|
const at = /* @__PURE__ */ new Date();
|
|
@@ -5856,21 +5902,23 @@ async function runSecretsReset(opts, io) {
|
|
|
5856
5902
|
const stdout = opts.io?.stdout ?? process.stdout;
|
|
5857
5903
|
stdout.write(resetPreamble(path5, resetBackupPath(path5, at), names, envKeyed));
|
|
5858
5904
|
const answer = await readLineFromTTY(stdin, stdout, "Type RESET to continue: ", true);
|
|
5859
|
-
if (answer === CANCELLED) return cancelledResult(io, json);
|
|
5905
|
+
if (answer === CANCELLED) return cancelledResult(io, json, "reset");
|
|
5860
5906
|
if (answer.trim().toLowerCase() !== "reset") return abortedResult(io, json, "reset");
|
|
5861
5907
|
} else {
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5908
|
+
return failResult(
|
|
5909
|
+
io,
|
|
5910
|
+
json,
|
|
5911
|
+
"reset",
|
|
5912
|
+
`refusing to reset the vault without confirmation and ${nonTTYEnds(opts)}.`,
|
|
5913
|
+
{
|
|
5914
|
+
exitCode: 2,
|
|
5915
|
+
detail: "Re-run with --force to reset it. The old vault is moved aside, not deleted, and every entry has to be set again."
|
|
5916
|
+
}
|
|
5917
|
+
);
|
|
5870
5918
|
}
|
|
5871
5919
|
}
|
|
5872
5920
|
const passphrase = await resolvePassphrase(opts, io, true, NEW_PASSPHRASE_LABELS);
|
|
5873
|
-
if (passphrase === CANCELLED) return cancelledResult(io, json);
|
|
5921
|
+
if (passphrase === CANCELLED) return cancelledResult(io, json, "reset");
|
|
5874
5922
|
if (passphrase === NO_ECHO) {
|
|
5875
5923
|
return fail(noEchoRefusal("New passphrase required.", "Set YAW_MCP_VAULT_PASSPHRASE instead."));
|
|
5876
5924
|
}
|
|
@@ -5880,8 +5928,8 @@ async function runSecretsReset(opts, io) {
|
|
|
5880
5928
|
);
|
|
5881
5929
|
}
|
|
5882
5930
|
if (guardable && vault !== null && scripted.length === 0) {
|
|
5883
|
-
const verdict = await
|
|
5884
|
-
|
|
5931
|
+
const verdict = await resetGuardVerdict(vault, passphrase);
|
|
5932
|
+
if (typeof verdict === "object") return fail(guardFailedMessage("that passphrase", path5, verdict.failed));
|
|
5885
5933
|
if (verdict !== "wrong") return fail(alreadyOpensMessage(verdict, "that passphrase", path5));
|
|
5886
5934
|
}
|
|
5887
5935
|
let fresh;
|
|
@@ -5954,15 +6002,10 @@ async function runSecretsAudit(opts, io) {
|
|
|
5954
6002
|
home
|
|
5955
6003
|
);
|
|
5956
6004
|
} catch (err) {
|
|
5957
|
-
|
|
5958
|
-
if (opts.json) io.err(`${JSON.stringify({ ok: false, error: msg })}
|
|
5959
|
-
`);
|
|
5960
|
-
else io.err(`yaw-mcp secrets audit: ${msg}
|
|
5961
|
-
`);
|
|
5962
|
-
return { exitCode: 1 };
|
|
6005
|
+
return failResult(io, opts.json, "audit", err instanceof Error ? err.message : String(err));
|
|
5963
6006
|
}
|
|
5964
6007
|
if (opts.json) {
|
|
5965
|
-
io.out(`${JSON.stringify({ ok: true, count: events.length, events }
|
|
6008
|
+
io.out(`${JSON.stringify({ ok: true, count: events.length, events })}
|
|
5966
6009
|
`);
|
|
5967
6010
|
return { exitCode: 0 };
|
|
5968
6011
|
}
|
|
@@ -6181,7 +6224,7 @@ async function runTrustGrant(opts) {
|
|
|
6181
6224
|
return { exitCode: 1 };
|
|
6182
6225
|
}
|
|
6183
6226
|
const question = serverCount === 0 ? " Approve this file? It defines no servers. [y/N] " : ` Read ${serverCount === 1 ? "the 1 command" : `all ${serverCount} commands`} above. Approve this file? [y/N] `;
|
|
6184
|
-
const answer = await askYesNo(opts, question);
|
|
6227
|
+
const answer = await askYesNo(opts, question, readTrustAnswer);
|
|
6185
6228
|
if (answer !== "y" && answer !== "yes") {
|
|
6186
6229
|
printErr("yaw-mcp trust: Aborted. Nothing was approved.");
|
|
6187
6230
|
return { exitCode: 1 };
|
|
@@ -6509,12 +6552,8 @@ function isInteractive(opts) {
|
|
|
6509
6552
|
if (opts.promptAnswer !== void 0) return true;
|
|
6510
6553
|
return Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY);
|
|
6511
6554
|
}
|
|
6512
|
-
async function
|
|
6513
|
-
|
|
6514
|
-
const input = opts.io?.stdin ?? process.stdin;
|
|
6515
|
-
const output = opts.io?.stdout ?? process.stdout;
|
|
6516
|
-
const answer = await readAnswerFromTTY(input, output, question);
|
|
6517
|
-
return (answer ?? "").trim().toLowerCase();
|
|
6555
|
+
async function readTrustAnswer(input, output, question) {
|
|
6556
|
+
return await readAnswerFromTTY(input, output, question) ?? "";
|
|
6518
6557
|
}
|
|
6519
6558
|
|
|
6520
6559
|
// src/call-cmd.ts
|
|
@@ -6885,14 +6924,16 @@ var SUBCOMMAND_SPEC = [
|
|
|
6885
6924
|
},
|
|
6886
6925
|
// Same client list as install/uninstall -- one INSTALL_CLIENTS constant
|
|
6887
6926
|
// feeds all three, so a new client cannot appear in one and not the others.
|
|
6888
|
-
// --remove-originals / --keep-originals
|
|
6889
|
-
//
|
|
6890
|
-
//
|
|
6927
|
+
// --remove-originals / --keep-originals answer the duplicate-run question
|
|
6928
|
+
// without a prompt, and --force answers the other one -- whether to change
|
|
6929
|
+
// a server bundles.json already has -- which off a TTY is refused without
|
|
6930
|
+
// it. A script needs both answers, so all three MUST be completable.
|
|
6931
|
+
// Mirrors parseImportArgs in src/import-cmd.ts.
|
|
6891
6932
|
{
|
|
6892
6933
|
name: "import",
|
|
6893
6934
|
description: "Adopt a client's existing MCP servers into bundles.json",
|
|
6894
6935
|
positional: [[...INSTALL_CLIENTS]],
|
|
6895
|
-
flags: ["--scope", "--project-dir", "--dry-run", "--remove-originals", "--keep-originals", "--help"]
|
|
6936
|
+
flags: ["--scope", "--project-dir", "--dry-run", "--remove-originals", "--keep-originals", "--force", "--help"]
|
|
6896
6937
|
},
|
|
6897
6938
|
// --force / --yes gate the destructive removal (confirm on a TTY, refuse off
|
|
6898
6939
|
// one), so they MUST be completable -- a user who cannot tab --force will not
|
|
@@ -7246,7 +7287,7 @@ ${caseBranches}
|
|
|
7246
7287
|
import { closeSync, existsSync as existsSync6, fstatSync, openSync, readFileSync as readFileSync3, readSync } from "fs";
|
|
7247
7288
|
import { readFile as readFile13 } from "fs/promises";
|
|
7248
7289
|
import { homedir as homedir15 } from "os";
|
|
7249
|
-
import { join as join14, posix, resolve as resolve7, win32 } from "path";
|
|
7290
|
+
import { join as join14, posix as posix2, resolve as resolve7, win32 as win322 } from "path";
|
|
7250
7291
|
|
|
7251
7292
|
// src/cli-shadows.ts
|
|
7252
7293
|
var EMPTY = [];
|
|
@@ -8382,7 +8423,6 @@ import { existsSync as existsSync5 } from "fs";
|
|
|
8382
8423
|
import { chmod as chmod6, mkdir as mkdir4, readdir, readFile as readFile12, unlink as unlink2 } from "fs/promises";
|
|
8383
8424
|
import { homedir as homedir14 } from "os";
|
|
8384
8425
|
import { join as join13, resolve as resolve6 } from "path";
|
|
8385
|
-
import { createInterface as createInterface2 } from "readline/promises";
|
|
8386
8426
|
|
|
8387
8427
|
// src/catalog-search.ts
|
|
8388
8428
|
var str = (v) => typeof v === "string" ? v : void 0;
|
|
@@ -8605,30 +8645,88 @@ function normalizeCatalogGrade(raw) {
|
|
|
8605
8645
|
import { readFile as readFile11, stat as stat5 } from "fs/promises";
|
|
8606
8646
|
import { homedir as homedir13 } from "os";
|
|
8607
8647
|
import { dirname as dirname7, join as join12, resolve as resolve5, sep } from "path";
|
|
8608
|
-
import { createInterface } from "readline/promises";
|
|
8648
|
+
import { createInterface as createInterface2 } from "readline/promises";
|
|
8609
8649
|
|
|
8610
|
-
// src/
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
|
|
8614
|
-
const
|
|
8615
|
-
|
|
8616
|
-
const
|
|
8617
|
-
const
|
|
8618
|
-
|
|
8619
|
-
|
|
8650
|
+
// src/write-failure.ts
|
|
8651
|
+
import { statSync as statSync3 } from "fs";
|
|
8652
|
+
import { posix, win32 } from "path";
|
|
8653
|
+
function describeWriteFailure(file, err, options = {}) {
|
|
8654
|
+
const disk = diskOf(options);
|
|
8655
|
+
const errno = typeof err === "object" && err !== null ? err : {};
|
|
8656
|
+
const code = typeof errno.code === "string" ? errno.code : void 0;
|
|
8657
|
+
const syscall = typeof errno.syscall === "string" ? errno.syscall : void 0;
|
|
8658
|
+
const errPath = typeof errno.path === "string" ? errno.path : void 0;
|
|
8659
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
8660
|
+
const head = `failed to write ${file}`;
|
|
8661
|
+
if (code === "EEXIST" && syscall === "mkdir" || code === "ENOTDIR") {
|
|
8662
|
+
const inTheWay = describeFileInTheWay(file, options);
|
|
8663
|
+
if (inTheWay !== null) return `${head}: ${inTheWay}`;
|
|
8664
|
+
}
|
|
8665
|
+
if (code === "EPERM" || code === "EACCES" || code === "EBUSY") {
|
|
8666
|
+
const target = code === "EBUSY" ? null : disk.stat(file);
|
|
8667
|
+
if (target !== null && !target.directory && target.readOnly && (disk.win || errPath === file)) {
|
|
8668
|
+
const clear = disk.win ? `clear its read-only attribute (\`attrib -R "${file}"\`)` : `make it writable (\`chmod u+w "${file}"\`)`;
|
|
8669
|
+
return `${head}: it is read-only -- ${clear}, then re-run`;
|
|
8670
|
+
}
|
|
8671
|
+
const creatingSibling = syscall === "open" && errPath !== void 0 && errPath !== file;
|
|
8672
|
+
if (code !== "EBUSY" && (creatingSibling || !disk.win && syscall === "rename")) {
|
|
8673
|
+
return `${head}: your account may not create or replace files in ${disk.paths.dirname(file)} (${code}) -- fix that directory's permissions, then re-run`;
|
|
8674
|
+
}
|
|
8675
|
+
if (disk.win && (syscall === "rename" || errPath === file)) {
|
|
8676
|
+
return `${head}: another program may be holding it open, or your account may not replace it (${code}) -- close whatever has it open (an editor, a sync client, a virus scanner) or fix its permissions, then re-run`;
|
|
8677
|
+
}
|
|
8678
|
+
}
|
|
8679
|
+
const env = options.env;
|
|
8680
|
+
if (env !== void 0 && syscall === "mkdir" && errPath !== void 0 && disk.atOrAbove(errPath, env.value)) {
|
|
8681
|
+
return `${head}: ${message} -- ${env.name} is set to ${env.value}; check that it names a directory that can be created, then re-run`;
|
|
8682
|
+
}
|
|
8683
|
+
return `${head}: ${message}`;
|
|
8684
|
+
}
|
|
8685
|
+
function describeFileInTheWay(file, options = {}) {
|
|
8686
|
+
const disk = diskOf(options);
|
|
8687
|
+
let blocker = null;
|
|
8688
|
+
let cursor = disk.paths.dirname(file);
|
|
8689
|
+
while (true) {
|
|
8690
|
+
const state = disk.stat(cursor);
|
|
8691
|
+
if (state !== null) {
|
|
8692
|
+
blocker = state.directory ? null : cursor;
|
|
8693
|
+
break;
|
|
8694
|
+
}
|
|
8695
|
+
const parent = disk.paths.dirname(cursor);
|
|
8696
|
+
if (parent === cursor) break;
|
|
8697
|
+
cursor = parent;
|
|
8698
|
+
}
|
|
8699
|
+
if (blocker === null) return null;
|
|
8700
|
+
const env = options.env;
|
|
8701
|
+
if (env !== void 0 && disk.atOrAbove(blocker, env.value)) {
|
|
8702
|
+
return `${blocker} is a file, not a directory, and ${env.name} (set to ${env.value}) puts ${disk.paths.basename(file)} under it -- point ${env.name} at a directory, then re-run`;
|
|
8703
|
+
}
|
|
8704
|
+
return `${blocker} is a file, not a directory -- move or rename it, then re-run`;
|
|
8705
|
+
}
|
|
8706
|
+
function diskOf(options) {
|
|
8707
|
+
const win = (options.platform ?? process.platform) === "win32";
|
|
8708
|
+
const paths = win ? win32 : posix;
|
|
8709
|
+
const fold = (p) => {
|
|
8710
|
+
const resolved = paths.resolve(p);
|
|
8711
|
+
return win ? resolved.toLowerCase() : resolved;
|
|
8620
8712
|
};
|
|
8621
|
-
|
|
8622
|
-
|
|
8713
|
+
return {
|
|
8714
|
+
win,
|
|
8715
|
+
paths,
|
|
8716
|
+
stat: options.statPath ?? statOnDisk,
|
|
8717
|
+
atOrAbove: (a, b) => {
|
|
8718
|
+
const top = fold(a);
|
|
8719
|
+
const under = fold(b);
|
|
8720
|
+
return under === top || under.startsWith(top.endsWith(paths.sep) ? top : `${top}${paths.sep}`);
|
|
8721
|
+
}
|
|
8722
|
+
};
|
|
8723
|
+
}
|
|
8724
|
+
function statOnDisk(path5) {
|
|
8623
8725
|
try {
|
|
8624
|
-
|
|
8625
|
-
|
|
8626
|
-
|
|
8627
|
-
|
|
8628
|
-
throw err;
|
|
8629
|
-
} finally {
|
|
8630
|
-
rl.off("close", onClose);
|
|
8631
|
-
rl.off("SIGINT", onSigint);
|
|
8726
|
+
const st = statSync3(path5);
|
|
8727
|
+
return { directory: st.isDirectory(), readOnly: (st.mode & 128) === 0 };
|
|
8728
|
+
} catch {
|
|
8729
|
+
return null;
|
|
8632
8730
|
}
|
|
8633
8731
|
}
|
|
8634
8732
|
|
|
@@ -8655,6 +8753,29 @@ function describeContainer(file, containerPath) {
|
|
|
8655
8753
|
const tail = containerPath.slice(2).map((k) => `.${k}`).join("");
|
|
8656
8754
|
return `${file} under ${containerPath[0]}[${JSON.stringify(containerPath[1])}]${tail}`;
|
|
8657
8755
|
}
|
|
8756
|
+
function spellRootDefault(rootDefault) {
|
|
8757
|
+
return `${rootDefault.key} = ${JSON.stringify(rootDefault.value)}`;
|
|
8758
|
+
}
|
|
8759
|
+
function spellRootValue(value, syntax) {
|
|
8760
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
8761
|
+
if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return String(value);
|
|
8762
|
+
if (value instanceof Date) return value.toISOString();
|
|
8763
|
+
return Array.isArray(value) ? describeValueShape(value) : containerNounFor(syntax);
|
|
8764
|
+
}
|
|
8765
|
+
var KEPT_ROOT_VALUE_STEP = "Edit that value by hand to change it.";
|
|
8766
|
+
function rootLinePlacement(syntax) {
|
|
8767
|
+
return syntax === "TOML" ? "above the first table in the file" : "at the top level of the file";
|
|
8768
|
+
}
|
|
8769
|
+
function keptRootShapeStep(syntax) {
|
|
8770
|
+
return `To change it, delete it by hand and set the key on one line ${rootLinePlacement(syntax)}.`;
|
|
8771
|
+
}
|
|
8772
|
+
function keptRootStep(value, syntax) {
|
|
8773
|
+
const scalar = typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean" || value instanceof Date;
|
|
8774
|
+
return scalar ? KEPT_ROOT_VALUE_STEP : keptRootShapeStep(syntax);
|
|
8775
|
+
}
|
|
8776
|
+
function unspliceableFix(read) {
|
|
8777
|
+
return read.fix ?? "rewrite it by hand as a table of its own (or delete it)";
|
|
8778
|
+
}
|
|
8658
8779
|
function logInstallTail(log2, err, direct, bundles) {
|
|
8659
8780
|
const n = direct.names.length;
|
|
8660
8781
|
if (n > 0) {
|
|
@@ -8683,6 +8804,23 @@ function logInstallTail(log2, err, direct, bundles) {
|
|
|
8683
8804
|
function resolveAppData(opts) {
|
|
8684
8805
|
return resolveAppDataDir({ appData: opts.appData, home: opts.home });
|
|
8685
8806
|
}
|
|
8807
|
+
function rootDefaultsForUsage() {
|
|
8808
|
+
return INSTALL_TARGETS.filter((t) => (t.config.rootDefaults?.length ?? 0) > 0).map(
|
|
8809
|
+
(t) => `${t.label}: ${(t.config.rootDefaults ?? []).map(spellRootDefault).join(", ")}`
|
|
8810
|
+
);
|
|
8811
|
+
}
|
|
8812
|
+
function rerunUsage() {
|
|
8813
|
+
const defaults = rootDefaultsForUsage();
|
|
8814
|
+
if (defaults.length === 0) {
|
|
8815
|
+
return " Re-running install over an entry that already matches is a no-op (exit 0, no prompt).\n";
|
|
8816
|
+
}
|
|
8817
|
+
return " Re-running install over an entry that already matches is a no-op (exit 0, no\n prompt) -- unless the file lacks a top-level setting its client needs:\n" + defaults.map((d) => ` ${d}
|
|
8818
|
+
`).join("") + " The re-run then adds that setting (--dry-run previews it). It is add-only:\n a value you set is left alone, and install says so.\n";
|
|
8819
|
+
}
|
|
8820
|
+
function refusalUsage() {
|
|
8821
|
+
const setting = rootDefaultsForUsage().length > 0 ? " one that sets a top-level setting above to a value no release of its client\n loads (an integer outside the range a TOML integer holds). The message\n says what to change by hand.\n" : " one that its client cannot load. The message says what to change by hand.\n";
|
|
8822
|
+
return " A file install will not write into exits 1 with nothing written, under\n --dry-run and --skip too: one that does not parse, for example, or\n" + setting;
|
|
8823
|
+
}
|
|
8686
8824
|
var USAGE = (
|
|
8687
8825
|
// DERIVED, never a hand-kept list: `parseInstallArgs` validates against
|
|
8688
8826
|
// `clientChoices("install")`, so a literal synopsis is a promise the parser
|
|
@@ -8694,15 +8832,21 @@ var USAGE = (
|
|
|
8694
8832
|
yaw-mcp install --list (detect clients; no writes)
|
|
8695
8833
|
yaw-mcp install --all (install into every client yaw-mcp supports on this OS)
|
|
8696
8834
|
|
|
8697
|
-
|
|
8698
|
-
|
|
8835
|
+
` + rerunUsage() + // Uninstall takes entries out and never a top-level key (see
|
|
8836
|
+
// keptRootDefaultLines), so "undo" has to say what it leaves.
|
|
8837
|
+
` Undo it with \`yaw-mcp uninstall <client>\`${rootDefaultsForUsage().length > 0 ? ", which leaves such a setting in place" : ""}.
|
|
8699
8838
|
|
|
8700
|
-
When a different \`` + ENTRY_NAME + "` entry is already in the config, install asks on a TTY\n and refuses without one, showing what differs (exit 2; a real failure, such\n as a malformed config, exits 1). Under --all the run exits 2 when every\n client that did not succeed was refused this way, and 1 if any one failed.\n Answer up front with:\n --force Overwrite whatever is there, env included: the new entry keeps\n none of the old entry's env, and install names each key it drops.\n --repair Replace an entry that has DRIFTED from what install writes,\n keeping the old entry's string-valued env;
|
|
8839
|
+
When a different \`` + ENTRY_NAME + "` entry is already in the config, install asks on a TTY\n and refuses without one, showing what differs (exit 2; a real failure, such\n as a malformed config, exits 1). Under --all the run exits 2 when every\n client that did not succeed was refused this way, and 1 if any one failed.\n Answer up front with:\n --force Overwrite whatever is there, env included: the new entry keeps\n none of the old entry's env, and install names each key it drops.\n --repair Replace an entry that has DRIFTED from what install writes,\n keeping the old entry's string-valued env; over one that\n already matches it does what a re-run does (above), so a\n fixup script can run it unconditionally.\n --skip Leave the existing entry, and the rest of the file, untouched\n and exit 0.\n --dry-run Print what WOULD be written -- the entry, a top-level setting\n it adds, any permissions patch -- and exit 0 without touching\n a file.\n\n" + refusalUsage() + "\n Deprecated (accepted, ignored, warns): --token <mcp_pat_...>, --no-yaw-mcp-config.\n yaw-mcp is local-only -- it stores no token and never writes ~/.yaw-mcp/config.json.\n Configure servers in ~/.yaw-mcp/bundles.json (see `yaw-mcp add <slug>`)."
|
|
8701
8840
|
);
|
|
8702
|
-
function describeUnreadableConfig(cmd, path5, err) {
|
|
8703
|
-
|
|
8841
|
+
function describeUnreadableConfig(cmd, path5, err, env) {
|
|
8842
|
+
const code = err.code;
|
|
8843
|
+
if (code === "EISDIR") {
|
|
8704
8844
|
return `yaw-mcp ${cmd}: ${path5} is a directory, not a file -- move or remove it, then re-run.`;
|
|
8705
8845
|
}
|
|
8846
|
+
if (code === "ENOTDIR") {
|
|
8847
|
+
const inTheWay = describeFileInTheWay(path5, { env });
|
|
8848
|
+
if (inTheWay !== null) return `yaw-mcp ${cmd}: cannot read ${path5}: ${inTheWay}.`;
|
|
8849
|
+
}
|
|
8706
8850
|
return `yaw-mcp ${cmd}: cannot read ${path5}: ${err.message}`;
|
|
8707
8851
|
}
|
|
8708
8852
|
function clientUnavailableMessage(cmd, target, os, genericFix) {
|
|
@@ -8846,6 +8990,8 @@ ${USAGE}`);
|
|
|
8846
8990
|
const { target, os, scope, projectDir, resolved } = plan;
|
|
8847
8991
|
log2(`Target: ${target.label} (${scope})`);
|
|
8848
8992
|
log2(`File: ${resolved.absolute}`);
|
|
8993
|
+
const rowArgs = rowResolveArgs(opts, os, projectDir);
|
|
8994
|
+
const home = rowArgs.home;
|
|
8849
8995
|
const containerPath = resolved.containerPath;
|
|
8850
8996
|
const selectedSites = selectSites(plan.sites);
|
|
8851
8997
|
const site = selectedSites[0];
|
|
@@ -8855,7 +9001,14 @@ ${USAGE}`);
|
|
|
8855
9001
|
const view = await readClientConfigFile(site, { transform: target.entry });
|
|
8856
9002
|
const read = view.read;
|
|
8857
9003
|
if (read.kind === "unreadable") {
|
|
8858
|
-
err(
|
|
9004
|
+
err(
|
|
9005
|
+
describeUnreadableConfig(
|
|
9006
|
+
"install",
|
|
9007
|
+
resolved.absolute,
|
|
9008
|
+
{ code: read.code, message: read.message },
|
|
9009
|
+
locationEnvHint(target, scope, rowArgs, resolved.absolute)
|
|
9010
|
+
)
|
|
9011
|
+
);
|
|
8859
9012
|
return { written: [], wouldWrite: [], messages, exitCode: 1 };
|
|
8860
9013
|
}
|
|
8861
9014
|
if (read.kind === "malformed") {
|
|
@@ -8871,6 +9024,20 @@ ${USAGE}`);
|
|
|
8871
9024
|
);
|
|
8872
9025
|
return { written: [], wouldWrite: [], messages, exitCode: 1 };
|
|
8873
9026
|
}
|
|
9027
|
+
if (read.kind === "unspliceable") {
|
|
9028
|
+
err(
|
|
9029
|
+
`yaw-mcp install: the "${read.key}" entry in ${resolved.absolute} is ${read.reason}, which install will not edit -- refusing to overwrite it; ${unspliceableFix(read)}, then re-run.`
|
|
9030
|
+
);
|
|
9031
|
+
return { written: [], wouldWrite: [], messages, exitCode: 1 };
|
|
9032
|
+
}
|
|
9033
|
+
const rootPlan = planRootDefaults(view, target.config.rootDefaults);
|
|
9034
|
+
for (const { rootDefault, value, float, refused } of rootPlan.kept) {
|
|
9035
|
+
if (refused?.everyRelease === void 0) continue;
|
|
9036
|
+
err(
|
|
9037
|
+
`yaw-mcp install: ${resolved.absolute} sets ${rootDefault.key} to ${float ?? spellRootValue(value, view.adapter.syntax)}, ${refused.everyRelease}, so ${target.label} will not load the file -- refusing to write into it; change that value by hand to ${refused.needs} (${JSON.stringify(rootDefault.value)} is recommended), then re-run.`
|
|
9038
|
+
);
|
|
9039
|
+
return { written: [], wouldWrite: [], messages, exitCode: 1 };
|
|
9040
|
+
}
|
|
8874
9041
|
const variantPaths = claudeCodeContainerPathVariants(
|
|
8875
9042
|
containerPath,
|
|
8876
9043
|
(prefix) => containerKeysAt(view.raw, site, prefix)
|
|
@@ -8964,15 +9131,6 @@ ${USAGE}`);
|
|
|
8964
9131
|
runtimeLines.push(`Kept existing env on the ${ENTRY_NAME} entry: ${keys}`);
|
|
8965
9132
|
}
|
|
8966
9133
|
}
|
|
8967
|
-
const home = opts.home ?? homedir13();
|
|
8968
|
-
const rowArgs = {
|
|
8969
|
-
os,
|
|
8970
|
-
home,
|
|
8971
|
-
appData: resolveAppDataDir({ appData: opts.appData, home: opts.home }),
|
|
8972
|
-
projectDir,
|
|
8973
|
-
claudeConfigDir: opts.claudeConfigDir,
|
|
8974
|
-
clientEnv: opts.clientEnv
|
|
8975
|
-
};
|
|
8976
9134
|
if (launchesViaNpx(entryToWrite)) {
|
|
8977
9135
|
const shadowed = await shadowedLocalLaunch(target, scope, rowArgs);
|
|
8978
9136
|
if (shadowed !== null) {
|
|
@@ -9034,9 +9192,25 @@ ${differs}
|
|
|
9034
9192
|
} else {
|
|
9035
9193
|
for (const line of runtimeLines) log2(line);
|
|
9036
9194
|
}
|
|
9195
|
+
const rootSets = rootPlan.set;
|
|
9196
|
+
for (const { rootDefault, value, float, refused } of rootPlan.kept) {
|
|
9197
|
+
const spelled = float ?? spellRootValue(value, view.adapter.syntax);
|
|
9198
|
+
const recommended = JSON.stringify(rootDefault.value);
|
|
9199
|
+
const step = keptRootStep(value, view.adapter.syntax);
|
|
9200
|
+
if (refused !== void 0) {
|
|
9201
|
+
const kind = refused.kind === void 0 ? "" : `${refused.kind} `;
|
|
9202
|
+
err(
|
|
9203
|
+
`yaw-mcp install: warning -- ${resolved.absolute} already sets ${rootDefault.key} to ${spelled}, ${kind}where ${target.label} needs ${refused.needs}, and install leaves a value you set alone. A ${target.label} release that reads the key will not load the file with that value; ${recommended} is recommended. ${step}`
|
|
9204
|
+
);
|
|
9205
|
+
} else {
|
|
9206
|
+
log2(
|
|
9207
|
+
`Note: ${resolved.absolute} already sets ${rootDefault.key} to ${spelled}, and install leaves a value you set alone. ${recommended} is recommended: ${rootDefault.why}. ${step}`
|
|
9208
|
+
);
|
|
9209
|
+
}
|
|
9210
|
+
}
|
|
9037
9211
|
let clientJson = null;
|
|
9038
9212
|
let repairedContainer = null;
|
|
9039
|
-
if (skipEntryWrite && !trimLegacy) {
|
|
9213
|
+
if (skipEntryWrite && !trimLegacy && rootSets.length === 0) {
|
|
9040
9214
|
clientJson = null;
|
|
9041
9215
|
} else {
|
|
9042
9216
|
const edits = [];
|
|
@@ -9053,12 +9227,17 @@ ${differs}
|
|
|
9053
9227
|
}
|
|
9054
9228
|
if (!skipEntryWrite) edits.push({ op: "upsert", key: ENTRY_NAME, entry: entryToWrite });
|
|
9055
9229
|
if (trimLegacy) edits.push({ op: "remove", key: legacyEntry });
|
|
9230
|
+
for (const rootDefault of rootSets) {
|
|
9231
|
+
edits.push({ op: "rootDefault", key: rootDefault.key, value: rootDefault.value });
|
|
9232
|
+
}
|
|
9056
9233
|
try {
|
|
9057
9234
|
clientJson = terminateWithNewline(applyClientConfigEdits(view, edits, site));
|
|
9058
9235
|
} catch (e) {
|
|
9059
|
-
|
|
9060
|
-
|
|
9061
|
-
)
|
|
9236
|
+
const settings = rootSets.map(spellRootDefault).join(" and ");
|
|
9237
|
+
const attempted = !skipEntryWrite ? `splice the "${ENTRY_NAME}" entry into ${resolved.absolute}` : trimLegacy && rootSets.length > 0 ? `remove the legacy "${legacyEntry}" entry from ${resolved.absolute} and set ${settings} in it` : trimLegacy ? `remove the legacy "${legacyEntry}" entry from ${resolved.absolute}` : `set ${settings} in ${resolved.absolute}`;
|
|
9238
|
+
const byHand = `add ${settings} ${rootLinePlacement(view.adapter.syntax)}`;
|
|
9239
|
+
const remedy = !skipEntryWrite || rootSets.length === 0 ? "" : trimLegacy ? ` The "${ENTRY_NAME}" entry is already correct, and the legacy "${legacyEntry}" entry is still in the file; to finish by hand, delete that entry and ${byHand}.` : ` The "${ENTRY_NAME}" entry is already correct; to finish by hand, ${byHand}.`;
|
|
9240
|
+
err(`yaw-mcp install: failed to ${attempted} (${e.message}). Refusing to overwrite.${remedy}`);
|
|
9062
9241
|
return { written: [], wouldWrite: [], messages, exitCode: 1 };
|
|
9063
9242
|
}
|
|
9064
9243
|
}
|
|
@@ -9105,7 +9284,7 @@ ${differs}
|
|
|
9105
9284
|
);
|
|
9106
9285
|
if (opts.dryRun) {
|
|
9107
9286
|
const extraPreview = [];
|
|
9108
|
-
const extraWouldWrite = await applyToExtraSites({
|
|
9287
|
+
const extraWouldWrite = (await applyToExtraSites({
|
|
9109
9288
|
cmd: "install",
|
|
9110
9289
|
sites: extraSites,
|
|
9111
9290
|
transform: target.entry,
|
|
@@ -9117,7 +9296,7 @@ ${differs}
|
|
|
9117
9296
|
dryRun: true,
|
|
9118
9297
|
log: (s) => extraPreview.push([log2, s]),
|
|
9119
9298
|
err: (s) => extraPreview.push([err, s])
|
|
9120
|
-
});
|
|
9299
|
+
})).touched;
|
|
9121
9300
|
const flushExtraPreview = () => {
|
|
9122
9301
|
for (const [sink, line] of extraPreview) sink(line);
|
|
9123
9302
|
};
|
|
@@ -9129,16 +9308,19 @@ Nothing to do: ${target.label} (${scope}) is already configured.`);
|
|
|
9129
9308
|
}
|
|
9130
9309
|
if (repairedContainer) log2(containerRepairNote(repairedContainer, "would replace"));
|
|
9131
9310
|
log2("\n--- dry run: would add the following (the rest of each file is left as-is) ---");
|
|
9132
|
-
if (clientJson !== null && !skipEntryWrite) {
|
|
9133
|
-
const
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9311
|
+
if (clientJson !== null && (!skipEntryWrite || rootSets.length > 0)) {
|
|
9312
|
+
const blocks = [];
|
|
9313
|
+
if (rootSets.length > 0) blocks.push(previewRootDefaults(view, rootSets));
|
|
9314
|
+
if (!skipEntryWrite) {
|
|
9315
|
+
const previewEntry = envCarried && entryToWrite.env ? {
|
|
9316
|
+
...entryToWrite,
|
|
9317
|
+
env: Object.fromEntries(Object.keys(entryToWrite.env).map((k) => [k, DRY_RUN_ENV_PLACEHOLDER]))
|
|
9318
|
+
} : entryToWrite;
|
|
9319
|
+
blocks.push(view.adapter.renderPreview(view.address, ENTRY_NAME, previewEntry, read.kind === "absent"));
|
|
9320
|
+
}
|
|
9321
|
+
log2(`
|
|
9139
9322
|
# ${resolved.absolute}
|
|
9140
|
-
${
|
|
9141
|
-
);
|
|
9323
|
+
${blocks.join("\n")}`);
|
|
9142
9324
|
}
|
|
9143
9325
|
for (const settingsPatch of settingsPatches) {
|
|
9144
9326
|
if (settingsPatch.changed) {
|
|
@@ -9146,6 +9328,9 @@ ${view.adapter.renderPreview(view.address, ENTRY_NAME, previewEntry, read.kind =
|
|
|
9146
9328
|
permissions.allow += ${JSON.stringify(settingsPatch.added)}`);
|
|
9147
9329
|
}
|
|
9148
9330
|
}
|
|
9331
|
+
for (const rootDefault of rootSets) {
|
|
9332
|
+
log2(`Would add ${spellRootDefault(rootDefault)} to ${resolved.absolute}: ${rootDefault.why}.`);
|
|
9333
|
+
}
|
|
9149
9334
|
const freshNote2 = yawFreshPaneNote({
|
|
9150
9335
|
grantPatches: settingsPatches,
|
|
9151
9336
|
target,
|
|
@@ -9195,7 +9380,9 @@ permissions.allow += ${JSON.stringify(settingsPatch.added)}`);
|
|
|
9195
9380
|
try {
|
|
9196
9381
|
await atomicWriteFile(resolved.absolute, clientJson);
|
|
9197
9382
|
} catch (e) {
|
|
9198
|
-
err(
|
|
9383
|
+
err(
|
|
9384
|
+
`yaw-mcp install: ${describeWriteFailure(resolved.absolute, e, { env: locationEnvHint(target, scope, rowArgs, resolved.absolute) })}.`
|
|
9385
|
+
);
|
|
9199
9386
|
return { written, wouldWrite: [], messages, exitCode: 1 };
|
|
9200
9387
|
}
|
|
9201
9388
|
log2(`Wrote ${resolved.absolute}`);
|
|
@@ -9204,22 +9391,25 @@ permissions.allow += ${JSON.stringify(settingsPatch.added)}`);
|
|
|
9204
9391
|
if (trimLegacy) {
|
|
9205
9392
|
log2(`Removed the legacy "${legacyEntry}" entry -- it would have run yaw-mcp a second time.`);
|
|
9206
9393
|
}
|
|
9394
|
+
for (const rootDefault of rootSets) {
|
|
9395
|
+
log2(`Added ${spellRootDefault(rootDefault)} to ${resolved.absolute}: ${rootDefault.why}.`);
|
|
9396
|
+
}
|
|
9207
9397
|
}
|
|
9208
|
-
|
|
9209
|
-
|
|
9210
|
-
|
|
9211
|
-
|
|
9212
|
-
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
9398
|
+
const extras = await applyToExtraSites({
|
|
9399
|
+
cmd: "install",
|
|
9400
|
+
sites: extraSites,
|
|
9401
|
+
transform: target.entry,
|
|
9402
|
+
// The BASE entry, not `entryToWrite`: each copy composes its own from
|
|
9403
|
+
// its own carry. See applyToExtraSites.
|
|
9404
|
+
compose: { base: newEntry, os, force: opts.force === true },
|
|
9405
|
+
keepLegacy: opts.keepLegacy === true,
|
|
9406
|
+
authorised: overwriteAuthorised,
|
|
9407
|
+
dryRun: false,
|
|
9408
|
+
log: log2,
|
|
9409
|
+
err
|
|
9410
|
+
});
|
|
9411
|
+
written.push(...extras.touched);
|
|
9412
|
+
const entryWritten = clientJson !== null && !skipEntryWrite || extras.entryWrites.length > 0;
|
|
9223
9413
|
for (const settingsPatch of settingsPatches) {
|
|
9224
9414
|
if (!settingsPatch.changed) continue;
|
|
9225
9415
|
if (!sameFingerprint(settingsPatch.fingerprint, await fileFingerprint(settingsPatch.path))) {
|
|
@@ -9278,9 +9468,17 @@ Done: ${target.label} is configured. Restart it in this project and approve the
|
|
|
9278
9468
|
// line's: a client that watches its config file must not be told to
|
|
9279
9469
|
// restart, and one that needs a window reload must not be told the
|
|
9280
9470
|
// editor. `reload` defaults to "restart", whose clause is what every
|
|
9281
|
-
// pre-existing row printed, byte for byte.
|
|
9471
|
+
// pre-existing row printed, byte for byte. A run in which no file got
|
|
9472
|
+
// a new or changed entry -- its writes were a legacy trim, a top-level
|
|
9473
|
+
// default (Codex's startup grace) and/or a permissions.allow grant, on
|
|
9474
|
+
// the primary or on an editor copy -- names "the change", never a new
|
|
9475
|
+
// server. Any entry written anywhere keeps the server wording.
|
|
9282
9476
|
`
|
|
9283
|
-
Done: ${target.label} is configured. ${reloadDoneClause(
|
|
9477
|
+
Done: ${target.label} is configured. ${reloadDoneClause(
|
|
9478
|
+
target.reload,
|
|
9479
|
+
target.label,
|
|
9480
|
+
entryWritten ? "server" : "change"
|
|
9481
|
+
)}`
|
|
9284
9482
|
)
|
|
9285
9483
|
);
|
|
9286
9484
|
return { written, wouldWrite: [], messages, exitCode: 0 };
|
|
@@ -9350,7 +9548,7 @@ function sameFingerprint(a, b) {
|
|
|
9350
9548
|
async function promptCollision(path5, diff, io, keptEnvKeys) {
|
|
9351
9549
|
const stdin = io?.stdin ?? process.stdin;
|
|
9352
9550
|
const stdout = io?.stdout ?? process.stdout;
|
|
9353
|
-
const rl =
|
|
9551
|
+
const rl = createInterface2({ input: stdin, output: stdout, terminal: io?.terminal });
|
|
9354
9552
|
try {
|
|
9355
9553
|
const raw = await questionOrEmpty(
|
|
9356
9554
|
rl,
|
|
@@ -9422,6 +9620,7 @@ function describeEntryDiff(stored, nextEntry) {
|
|
|
9422
9620
|
async function applyToExtraSites(args) {
|
|
9423
9621
|
const { cmd, compose, log: log2, err } = args;
|
|
9424
9622
|
const touched = [];
|
|
9623
|
+
const entryWrites = [];
|
|
9425
9624
|
for (const site of args.sites) {
|
|
9426
9625
|
const where = site.resolved.absolute;
|
|
9427
9626
|
const named = `${where} (${site.label})`;
|
|
@@ -9469,11 +9668,12 @@ async function applyToExtraSites(args) {
|
|
|
9469
9668
|
carried: compose.force ? {} : view.carried()
|
|
9470
9669
|
});
|
|
9471
9670
|
const stored = view.normalized();
|
|
9472
|
-
|
|
9671
|
+
const entryChanges = !hasEntry || !deepEqualJson(stored, entry);
|
|
9672
|
+
if (!entryChanges && !trimLegacy) {
|
|
9473
9673
|
log2(`The "${ENTRY_NAME}" entry in ${named} is already correct.`);
|
|
9474
9674
|
continue;
|
|
9475
9675
|
}
|
|
9476
|
-
if (hasEntry &&
|
|
9676
|
+
if (hasEntry && entryChanges && !args.authorised) {
|
|
9477
9677
|
err(
|
|
9478
9678
|
`yaw-mcp ${cmd}: warning -- ${named} already has a differing "${ENTRY_NAME}" entry; left untouched. Re-run with --repair to bring every copy up to date, or --force to overwrite them.`
|
|
9479
9679
|
);
|
|
@@ -9503,19 +9703,21 @@ async function applyToExtraSites(args) {
|
|
|
9503
9703
|
if (args.dryRun) {
|
|
9504
9704
|
log2(`Would also write the "${ENTRY_NAME}" entry to ${named}.`);
|
|
9505
9705
|
touched.push(where);
|
|
9706
|
+
if (entryChanges) entryWrites.push(where);
|
|
9506
9707
|
continue;
|
|
9507
9708
|
}
|
|
9508
9709
|
try {
|
|
9509
9710
|
await atomicWriteFile(where, next);
|
|
9510
9711
|
log2(`Wrote ${named}`);
|
|
9511
9712
|
touched.push(where);
|
|
9713
|
+
if (entryChanges) entryWrites.push(where);
|
|
9512
9714
|
} catch (e) {
|
|
9513
9715
|
err(
|
|
9514
9716
|
`yaw-mcp ${cmd}: warning -- failed to write ${named} (${e.message}); left unchanged. That copy of the client will not see yaw-mcp.`
|
|
9515
9717
|
);
|
|
9516
9718
|
}
|
|
9517
9719
|
}
|
|
9518
|
-
return touched;
|
|
9720
|
+
return { touched, entryWrites };
|
|
9519
9721
|
}
|
|
9520
9722
|
function looksLikeFlag(value) {
|
|
9521
9723
|
return value.startsWith("-");
|
|
@@ -9655,7 +9857,7 @@ async function runInstallList(opts, log2, messages) {
|
|
|
9655
9857
|
const home = opts.home ?? homedir13();
|
|
9656
9858
|
const cwd = resolve5(opts.cwd ?? process.cwd(), opts.projectDir ?? ".");
|
|
9657
9859
|
const os = opts.os ?? CURRENT_OS;
|
|
9658
|
-
const
|
|
9860
|
+
const where = {
|
|
9659
9861
|
home,
|
|
9660
9862
|
os,
|
|
9661
9863
|
cwd,
|
|
@@ -9665,12 +9867,15 @@ async function runInstallList(opts, log2, messages) {
|
|
|
9665
9867
|
// show "not installed" beside an entry sitting at the redirected path.
|
|
9666
9868
|
clientEnv: opts.clientEnv,
|
|
9667
9869
|
appData: resolveAppData(opts)
|
|
9668
|
-
}
|
|
9669
|
-
const
|
|
9870
|
+
};
|
|
9871
|
+
const probes = await probeClientsAsync(where);
|
|
9872
|
+
const rootPlans = [];
|
|
9873
|
+
for (const p of probes) rootPlans.push(await listRootPlan(p, where));
|
|
9874
|
+
const rows = probes.map((p, i) => ({
|
|
9670
9875
|
client: INSTALL_TARGETS.find((t) => t.clientId === p.clientId)?.label ?? p.clientId,
|
|
9671
9876
|
scope: p.scope,
|
|
9672
9877
|
path: displayPath(p.path, home, os),
|
|
9673
|
-
status: statusFor(p)
|
|
9878
|
+
status: statusFor(p, rootPlans[i])
|
|
9674
9879
|
}));
|
|
9675
9880
|
const installed = probes.filter((p) => p.hasMcpEntry && p.unloadable === null).length;
|
|
9676
9881
|
const available = probes.filter((p) => !p.unavailable).length;
|
|
@@ -9698,17 +9903,84 @@ async function runInstallList(opts, log2, messages) {
|
|
|
9698
9903
|
);
|
|
9699
9904
|
log2("");
|
|
9700
9905
|
}
|
|
9906
|
+
for (const [i, p] of probes.entries()) {
|
|
9907
|
+
const plan = rootPlans[i];
|
|
9908
|
+
if (plan === null) continue;
|
|
9909
|
+
for (const line of listRootNotes(p, plan, { home, os, cwd, projectDirGiven: opts.projectDir !== void 0 })) {
|
|
9910
|
+
log2(line);
|
|
9911
|
+
}
|
|
9912
|
+
log2("");
|
|
9913
|
+
}
|
|
9701
9914
|
log2("Install into a specific client: `yaw-mcp install <client> [--scope user|project|local]`");
|
|
9702
9915
|
log2("Install into every supported client (user scope where supported): `yaw-mcp install --all`");
|
|
9703
9916
|
return { written: [], wouldWrite: [], messages, exitCode: 0 };
|
|
9704
9917
|
}
|
|
9705
|
-
function
|
|
9918
|
+
async function listRootPlan(p, where) {
|
|
9919
|
+
if (p.unavailable || !p.hasMcpEntry || p.unloadable !== null) return null;
|
|
9920
|
+
const target = INSTALL_TARGETS.find((t) => t.clientId === p.clientId);
|
|
9921
|
+
const defaults = target?.config.rootDefaults;
|
|
9922
|
+
if (target === void 0 || defaults === void 0 || defaults.length === 0) return null;
|
|
9923
|
+
const spec = target.scopes.find((s) => s.scope === p.scope);
|
|
9924
|
+
if (spec === void 0) return null;
|
|
9925
|
+
let site;
|
|
9926
|
+
try {
|
|
9927
|
+
site = resolveInstallSites({
|
|
9928
|
+
clientId: target.clientId,
|
|
9929
|
+
scope: p.scope,
|
|
9930
|
+
os: where.os,
|
|
9931
|
+
home: where.home,
|
|
9932
|
+
appData: where.appData,
|
|
9933
|
+
projectDir: spec.requiresProjectDir ? where.cwd : void 0,
|
|
9934
|
+
claudeConfigDir: where.claudeConfigDir,
|
|
9935
|
+
clientEnv: where.clientEnv
|
|
9936
|
+
})[0];
|
|
9937
|
+
} catch {
|
|
9938
|
+
return null;
|
|
9939
|
+
}
|
|
9940
|
+
if (site.resolved.absolute !== p.path) return null;
|
|
9941
|
+
const plan = planRootDefaults(await readClientConfigFile(site, { transform: target.entry }), defaults);
|
|
9942
|
+
return plan.set.length > 0 || plan.kept.some((k) => k.refused !== void 0) ? plan : null;
|
|
9943
|
+
}
|
|
9944
|
+
function listRootNotes(p, plan, at) {
|
|
9945
|
+
const target = INSTALL_TARGETS.find((t) => t.clientId === p.clientId);
|
|
9946
|
+
const label = target?.label ?? p.clientId;
|
|
9947
|
+
const file = displayPath(p.path, at.home, at.os);
|
|
9948
|
+
const lines = [];
|
|
9949
|
+
for (const { rootDefault, value, float, refused } of plan.kept) {
|
|
9950
|
+
if (refused === void 0) continue;
|
|
9951
|
+
const spelled = float ?? spellRootValue(value, p.syntax);
|
|
9952
|
+
const recommended = JSON.stringify(rootDefault.value);
|
|
9953
|
+
if (refused.everyRelease !== void 0) {
|
|
9954
|
+
lines.push(
|
|
9955
|
+
`Note: ${file} sets ${rootDefault.key} to ${spelled}, ${refused.everyRelease}, so ${label} will not load the file -- change that value by hand to ${refused.needs} (${recommended} is recommended).`
|
|
9956
|
+
);
|
|
9957
|
+
continue;
|
|
9958
|
+
}
|
|
9959
|
+
const kind = refused.kind === void 0 ? "" : `${refused.kind} `;
|
|
9960
|
+
lines.push(
|
|
9961
|
+
`Note: ${file} sets ${rootDefault.key} to ${spelled}, ${kind}where ${label} needs ${refused.needs} -- a ${label} release that reads the key will not load the file with that value; ${recommended} is recommended. ${keptRootStep(value, p.syntax)}`
|
|
9962
|
+
);
|
|
9963
|
+
}
|
|
9964
|
+
if (plan.set.length > 0) {
|
|
9965
|
+
const scopeSpec = target?.scopes.find((s) => s.scope === p.scope);
|
|
9966
|
+
const projectFlag = at.projectDirGiven && scopeSpec?.requiresProjectDir === true ? ` --project-dir ${quoteArgForDisplay(at.cwd) ?? at.cwd}` : "";
|
|
9967
|
+
const run2 = `yaw-mcp install ${p.clientId}${p.scope === "user" ? "" : ` --scope ${p.scope}`}${projectFlag}`;
|
|
9968
|
+
for (const rootDefault of plan.set) {
|
|
9969
|
+
lines.push(
|
|
9970
|
+
`Note: ${file} has the ${label} (${p.scope}) entry but does not set ${spellRootDefault(rootDefault)}: ${rootDefault.why}. \`${run2}\` adds it.`
|
|
9971
|
+
);
|
|
9972
|
+
}
|
|
9973
|
+
}
|
|
9974
|
+
return lines;
|
|
9975
|
+
}
|
|
9976
|
+
function statusFor(p, rootPlan = null) {
|
|
9706
9977
|
if (p.unavailable) return p.unavailableReason !== void 0 ? "not supported yet" : "unavailable";
|
|
9707
9978
|
if (p.malformed) return "malformed";
|
|
9708
9979
|
if (p.unreadable) return `unreadable: ${p.unreadable}`;
|
|
9709
9980
|
if (p.unloadable) return "not loading (comments or trailing commas)";
|
|
9710
9981
|
const keySuffix = p.entryProjectKey ? " (other drive case)" : "";
|
|
9711
|
-
|
|
9982
|
+
const rootSuffix = rootPlan === null ? "" : rootPlan.kept.some((k) => k.refused !== void 0) ? " (setting refused)" : rootPlan.set.length > 0 ? " (setting missing)" : "";
|
|
9983
|
+
if (p.hasMcpEntry) return `installed${keySuffix}${rootSuffix}`;
|
|
9712
9984
|
if (p.hasLegacyEntry) return `legacy: ${p.legacyEntryName ?? "unknown"}${keySuffix}`;
|
|
9713
9985
|
if (!p.exists) return "not installed";
|
|
9714
9986
|
return p.containerEntries > 0 ? "other-entries" : "no-entries";
|
|
@@ -9944,7 +10216,7 @@ function entryEnvKeys(entry) {
|
|
|
9944
10216
|
async function promptUninstall(question, io) {
|
|
9945
10217
|
const stdin = io?.stdin ?? process.stdin;
|
|
9946
10218
|
const stdout = io?.stdout ?? process.stdout;
|
|
9947
|
-
const rl =
|
|
10219
|
+
const rl = createInterface2({ input: stdin, output: stdout, terminal: io?.terminal });
|
|
9948
10220
|
try {
|
|
9949
10221
|
const raw = await questionOrEmpty(rl, question);
|
|
9950
10222
|
if (raw === QUESTION_CANCELLED) return "cancelled";
|
|
@@ -9968,6 +10240,39 @@ function launchesViaNpx(entry) {
|
|
|
9968
10240
|
const launcher = (command.split(/[\\/]/).pop() ?? command).toLowerCase();
|
|
9969
10241
|
return (launcher === "cmd" || launcher === "cmd.exe") && Array.isArray(args) && typeof args[0] === "string" && args[0].toLowerCase() === "/c" && typeof args[1] === "string" && nodeLaunchKind(args[1]) === "npx";
|
|
9970
10242
|
}
|
|
10243
|
+
function rowResolveArgs(opts, os, projectDir) {
|
|
10244
|
+
return {
|
|
10245
|
+
os,
|
|
10246
|
+
home: opts.home ?? homedir13(),
|
|
10247
|
+
appData: resolveAppDataDir({ appData: opts.appData, home: opts.home }),
|
|
10248
|
+
projectDir,
|
|
10249
|
+
claudeConfigDir: opts.claudeConfigDir,
|
|
10250
|
+
clientEnv: opts.clientEnv
|
|
10251
|
+
};
|
|
10252
|
+
}
|
|
10253
|
+
function locationEnvHint(target, scope, where, file) {
|
|
10254
|
+
const env = where.clientEnv ?? {};
|
|
10255
|
+
for (const name of CLIENT_ENV_VARS) {
|
|
10256
|
+
const key = Object.keys(readClientEnv({ [name]: "set" }))[0];
|
|
10257
|
+
if (key === void 0) continue;
|
|
10258
|
+
const value = key === "claudeConfigDir" ? where.claudeConfigDir ?? env.claudeConfigDir : env[key];
|
|
10259
|
+
if (value === void 0 || value.length === 0) continue;
|
|
10260
|
+
let unmoved;
|
|
10261
|
+
try {
|
|
10262
|
+
unmoved = resolveInstallPath({
|
|
10263
|
+
clientId: target.clientId,
|
|
10264
|
+
scope,
|
|
10265
|
+
...where,
|
|
10266
|
+
claudeConfigDir: key === "claudeConfigDir" ? void 0 : where.claudeConfigDir,
|
|
10267
|
+
clientEnv: { ...env, [key]: void 0 }
|
|
10268
|
+
}).absolute;
|
|
10269
|
+
} catch {
|
|
10270
|
+
continue;
|
|
10271
|
+
}
|
|
10272
|
+
if (samePathKey(unmoved) !== samePathKey(file)) return { name, value };
|
|
10273
|
+
}
|
|
10274
|
+
return void 0;
|
|
10275
|
+
}
|
|
9971
10276
|
async function shadowedLocalLaunch(target, scope, where) {
|
|
9972
10277
|
if (!target.hooks?.alsoReads) return null;
|
|
9973
10278
|
let sites;
|
|
@@ -10087,7 +10392,14 @@ ${UNINSTALL_USAGE}`);
|
|
|
10087
10392
|
const view = await readClientConfigFile(site, { transform: target.entry });
|
|
10088
10393
|
const read = view.read;
|
|
10089
10394
|
if (read.kind === "unreadable") {
|
|
10090
|
-
err(
|
|
10395
|
+
err(
|
|
10396
|
+
describeUnreadableConfig(
|
|
10397
|
+
"uninstall",
|
|
10398
|
+
resolved.absolute,
|
|
10399
|
+
{ code: read.code, message: read.message },
|
|
10400
|
+
locationEnvHint(target, scope, rowResolveArgs(opts, os, projectDir), resolved.absolute)
|
|
10401
|
+
)
|
|
10402
|
+
);
|
|
10091
10403
|
return { written: [], wouldWrite: [], messages, exitCode: 1 };
|
|
10092
10404
|
}
|
|
10093
10405
|
if (read.kind === "malformed") {
|
|
@@ -10096,6 +10408,12 @@ ${UNINSTALL_USAGE}`);
|
|
|
10096
10408
|
);
|
|
10097
10409
|
return { written: [], wouldWrite: [], messages, exitCode: 1 };
|
|
10098
10410
|
}
|
|
10411
|
+
if (read.kind === "unspliceable") {
|
|
10412
|
+
err(
|
|
10413
|
+
`yaw-mcp uninstall: the "${read.key}" entry in ${resolved.absolute} is ${read.reason}, which uninstall will not edit -- nothing was removed; ${unspliceableFix(read)}, then re-run.`
|
|
10414
|
+
);
|
|
10415
|
+
return { written: [], wouldWrite: [], messages, exitCode: 1 };
|
|
10416
|
+
}
|
|
10099
10417
|
const variantPaths = claudeCodeContainerPathVariants(
|
|
10100
10418
|
containerPath,
|
|
10101
10419
|
(prefix) => containerKeysAt(view.raw, site, prefix)
|
|
@@ -10136,14 +10454,7 @@ ${UNINSTALL_USAGE}`);
|
|
|
10136
10454
|
`yaw-mcp uninstall: warning -- could not patch ${settingsPatch.path} (${settingsPatch.malformedReason}); left unchanged. Remove "${CLAUDE_CODE_ALLOW_PATTERN}" from permissions.allow by hand.`
|
|
10137
10455
|
);
|
|
10138
10456
|
}
|
|
10139
|
-
const rowArgs =
|
|
10140
|
-
os,
|
|
10141
|
-
home,
|
|
10142
|
-
appData: resolveAppDataDir({ appData: opts.appData, home: opts.home }),
|
|
10143
|
-
projectDir,
|
|
10144
|
-
claudeConfigDir: opts.claudeConfigDir,
|
|
10145
|
-
clientEnv: opts.clientEnv
|
|
10146
|
-
};
|
|
10457
|
+
const rowArgs = rowResolveArgs(opts, os, projectDir);
|
|
10147
10458
|
const primaryPatch = grant.patches.find((p) => !p.yawHome) ?? null;
|
|
10148
10459
|
const scopedGrantNote = grant.overlay !== null || primaryPatch === null ? null : configDirScopedGrantNote({
|
|
10149
10460
|
cmd: "uninstall",
|
|
@@ -10203,7 +10514,7 @@ ${UNINSTALL_USAGE}`);
|
|
|
10203
10514
|
}
|
|
10204
10515
|
if (scopedGrantNote !== null) log2(scopedGrantNote);
|
|
10205
10516
|
const extraPreview = [];
|
|
10206
|
-
const extraWouldRemove = await applyToExtraSites({
|
|
10517
|
+
const extraWouldRemove = (await applyToExtraSites({
|
|
10207
10518
|
cmd: "uninstall",
|
|
10208
10519
|
sites: extraSites,
|
|
10209
10520
|
transform: target.entry,
|
|
@@ -10213,7 +10524,7 @@ ${UNINSTALL_USAGE}`);
|
|
|
10213
10524
|
dryRun: true,
|
|
10214
10525
|
log: (line) => extraPreview.push({ stream: "log", line }),
|
|
10215
10526
|
err: (line) => extraPreview.push({ stream: "err", line })
|
|
10216
|
-
});
|
|
10527
|
+
})).touched;
|
|
10217
10528
|
const flushExtraPreview = (warnings) => {
|
|
10218
10529
|
for (const { stream, line } of extraPreview) {
|
|
10219
10530
|
if (stream === "err" && !warnings) continue;
|
|
@@ -10249,6 +10560,9 @@ Nothing to do: ${target.label} (${scope}) has no yaw-mcp entry.`
|
|
|
10249
10560
|
log2(`
|
|
10250
10561
|
--- dry run: would remove the following (the rest of each file is left as-is) ---`);
|
|
10251
10562
|
for (const line of preview) log2(` ${line}`);
|
|
10563
|
+
if (removals.length > 0) {
|
|
10564
|
+
for (const line of keptRootDefaultLines(target, view, resolved.absolute, "dry-run")) log2(line);
|
|
10565
|
+
}
|
|
10252
10566
|
flushExtraPreview(true);
|
|
10253
10567
|
const wouldWrite = [];
|
|
10254
10568
|
if (removals.length > 0) wouldWrite.push(resolved.absolute);
|
|
@@ -10317,7 +10631,9 @@ Nothing to do: ${target.label} (${scope}) has no yaw-mcp entry.`
|
|
|
10317
10631
|
try {
|
|
10318
10632
|
await atomicWriteFile(resolved.absolute, clientJson);
|
|
10319
10633
|
} catch (e) {
|
|
10320
|
-
err(
|
|
10634
|
+
err(
|
|
10635
|
+
`yaw-mcp uninstall: ${describeWriteFailure(resolved.absolute, e, { env: locationEnvHint(target, scope, rowArgs, resolved.absolute) })}.`
|
|
10636
|
+
);
|
|
10321
10637
|
return { written, wouldWrite: [], messages, exitCode: 1 };
|
|
10322
10638
|
}
|
|
10323
10639
|
log2(`Wrote ${resolved.absolute}`);
|
|
@@ -10326,9 +10642,11 @@ Nothing to do: ${target.label} (${scope}) has no yaw-mcp entry.`
|
|
|
10326
10642
|
if (s.hasEntry) log2(`Removed the "${ENTRY_NAME}" entry${where(s)}.`);
|
|
10327
10643
|
if (trimsLegacy(s)) log2(`Removed the legacy "${s.legacyEntry}" entry${where(s)}.`);
|
|
10328
10644
|
}
|
|
10645
|
+
const after = classifyClientConfig(clientJson, site, { transform: target.entry });
|
|
10646
|
+
for (const line of keptRootDefaultLines(target, after, resolved.absolute, "live")) log2(line);
|
|
10329
10647
|
}
|
|
10330
10648
|
written.push(
|
|
10331
|
-
...await applyToExtraSites({
|
|
10649
|
+
...(await applyToExtraSites({
|
|
10332
10650
|
cmd: "uninstall",
|
|
10333
10651
|
sites: extraSites,
|
|
10334
10652
|
transform: target.entry,
|
|
@@ -10338,7 +10656,7 @@ Nothing to do: ${target.label} (${scope}) has no yaw-mcp entry.`
|
|
|
10338
10656
|
dryRun: false,
|
|
10339
10657
|
log: log2,
|
|
10340
10658
|
err
|
|
10341
|
-
})
|
|
10659
|
+
})).touched
|
|
10342
10660
|
);
|
|
10343
10661
|
for (const settingsPatch of settingsPatches) {
|
|
10344
10662
|
if (!settingsPatch.changed) continue;
|
|
@@ -10376,6 +10694,15 @@ function uninstallDoneLine(target, display) {
|
|
|
10376
10694
|
return `
|
|
10377
10695
|
Done: ${head} ${reloadRemovalClause(target.reload, target.label)}${note === void 0 ? "" : ` ${note}`} Your servers in ~/.yaw-mcp/bundles.json are untouched -- \`yaw-mcp install ${target.clientId}\` wires it back.`;
|
|
10378
10696
|
}
|
|
10697
|
+
function keptRootDefaultLines(target, view, file, mode) {
|
|
10698
|
+
const defaults = target.config.rootDefaults;
|
|
10699
|
+
if (defaults === void 0 || defaults.length === 0 || view.read.kind !== "ok") return [];
|
|
10700
|
+
const plan = planRootDefaults(view, defaults);
|
|
10701
|
+
const verb = mode === "dry-run" ? "Would keep" : "Keeping";
|
|
10702
|
+
return defaults.filter((d) => !plan.set.includes(d) && !plan.kept.some((k) => k.rootDefault === d)).map(
|
|
10703
|
+
(d) => `${verb} ${d.key} at ${JSON.stringify(d.value)} in ${file}: uninstall leaves top-level settings alone -- this one is not a server, and it may be your own. Delete the line that sets it by hand if you no longer want it.`
|
|
10704
|
+
);
|
|
10705
|
+
}
|
|
10379
10706
|
|
|
10380
10707
|
// src/try-cmd.ts
|
|
10381
10708
|
var USAGE_INDENT = " ".repeat(23);
|
|
@@ -10561,8 +10888,14 @@ function rejectUntrustedMarker(marker) {
|
|
|
10561
10888
|
if (typeof marker.schemaVersion === "number" && marker.schemaVersion > TRIAL_SCHEMA_VERSION) {
|
|
10562
10889
|
return `was written by a newer yaw-mcp (schemaVersion ${marker.schemaVersion} > ${TRIAL_SCHEMA_VERSION})`;
|
|
10563
10890
|
}
|
|
10891
|
+
if (marker.format !== void 0 && !isReadableFormat(marker.format)) {
|
|
10892
|
+
return `records a config format this yaw-mcp cannot read (${JSON.stringify(marker.format)})`;
|
|
10893
|
+
}
|
|
10564
10894
|
return null;
|
|
10565
10895
|
}
|
|
10896
|
+
function isReadableFormat(value) {
|
|
10897
|
+
return typeof value === "string" && CONFIG_FORMATS.includes(value) && hasConfigAdapter(value);
|
|
10898
|
+
}
|
|
10566
10899
|
function trialLaunchFingerprint(entry) {
|
|
10567
10900
|
const command = typeof entry.command === "string" ? entry.command : "";
|
|
10568
10901
|
const args = Array.isArray(entry.args) ? entry.args.filter((a) => typeof a === "string") : [];
|
|
@@ -10584,8 +10917,9 @@ async function readTrialMarker(markerPath) {
|
|
|
10584
10917
|
return null;
|
|
10585
10918
|
}
|
|
10586
10919
|
}
|
|
10587
|
-
async function peelEntryFromConfig(
|
|
10588
|
-
const
|
|
10920
|
+
async function peelEntryFromConfig(marker, dryRun = false) {
|
|
10921
|
+
const { clientPath, entryName, entryFingerprint: expectFingerprint } = marker;
|
|
10922
|
+
const site = markerSite(marker);
|
|
10589
10923
|
const view = await readClientConfigFile(site);
|
|
10590
10924
|
const read = view.read;
|
|
10591
10925
|
if (read.kind === "absent") return "absent";
|
|
@@ -10608,28 +10942,29 @@ async function peelEntryFromConfig(clientPath, containerPath, entryName, dryRun
|
|
|
10608
10942
|
await atomicWriteFile(clientPath, terminateWithNewline(next));
|
|
10609
10943
|
return "removed";
|
|
10610
10944
|
}
|
|
10611
|
-
function
|
|
10945
|
+
function markerFormat(marker) {
|
|
10946
|
+
if (marker.format !== void 0) return marker.format;
|
|
10947
|
+
return /\.toml$/i.test(marker.clientPath) ? "toml" : "jsonc";
|
|
10948
|
+
}
|
|
10949
|
+
function markerSite(marker) {
|
|
10612
10950
|
return {
|
|
10613
10951
|
id: "trial",
|
|
10614
10952
|
label: "trial entry",
|
|
10615
|
-
resolved: { absolute: clientPath, display: clientPath, containerPath: [...containerPath] },
|
|
10616
|
-
format:
|
|
10953
|
+
resolved: { absolute: marker.clientPath, display: marker.clientPath, containerPath: [...marker.containerPath] },
|
|
10954
|
+
format: markerFormat(marker),
|
|
10617
10955
|
detectDir: null
|
|
10618
10956
|
};
|
|
10619
10957
|
}
|
|
10958
|
+
function notAContainer(marker) {
|
|
10959
|
+
return `${marker.clientPath} is not ${containerNounFor(syntaxNameFor(markerFormat(marker)))}`;
|
|
10960
|
+
}
|
|
10620
10961
|
function configHasEntry(raw, site, entryName) {
|
|
10621
10962
|
return classifyClientConfig(raw, site).entry(entryName) !== void 0;
|
|
10622
10963
|
}
|
|
10623
10964
|
async function peelTrialEntry(marker, dryRun = false) {
|
|
10624
10965
|
if (rejectUntrustedMarker(marker) !== null) return "failed";
|
|
10625
10966
|
try {
|
|
10626
|
-
const outcome = await peelEntryFromConfig(
|
|
10627
|
-
marker.clientPath,
|
|
10628
|
-
marker.containerPath,
|
|
10629
|
-
marker.entryName,
|
|
10630
|
-
dryRun,
|
|
10631
|
-
marker.entryFingerprint
|
|
10632
|
-
);
|
|
10967
|
+
const outcome = await peelEntryFromConfig(marker, dryRun);
|
|
10633
10968
|
return outcome === "not-object" ? "failed" : outcome;
|
|
10634
10969
|
} catch {
|
|
10635
10970
|
return "failed";
|
|
@@ -10816,7 +11151,11 @@ async function runTry(opts) {
|
|
|
10816
11151
|
// actually written -- not from `server`, so the Windows `cmd /c` wrap that
|
|
10817
11152
|
// buildLaunchEntry adds is inside the fingerprint, exactly as it will be
|
|
10818
11153
|
// read back out of the config.
|
|
10819
|
-
entryFingerprint: trialLaunchFingerprint(entryToWrite)
|
|
11154
|
+
entryFingerprint: trialLaunchFingerprint(entryToWrite),
|
|
11155
|
+
// The syntax of the file the entry goes into -- the SAME site the read and
|
|
11156
|
+
// the splice below use -- so try-cleanup and doctor's GC read it back with
|
|
11157
|
+
// that adapter (see TrialMarker.format). "toml" for Codex CLI.
|
|
11158
|
+
format: site.format
|
|
10820
11159
|
};
|
|
10821
11160
|
const readClientView = async () => {
|
|
10822
11161
|
const view = await readClientConfigFile(site);
|
|
@@ -10965,18 +11304,6 @@ function isInteractive2(opts) {
|
|
|
10965
11304
|
if (opts.promptAnswer !== void 0) return true;
|
|
10966
11305
|
return Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY);
|
|
10967
11306
|
}
|
|
10968
|
-
async function askYesNo2(opts, question) {
|
|
10969
|
-
if (opts.promptAnswer !== void 0) return opts.promptAnswer.trim().toLowerCase();
|
|
10970
|
-
const input = opts.io?.stdin ?? process.stdin;
|
|
10971
|
-
const output = opts.io?.stdout ?? process.stdout;
|
|
10972
|
-
const rl = createInterface2({ input, output, terminal: opts.io?.terminal });
|
|
10973
|
-
try {
|
|
10974
|
-
const raw = await questionOrEmpty(rl, question);
|
|
10975
|
-
return raw === QUESTION_CANCELLED ? raw : raw.trim().toLowerCase();
|
|
10976
|
-
} finally {
|
|
10977
|
-
rl.close();
|
|
10978
|
-
}
|
|
10979
|
-
}
|
|
10980
11307
|
async function runTryCleanup(opts) {
|
|
10981
11308
|
const out = opts.out ?? createStreamWriter(process.stdout);
|
|
10982
11309
|
const err = opts.err ?? createStreamWriter(process.stderr);
|
|
@@ -11032,7 +11359,7 @@ async function runTryCleanup(opts) {
|
|
|
11032
11359
|
printErr(" Re-run with --force (or -y) to remove it.");
|
|
11033
11360
|
return { exitCode: 2, written: [] };
|
|
11034
11361
|
}
|
|
11035
|
-
const answer = await
|
|
11362
|
+
const answer = await askYesNo(opts, ` Remove "${marker.entryName}"? [y/N] `);
|
|
11036
11363
|
if (answer === QUESTION_CANCELLED) {
|
|
11037
11364
|
printErr("yaw-mcp try-cleanup: Cancelled. Nothing was removed.");
|
|
11038
11365
|
return { exitCode: 130, written: [] };
|
|
@@ -11044,14 +11371,9 @@ async function runTryCleanup(opts) {
|
|
|
11044
11371
|
}
|
|
11045
11372
|
const written = [];
|
|
11046
11373
|
let leftReplacedEntry = false;
|
|
11374
|
+
let peelFailure = null;
|
|
11047
11375
|
try {
|
|
11048
|
-
const outcome = await peelEntryFromConfig(
|
|
11049
|
-
marker.clientPath,
|
|
11050
|
-
marker.containerPath,
|
|
11051
|
-
marker.entryName,
|
|
11052
|
-
false,
|
|
11053
|
-
marker.entryFingerprint
|
|
11054
|
-
);
|
|
11376
|
+
const outcome = await peelEntryFromConfig(marker);
|
|
11055
11377
|
if (outcome === "replaced") {
|
|
11056
11378
|
leftReplacedEntry = true;
|
|
11057
11379
|
printErr(
|
|
@@ -11062,14 +11384,19 @@ async function runTryCleanup(opts) {
|
|
|
11062
11384
|
written.push(marker.clientPath);
|
|
11063
11385
|
print(`Removed ${marker.entryName} from ${marker.clientPath}`);
|
|
11064
11386
|
} else if (outcome === "not-object") {
|
|
11065
|
-
|
|
11066
|
-
`yaw-mcp try-cleanup: warning -- couldn't strip ${marker.entryName} from ${marker.clientPath} (${marker.clientPath} is not a JSON object).`
|
|
11067
|
-
);
|
|
11387
|
+
peelFailure = notAContainer(marker);
|
|
11068
11388
|
}
|
|
11069
11389
|
} catch (e) {
|
|
11390
|
+
peelFailure = e.message;
|
|
11391
|
+
}
|
|
11392
|
+
if (peelFailure !== null) {
|
|
11393
|
+
printErr(
|
|
11394
|
+
`yaw-mcp try-cleanup: couldn't strip ${marker.entryName} from ${marker.clientPath} (${peelFailure}) -- it may still be wired in, so the trial marker was kept.`
|
|
11395
|
+
);
|
|
11070
11396
|
printErr(
|
|
11071
|
-
`
|
|
11397
|
+
` Fix that file (or remove the ${marker.entryName} entry from it by hand), then re-run: yaw-mcp try-cleanup ${slug}`
|
|
11072
11398
|
);
|
|
11399
|
+
return { exitCode: 1, written: [] };
|
|
11073
11400
|
}
|
|
11074
11401
|
try {
|
|
11075
11402
|
await unlink2(markerPath);
|
|
@@ -11140,13 +11467,7 @@ async function gcExpiredTrials(opts) {
|
|
|
11140
11467
|
for (const { marker, path: path5 } of scan.expired) {
|
|
11141
11468
|
let stage = "peel";
|
|
11142
11469
|
try {
|
|
11143
|
-
const outcome = await peelEntryFromConfig(
|
|
11144
|
-
marker.clientPath,
|
|
11145
|
-
marker.containerPath,
|
|
11146
|
-
marker.entryName,
|
|
11147
|
-
false,
|
|
11148
|
-
marker.entryFingerprint
|
|
11149
|
-
);
|
|
11470
|
+
const outcome = await peelEntryFromConfig(marker);
|
|
11150
11471
|
if (outcome === "replaced") {
|
|
11151
11472
|
stage = "replaced";
|
|
11152
11473
|
let markerRemoved = true;
|
|
@@ -11168,7 +11489,7 @@ async function gcExpiredTrials(opts) {
|
|
|
11168
11489
|
continue;
|
|
11169
11490
|
}
|
|
11170
11491
|
if (outcome === "not-object") {
|
|
11171
|
-
throw new Error(
|
|
11492
|
+
throw new Error(notAContainer(marker));
|
|
11172
11493
|
}
|
|
11173
11494
|
stage = "unlink";
|
|
11174
11495
|
await unlink2(path5);
|
|
@@ -11436,7 +11757,7 @@ function foldBundleWarnings(warnings, probe) {
|
|
|
11436
11757
|
const prefix = `${probe.path}:`;
|
|
11437
11758
|
return warnings.filter((w) => !w.startsWith(prefix));
|
|
11438
11759
|
}
|
|
11439
|
-
var VERSION = true ? "1.0.
|
|
11760
|
+
var VERSION = true ? "1.0.16" : "dev";
|
|
11440
11761
|
var DOCTOR_USAGE = `Usage: yaw-mcp doctor [--json]
|
|
11441
11762
|
|
|
11442
11763
|
Print a diagnostic of your yaw-mcp setup.
|
|
@@ -11492,9 +11813,12 @@ async function collectStateStatus(opts) {
|
|
|
11492
11813
|
return { disabled, filePath, peek, persisted };
|
|
11493
11814
|
}
|
|
11494
11815
|
function describeClient(c) {
|
|
11495
|
-
const installCmd =
|
|
11816
|
+
const installCmd = installCommandFor(c);
|
|
11496
11817
|
const client = INSTALL_TARGETS.find((t) => t.clientId === c.clientId)?.label ?? c.clientId;
|
|
11497
|
-
return { client, label: `${client} (${c.scope})`, status: renderClientStatus(c, installCmd) };
|
|
11818
|
+
return { client, label: `${client} (${c.scope})`, status: renderClientStatus(c, installCmd, client) };
|
|
11819
|
+
}
|
|
11820
|
+
function installCommandFor(c) {
|
|
11821
|
+
return `yaw-mcp install ${c.clientId}${c.scope === "user" ? "" : ` --scope ${c.scope}`}`;
|
|
11498
11822
|
}
|
|
11499
11823
|
var TRANSIENT_READ_CODES = /* @__PURE__ */ new Set(["EBUSY", "EAGAIN"]);
|
|
11500
11824
|
function isTransientRead(c) {
|
|
@@ -11511,7 +11835,28 @@ function clientCannotLaunch(c) {
|
|
|
11511
11835
|
// exit 2); a strict file that HOLDS the "mcp" entry is the state this
|
|
11512
11836
|
// fold exists for -- the CLIENTS row says the entry is not loading while
|
|
11513
11837
|
// DIAGNOSIS said "All good", on --json too.
|
|
11514
|
-
c.unloadable !== null && c.hasMcpEntry ||
|
|
11838
|
+
c.unloadable !== null && c.hasMcpEntry || // The same fold one level up the file: our entry sits in a file whose
|
|
11839
|
+
// client refuses to load it over a TOP-LEVEL setting -- Codex's
|
|
11840
|
+
// `mcp_optional_startup_grace_ms` at -1, "0" or 0.0, which a Codex that
|
|
11841
|
+
// reads the key (0.151 on, whose source types it as a u64) stops on at
|
|
11842
|
+
// startup, measured on 0.156.1: "failed to load bootstrap configuration",
|
|
11843
|
+
// exit 1 -- or at an integer no release loads. The client starts nothing
|
|
11844
|
+
// from that file, ours included, which is this fold's definition, and the
|
|
11845
|
+
// CLIENTS line no longer reads OK. Only WITH our entry, for the reason the
|
|
11846
|
+
// strict-file line above gives: a file yaw-mcp was never installed to is
|
|
11847
|
+
// advice (the CLIENTS line carries it), not a fault of this setup.
|
|
11848
|
+
//
|
|
11849
|
+
// A MISSING top-level setting is not here, on the precedent of a legacy
|
|
11850
|
+
// entry beside a working one: the file loads and yaw-mcp starts, and what
|
|
11851
|
+
// the missing key costs depends on the client (Codex 0.151 and later give
|
|
11852
|
+
// optional servers one shared second to start and leave a slower yaw-mcp
|
|
11853
|
+
// out of that whole session; an older Codex does not read the key) -- a
|
|
11854
|
+
// degraded setup with an install run that fixes it, which the CLIENTS line
|
|
11855
|
+
// and DIAGNOSIS (rootDefaultSteps) name, not one that cannot launch. Folding
|
|
11856
|
+
// it would take every Codex setup installed before the key existed to exit
|
|
11857
|
+
// 2, and the Yaw Terminal panel that polls `doctor --json` to "Warnings
|
|
11858
|
+
// need attention", over a step the report already gives.
|
|
11859
|
+
c.hasMcpEntry && c.rootDefaults.some((d) => d.state === "refused" || d.state === "refused-every-release") || c.launchCommandMissing !== null || c.launchOamEntryMissing !== null || c.launchOamNotAbsolute !== null;
|
|
11515
11860
|
}
|
|
11516
11861
|
function clientLaunchWarnings(clients) {
|
|
11517
11862
|
const grouped = /* @__PURE__ */ new Map();
|
|
@@ -11526,6 +11871,22 @@ function clientLaunchWarnings(clients) {
|
|
|
11526
11871
|
}
|
|
11527
11872
|
return [...grouped.values()].map((g) => `${g.path}: ${g.client} (${g.scopes.join(", ")}) ${g.status}`);
|
|
11528
11873
|
}
|
|
11874
|
+
function rootDefaultSteps(clients) {
|
|
11875
|
+
const steps = /* @__PURE__ */ new Map();
|
|
11876
|
+
for (const c of clients) {
|
|
11877
|
+
if (!c.hasMcpEntry || c.launchForeignPath !== null) continue;
|
|
11878
|
+
for (const d of c.rootDefaults) {
|
|
11879
|
+
if (d.state !== "missing") continue;
|
|
11880
|
+
const key = `${c.path}\0${d.key}`;
|
|
11881
|
+
if (steps.has(key)) continue;
|
|
11882
|
+
steps.set(
|
|
11883
|
+
key,
|
|
11884
|
+
`Run \`${installCommandFor(c)}\` to add ${d.key} = ${JSON.stringify(d.recommended)} to ${c.path}: ${d.why}.`
|
|
11885
|
+
);
|
|
11886
|
+
}
|
|
11887
|
+
}
|
|
11888
|
+
return [...steps.values()];
|
|
11889
|
+
}
|
|
11529
11890
|
async function runDoctor(opts = {}) {
|
|
11530
11891
|
if (opts.json) return runDoctorJson(opts);
|
|
11531
11892
|
const lines = [];
|
|
@@ -11662,6 +12023,7 @@ async function runDoctor(opts = {}) {
|
|
|
11662
12023
|
print(" Add one with `yaw-mcp add <slug>`; `yaw-mcp search <text>` finds slugs.");
|
|
11663
12024
|
}
|
|
11664
12025
|
}
|
|
12026
|
+
for (const step of rootDefaultSteps(clients)) print(` ${step}`);
|
|
11665
12027
|
return { exitCode, lines, snapshot: { version: VERSION, config, clients } };
|
|
11666
12028
|
}
|
|
11667
12029
|
async function runDoctorJson(opts) {
|
|
@@ -11837,6 +12199,7 @@ async function runDoctorJson(opts) {
|
|
|
11837
12199
|
summary += " No MCP servers are configured yet -- add one with `yaw-mcp add <slug>`.";
|
|
11838
12200
|
}
|
|
11839
12201
|
}
|
|
12202
|
+
for (const step of rootDefaultSteps(clients)) summary += ` ${step}`;
|
|
11840
12203
|
const snapshotJson = {
|
|
11841
12204
|
timestamp,
|
|
11842
12205
|
version: VERSION,
|
|
@@ -11933,10 +12296,14 @@ async function collectVaultStatus(opts) {
|
|
|
11933
12296
|
let passphraseUnlocks = null;
|
|
11934
12297
|
let checkMarkerCorrupt = false;
|
|
11935
12298
|
if (passphrase !== "" && vault !== null && vaultVerifiesPassphrases(vault)) {
|
|
11936
|
-
|
|
11937
|
-
|
|
11938
|
-
|
|
11939
|
-
|
|
12299
|
+
try {
|
|
12300
|
+
const verdict = await checkVaultPassphrase(vault, passphrase);
|
|
12301
|
+
passphraseUnlocks = verdict === "opens";
|
|
12302
|
+
checkMarkerCorrupt = verdict === "marker-corrupt";
|
|
12303
|
+
} catch {
|
|
12304
|
+
} finally {
|
|
12305
|
+
lock();
|
|
12306
|
+
}
|
|
11940
12307
|
}
|
|
11941
12308
|
const refs = [];
|
|
11942
12309
|
const malformed = [];
|
|
@@ -12341,7 +12708,7 @@ function schemaSuffix(f) {
|
|
|
12341
12708
|
return ` (schema v${f.version}, this yaw-mcp supports v${CURRENT_SCHEMA_VERSION})`;
|
|
12342
12709
|
return ` (schema v${f.version})`;
|
|
12343
12710
|
}
|
|
12344
|
-
function renderClientStatus(c, installCmd) {
|
|
12711
|
+
function renderClientStatus(c, installCmd, client) {
|
|
12345
12712
|
if (c.unavailable) {
|
|
12346
12713
|
return c.unavailableReason !== void 0 ? `not supported on this OS yet -- ${c.unavailableReason}` : "unavailable on this OS";
|
|
12347
12714
|
}
|
|
@@ -12352,7 +12719,8 @@ function renderClientStatus(c, installCmd) {
|
|
|
12352
12719
|
return `exists but could not be read (${c.unreadable}) -- check the file and its permissions, then rerun doctor`;
|
|
12353
12720
|
}
|
|
12354
12721
|
if (c.malformed) {
|
|
12355
|
-
|
|
12722
|
+
const detail = c.malformedDetail !== null ? ` (${c.malformedDetail})` : "";
|
|
12723
|
+
return `exists but ${c.syntax} is malformed${detail} -- install refuses to overwrite it; ${unparseableConfigFix(`run \`${installCmd}\``, c.syntax)}`;
|
|
12356
12724
|
}
|
|
12357
12725
|
if (c.containerBlocked !== null) {
|
|
12358
12726
|
return `present, but ${c.containerBlocked}, not ${containerNounFor(c.syntax)} -- install refuses to overwrite it; ${blockedContainerFix(`run \`${installCmd}\``, c.syntax)}`;
|
|
@@ -12360,6 +12728,12 @@ function renderClientStatus(c, installCmd) {
|
|
|
12360
12728
|
if (c.unloadable !== null) {
|
|
12361
12729
|
return `exists but ${c.unloadable} -- install refuses to write into it; ${unloadableConfigFix(`run \`${installCmd}\``)}`;
|
|
12362
12730
|
}
|
|
12731
|
+
const noReleaseLoads = c.rootDefaults.find(
|
|
12732
|
+
(d) => d.state === "refused-every-release"
|
|
12733
|
+
);
|
|
12734
|
+
if (noReleaseLoads !== void 0) {
|
|
12735
|
+
return `exists but sets ${noReleaseLoads.key} to ${noReleaseLoads.value}, ${noReleaseLoads.everyRelease}, so ${client} will not load the file -- install refuses to write into it; ${noReleaseLoads.fix}, then run \`${installCmd}\``;
|
|
12736
|
+
}
|
|
12363
12737
|
if (c.entryUnspliceable !== null) {
|
|
12364
12738
|
return `has "${ENTRY_NAME}" entry, but it is ${c.entryUnspliceable.reason} -- install will not edit it and doctor cannot check its launch command; ${c.entryUnspliceable.fix}, then run \`${installCmd}\``;
|
|
12365
12739
|
}
|
|
@@ -12368,23 +12742,25 @@ function renderClientStatus(c, installCmd) {
|
|
|
12368
12742
|
}
|
|
12369
12743
|
const legacy = c.hasLegacyEntry ? `; legacy "${c.legacyEntryName}" entry also present -- install removes it as it writes the working entry` : "";
|
|
12370
12744
|
const keyNote = c.entryProjectKey ? `; found under projects[${JSON.stringify(c.entryProjectKey)}], the same directory spelled with the other drive-letter case -- only a Claude Code whose cwd is spelled that way reads it, and \`${installCmd}\` writes the canonical key` : "";
|
|
12745
|
+
const rootClause = (remedy) => c.rootDefaults.map((d) => rootDefaultClause(d, { client, installCmd, remedy, syntax: c.syntax })).join("");
|
|
12371
12746
|
if (c.launchCommandMissing) {
|
|
12372
|
-
return `has "${ENTRY_NAME}" entry, but its launch command does not exist: ${c.launchCommandMissing} -- the client cannot start yaw-mcp; rerun \`${installCmd}\`${legacy}${keyNote}`;
|
|
12747
|
+
return `has "${ENTRY_NAME}" entry, but its launch command does not exist: ${c.launchCommandMissing} -- the client cannot start yaw-mcp; rerun \`${installCmd}\`${legacy}${rootClause("rerun")}${keyNote}`;
|
|
12373
12748
|
}
|
|
12374
12749
|
if (c.launchOamEntryMissing) {
|
|
12375
|
-
return `has "${ENTRY_NAME}" entry running on oam, but its entry file does not exist: ${c.launchOamEntryMissing} -- oam cannot fetch it on demand the way npx would; rerun \`${installCmd}\`${legacy}${keyNote}`;
|
|
12750
|
+
return `has "${ENTRY_NAME}" entry running on oam, but its entry file does not exist: ${c.launchOamEntryMissing} -- oam cannot fetch it on demand the way npx would; rerun \`${installCmd}\`${legacy}${rootClause("rerun")}${keyNote}`;
|
|
12376
12751
|
}
|
|
12377
12752
|
if (c.launchOamNotAbsolute) {
|
|
12378
|
-
return `has "${ENTRY_NAME}" entry with a bare "${c.launchOamNotAbsolute}" command -- it resolves against the client's PATH, which a GUI-launched client does not inherit from your shell; rerun \`${installCmd}\` to write an absolute path (set OAM_BIN to oam's full path first if install cannot find it)${legacy}${keyNote}`;
|
|
12753
|
+
return `has "${ENTRY_NAME}" entry with a bare "${c.launchOamNotAbsolute}" command -- it resolves against the client's PATH, which a GUI-launched client does not inherit from your shell; rerun \`${installCmd}\` to write an absolute path (set OAM_BIN to oam's full path first if install cannot find it)${legacy}${rootClause("rerun")}${keyNote}`;
|
|
12379
12754
|
}
|
|
12380
12755
|
if (c.launchForeignPath) {
|
|
12381
|
-
return `has "${ENTRY_NAME}" entry${c.launchRuntime === "oam" ? " (runs on oam)" : ""} whose launch path is for another OS: ${c.launchForeignPath} -- not verified from here${c.hasLegacyEntry ? `; legacy "${c.legacyEntryName}" entry also present -- remove it to avoid running yaw-mcp twice` : ""}${keyNote}`;
|
|
12756
|
+
return `has "${ENTRY_NAME}" entry${c.launchRuntime === "oam" ? " (runs on oam)" : ""} whose launch path is for another OS: ${c.launchForeignPath} -- not verified from here${c.hasLegacyEntry ? `; legacy "${c.legacyEntryName}" entry also present -- remove it to avoid running yaw-mcp twice` : ""}${rootClause("by-hand")}${keyNote}`;
|
|
12382
12757
|
}
|
|
12758
|
+
const ok = c.rootDefaults.some((d) => d.state === "refused") ? "" : "OK -- ";
|
|
12383
12759
|
if (c.hasMcpEntry && c.hasLegacyEntry) {
|
|
12384
|
-
return
|
|
12760
|
+
return `${ok}has "${ENTRY_NAME}" entry${c.launchRuntime === "oam" ? " (runs on oam)" : ""}; legacy "${c.legacyEntryName}" entry also present -- remove it to avoid running yaw-mcp twice${rootClause("run")}${keyNote}`;
|
|
12385
12761
|
}
|
|
12386
12762
|
if (c.hasMcpEntry) {
|
|
12387
|
-
return
|
|
12763
|
+
return `${ok}has "${ENTRY_NAME}" entry${c.launchRuntime === "oam" ? " (runs on oam)" : ""}${rootClause("run")}${keyNote}`;
|
|
12388
12764
|
}
|
|
12389
12765
|
if (c.hasLegacyEntry) {
|
|
12390
12766
|
return `legacy "${c.legacyEntryName}" entry present -- run \`${installCmd}\` to migrate; install removes the legacy entry as it writes the new one${keyNote}`;
|
|
@@ -12392,12 +12768,27 @@ function renderClientStatus(c, installCmd) {
|
|
|
12392
12768
|
if (c.exists) return `present, no "${ENTRY_NAME}" entry -- run \`${installCmd}\``;
|
|
12393
12769
|
return `not configured -- run \`${installCmd}\``;
|
|
12394
12770
|
}
|
|
12771
|
+
function rootDefaultClause(d, line) {
|
|
12772
|
+
switch (d.state) {
|
|
12773
|
+
case "missing": {
|
|
12774
|
+
const setting = `${d.key} = ${JSON.stringify(d.recommended)}`;
|
|
12775
|
+
const step = line.remedy === "rerun" ? `install adds ${setting} as it writes the working entry` : line.remedy === "run" ? `run \`${line.installCmd}\` to add ${setting}` : `set ${setting} by hand, on one line ${rootLinePlacement2(line.syntax)}`;
|
|
12776
|
+
return `; the file does not set ${d.key} -- ${step}`;
|
|
12777
|
+
}
|
|
12778
|
+
case "refused":
|
|
12779
|
+
return `; the file sets ${d.key} to ${d.value}, ${d.kind === null ? "" : `${d.kind} `}where ${line.client} needs ${d.needs} -- a ${line.client} release that reads the key will not load the file with that value, and install leaves a value you set alone; ${d.fix}`;
|
|
12780
|
+
case "other":
|
|
12781
|
+
case "refused-every-release":
|
|
12782
|
+
return "";
|
|
12783
|
+
}
|
|
12784
|
+
}
|
|
12395
12785
|
var EMPTY_PROBE = {
|
|
12396
12786
|
hasMcpEntry: false,
|
|
12397
12787
|
containerEntries: 0,
|
|
12398
12788
|
hasLegacyEntry: false,
|
|
12399
12789
|
legacyEntryName: null,
|
|
12400
12790
|
malformed: false,
|
|
12791
|
+
malformedDetail: null,
|
|
12401
12792
|
unloadable: null,
|
|
12402
12793
|
unreadable: null,
|
|
12403
12794
|
unreadableCode: null,
|
|
@@ -12409,9 +12800,13 @@ var EMPTY_PROBE = {
|
|
|
12409
12800
|
launchForeignPath: null,
|
|
12410
12801
|
entryProjectKey: null,
|
|
12411
12802
|
entryUnspliceable: null,
|
|
12412
|
-
containerUnspliceable: null
|
|
12803
|
+
containerUnspliceable: null,
|
|
12804
|
+
rootDefaults: []
|
|
12413
12805
|
};
|
|
12414
12806
|
var MALFORMED = { ...EMPTY_PROBE, malformed: true };
|
|
12807
|
+
function malformedProbe(read) {
|
|
12808
|
+
return { ...MALFORMED, malformedDetail: read.reason === "encoding" ? read.detail : null };
|
|
12809
|
+
}
|
|
12415
12810
|
function unreadableProbe(err) {
|
|
12416
12811
|
const code = err?.code;
|
|
12417
12812
|
return {
|
|
@@ -12471,24 +12866,24 @@ function* enumerateProbeSlots(opts) {
|
|
|
12471
12866
|
syntax: syntaxNameFor(site.format),
|
|
12472
12867
|
containerPath: addressOf(site).containerPath
|
|
12473
12868
|
},
|
|
12474
|
-
read: exists2 ? { path: site.resolved.absolute, site, transform: target.entry } : null
|
|
12869
|
+
read: exists2 ? { path: site.resolved.absolute, site, transform: target.entry, rootDefaults: target.config.rootDefaults } : null
|
|
12475
12870
|
};
|
|
12476
12871
|
}
|
|
12477
12872
|
}
|
|
12478
12873
|
}
|
|
12479
12874
|
function probeClients(opts) {
|
|
12480
12875
|
const out = [];
|
|
12481
|
-
const readConfig = opts.readClientConfig ?? ((p) => readFileSync3(p
|
|
12876
|
+
const readConfig = opts.readClientConfig ?? ((p) => readFileSync3(p));
|
|
12482
12877
|
const platform = opts.platform ?? process.platform;
|
|
12483
12878
|
for (const { result, read } of enumerateProbeSlots(opts)) {
|
|
12484
12879
|
if (read) {
|
|
12485
|
-
let
|
|
12880
|
+
let loaded = null;
|
|
12486
12881
|
try {
|
|
12487
|
-
|
|
12882
|
+
loaded = readConfig(read.path);
|
|
12488
12883
|
} catch (err) {
|
|
12489
12884
|
Object.assign(result, unreadableProbe(err));
|
|
12490
12885
|
}
|
|
12491
|
-
if (
|
|
12886
|
+
if (loaded !== null) Object.assign(result, classifyProbeRead(loaded, read, existsSync6, platform));
|
|
12492
12887
|
}
|
|
12493
12888
|
out.push(result);
|
|
12494
12889
|
}
|
|
@@ -12543,11 +12938,19 @@ function oamRunEntryFromTokens(tokens) {
|
|
|
12543
12938
|
return tokens.slice(sub + 1).find((t) => !t.startsWith("-")) ?? null;
|
|
12544
12939
|
}
|
|
12545
12940
|
var JSON_PROBE_FORMATS = /* @__PURE__ */ new Set(["json", "jsonc"]);
|
|
12941
|
+
function classifyProbeRead(loaded, read, exists2, platform) {
|
|
12942
|
+
if (typeof loaded === "string") return classifyProbe(loaded, read, exists2, platform);
|
|
12943
|
+
const decoded = decodeClientConfigBytes(loaded, read.site.format);
|
|
12944
|
+
return decoded.malformed === null ? classifyProbe(decoded.text, read, exists2, platform) : malformedProbe(decoded.malformed);
|
|
12945
|
+
}
|
|
12546
12946
|
function classifyProbe(raw, read, exists2, platform) {
|
|
12547
|
-
return JSON_PROBE_FORMATS.has(read.site.format) ? classifyProbeContent(raw, read.site.resolved.containerPath, read.site.format === "json", exists2, platform) : classifyProbeViaAdapter(raw, read.site, read.transform, exists2, platform);
|
|
12947
|
+
return JSON_PROBE_FORMATS.has(read.site.format) ? classifyProbeContent(raw, read.site.resolved.containerPath, read.site.format === "json", exists2, platform) : classifyProbeViaAdapter(raw, read.site, read.transform, read.rootDefaults, exists2, platform);
|
|
12548
12948
|
}
|
|
12549
|
-
function classifyProbeViaAdapter(raw, site, transform, exists2, platform) {
|
|
12949
|
+
function classifyProbeViaAdapter(raw, site, transform, rootDefaults, exists2, platform) {
|
|
12550
12950
|
const view = classifyClientConfig(raw, site, { transform });
|
|
12951
|
+
return { ...classifyAdapterView(view, exists2, platform), rootDefaults: probeRootDefaults(view, rootDefaults) };
|
|
12952
|
+
}
|
|
12953
|
+
function classifyAdapterView(view, exists2, platform) {
|
|
12551
12954
|
const read = view.read;
|
|
12552
12955
|
const violation = view.unloadable();
|
|
12553
12956
|
const unloadable = violation ? unloadableConfigProblem(violation) : null;
|
|
@@ -12557,7 +12960,7 @@ function classifyProbeViaAdapter(raw, site, transform, exists2, platform) {
|
|
|
12557
12960
|
case "unreadable":
|
|
12558
12961
|
return { ...EMPTY_PROBE, unreadable: read.message, unreadableCode: read.code };
|
|
12559
12962
|
case "malformed":
|
|
12560
|
-
return
|
|
12963
|
+
return malformedProbe(read);
|
|
12561
12964
|
case "blocked":
|
|
12562
12965
|
return read.reparable ? { ...EMPTY_PROBE, unloadable } : { ...EMPTY_PROBE, unloadable, containerBlocked: `"${read.path.join(".")}" is ${read.shape}` };
|
|
12563
12966
|
case "unspliceable":
|
|
@@ -12598,8 +13001,63 @@ function classifyProbeViaAdapter(raw, site, transform, exists2, platform) {
|
|
|
12598
13001
|
}
|
|
12599
13002
|
}
|
|
12600
13003
|
}
|
|
13004
|
+
function probeRootDefaults(view, defaults) {
|
|
13005
|
+
if (defaults === void 0 || defaults.length === 0) return [];
|
|
13006
|
+
const plan = planRootDefaults(view, defaults);
|
|
13007
|
+
const syntax = view.adapter.syntax;
|
|
13008
|
+
const out = [];
|
|
13009
|
+
for (const rootDefault of defaults) {
|
|
13010
|
+
const base = { key: rootDefault.key, recommended: rootDefault.value, why: rootDefault.why };
|
|
13011
|
+
if (plan.set.includes(rootDefault)) {
|
|
13012
|
+
out.push({ ...base, state: "missing", value: null, kind: null, needs: null, everyRelease: null, fix: null });
|
|
13013
|
+
continue;
|
|
13014
|
+
}
|
|
13015
|
+
const kept = plan.kept.find((k) => k.rootDefault === rootDefault);
|
|
13016
|
+
if (kept === void 0) continue;
|
|
13017
|
+
const { value, float, refused } = kept;
|
|
13018
|
+
const spelled = float ?? spellRootValue2(value, syntax);
|
|
13019
|
+
if (refused === void 0) {
|
|
13020
|
+
out.push({ ...base, state: "other", value: spelled, kind: null, needs: null, everyRelease: null, fix: null });
|
|
13021
|
+
continue;
|
|
13022
|
+
}
|
|
13023
|
+
const recommended = `(${JSON.stringify(rootDefault.value)} is recommended)`;
|
|
13024
|
+
const kind = refused.kind ?? null;
|
|
13025
|
+
if (refused.everyRelease !== void 0) {
|
|
13026
|
+
out.push({
|
|
13027
|
+
...base,
|
|
13028
|
+
state: "refused-every-release",
|
|
13029
|
+
value: spelled,
|
|
13030
|
+
kind,
|
|
13031
|
+
needs: refused.needs,
|
|
13032
|
+
everyRelease: refused.everyRelease,
|
|
13033
|
+
fix: `change that value by hand to ${refused.needs} ${recommended}`
|
|
13034
|
+
});
|
|
13035
|
+
continue;
|
|
13036
|
+
}
|
|
13037
|
+
const scalar = typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean" || value instanceof Date;
|
|
13038
|
+
out.push({
|
|
13039
|
+
...base,
|
|
13040
|
+
state: "refused",
|
|
13041
|
+
value: spelled,
|
|
13042
|
+
kind,
|
|
13043
|
+
needs: refused.needs,
|
|
13044
|
+
everyRelease: null,
|
|
13045
|
+
fix: scalar ? `edit that value by hand ${recommended}` : `delete it by hand and set the key on one line ${rootLinePlacement2(syntax)} ${recommended}`
|
|
13046
|
+
});
|
|
13047
|
+
}
|
|
13048
|
+
return out;
|
|
13049
|
+
}
|
|
13050
|
+
function spellRootValue2(value, syntax) {
|
|
13051
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
13052
|
+
if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return String(value);
|
|
13053
|
+
if (value instanceof Date) return value.toISOString();
|
|
13054
|
+
return Array.isArray(value) ? describeValueShape(value) : containerNounFor(syntax);
|
|
13055
|
+
}
|
|
13056
|
+
function rootLinePlacement2(syntax) {
|
|
13057
|
+
return syntax === "TOML" ? "above the first table in the file" : "at the top level of the file";
|
|
13058
|
+
}
|
|
12601
13059
|
function launchChecks(entry, exists2, platform) {
|
|
12602
|
-
const isAbsolute2 = platform === "win32" ?
|
|
13060
|
+
const isAbsolute2 = platform === "win32" ? win322.isAbsolute : posix2.isAbsolute;
|
|
12603
13061
|
let launchCommandMissing = null;
|
|
12604
13062
|
let launchRuntime = null;
|
|
12605
13063
|
let launchOamNotAbsolute = null;
|
|
@@ -12679,6 +13137,7 @@ function classifyProbeContent(raw, containerPath, strict, exists2 = existsSync6,
|
|
|
12679
13137
|
hasLegacyEntry: legacyEntryName !== null,
|
|
12680
13138
|
legacyEntryName,
|
|
12681
13139
|
malformed: false,
|
|
13140
|
+
malformedDetail: null,
|
|
12682
13141
|
unloadable,
|
|
12683
13142
|
unreadable: null,
|
|
12684
13143
|
unreadableCode: null,
|
|
@@ -12694,7 +13153,11 @@ function classifyProbeContent(raw, containerPath, strict, exists2 = existsSync6,
|
|
|
12694
13153
|
entryProjectKey: ENTRY_NAME in container || legacyEntryName !== null ? entryProjectKey : null,
|
|
12695
13154
|
// A JSON object key is always spliceable, and so is a JSON container.
|
|
12696
13155
|
entryUnspliceable: null,
|
|
12697
|
-
containerUnspliceable: null
|
|
13156
|
+
containerUnspliceable: null,
|
|
13157
|
+
// No JSON-family row declares a top-level default: their adapters
|
|
13158
|
+
// implement neither readRootKey nor insertRootKey, and a row may declare
|
|
13159
|
+
// one only on a format whose adapter does (ConfigShape.rootDefaults).
|
|
13160
|
+
rootDefaults: []
|
|
12698
13161
|
};
|
|
12699
13162
|
} catch {
|
|
12700
13163
|
return { ...MALFORMED };
|
|
@@ -12705,13 +13168,13 @@ async function probeClientsAsync(opts) {
|
|
|
12705
13168
|
const platform = opts.platform ?? process.platform;
|
|
12706
13169
|
for (const { result, read } of enumerateProbeSlots(opts)) {
|
|
12707
13170
|
if (read) {
|
|
12708
|
-
let
|
|
13171
|
+
let loaded = null;
|
|
12709
13172
|
try {
|
|
12710
|
-
|
|
13173
|
+
loaded = opts.readClientConfig ? opts.readClientConfig(read.path) : await readFile13(read.path);
|
|
12711
13174
|
} catch (err) {
|
|
12712
13175
|
Object.assign(result, unreadableProbe(err));
|
|
12713
13176
|
}
|
|
12714
|
-
if (
|
|
13177
|
+
if (loaded !== null) Object.assign(result, classifyProbeRead(loaded, read, existsSync6, platform));
|
|
12715
13178
|
}
|
|
12716
13179
|
out.push(result);
|
|
12717
13180
|
}
|
|
@@ -12983,15 +13446,15 @@ function touch(cache, key, value) {
|
|
|
12983
13446
|
cache.delete(key);
|
|
12984
13447
|
cache.set(key, value);
|
|
12985
13448
|
}
|
|
12986
|
-
var
|
|
13449
|
+
var SEP2 = "\0";
|
|
12987
13450
|
var ESC2 = String.fromCharCode(1);
|
|
12988
13451
|
function esc(text) {
|
|
12989
|
-
return text.includes(ESC2) || text.includes(
|
|
13452
|
+
return text.includes(ESC2) || text.includes(SEP2) ? text.replaceAll(ESC2, ESC2 + ESC2).replaceAll(SEP2, ESC2 + SEP2) : text;
|
|
12990
13453
|
}
|
|
12991
13454
|
function serverSignature(server) {
|
|
12992
|
-
let sig = `${esc(server.namespace)}${
|
|
13455
|
+
let sig = `${esc(server.namespace)}${SEP2}${esc(server.name)}${SEP2}${esc(server.description ?? "")}`;
|
|
12993
13456
|
for (const tool of server.tools) {
|
|
12994
|
-
sig += `${
|
|
13457
|
+
sig += `${SEP2}${esc(tool.name)}${SEP2}${esc(tool.description ?? "")}`;
|
|
12995
13458
|
}
|
|
12996
13459
|
return sig;
|
|
12997
13460
|
}
|
|
@@ -13457,7 +13920,7 @@ async function runFoundryExport(opts) {
|
|
|
13457
13920
|
}
|
|
13458
13921
|
|
|
13459
13922
|
// src/heal-entries.ts
|
|
13460
|
-
import { statSync as
|
|
13923
|
+
import { statSync as statSync4 } from "fs";
|
|
13461
13924
|
function norm(p, platform = process.platform) {
|
|
13462
13925
|
const slashed = p.split("\\").join("/");
|
|
13463
13926
|
return platform === "win32" ? slashed.toLowerCase() : slashed;
|
|
@@ -13472,18 +13935,20 @@ function isOwnBrokerEntry(entryPath) {
|
|
|
13472
13935
|
}
|
|
13473
13936
|
function isLaunchableFile(entryPath) {
|
|
13474
13937
|
try {
|
|
13475
|
-
return
|
|
13938
|
+
return statSync4(entryPath).isFile();
|
|
13476
13939
|
} catch {
|
|
13477
13940
|
return false;
|
|
13478
13941
|
}
|
|
13479
13942
|
}
|
|
13480
13943
|
async function healStaleBrokerEntries(opts = {}) {
|
|
13481
13944
|
const env = opts.env ?? process.env;
|
|
13482
|
-
if (isReadOnlyDiagnostics(env)) return { healed: [], unhealable: [] };
|
|
13945
|
+
if (isReadOnlyDiagnostics(env)) return { healed: [], unhealable: [], failed: [] };
|
|
13483
13946
|
const os = opts.os ?? CURRENT_OS;
|
|
13484
13947
|
const platform = opts.platform ?? process.platform;
|
|
13485
13948
|
const healed = [];
|
|
13486
13949
|
const unhealable = [];
|
|
13950
|
+
const failed = [];
|
|
13951
|
+
const writeConfig = opts.writeConfig ?? atomicWriteFile;
|
|
13487
13952
|
let replacement = null;
|
|
13488
13953
|
const replacementFor = async () => {
|
|
13489
13954
|
if (replacement !== null) return replacement;
|
|
@@ -13541,17 +14006,32 @@ async function healStaleBrokerEntries(opts = {}) {
|
|
|
13541
14006
|
const nextLaunch = launchOf(next);
|
|
13542
14007
|
const nextEntry = nextLaunch === null ? null : oamRunEntryPath(nextLaunch.command, nextLaunch.args);
|
|
13543
14008
|
if (nextEntry !== null && norm(nextEntry, platform) === norm(entryPath, platform)) return;
|
|
13544
|
-
|
|
13545
|
-
const text = applyClientConfigEdits(view, [{ op: "upsert", key: ENTRY_NAME, entry: next }], site);
|
|
13546
|
-
await atomicWriteFile(site.resolved.absolute, text);
|
|
13547
|
-
}
|
|
13548
|
-
healed.push({
|
|
14009
|
+
const outcome = {
|
|
13549
14010
|
clientId: target.clientId,
|
|
13550
14011
|
scope,
|
|
13551
14012
|
path: site.resolved.absolute,
|
|
13552
14013
|
from: entryPath,
|
|
13553
14014
|
to: nextEntry ?? "npx"
|
|
13554
|
-
}
|
|
14015
|
+
};
|
|
14016
|
+
let text;
|
|
14017
|
+
try {
|
|
14018
|
+
text = applyClientConfigEdits(view, [{ op: "upsert", key: ENTRY_NAME, entry: next }], site);
|
|
14019
|
+
} catch (err) {
|
|
14020
|
+
failed.push({
|
|
14021
|
+
...outcome,
|
|
14022
|
+
error: `failed to splice the "${ENTRY_NAME}" entry into ${site.resolved.absolute} (${err instanceof Error ? err.message : String(err)})`
|
|
14023
|
+
});
|
|
14024
|
+
return;
|
|
14025
|
+
}
|
|
14026
|
+
if (opts.dryRun !== true) {
|
|
14027
|
+
try {
|
|
14028
|
+
await writeConfig(site.resolved.absolute, terminateWithNewline(text));
|
|
14029
|
+
} catch (err) {
|
|
14030
|
+
failed.push({ ...outcome, error: describeWriteFailure(site.resolved.absolute, err) });
|
|
14031
|
+
return;
|
|
14032
|
+
}
|
|
14033
|
+
}
|
|
14034
|
+
healed.push(outcome);
|
|
13555
14035
|
} catch (err) {
|
|
13556
14036
|
log("warn", "Could not heal a stale yaw-mcp entry", {
|
|
13557
14037
|
path: site.resolved.absolute,
|
|
@@ -13592,19 +14072,28 @@ async function healStaleBrokerEntries(opts = {}) {
|
|
|
13592
14072
|
clients: healed.map((h) => `${h.clientId} (${h.scope})`)
|
|
13593
14073
|
});
|
|
13594
14074
|
}
|
|
13595
|
-
return { healed, unhealable };
|
|
14075
|
+
return { healed, unhealable, failed };
|
|
13596
14076
|
}
|
|
13597
14077
|
async function maybeHealStaleBrokerEntries(opts = {}) {
|
|
13598
14078
|
const env = opts.env ?? process.env;
|
|
13599
|
-
if (isFeatureDisabled("YAW_MCP_AUTO_HEAL", env)) return { healed: [], unhealable: [] };
|
|
14079
|
+
if (isFeatureDisabled("YAW_MCP_AUTO_HEAL", env)) return { healed: [], unhealable: [], failed: [] };
|
|
14080
|
+
let result;
|
|
13600
14081
|
try {
|
|
13601
|
-
|
|
14082
|
+
result = await healStaleBrokerEntries(opts);
|
|
13602
14083
|
} catch (err) {
|
|
13603
14084
|
log("warn", "Stale-entry heal pass failed", {
|
|
13604
14085
|
error: err instanceof Error ? err.message : String(err)
|
|
13605
14086
|
});
|
|
13606
|
-
return { healed: [], unhealable: [] };
|
|
14087
|
+
return { healed: [], unhealable: [], failed: [] };
|
|
14088
|
+
}
|
|
14089
|
+
for (const f of result.failed) {
|
|
14090
|
+
log("warn", "Could not heal a stale yaw-mcp entry", {
|
|
14091
|
+
client: `${f.clientId} (${f.scope})`,
|
|
14092
|
+
path: f.path,
|
|
14093
|
+
error: f.error
|
|
14094
|
+
});
|
|
13607
14095
|
}
|
|
14096
|
+
return result;
|
|
13608
14097
|
}
|
|
13609
14098
|
|
|
13610
14099
|
// src/heal-cmd.ts
|
|
@@ -13627,26 +14116,45 @@ function describe(h) {
|
|
|
13627
14116
|
was -> ${h.from}
|
|
13628
14117
|
now -> ${h.to}`;
|
|
13629
14118
|
}
|
|
13630
|
-
|
|
14119
|
+
function describeFailures(failed, dryRun) {
|
|
14120
|
+
const one = failed.length === 1;
|
|
14121
|
+
const rows = failed.map((f) => ` ${f.clientId} (${f.scope}): ${f.path}
|
|
14122
|
+
still -> ${f.from}
|
|
14123
|
+
${f.error}`);
|
|
14124
|
+
return `yaw-mcp heal: ${dryRun ? "cannot" : "could not"} re-point ${failed.length} stale ${one ? "entry" : "entries"}:
|
|
14125
|
+
${rows.join("\n")}
|
|
14126
|
+
` + (one ? "It still names a launch file that no longer exists, so its client cannot start yaw-mcp -- fix what the line above says, then re-run `yaw-mcp heal`.\n" : "Each still names a launch file that no longer exists, so its client cannot start yaw-mcp -- fix what each entry's last line says, then re-run `yaw-mcp heal`.\n");
|
|
14127
|
+
}
|
|
14128
|
+
async function runHeal(options = {}, sweep = healStaleBrokerEntries) {
|
|
13631
14129
|
let result;
|
|
13632
14130
|
try {
|
|
13633
|
-
result = await
|
|
14131
|
+
result = await sweep({ dryRun: options.dryRun });
|
|
13634
14132
|
} catch (err) {
|
|
13635
14133
|
process.stderr.write(`yaw-mcp heal: ${err instanceof Error ? err.message : String(err)}
|
|
13636
14134
|
`);
|
|
13637
14135
|
return { exitCode: 1 };
|
|
13638
14136
|
}
|
|
13639
|
-
const { healed, unhealable } = result;
|
|
14137
|
+
const { healed, unhealable, failed } = result;
|
|
14138
|
+
const exitCode = failed.length > 0 ? 1 : 0;
|
|
14139
|
+
const reportFailures = (afterTranscript) => {
|
|
14140
|
+
if (failed.length === 0) return;
|
|
14141
|
+
process.stderr.write(`${afterTranscript ? "\n" : ""}${describeFailures(failed, options.dryRun === true)}`);
|
|
14142
|
+
};
|
|
13640
14143
|
if (options.json === true) {
|
|
13641
14144
|
process.stdout.write(
|
|
13642
|
-
`${JSON.stringify({ healed, unhealable, count: healed.length, dryRun: options.dryRun === true }, null, 2)}
|
|
14145
|
+
`${JSON.stringify({ healed, unhealable, failed, count: healed.length, dryRun: options.dryRun === true }, null, 2)}
|
|
13643
14146
|
`
|
|
13644
14147
|
);
|
|
13645
|
-
|
|
14148
|
+
reportFailures(false);
|
|
14149
|
+
return { exitCode };
|
|
13646
14150
|
}
|
|
14151
|
+
let printed = false;
|
|
13647
14152
|
if (options.quiet !== true) {
|
|
13648
14153
|
if (healed.length === 0) {
|
|
13649
|
-
|
|
14154
|
+
if (failed.length === 0) {
|
|
14155
|
+
process.stdout.write("No stale yaw-mcp entries found.\n");
|
|
14156
|
+
printed = true;
|
|
14157
|
+
}
|
|
13650
14158
|
} else {
|
|
13651
14159
|
const verb = options.dryRun === true ? "Would re-point" : "Re-pointed";
|
|
13652
14160
|
process.stdout.write(
|
|
@@ -13654,18 +14162,20 @@ async function runHeal(options = {}) {
|
|
|
13654
14162
|
${healed.map(describe).join("\n")}
|
|
13655
14163
|
` + (options.dryRun === true ? "" : "\nRestart the affected client(s) to pick this up.\n")
|
|
13656
14164
|
);
|
|
14165
|
+
printed = true;
|
|
13657
14166
|
}
|
|
13658
14167
|
if (unhealable.length > 0) {
|
|
13659
14168
|
process.stdout.write(
|
|
13660
|
-
|
|
13661
|
-
${unhealable.length} config${unhealable.length === 1 ? "" : "s"} could not be checked:
|
|
14169
|
+
`${printed ? "\n" : ""}${unhealable.length} config${unhealable.length === 1 ? "" : "s"} could not be checked:
|
|
13662
14170
|
${unhealable.map((u) => ` ${u.clientId} (${u.scope}): ${u.path} -- ${u.reason}`).join("\n")}
|
|
13663
14171
|
Run \`yaw-mcp doctor\` for what each one needs.
|
|
13664
14172
|
`
|
|
13665
14173
|
);
|
|
14174
|
+
printed = true;
|
|
13666
14175
|
}
|
|
13667
14176
|
}
|
|
13668
|
-
|
|
14177
|
+
reportFailures(printed);
|
|
14178
|
+
return { exitCode };
|
|
13669
14179
|
}
|
|
13670
14180
|
|
|
13671
14181
|
// src/import-cmd.ts
|
|
@@ -13689,7 +14199,11 @@ var IMPORT_USAGE = `Usage: yaw-mcp import <client> [flags]
|
|
|
13689
14199
|
|
|
13690
14200
|
A server already in bundles.json is MERGED, with the client's copy winning,
|
|
13691
14201
|
so the plan names every entry that would be replaced and shows the launch
|
|
13692
|
-
command it would replace.
|
|
14202
|
+
command it would replace. When the merge would change the stored entry, a
|
|
14203
|
+
terminal run asks first -- [o]verwrite, [s]kip or [a]bort, and a bare Enter
|
|
14204
|
+
skips that server -- and a run off one writes nothing and exits 2 unless you
|
|
14205
|
+
pass --force. A stored entry the merge would leave as it is is not asked
|
|
14206
|
+
about. A VS Code server written with a \${input:...} or
|
|
13693
14207
|
\${env:...} variable is skipped by name: VS Code expands those itself and
|
|
13694
14208
|
yaw-mcp does not, so importing one would produce a server that cannot start.
|
|
13695
14209
|
|
|
@@ -13706,10 +14220,14 @@ Flags:
|
|
|
13706
14220
|
one config file. Defaults to the client's user scope.
|
|
13707
14221
|
--project-dir <dir> Project root for a project/workspace scope
|
|
13708
14222
|
(default: the current directory).
|
|
13709
|
-
--dry-run Show what would be imported
|
|
14223
|
+
--dry-run Show what would be imported -- and, with
|
|
14224
|
+
--remove-originals, which client entries would be
|
|
14225
|
+
removed. Writes nothing.
|
|
13710
14226
|
--remove-originals Remove the imported entries from the client config
|
|
13711
14227
|
without asking.
|
|
13712
|
-
--keep-originals Leave the client config alone without asking
|
|
14228
|
+
--keep-originals Leave the client config alone without asking.
|
|
14229
|
+
--force Overwrite a bundles.json entry the import would change
|
|
14230
|
+
without asking.`;
|
|
13713
14231
|
var SELF_ENTRY_NAMES = /* @__PURE__ */ new Set([ENTRY_NAME, ...LEGACY_ENTRY_NAMES, "mcp-connect"]);
|
|
13714
14232
|
function isSelfEntry(key) {
|
|
13715
14233
|
return SELF_ENTRY_NAMES.has(key) || key.startsWith(TRIAL_ENTRY_PREFIX);
|
|
@@ -13829,6 +14347,48 @@ function renderLaunch2(shape) {
|
|
|
13829
14347
|
}
|
|
13830
14348
|
return shape.url ? `HTTP ${displaySafe(shape.url)}` : "(no launch command)";
|
|
13831
14349
|
}
|
|
14350
|
+
async function storedEntryChanges(preview, home, warnOnce) {
|
|
14351
|
+
const unreadable = ["the stored entry could not be read back to compare, so it is treated as changed"];
|
|
14352
|
+
if (preview.namespace === void 0) return unreadable;
|
|
14353
|
+
try {
|
|
14354
|
+
const stored = await previewUpsertUserBundle({ namespace: preview.namespace }, { home });
|
|
14355
|
+
for (const w of stored.warnings) warnOnce(w);
|
|
14356
|
+
if (!stored.replaced || JSON.stringify(stored.replacing) !== JSON.stringify(preview.replacing)) return unreadable;
|
|
14357
|
+
if (deepEqualJson(stored.entry, preview.entry)) return null;
|
|
14358
|
+
return describeEntryDiff(stored.entry, preview.entry).map(displaySafe);
|
|
14359
|
+
} catch {
|
|
14360
|
+
return unreadable;
|
|
14361
|
+
}
|
|
14362
|
+
}
|
|
14363
|
+
function indentLines(lines, indent) {
|
|
14364
|
+
return lines.map((l) => `${indent}${l}`).join("\n");
|
|
14365
|
+
}
|
|
14366
|
+
async function askBundleCollisions(changing, bundlesFile, io) {
|
|
14367
|
+
const rl = createInterface3({
|
|
14368
|
+
input: io?.stdin ?? process.stdin,
|
|
14369
|
+
output: io?.stdout ?? process.stdout,
|
|
14370
|
+
terminal: io?.terminal
|
|
14371
|
+
});
|
|
14372
|
+
const answers = /* @__PURE__ */ new Map();
|
|
14373
|
+
try {
|
|
14374
|
+
for (const c of changing) {
|
|
14375
|
+
const diff = indentLines(c.changes ?? [], " ");
|
|
14376
|
+
const raw = await questionOrEmpty(
|
|
14377
|
+
rl,
|
|
14378
|
+
`${bundlesFile} already has an entry "${displaySafe(c.plannedNamespace)}" that differs from the one importing ${displayArg(c.key)} would write:
|
|
14379
|
+
${diff}
|
|
14380
|
+
[o]verwrite, [s]kip, or [a]bort? (default: skip) `
|
|
14381
|
+
);
|
|
14382
|
+
if (raw === QUESTION_CANCELLED) return "cancelled";
|
|
14383
|
+
const answer = raw.trim().toLowerCase();
|
|
14384
|
+
if (answer.startsWith("a")) return "abort";
|
|
14385
|
+
answers.set(c, answer.startsWith("o") ? "overwrite" : "skip");
|
|
14386
|
+
}
|
|
14387
|
+
return answers;
|
|
14388
|
+
} finally {
|
|
14389
|
+
rl.close();
|
|
14390
|
+
}
|
|
14391
|
+
}
|
|
13832
14392
|
function describeContainer2(ref) {
|
|
13833
14393
|
return `${displaySafe(ref.resolved.absolute)} (${ref.resolved.containerPath.join(".")})`;
|
|
13834
14394
|
}
|
|
@@ -13938,6 +14498,12 @@ ${IMPORT_USAGE}` };
|
|
|
13938
14498
|
case "--keep-originals":
|
|
13939
14499
|
opts.keepOriginals = true;
|
|
13940
14500
|
break;
|
|
14501
|
+
// install's word for the same answer: replace a differing entry without
|
|
14502
|
+
// asking. Unrelated to the two flags above, which answer the question
|
|
14503
|
+
// about the CLIENT config.
|
|
14504
|
+
case "--force":
|
|
14505
|
+
opts.force = true;
|
|
14506
|
+
break;
|
|
13941
14507
|
case "-h":
|
|
13942
14508
|
case "--help":
|
|
13943
14509
|
return { ok: false, error: IMPORT_USAGE, help: true };
|
|
@@ -13974,17 +14540,80 @@ function isInteractive3(opts) {
|
|
|
13974
14540
|
if (opts.promptAnswer !== void 0) return true;
|
|
13975
14541
|
return Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY);
|
|
13976
14542
|
}
|
|
13977
|
-
async function
|
|
13978
|
-
|
|
13979
|
-
const
|
|
13980
|
-
|
|
13981
|
-
|
|
13982
|
-
|
|
13983
|
-
|
|
13984
|
-
|
|
13985
|
-
|
|
13986
|
-
|
|
14543
|
+
async function searchForBroker(site, sourceRef, source, opts, home) {
|
|
14544
|
+
const { target } = site;
|
|
14545
|
+
const searched = [sourceRef];
|
|
14546
|
+
let installRef = site.scope === "user" ? searched[0] : null;
|
|
14547
|
+
for (const spec of target.scopes) {
|
|
14548
|
+
if (spec.scope === site.scope) continue;
|
|
14549
|
+
try {
|
|
14550
|
+
const others = resolveInstallSites({
|
|
14551
|
+
clientId: target.clientId,
|
|
14552
|
+
scope: spec.scope,
|
|
14553
|
+
os: site.os,
|
|
14554
|
+
home,
|
|
14555
|
+
appData: resolveAppDataDir({ appData: opts.appData, home }),
|
|
14556
|
+
// Same env the target scope resolved with, so an env-redirected client
|
|
14557
|
+
// is searched at its REAL other-scope path rather than the default one.
|
|
14558
|
+
clientEnv: opts.clientEnv,
|
|
14559
|
+
// The project the user is standing in -- the same resolution
|
|
14560
|
+
// resolveInstallSite would have made had that scope been the target.
|
|
14561
|
+
projectDir: spec.requiresProjectDir ? site.projectDir ?? resolvePath(opts.cwd ?? process.cwd(), ".") : void 0,
|
|
14562
|
+
claudeConfigDir: opts.claudeConfigDir
|
|
14563
|
+
});
|
|
14564
|
+
for (const other of others) {
|
|
14565
|
+
const already = searched.find(
|
|
14566
|
+
(r) => r.resolved.absolute === other.resolved.absolute && r.resolved.containerPath.join(".") === other.resolved.containerPath.join(".")
|
|
14567
|
+
);
|
|
14568
|
+
const ref = already ?? other;
|
|
14569
|
+
if (!already) searched.push(ref);
|
|
14570
|
+
if (spec.scope === "user" && installRef === null) installRef = ref;
|
|
14571
|
+
}
|
|
14572
|
+
} catch {
|
|
14573
|
+
}
|
|
14574
|
+
}
|
|
14575
|
+
let wiredIn = null;
|
|
14576
|
+
const refused = /* @__PURE__ */ new Map();
|
|
14577
|
+
for (let i = 0; i < searched.length; i++) {
|
|
14578
|
+
const read = i === 0 ? { state: "container", wired: isWiredIn(source) } : await readContainer(searched[i]);
|
|
14579
|
+
if (read.state === "container" && read.wired) {
|
|
14580
|
+
wiredIn = searched[i];
|
|
14581
|
+
break;
|
|
14582
|
+
}
|
|
14583
|
+
if (read.state === "refused") refused.set(searched[i], read);
|
|
14584
|
+
}
|
|
14585
|
+
return { searched, wiredIn, refused, installRef };
|
|
14586
|
+
}
|
|
14587
|
+
function removalRefusal(search, target) {
|
|
14588
|
+
const { searched, refused, installRef } = search;
|
|
14589
|
+
const noEntry = searched.filter((r) => !refused.has(r));
|
|
14590
|
+
const clauses = [`no yaw-mcp entry in ${noEntry.map(describeContainer2).join(" or ")}`];
|
|
14591
|
+
for (const r of refused.values()) if (!clauses.includes(r.clause)) clauses.push(r.clause);
|
|
14592
|
+
const installCmd = `yaw-mcp install ${target.clientId}`;
|
|
14593
|
+
const blocking = installRef ? refused.get(installRef) : void 0;
|
|
14594
|
+
const next = blocking ? `\`${installCmd}\` ${blocking.installSays}; ${blocking.fix(`run \`${installCmd}\` and re-run this with --remove-originals`)}.` : `Run \`${installCmd}\` first, then re-run this with --remove-originals.`;
|
|
14595
|
+
return `${clauses.join(", and ")}, so ${target.label} would be left with no way to reach them. ${next}`;
|
|
14596
|
+
}
|
|
14597
|
+
function spliceOutOriginals(raw, site, keys, transform) {
|
|
14598
|
+
let next = raw;
|
|
14599
|
+
const removed = [];
|
|
14600
|
+
const unremovable = [];
|
|
14601
|
+
for (const key of keys) {
|
|
14602
|
+
try {
|
|
14603
|
+
const at = classifyClientConfig(next, site, { transform });
|
|
14604
|
+
const edits = [{ op: "remove", key }];
|
|
14605
|
+
const after = applyClientConfigEdits(at, edits, site);
|
|
14606
|
+
if (after !== next) removed.push(key);
|
|
14607
|
+
next = after;
|
|
14608
|
+
} catch (e) {
|
|
14609
|
+
unremovable.push(`${displayArg(key)} (${e instanceof Error ? e.message : String(e)})`);
|
|
14610
|
+
}
|
|
13987
14611
|
}
|
|
14612
|
+
return { next, removed, unremovable };
|
|
14613
|
+
}
|
|
14614
|
+
function unremovableNote(outcome, file, unremovable, label) {
|
|
14615
|
+
const one = unremovable.length === 1;
|
|
14616
|
+
return `yaw-mcp import: ${outcome} from ${file}: ${unremovable.join("; ")}. Remove ${one ? "that entry" : "those entries"} by hand; ${label} would otherwise keep launching ${one ? "it" : "them"} alongside yaw-mcp.`;
|
|
13988
14617
|
}
|
|
13989
14618
|
async function runImport(opts) {
|
|
13990
14619
|
const out = opts.out ?? createStreamWriter(process.stdout);
|
|
@@ -14092,13 +14721,16 @@ Nothing to import: no servers in ${displaySafe(resolved.absolute)} beyond yaw-mc
|
|
|
14092
14721
|
reportSkips();
|
|
14093
14722
|
return { exitCode: 0, written: [] };
|
|
14094
14723
|
}
|
|
14724
|
+
const unpreviewed = /* @__PURE__ */ new Set();
|
|
14095
14725
|
for (const c of candidates) {
|
|
14096
14726
|
try {
|
|
14097
14727
|
const preview = await previewUpsertUserBundle(c.entry, { home });
|
|
14098
14728
|
for (const w of preview.warnings) warnOnce(w);
|
|
14099
14729
|
c.plannedNamespace = preview.namespace ?? c.namespace;
|
|
14100
14730
|
c.replacing = preview.replaced ? preview.replacing : void 0;
|
|
14731
|
+
if (preview.replaced) c.changes = await storedEntryChanges(preview, home, warnOnce) ?? void 0;
|
|
14101
14732
|
} catch (e) {
|
|
14733
|
+
unpreviewed.add(c);
|
|
14102
14734
|
warnOnce(`could not preview the write against bundles.json: ${e instanceof Error ? e.message : String(e)}`);
|
|
14103
14735
|
}
|
|
14104
14736
|
}
|
|
@@ -14131,15 +14763,107 @@ Skipped yaw-mcp's own entries: ${skippedSelf.map(displayArg).join(", ")}`);
|
|
|
14131
14763
|
`warning: namespace collision -- ${keys.map(displayArg).join(" and ")} both derive "${ns}", so only the last one imported keeps that namespace. Rename one in ${displaySafe(resolved.absolute)} and re-run, or edit the namespace in bundles.json.`
|
|
14132
14764
|
);
|
|
14133
14765
|
}
|
|
14766
|
+
const changing = candidates.filter((c) => c.changes !== void 0);
|
|
14134
14767
|
if (opts.dryRun) {
|
|
14768
|
+
if (changing.length > 0) print("");
|
|
14769
|
+
for (const c of changing) {
|
|
14770
|
+
const how = opts.force ? "--force" : "a real run asks first, and off a terminal needs --force";
|
|
14771
|
+
print(`Would overwrite the "${displaySafe(c.plannedNamespace)}" entry in bundles.json (${how}):`);
|
|
14772
|
+
for (const d of c.changes ?? []) print(` ${d}`);
|
|
14773
|
+
}
|
|
14774
|
+
if (opts.removeOriginals && !opts.keepOriginals) {
|
|
14775
|
+
const file = displaySafe(resolved.absolute);
|
|
14776
|
+
const planned = /* @__PURE__ */ new Map();
|
|
14777
|
+
for (const c of candidates) if (!unpreviewed.has(c)) planned.set(c.plannedNamespace, c);
|
|
14778
|
+
if (planned.size === 0) {
|
|
14779
|
+
printErr(
|
|
14780
|
+
`yaw-mcp import: would remove nothing from ${file} -- none of these servers would be imported, because their write to bundles.json could not be previewed (the warning above says why).`
|
|
14781
|
+
);
|
|
14782
|
+
} else {
|
|
14783
|
+
const broker = await searchForBroker(site, siteAt(targetSite, sourcePath), source, opts, home);
|
|
14784
|
+
if (broker.wiredIn === null) {
|
|
14785
|
+
printErr(`Would not remove the originals: ${removalRefusal(broker, target)}`);
|
|
14786
|
+
} else {
|
|
14787
|
+
const keys = [...planned.values()].map((c) => c.key);
|
|
14788
|
+
const preview = spliceOutOriginals(view.raw ?? "", siteAt(targetSite, sourcePath), keys, target.entry);
|
|
14789
|
+
if (preview.unremovable.length > 0) {
|
|
14790
|
+
printErr(unremovableNote("would not be removed", file, preview.unremovable, target.label));
|
|
14791
|
+
}
|
|
14792
|
+
const count = preview.removed.length;
|
|
14793
|
+
if (count === 0) {
|
|
14794
|
+
printErr(
|
|
14795
|
+
`yaw-mcp import: would remove nothing from ${file}; it would be left unchanged. The servers would be imported either way.`
|
|
14796
|
+
);
|
|
14797
|
+
} else {
|
|
14798
|
+
print("");
|
|
14799
|
+
if (broker.wiredIn !== broker.searched[0]) {
|
|
14800
|
+
print(`Reached through the yaw-mcp entry in ${describeContainer2(broker.wiredIn)}.`);
|
|
14801
|
+
}
|
|
14802
|
+
print(`Would remove ${count} ${count === 1 ? "entry" : "entries"} from ${file} (--remove-originals):`);
|
|
14803
|
+
for (const key of preview.removed) print(` ${displayArg(key)}`);
|
|
14804
|
+
}
|
|
14805
|
+
}
|
|
14806
|
+
}
|
|
14807
|
+
}
|
|
14135
14808
|
print("\n--- dry run: nothing was written ---");
|
|
14136
14809
|
return { exitCode: 0, written: [] };
|
|
14137
14810
|
}
|
|
14811
|
+
const bundlesFile = displaySafe(localBundlesPath(userConfigDir(home)));
|
|
14812
|
+
const declined = /* @__PURE__ */ new Set();
|
|
14813
|
+
if (changing.length > 0) {
|
|
14814
|
+
let answers = null;
|
|
14815
|
+
if (!opts.force) {
|
|
14816
|
+
if (!isInteractive3(opts)) {
|
|
14817
|
+
const one = changing.length === 1;
|
|
14818
|
+
const blocks = changing.map(
|
|
14819
|
+
(c) => ` "${displaySafe(c.plannedNamespace)}" differs from the one importing ${displayArg(c.key)} would write:
|
|
14820
|
+
` + indentLines(c.changes ?? [], " ")
|
|
14821
|
+
);
|
|
14822
|
+
printErr(
|
|
14823
|
+
`yaw-mcp import: ${bundlesFile} already has ${changing.length === 1 ? "an entry" : `${changing.length} entries`} this import would change, and there is no terminal to ask on. Nothing was written.
|
|
14824
|
+
${blocks.join("\n")}
|
|
14825
|
+
Re-run with --force to overwrite ${one ? "it" : "them"}, or --dry-run to preview.`
|
|
14826
|
+
);
|
|
14827
|
+
return { exitCode: 2, written: [] };
|
|
14828
|
+
}
|
|
14829
|
+
const asked = await askBundleCollisions(changing, bundlesFile, opts.io);
|
|
14830
|
+
if (asked === "abort") {
|
|
14831
|
+
printErr("yaw-mcp import: Aborted. Nothing was written.");
|
|
14832
|
+
return { exitCode: 1, written: [] };
|
|
14833
|
+
}
|
|
14834
|
+
if (asked === "cancelled") {
|
|
14835
|
+
printErr("yaw-mcp import: Cancelled. Nothing was written.");
|
|
14836
|
+
return { exitCode: 130, written: [] };
|
|
14837
|
+
}
|
|
14838
|
+
answers = asked;
|
|
14839
|
+
}
|
|
14840
|
+
print("");
|
|
14841
|
+
for (const c of changing) {
|
|
14842
|
+
const ns = displaySafe(c.plannedNamespace);
|
|
14843
|
+
if (answers === null) {
|
|
14844
|
+
print(`Overwriting the "${ns}" entry in bundles.json (--force):`);
|
|
14845
|
+
for (const d of c.changes ?? []) print(` ${d}`);
|
|
14846
|
+
} else if (answers.get(c) === "overwrite") {
|
|
14847
|
+
print(`Overwriting the "${ns}" entry in bundles.json.`);
|
|
14848
|
+
} else {
|
|
14849
|
+
declined.add(c);
|
|
14850
|
+
print(`Left the "${ns}" entry in bundles.json as it is -- ${displayArg(c.key)} is not imported.`);
|
|
14851
|
+
}
|
|
14852
|
+
}
|
|
14853
|
+
}
|
|
14854
|
+
const toWrite = candidates.filter((c) => !declined.has(c));
|
|
14855
|
+
if (toWrite.length === 0) {
|
|
14856
|
+
print(
|
|
14857
|
+
`
|
|
14858
|
+
Nothing imported: every server was skipped, so bundles.json and ${displaySafe(resolved.absolute)} are unchanged.`
|
|
14859
|
+
);
|
|
14860
|
+
return { exitCode: 0, written: [] };
|
|
14861
|
+
}
|
|
14138
14862
|
const written = [];
|
|
14139
14863
|
const results = [];
|
|
14140
14864
|
const writtenNamespaces = /* @__PURE__ */ new Set();
|
|
14141
14865
|
let updated = 0;
|
|
14142
|
-
for (const c of
|
|
14866
|
+
for (const c of toWrite) {
|
|
14143
14867
|
try {
|
|
14144
14868
|
const res = await upsertUserBundle(c.entry, { home });
|
|
14145
14869
|
for (const w of res.warnings) warnOnce(w);
|
|
@@ -14195,59 +14919,13 @@ If the previous entry was a different server you meant to keep, restore it from
|
|
|
14195
14919
|
print(`Left ${displaySafe(resolved.absolute)} alone (--keep-originals).`);
|
|
14196
14920
|
return { exitCode: 0, written };
|
|
14197
14921
|
}
|
|
14198
|
-
const
|
|
14199
|
-
|
|
14200
|
-
for (const spec of target.scopes) {
|
|
14201
|
-
if (spec.scope === site.scope) continue;
|
|
14202
|
-
try {
|
|
14203
|
-
const others = resolveInstallSites({
|
|
14204
|
-
clientId: target.clientId,
|
|
14205
|
-
scope: spec.scope,
|
|
14206
|
-
os: site.os,
|
|
14207
|
-
home,
|
|
14208
|
-
appData: resolveAppDataDir({ appData: opts.appData, home }),
|
|
14209
|
-
// Same env the target scope resolved with, so an env-redirected client
|
|
14210
|
-
// is searched at its REAL other-scope path rather than the default one.
|
|
14211
|
-
clientEnv: opts.clientEnv,
|
|
14212
|
-
// The project the user is standing in -- the same resolution
|
|
14213
|
-
// resolveInstallSite would have made had that scope been the target.
|
|
14214
|
-
projectDir: spec.requiresProjectDir ? site.projectDir ?? resolvePath(opts.cwd ?? process.cwd(), ".") : void 0,
|
|
14215
|
-
claudeConfigDir: opts.claudeConfigDir
|
|
14216
|
-
});
|
|
14217
|
-
for (const other of others) {
|
|
14218
|
-
const already = searched.find(
|
|
14219
|
-
(r) => r.resolved.absolute === other.resolved.absolute && r.resolved.containerPath.join(".") === other.resolved.containerPath.join(".")
|
|
14220
|
-
);
|
|
14221
|
-
const ref = already ?? other;
|
|
14222
|
-
if (!already) searched.push(ref);
|
|
14223
|
-
if (spec.scope === "user" && installRef === null) installRef = ref;
|
|
14224
|
-
}
|
|
14225
|
-
} catch {
|
|
14226
|
-
}
|
|
14227
|
-
}
|
|
14228
|
-
let wiredIn = null;
|
|
14229
|
-
const refused = /* @__PURE__ */ new Map();
|
|
14230
|
-
for (let i = 0; i < searched.length; i++) {
|
|
14231
|
-
const read2 = i === 0 ? { state: "container", wired: isWiredIn(source) } : await readContainer(searched[i]);
|
|
14232
|
-
if (read2.state === "container" && read2.wired) {
|
|
14233
|
-
wiredIn = searched[i];
|
|
14234
|
-
break;
|
|
14235
|
-
}
|
|
14236
|
-
if (read2.state === "refused") refused.set(searched[i], read2);
|
|
14237
|
-
}
|
|
14922
|
+
const search = await searchForBroker(site, siteAt(targetSite, sourcePath), source, opts, home);
|
|
14923
|
+
const wiredIn = search.wiredIn;
|
|
14238
14924
|
if (!wiredIn) {
|
|
14239
|
-
|
|
14240
|
-
const clauses = [`no yaw-mcp entry in ${noEntry.map(describeContainer2).join(" or ")}`];
|
|
14241
|
-
for (const r of refused.values()) if (!clauses.includes(r.clause)) clauses.push(r.clause);
|
|
14242
|
-
const installCmd = `yaw-mcp install ${target.clientId}`;
|
|
14243
|
-
const blocking = installRef ? refused.get(installRef) : void 0;
|
|
14244
|
-
const next2 = blocking ? `\`${installCmd}\` ${blocking.installSays}; ${blocking.fix(`run \`${installCmd}\` and re-run this with --remove-originals`)}.` : `Run \`${installCmd}\` first, then re-run this with --remove-originals.`;
|
|
14245
|
-
printErr(
|
|
14246
|
-
`Not removing the originals: ${clauses.join(", and ")}, so ${target.label} would be left with no way to reach them. ${next2}`
|
|
14247
|
-
);
|
|
14925
|
+
printErr(`Not removing the originals: ${removalRefusal(search, target)}`);
|
|
14248
14926
|
return { exitCode: 0, written };
|
|
14249
14927
|
}
|
|
14250
|
-
if (wiredIn !== searched[0]) {
|
|
14928
|
+
if (wiredIn !== search.searched[0]) {
|
|
14251
14929
|
print(`Reached through the yaw-mcp entry in ${describeContainer2(wiredIn)}.`);
|
|
14252
14930
|
}
|
|
14253
14931
|
if (!opts.removeOriginals) {
|
|
@@ -14257,7 +14935,7 @@ If the previous entry was a different server you meant to keep, restore it from
|
|
|
14257
14935
|
);
|
|
14258
14936
|
return { exitCode: 0, written };
|
|
14259
14937
|
}
|
|
14260
|
-
const answer = await
|
|
14938
|
+
const answer = await askYesNo(
|
|
14261
14939
|
opts,
|
|
14262
14940
|
` Remove ${imported.length === 1 ? "it" : `those ${imported.length} entries`} from ${resolved.absolute}? [y/N] `
|
|
14263
14941
|
);
|
|
@@ -14270,26 +14948,16 @@ If the previous entry was a different server you meant to keep, restore it from
|
|
|
14270
14948
|
return { exitCode: 0, written };
|
|
14271
14949
|
}
|
|
14272
14950
|
}
|
|
14273
|
-
const
|
|
14274
|
-
|
|
14275
|
-
|
|
14276
|
-
|
|
14277
|
-
|
|
14278
|
-
|
|
14279
|
-
|
|
14280
|
-
|
|
14281
|
-
const after = applyClientConfigEdits(at, edits, removalSite);
|
|
14282
|
-
if (after !== next) removed++;
|
|
14283
|
-
next = after;
|
|
14284
|
-
} catch (e) {
|
|
14285
|
-
unremovable.push(`${displayArg(r.candidate.key)} (${e instanceof Error ? e.message : String(e)})`);
|
|
14286
|
-
}
|
|
14287
|
-
}
|
|
14288
|
-
if (unremovable.length > 0) {
|
|
14289
|
-
printErr(
|
|
14290
|
-
`yaw-mcp import: could not be removed from ${displaySafe(resolved.absolute)}: ${unremovable.join("; ")}. Remove ${unremovable.length === 1 ? "that entry" : "those entries"} by hand; ${target.label} would otherwise keep launching ${unremovable.length === 1 ? "it" : "them"} alongside yaw-mcp.`
|
|
14291
|
-
);
|
|
14951
|
+
const splice = spliceOutOriginals(
|
|
14952
|
+
view.raw ?? "",
|
|
14953
|
+
siteAt(targetSite, sourcePath),
|
|
14954
|
+
imported.map((r) => r.candidate.key),
|
|
14955
|
+
target.entry
|
|
14956
|
+
);
|
|
14957
|
+
if (splice.unremovable.length > 0) {
|
|
14958
|
+
printErr(unremovableNote("could not be removed", displaySafe(resolved.absolute), splice.unremovable, target.label));
|
|
14292
14959
|
}
|
|
14960
|
+
const removed = splice.removed.length;
|
|
14293
14961
|
if (removed === 0) {
|
|
14294
14962
|
printErr(
|
|
14295
14963
|
`yaw-mcp import: nothing was removed from ${displaySafe(resolved.absolute)}; it was left unchanged. The servers are imported either way.`
|
|
@@ -14297,7 +14965,7 @@ If the previous entry was a different server you meant to keep, restore it from
|
|
|
14297
14965
|
return { exitCode: 0, written };
|
|
14298
14966
|
}
|
|
14299
14967
|
try {
|
|
14300
|
-
await atomicWriteFile(resolved.absolute, terminateWithNewline(next));
|
|
14968
|
+
await atomicWriteFile(resolved.absolute, terminateWithNewline(splice.next));
|
|
14301
14969
|
} catch (e) {
|
|
14302
14970
|
printErr(
|
|
14303
14971
|
`yaw-mcp import: could not write ${displaySafe(resolved.absolute)} (${e.message}). It was left unchanged; the servers are imported either way.`
|
|
@@ -14314,7 +14982,6 @@ If the previous entry was a different server you meant to keep, restore it from
|
|
|
14314
14982
|
// src/local-add-cmd.ts
|
|
14315
14983
|
import { readFile as readFile14 } from "fs/promises";
|
|
14316
14984
|
import { homedir as homedir19 } from "os";
|
|
14317
|
-
import { createInterface as createInterface4 } from "readline/promises";
|
|
14318
14985
|
var ADD_USAGE = `Usage: yaw-mcp add <slug> [flags]
|
|
14319
14986
|
yaw-mcp add <name> --command "<launch line>" [flags]
|
|
14320
14987
|
yaw-mcp add <name> --url <https://...> [flags]
|
|
@@ -14973,18 +15640,6 @@ function isInteractive4(opts) {
|
|
|
14973
15640
|
if (opts.promptAnswer !== void 0) return true;
|
|
14974
15641
|
return Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY);
|
|
14975
15642
|
}
|
|
14976
|
-
async function askYesNo4(opts, question) {
|
|
14977
|
-
if (opts.promptAnswer !== void 0) return opts.promptAnswer.trim().toLowerCase();
|
|
14978
|
-
const input = opts.io?.stdin ?? process.stdin;
|
|
14979
|
-
const output = opts.io?.stdout ?? process.stdout;
|
|
14980
|
-
const rl = createInterface4({ input, output, terminal: opts.io?.terminal });
|
|
14981
|
-
try {
|
|
14982
|
-
const raw = await questionOrEmpty(rl, question);
|
|
14983
|
-
return raw === QUESTION_CANCELLED ? raw : raw.trim().toLowerCase();
|
|
14984
|
-
} finally {
|
|
14985
|
-
rl.close();
|
|
14986
|
-
}
|
|
14987
|
-
}
|
|
14988
15643
|
async function runRemove(opts) {
|
|
14989
15644
|
const out = opts.out ?? createStreamWriter(process.stdout);
|
|
14990
15645
|
const err = opts.err ?? createStreamWriter(process.stderr);
|
|
@@ -15020,7 +15675,7 @@ async function runRemove(opts) {
|
|
|
15020
15675
|
printErr(" Re-run with --force (or -y) to remove it.");
|
|
15021
15676
|
return { exitCode: 2, written: [] };
|
|
15022
15677
|
}
|
|
15023
|
-
const answer = await
|
|
15678
|
+
const answer = await askYesNo(opts, ` Remove "${doomed.namespace}"? [y/N] `);
|
|
15024
15679
|
if (answer === QUESTION_CANCELLED) {
|
|
15025
15680
|
printErr("yaw-mcp remove: Cancelled. Nothing was removed.");
|
|
15026
15681
|
return { exitCode: 130, written: [] };
|
|
@@ -15187,7 +15842,6 @@ ${servers.length} server${servers.length === 1 ? "" : "s"} in ${loaded.path}`);
|
|
|
15187
15842
|
import { existsSync as existsSync7 } from "fs";
|
|
15188
15843
|
import { readFile as readFile15 } from "fs/promises";
|
|
15189
15844
|
import { homedir as homedir20 } from "os";
|
|
15190
|
-
import { createInterface as createInterface5 } from "readline/promises";
|
|
15191
15845
|
var SET_USAGE = `Usage: yaw-mcp set <slug-or-namespace> <key=value> [<key=value> ...] [flags]
|
|
15192
15846
|
|
|
15193
15847
|
Change per-server fields in your local ~/.yaw-mcp/bundles.json without
|
|
@@ -15355,18 +16009,6 @@ function isInteractive5(opts) {
|
|
|
15355
16009
|
if (opts.promptAnswer !== void 0) return true;
|
|
15356
16010
|
return Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY);
|
|
15357
16011
|
}
|
|
15358
|
-
async function askYesNo5(opts, question) {
|
|
15359
|
-
if (opts.promptAnswer !== void 0) return opts.promptAnswer.trim().toLowerCase();
|
|
15360
|
-
const input = opts.io?.stdin ?? process.stdin;
|
|
15361
|
-
const output = opts.io?.stdout ?? process.stdout;
|
|
15362
|
-
const rl = createInterface5({ input, output, terminal: opts.io?.terminal });
|
|
15363
|
-
try {
|
|
15364
|
-
const raw = await questionOrEmpty(rl, question);
|
|
15365
|
-
return raw === QUESTION_CANCELLED ? raw : raw.trim().toLowerCase();
|
|
15366
|
-
} finally {
|
|
15367
|
-
rl.close();
|
|
15368
|
-
}
|
|
15369
|
-
}
|
|
15370
16012
|
function render(value) {
|
|
15371
16013
|
return value === void 0 ? "unset" : JSON.stringify(value);
|
|
15372
16014
|
}
|
|
@@ -15537,7 +16179,7 @@ async function runSet(opts) {
|
|
|
15537
16179
|
}
|
|
15538
16180
|
return { exitCode: 2, written: [] };
|
|
15539
16181
|
}
|
|
15540
|
-
const answer = await
|
|
16182
|
+
const answer = await askYesNo(opts, `${phrase[0].toUpperCase()}${phrase.slice(1)} on "${namespace}"? [y/N] `);
|
|
15541
16183
|
if (answer === QUESTION_CANCELLED) {
|
|
15542
16184
|
if (opts.json) printErr(JSON.stringify({ ok: false, error: "Cancelled.", cancelled: true, path: path5, namespace }));
|
|
15543
16185
|
else printErr("Aborted.");
|
|
@@ -15653,7 +16295,6 @@ async function runEnableDisable(opts) {
|
|
|
15653
16295
|
import { existsSync as existsSync8 } from "fs";
|
|
15654
16296
|
import { unlink as unlink3 } from "fs/promises";
|
|
15655
16297
|
import { homedir as homedir21 } from "os";
|
|
15656
|
-
import { createInterface as createInterface6 } from "readline/promises";
|
|
15657
16298
|
var RESET_LEARNING_USAGE = `Usage: yaw-mcp reset-learning
|
|
15658
16299
|
|
|
15659
16300
|
Delete ~/.yaw-mcp/state.json so cross-session learning starts fresh.
|
|
@@ -15699,18 +16340,6 @@ function isInteractive6(opts) {
|
|
|
15699
16340
|
if (opts.promptAnswer !== void 0) return true;
|
|
15700
16341
|
return Boolean(process.stdin.isTTY) && Boolean(process.stdout.isTTY);
|
|
15701
16342
|
}
|
|
15702
|
-
async function askYesNo6(opts, question) {
|
|
15703
|
-
if (opts.promptAnswer !== void 0) return opts.promptAnswer.trim().toLowerCase();
|
|
15704
|
-
const input = opts.io?.stdin ?? process.stdin;
|
|
15705
|
-
const output = opts.io?.stdout ?? process.stdout;
|
|
15706
|
-
const rl = createInterface6({ input, output, terminal: opts.io?.terminal });
|
|
15707
|
-
try {
|
|
15708
|
-
const raw = await questionOrEmpty(rl, question);
|
|
15709
|
-
return raw === QUESTION_CANCELLED ? raw : raw.trim().toLowerCase();
|
|
15710
|
-
} finally {
|
|
15711
|
-
rl.close();
|
|
15712
|
-
}
|
|
15713
|
-
}
|
|
15714
16343
|
async function runResetLearning(opts = {}) {
|
|
15715
16344
|
const home = opts.home ?? homedir21();
|
|
15716
16345
|
const env = opts.env ?? process.env;
|
|
@@ -15754,7 +16383,7 @@ async function runResetLearning(opts = {}) {
|
|
|
15754
16383
|
printErr(" Re-run with --force (or -y).");
|
|
15755
16384
|
return { exitCode: 2, lines, removed: false, path: filePath };
|
|
15756
16385
|
}
|
|
15757
|
-
const answer = await
|
|
16386
|
+
const answer = await askYesNo(opts, "Delete it? [y/N] ");
|
|
15758
16387
|
if (answer === QUESTION_CANCELLED) {
|
|
15759
16388
|
printErr("yaw-mcp reset-learning: Cancelled. Nothing was deleted.");
|
|
15760
16389
|
return { exitCode: 130, lines, removed: false, path: filePath };
|
|
@@ -16467,7 +17096,7 @@ function pushToolCall(history, record, limit = HISTORY_LIMIT) {
|
|
|
16467
17096
|
}
|
|
16468
17097
|
|
|
16469
17098
|
// src/install-nudge.ts
|
|
16470
|
-
import { existsSync as existsSync9, mkdirSync as mkdirSync3, readFileSync as readFileSync6, statSync as
|
|
17099
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync3, readFileSync as readFileSync6, statSync as statSync5, writeFileSync as writeFileSync2 } from "fs";
|
|
16471
17100
|
import { dirname as dirname8, join as join15 } from "path";
|
|
16472
17101
|
var INSTALL_NUDGE_MIN_COUNT = 5;
|
|
16473
17102
|
var INSTALL_NUDGE_COOLDOWN_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
@@ -16488,7 +17117,7 @@ function readState(home) {
|
|
|
16488
17117
|
return { nudges: [] };
|
|
16489
17118
|
}
|
|
16490
17119
|
try {
|
|
16491
|
-
const st =
|
|
17120
|
+
const st = statSync5(path5);
|
|
16492
17121
|
if (stateMemo && stateMemo.path === path5 && stateMemo.mtimeMs === st.mtimeMs && stateMemo.size === st.size) {
|
|
16493
17122
|
return stateMemo.state;
|
|
16494
17123
|
}
|
|
@@ -16534,7 +17163,7 @@ function recordNudges(clis, home, now = Date.now) {
|
|
|
16534
17163
|
writeFileSync2(path5, `${JSON.stringify({ nudges: kept }, null, 2)}
|
|
16535
17164
|
`, "utf8");
|
|
16536
17165
|
try {
|
|
16537
|
-
const st =
|
|
17166
|
+
const st = statSync5(path5);
|
|
16538
17167
|
stateMemo = { path: path5, mtimeMs: st.mtimeMs, size: st.size, state: { nudges: kept } };
|
|
16539
17168
|
} catch {
|
|
16540
17169
|
stateMemo = null;
|
|
@@ -18049,7 +18678,7 @@ async function bestOfNViaSampling(server, intent, candidates, n) {
|
|
|
18049
18678
|
import { spawn as spawn4 } from "child_process";
|
|
18050
18679
|
import { randomBytes as randomBytes3, randomUUID, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
18051
18680
|
import { createServer } from "http";
|
|
18052
|
-
import { win32 as
|
|
18681
|
+
import { win32 as win323 } from "path";
|
|
18053
18682
|
var SECRET_ENTRY_PAGE_TTL_MS = 3 * 6e4;
|
|
18054
18683
|
var MAX_BODY_BYTES = 16 * 1024;
|
|
18055
18684
|
var REPLY_DRAIN_MS = 2e3;
|
|
@@ -18102,7 +18731,7 @@ ${body}
|
|
|
18102
18731
|
function browserCommand(url, platform = process.platform, env = process.env) {
|
|
18103
18732
|
if (platform === "win32") {
|
|
18104
18733
|
const systemRoot = env.SystemRoot ?? env.SYSTEMROOT ?? env.windir ?? env.WINDIR ?? "C:\\Windows";
|
|
18105
|
-
return { command:
|
|
18734
|
+
return { command: win323.join(systemRoot, "System32", "rundll32.exe"), args: ["url.dll,FileProtocolHandler", url] };
|
|
18106
18735
|
}
|
|
18107
18736
|
if (platform === "darwin") return { command: "/usr/bin/open", args: [url] };
|
|
18108
18737
|
if (!env.DISPLAY && !env.WAYLAND_DISPLAY) return null;
|
|
@@ -18146,6 +18775,9 @@ function openInSystemBrowser(url, spawnLauncher = spawn4) {
|
|
|
18146
18775
|
}
|
|
18147
18776
|
function openSecretEntryPage(opts) {
|
|
18148
18777
|
if (opts.fields.length === 0) return Promise.reject(new Error("a secret entry page needs at least one field"));
|
|
18778
|
+
if (new Set(opts.fields.map((f) => f.name)).size !== opts.fields.length) {
|
|
18779
|
+
return Promise.reject(new Error("secret entry page field names must be unique"));
|
|
18780
|
+
}
|
|
18149
18781
|
const ttlMs = opts.ttlMs ?? SECRET_ENTRY_PAGE_TTL_MS;
|
|
18150
18782
|
const token = randomBytes3(32).toString("hex");
|
|
18151
18783
|
const expectedPath = Buffer.from(`/${token}`, "utf8");
|
|
@@ -18541,6 +19173,12 @@ function computeToolOverlaps(connections) {
|
|
|
18541
19173
|
});
|
|
18542
19174
|
return overlaps;
|
|
18543
19175
|
}
|
|
19176
|
+
function newExplicitLoadTally() {
|
|
19177
|
+
return { anyChanged: false, anyError: false, anyCapped: false, advertisedGrew: false };
|
|
19178
|
+
}
|
|
19179
|
+
function explicitLoadIsError(tally) {
|
|
19180
|
+
return tally.anyError || tally.anyCapped && !tally.anyChanged ? true : void 0;
|
|
19181
|
+
}
|
|
18544
19182
|
var ConnectServer = class _ConnectServer {
|
|
18545
19183
|
server;
|
|
18546
19184
|
clientBridge;
|
|
@@ -18661,9 +19299,12 @@ var ConnectServer = class _ConnectServer {
|
|
|
18661
19299
|
// Short-term memory of activation failures; used by dispatch to
|
|
18662
19300
|
// down-rank recently-flaky servers. Cleared on successful activation.
|
|
18663
19301
|
activationFailures = /* @__PURE__ */ new Map();
|
|
18664
|
-
// Session-scoped credential
|
|
18665
|
-
//
|
|
18666
|
-
//
|
|
19302
|
+
// Session-scoped credential values the user typed on the masked-entry page
|
|
19303
|
+
// when a server's stderr named a missing env var (maybeElicitAndRetry).
|
|
19304
|
+
// They fill in keys the server's bundles.json env leaves unset or empty; a
|
|
19305
|
+
// non-empty value in the file wins (see effectiveEntry), and a value the
|
|
19306
|
+
// child still rejects after the retry is dropped rather than kept to shadow
|
|
19307
|
+
// a later fix. Cleared on shutdown — persistence belongs in the Yaw MCP
|
|
18667
19308
|
// bundles.json, these are a "get me running now" shortcut.
|
|
18668
19309
|
elicitedEnv = /* @__PURE__ */ new Map();
|
|
18669
19310
|
// Stop-asking latch for the VAULT PASSPHRASE elicitation. Not keyed by
|
|
@@ -18700,22 +19341,30 @@ var ConnectServer = class _ConnectServer {
|
|
|
18700
19341
|
// credentials. Per-namespace (unlike the vault counter) because these are
|
|
18701
19342
|
// the child's own secrets. Bounds the re-ask that replaced the old
|
|
18702
19343
|
// "already elicited, never ask again" latch -- see MAX_CREDENTIAL_PROMPTS.
|
|
19344
|
+
// An expired page spends its ask like any other; what sets an expiry apart
|
|
19345
|
+
// is that it does not latch (below), so the next activate asks again while
|
|
19346
|
+
// this count allows.
|
|
18703
19347
|
credentialPrompts = /* @__PURE__ */ new Map();
|
|
18704
19348
|
// Latch: namespaces whose prompt has ended the asking for the session,
|
|
18705
19349
|
// keyed by the REASON so a follow-up activate can surface the right
|
|
18706
19350
|
// refusal. The vault uses a single boolean (`vaultPassphraseElicited`)
|
|
18707
|
-
// and the same shaped message regardless of why; here, "
|
|
18708
|
-
//
|
|
18709
|
-
// the
|
|
18710
|
-
//
|
|
18711
|
-
//
|
|
19351
|
+
// and the same shaped message regardless of why; here, "declined" is a
|
|
19352
|
+
// user decision (return the raw spawn error, the user knows what they
|
|
19353
|
+
// did), "empty" is the defensive twin of it (a page result with no
|
|
19354
|
+
// non-empty value, which the shipped page cannot produce -- see the
|
|
19355
|
+
// submitted branch of maybeElicitAndRetry), and "no-page" / "no-browser"
|
|
19356
|
+
// are wall-shaped failures a follow-up activate would hit identically,
|
|
19357
|
+
// so the user gets the bundles.json hint on every attempt. An expired page
|
|
19358
|
+
// never latches: the user may simply have been away.
|
|
18712
19359
|
//
|
|
18713
|
-
//
|
|
18714
|
-
//
|
|
18715
|
-
//
|
|
18716
|
-
//
|
|
18717
|
-
//
|
|
18718
|
-
//
|
|
19360
|
+
// There is no reset for either prompt's latch short of a new ConnectServer.
|
|
19361
|
+
// This one is cleared only by shutdown(); the vault's
|
|
19362
|
+
// (`vaultPassphraseElicited`) is never cleared at all, and
|
|
19363
|
+
// `clearSessionVaultPassphrase` -- called only from shutdown() and tests --
|
|
19364
|
+
// clears the vault PASSPHRASE, not a latch. `yaw-mcp secrets reset` runs in
|
|
19365
|
+
// its own process and cannot reach this one's state; it tells the user to
|
|
19366
|
+
// restart a running server instead. Not worth building a reset until a verb
|
|
19367
|
+
// that needs one (e.g. a per-server "forget I asked") actually lands.
|
|
18719
19368
|
credentialElicited = /* @__PURE__ */ new Map();
|
|
18720
19369
|
// In-flight activation promises, keyed by namespace. Dedupes
|
|
18721
19370
|
// concurrent activation attempts for the same namespace so that two
|
|
@@ -18785,8 +19434,8 @@ var ConnectServer = class _ConnectServer {
|
|
|
18785
19434
|
// Short-TTL dedup cache for discover output. Agents often call
|
|
18786
19435
|
// discover twice in quick succession (e.g. once to list, again after
|
|
18787
19436
|
// a failed activate) — the second call returns the same text if
|
|
18788
|
-
// nothing has changed.
|
|
18789
|
-
//
|
|
19437
|
+
// nothing has changed. See discoverCacheKey for the key's components; the
|
|
19438
|
+
// connected set is one, so activate/deactivate naturally invalidates.
|
|
18790
19439
|
discoverCache = null;
|
|
18791
19440
|
static DISCOVER_CACHE_TTL_MS = 3e3;
|
|
18792
19441
|
// Baseline idle-call threshold lives in resolveIdleThreshold() (module
|
|
@@ -18826,7 +19475,7 @@ var ConnectServer = class _ConnectServer {
|
|
|
18826
19475
|
static SHUTDOWN_DRAIN_MS = 2e3;
|
|
18827
19476
|
constructor() {
|
|
18828
19477
|
this.server = new Server(
|
|
18829
|
-
{ name: "yaw-mcp", version: true ? "1.0.
|
|
19478
|
+
{ name: "yaw-mcp", version: true ? "1.0.16" : "dev" },
|
|
18830
19479
|
{
|
|
18831
19480
|
capabilities: {
|
|
18832
19481
|
tools: { listChanged: true },
|
|
@@ -19066,11 +19715,16 @@ var ConnectServer = class _ConnectServer {
|
|
|
19066
19715
|
// show, so a curated list is still worth rendering over it.
|
|
19067
19716
|
//
|
|
19068
19717
|
// This is the ONE precedence rule for a cold server's tool list. Every
|
|
19069
|
-
// reader goes through it
|
|
19070
|
-
//
|
|
19071
|
-
//
|
|
19072
|
-
//
|
|
19073
|
-
//
|
|
19718
|
+
// reader of the LIST goes through it: getProfiledActiveServers merges once,
|
|
19719
|
+
// and what reads its result (the discover body, getDeferredServers and so
|
|
19720
|
+
// the deferred routes and tools/list, dispatch's sampling tiebreak) sees the
|
|
19721
|
+
// merged `server.toolCache`; rankableFor (the BM25 corpus),
|
|
19722
|
+
// estimateTokensFor, coldStartHint and unmatchedFilterNames call it
|
|
19723
|
+
// directly. Copies of the resolution used to live in readers with `??`
|
|
19724
|
+
// semantics (empty learned list WINS), so discover could rank a server on
|
|
19725
|
+
// an empty list while listing its curated tools. hasKnownTools and
|
|
19726
|
+
// isLearnedCacheStale read this.toolCache raw on purpose: they ask whether
|
|
19727
|
+
// a list was OBSERVED, and an empty one was.
|
|
19074
19728
|
//
|
|
19075
19729
|
// Identity preservation: when both sides resolve to the same array
|
|
19076
19730
|
// reference — which in practice means BOTH are undefined (server.ts
|
|
@@ -19312,18 +19966,46 @@ var ConnectServer = class _ConnectServer {
|
|
|
19312
19966
|
return changed;
|
|
19313
19967
|
}
|
|
19314
19968
|
/** The entry as a fresh activation would actually launch it: the config
|
|
19315
|
-
* file's entry with any session-elicited credentials
|
|
19969
|
+
* file's entry with any session-elicited credentials filling in the env
|
|
19970
|
+
* keys the file leaves unset or empty.
|
|
19971
|
+
*
|
|
19972
|
+
* The FILE wins for a key it sets to a non-empty value. The give-up and
|
|
19973
|
+
* refusal messages tell the user to set the key in bundles.json and
|
|
19974
|
+
* activate again, and that edit has to be what the next launch uses:
|
|
19975
|
+
* with the elicited value merged on top, a value typed this session
|
|
19976
|
+
* shadowed the file for the rest of it, so the recommended fix did
|
|
19977
|
+
* nothing until a client restart -- and the staleness check below, which
|
|
19978
|
+
* compares through this same function, never saw the edit either, so it
|
|
19979
|
+
* left the child running on the typed value. With the file winning, a
|
|
19980
|
+
* file value that differs from the typed one moves the launch identity
|
|
19981
|
+
* like any other env edit, and reconcileConfig reaps the child so the next
|
|
19982
|
+
* activate launches it from the file.
|
|
19316
19983
|
*
|
|
19317
|
-
* ONE copy, reached from
|
|
19318
|
-
*
|
|
19319
|
-
*
|
|
19320
|
-
*
|
|
19321
|
-
* connection
|
|
19322
|
-
*
|
|
19323
|
-
*
|
|
19984
|
+
* ONE copy, reached from the activation path (which builds the child from
|
|
19985
|
+
* it), the staleness check below (which compares a live child against it)
|
|
19986
|
+
* and handleReadTool's transient connect (which must inspect the server
|
|
19987
|
+
* under the env an activation would give it). Copies drifted the moment
|
|
19988
|
+
* elicitation existed: a connection is launched from the MERGED shape and
|
|
19989
|
+
* remembers it as connection.config, so comparing a freshly-parsed entry
|
|
19990
|
+
* against it directly reads every elicited server as "launch config
|
|
19991
|
+
* changed" and reaps a healthy child on the next unrelated edit. */
|
|
19324
19992
|
effectiveEntry(entry) {
|
|
19325
19993
|
const elicited = this.elicitedEnv.get(entry.namespace);
|
|
19326
|
-
|
|
19994
|
+
if (!elicited) return entry;
|
|
19995
|
+
const fillIns = {};
|
|
19996
|
+
for (const [key, value] of Object.entries(elicited)) {
|
|
19997
|
+
if (!this.entrySetsEnv(entry, key)) fillIns[key] = value;
|
|
19998
|
+
}
|
|
19999
|
+
return Object.keys(fillIns).length === 0 ? entry : { ...entry, env: { ...entry.env, ...fillIns } };
|
|
20000
|
+
}
|
|
20001
|
+
/** Does the config entry itself set `key` to a non-empty value? Such a key
|
|
20002
|
+
* belongs to the file: effectiveEntry never lets an elicited value replace
|
|
20003
|
+
* it, and maybeElicitAndRetry therefore never asks for it (the answer would
|
|
20004
|
+
* be ignored). An empty string counts as unset -- a `"GITHUB_TOKEN": ""`
|
|
20005
|
+
* placeholder is exactly the gap the prompt exists to fill. */
|
|
20006
|
+
entrySetsEnv(entry, key) {
|
|
20007
|
+
const value = entry?.env?.[key];
|
|
20008
|
+
return typeof value === "string" && value.length > 0;
|
|
19327
20009
|
}
|
|
19328
20010
|
/** Is this namespace exempt from the idle reaper (types.ts `pinned`)?
|
|
19329
20011
|
*
|
|
@@ -20152,10 +20834,9 @@ var ConnectServer = class _ConnectServer {
|
|
|
20152
20834
|
]
|
|
20153
20835
|
};
|
|
20154
20836
|
}
|
|
20155
|
-
// Drop the memoized discover body. The cache key only
|
|
20156
|
-
// (
|
|
20157
|
-
//
|
|
20158
|
-
// discover RENDERS but the key does not see -- activation failures
|
|
20837
|
+
// Drop the memoized discover body. The cache key covers only the components
|
|
20838
|
+
// discoverCacheKey (below) lists and explains, so state that discover
|
|
20839
|
+
// RENDERS but the key does not see -- activation failures
|
|
20159
20840
|
// (formatHealthWarning) and learning counters (usage:/reliability: lines)
|
|
20160
20841
|
// -- has to invalidate explicitly. Without this the exact case the cache
|
|
20161
20842
|
// was built for ("discover, failed activate, discover again") replays the
|
|
@@ -20230,7 +20911,7 @@ var ConnectServer = class _ConnectServer {
|
|
|
20230
20911
|
}
|
|
20231
20912
|
if (disabled.length > 0) {
|
|
20232
20913
|
parts.push(
|
|
20233
|
-
`Set "isActive": true for a server in
|
|
20914
|
+
`Set "isActive": true for a server in ${bundlesFileHint("defines-it")}; mcp_connect_discover lists what is installed but disabled. The edit is picked up on the next mcp_connect_* call, with no client restart.`
|
|
20234
20915
|
);
|
|
20235
20916
|
}
|
|
20236
20917
|
return parts.join(" ");
|
|
@@ -20267,7 +20948,7 @@ ${warmExecHint}` : ""}` : "";
|
|
|
20267
20948
|
const configured = this.config.servers.find((srv) => srv.namespace === focusNamespace);
|
|
20268
20949
|
if (configured && configured.isActive === false) {
|
|
20269
20950
|
return focusMiss(
|
|
20270
|
-
`"${focusNamespace}" is installed but disabled
|
|
20951
|
+
`"${focusNamespace}" is installed but disabled -- "isActive": false in ${bundlesFileHint("defines-it")}. Call mcp_connect_discover with no arguments to list what is available.`
|
|
20271
20952
|
);
|
|
20272
20953
|
}
|
|
20273
20954
|
if (configured) {
|
|
@@ -20279,7 +20960,7 @@ ${warmExecHint}` : ""}` : "";
|
|
|
20279
20960
|
1
|
|
20280
20961
|
)[0];
|
|
20281
20962
|
return focusMiss(
|
|
20282
|
-
near ? `"${focusNamespace}" is not in
|
|
20963
|
+
near ? `"${focusNamespace}" is not in ${bundlesFileHint("in-effect")}. Did you mean: ${near}?` : `"${focusNamespace}" is not in ${bundlesFileHint("in-effect")}. Call mcp_connect_discover with no arguments to list what is available.`
|
|
20283
20964
|
);
|
|
20284
20965
|
}
|
|
20285
20966
|
}
|
|
@@ -20702,7 +21383,7 @@ ${activeCount} loaded in this session, ${totalTools} ${totalTools === 1 ? "tool"
|
|
|
20702
21383
|
if (!refusal) return null;
|
|
20703
21384
|
switch (refusal.kind) {
|
|
20704
21385
|
case "disabled":
|
|
20705
|
-
return `"${refusal.namespace}" is installed but disabled. Set "isActive": true for it in
|
|
21386
|
+
return `"${refusal.namespace}" is installed but disabled. Set "isActive": true for it in ${bundlesFileHint("defines-it")} and try again to ${purpose} -- the edit is picked up on the next mcp_connect_* call, with no client restart.`;
|
|
20706
21387
|
case "profile":
|
|
20707
21388
|
return `"${refusal.namespace}" is not allowed by the project profile at ${refusal.profilePath}.`;
|
|
20708
21389
|
case "compliance":
|
|
@@ -20824,7 +21505,7 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
20824
21505
|
*/
|
|
20825
21506
|
coldStartHint(server) {
|
|
20826
21507
|
if (server.type !== "local" || server.command === void 0) return "";
|
|
20827
|
-
const cached = this.
|
|
21508
|
+
const cached = this.mergeToolCache(server).toolCache;
|
|
20828
21509
|
if (cached && cached.length > 0) return "";
|
|
20829
21510
|
const base = (server.command.split(/[\\/]/).pop() ?? server.command).replace(/\.(exe|cmd|bat|ps1)$/i, "");
|
|
20830
21511
|
const fetches = COLD_START_LAUNCHERS[base.toLowerCase()];
|
|
@@ -20941,9 +21622,14 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
20941
21622
|
}
|
|
20942
21623
|
// If the activation error names a missing credential (e.g. "GITHUB_TOKEN
|
|
20943
21624
|
// is required") AND the client supports elicitation, ask the user for
|
|
20944
|
-
// the values
|
|
20945
|
-
//
|
|
20946
|
-
//
|
|
21625
|
+
// the values on the masked loopback page and retry the activation with
|
|
21626
|
+
// them. Returns the retry's result; a refusal that says what went wrong
|
|
21627
|
+
// (the page could not start, could not be shown or expired; the values
|
|
21628
|
+
// just typed were not accepted; shutdown); or null when we can't/shouldn't
|
|
21629
|
+
// elicit and the caller's give-up path should report the raw spawn error.
|
|
21630
|
+
// Bounded rather than single-round: inside the retry an ask bought, only a
|
|
21631
|
+
// key nobody has typed yet gets another ask, and every ask spends one of
|
|
21632
|
+
// the namespace's MAX_CREDENTIAL_PROMPTS for the session.
|
|
20947
21633
|
async maybeElicitAndRetry(namespace, lastError, progress, fromPrewarm = false, isElicitRetry = false) {
|
|
20948
21634
|
if (lastError instanceof VaultPassphraseRequiredError) {
|
|
20949
21635
|
return this.elicitVaultPassphraseAndRetry(namespace, lastError, progress, fromPrewarm);
|
|
@@ -20951,7 +21637,10 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
20951
21637
|
const stderr = lastError instanceof ActivationError ? lastError.stderrTail : void 0;
|
|
20952
21638
|
const errMessage = lastError instanceof Error ? lastError.message : String(lastError);
|
|
20953
21639
|
const haystack = [stderr, errMessage].filter(Boolean).join("\n");
|
|
20954
|
-
const
|
|
21640
|
+
const liveEntry = this.config?.servers.find((s) => s.namespace === namespace);
|
|
21641
|
+
const missing = detectMissingCredentials(haystack).filter(
|
|
21642
|
+
(k) => !isInternalSecretEnvKey(k) && !this.entrySetsEnv(liveEntry, k)
|
|
21643
|
+
);
|
|
20955
21644
|
if (missing.length === 0) return null;
|
|
20956
21645
|
const supplied = this.elicitedEnv.get(namespace) ?? {};
|
|
20957
21646
|
if (isElicitRetry && missing.every((k) => k in supplied)) {
|
|
@@ -20964,8 +21653,12 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
20964
21653
|
message: lastError instanceof Error ? lastError.message : String(lastError)
|
|
20965
21654
|
});
|
|
20966
21655
|
this.invalidateDiscoverCache();
|
|
21656
|
+
const kept = { ...supplied };
|
|
21657
|
+
for (const key of missing) delete kept[key];
|
|
21658
|
+
if (Object.keys(kept).length === 0) this.elicitedEnv.delete(namespace);
|
|
21659
|
+
else this.elicitedEnv.set(namespace, kept);
|
|
20967
21660
|
const promptsSoFar = this.credentialPrompts.get(namespace) ?? 0;
|
|
20968
|
-
const retryHint = promptsSoFar >= MAX_CREDENTIAL_PROMPTS ?
|
|
21661
|
+
const retryHint = promptsSoFar >= MAX_CREDENTIAL_PROMPTS ? this.noFurtherCredentialPromptsHint(namespace, missing) : ` Activate "${namespace}" again to try new ones.`;
|
|
20969
21662
|
return {
|
|
20970
21663
|
ok: false,
|
|
20971
21664
|
isChanged: false,
|
|
@@ -21005,8 +21698,7 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21005
21698
|
this.credentialPrompts.set(namespace, asked + 1);
|
|
21006
21699
|
const isPlural = missing.length !== 1;
|
|
21007
21700
|
const what = isPlural ? "them" : "it";
|
|
21008
|
-
const
|
|
21009
|
-
const fixHint = `Set ${what} in this server's "env" in ~/.yaw-mcp/bundles.json to skip this prompt in future sessions.`;
|
|
21701
|
+
const fixHint = `Set ${what} in this server's "env" in ${bundlesFileHint("defines-it")} to skip this prompt in future sessions.`;
|
|
21010
21702
|
const why = `"${namespace}" cannot start: it reports ${missing.join(", ")} missing. ${fixHint}`;
|
|
21011
21703
|
const entry = await this.collectSecretOnLoopbackPage({
|
|
21012
21704
|
namespace,
|
|
@@ -21014,7 +21706,9 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21014
21706
|
secretNoun: isPlural ? `the values of ${missing.join(", ")}` : `the value of ${missing[0]}`,
|
|
21015
21707
|
page: {
|
|
21016
21708
|
title: `"${namespace}" needs ${isPlural ? "credentials" : "a credential"} to start`,
|
|
21017
|
-
|
|
21709
|
+
// "its" in both slots: the subject is the one server, however many
|
|
21710
|
+
// keys it named.
|
|
21711
|
+
intro: `"${namespace}" cannot start without ${missing.join(", ")} and reported its missing key${isPlural ? "s" : ""} on its own. Type ${isPlural ? "each value" : "the value"} below. yaw-mcp keeps ${what} in memory for this session only -- never written to disk, and never passed to anything other than "${namespace}". ${fixHint}`,
|
|
21018
21712
|
fields: missing.map((name) => ({ name, label: name })),
|
|
21019
21713
|
doneMessage: "Received. You can close this tab and return to your MCP client."
|
|
21020
21714
|
},
|
|
@@ -21040,9 +21734,8 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21040
21734
|
if (this.shuttingDown) return this.shuttingDownRefusal(namespace);
|
|
21041
21735
|
if (entry.reason !== "expired") {
|
|
21042
21736
|
this.credentialElicited.set(namespace, entry.reason);
|
|
21043
|
-
return this.credentialUnreachableRefusal(namespace, missing, entry.reason);
|
|
21044
21737
|
}
|
|
21045
|
-
return
|
|
21738
|
+
return this.credentialUnreachableRefusal(namespace, missing, entry.reason);
|
|
21046
21739
|
}
|
|
21047
21740
|
const values = {};
|
|
21048
21741
|
for (const key of missing) {
|
|
@@ -21180,36 +21873,52 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21180
21873
|
};
|
|
21181
21874
|
}
|
|
21182
21875
|
// The result for a missing-credential prompt whose masked-entry page never
|
|
21183
|
-
// took a value
|
|
21184
|
-
//
|
|
21185
|
-
//
|
|
21186
|
-
//
|
|
21187
|
-
//
|
|
21188
|
-
//
|
|
21189
|
-
//
|
|
21190
|
-
//
|
|
21191
|
-
//
|
|
21876
|
+
// took a value: it could not start, no browser could be opened for it, or
|
|
21877
|
+
// it expired with nothing submitted. The shape mirrors
|
|
21878
|
+
// vaultPassphraseUnreachable so a user who saw the vault message once
|
|
21879
|
+
// recognises this one: explain what could not happen, then say whether
|
|
21880
|
+
// activating again will open a new page, and point at the bundles.json env
|
|
21881
|
+
// path either way.
|
|
21882
|
+
//
|
|
21883
|
+
// The retry hint reads the latch and the budget, as the vault's reads its
|
|
21884
|
+
// latch, because the two outcomes differ. No-page and no-browser latch the
|
|
21885
|
+
// namespace before this runs (and the early check in maybeElicitAndRetry
|
|
21886
|
+
// re-renders this same refusal on every follow-up activate), so for them a
|
|
21887
|
+
// new page is never coming this session. An expired page does not latch:
|
|
21888
|
+
// the next activate opens a new page if the namespace has an ask left under
|
|
21889
|
+
// MAX_CREDENTIAL_PROMPTS, and returns the raw spawn error if it does not.
|
|
21192
21890
|
credentialUnreachableRefusal(namespace, missing, reason) {
|
|
21891
|
+
const isPlural = missing.length !== 1;
|
|
21892
|
+
const noun = isPlural ? "credentials" : "credential";
|
|
21193
21893
|
let what;
|
|
21194
21894
|
switch (reason) {
|
|
21195
21895
|
case "no-browser":
|
|
21196
|
-
what =
|
|
21896
|
+
what = `yaw-mcp could not open a browser on this machine for the page that takes the ${noun} in a masked field`;
|
|
21197
21897
|
break;
|
|
21198
21898
|
case "no-page":
|
|
21199
|
-
what =
|
|
21899
|
+
what = `yaw-mcp could not start the local page that takes the ${noun} in a masked field`;
|
|
21200
21900
|
break;
|
|
21201
21901
|
case "expired":
|
|
21202
|
-
|
|
21203
|
-
|
|
21204
|
-
);
|
|
21902
|
+
what = `the page that takes the ${noun} in a masked field expired with nothing submitted`;
|
|
21903
|
+
break;
|
|
21205
21904
|
}
|
|
21206
|
-
const
|
|
21905
|
+
const newPageComing = !this.credentialElicited.has(namespace) && (this.credentialPrompts.get(namespace) ?? 0) < MAX_CREDENTIAL_PROMPTS;
|
|
21906
|
+
const retryHint = newPageComing ? ` Activate "${namespace}" again for a new page, or set ${missing.join(", ")} in its "env" in ${bundlesFileHint("defines-it")} -- the edit is picked up on the next mcp_connect_* call, with no client restart.` : this.noFurtherCredentialPromptsHint(namespace, missing);
|
|
21207
21907
|
return {
|
|
21208
21908
|
ok: false,
|
|
21209
21909
|
isChanged: false,
|
|
21210
|
-
message: `Could not load "${namespace}": ${what}, so ${missing.join(", ")} is still missing.${retryHint}`
|
|
21910
|
+
message: `Could not load "${namespace}": ${what}, so ${missing.join(", ")} ${isPlural ? "are" : "is"} still missing.${retryHint}`
|
|
21211
21911
|
};
|
|
21212
21912
|
}
|
|
21913
|
+
// The retry hint for a namespace this session will not prompt for again
|
|
21914
|
+
// (latched, or MAX_CREDENTIAL_PROMPTS spent). One copy for every message
|
|
21915
|
+
// that ends the asking, so they cannot drift. The bundles.json edit it
|
|
21916
|
+
// recommends does get through: bundles.json is re-read at meta-tool
|
|
21917
|
+
// boundaries, effectiveEntry lets the file's value win over any elicited
|
|
21918
|
+
// one, and a spawn that succeeds never reaches the prompt or its latch.
|
|
21919
|
+
noFurtherCredentialPromptsHint(namespace, missing) {
|
|
21920
|
+
return ` No further prompts for "${namespace}" this session: set ${missing.join(", ")} in its "env" in ${bundlesFileHint("defines-it")} and activate again -- the edit is picked up on the next mcp_connect_* call, with no client restart.`;
|
|
21921
|
+
}
|
|
21213
21922
|
// Collect secret values WITHOUT them ever being typed into the client's
|
|
21214
21923
|
// own dialog. They are typed into masked fields on a one-shot page this
|
|
21215
21924
|
// process serves on 127.0.0.1 (secret-entry-page.ts, which carries the
|
|
@@ -21287,7 +21996,7 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21287
21996
|
},
|
|
21288
21997
|
() => page.result
|
|
21289
21998
|
);
|
|
21290
|
-
if (mode === "url" &&
|
|
21999
|
+
if (mode === "url" && !this.shuttingDown) this.notifyElicitationComplete(page.elicitationId, namespace);
|
|
21291
22000
|
if (outcome.kind === "submitted") return { kind: "submitted", values: outcome.values };
|
|
21292
22001
|
if (outcome.kind === "expired") return { kind: "unreachable", reason: "expired" };
|
|
21293
22002
|
return { kind: "failed" };
|
|
@@ -21318,7 +22027,9 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21318
22027
|
// which of these happened, because they need different words:
|
|
21319
22028
|
// unlocked -- verified and stored; retry the activation.
|
|
21320
22029
|
// rejected -- the user typed a passphrase and it did not verify.
|
|
21321
|
-
// unavailable -- declined
|
|
22030
|
+
// unavailable -- declined; no answer (the elicitation request failed,
|
|
22031
|
+
// or the page closed under the wait); or, from a drifted
|
|
22032
|
+
// page only, an empty submission.
|
|
21322
22033
|
// unreachable -- the masked-entry page never took a passphrase.
|
|
21323
22034
|
async promptForVaultPassphrase(namespace, lastError, progress) {
|
|
21324
22035
|
this.vaultPassphrasePrompts++;
|
|
@@ -21363,6 +22074,51 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21363
22074
|
this.vaultPassphraseElicited = true;
|
|
21364
22075
|
return { kind: "unlocked" };
|
|
21365
22076
|
}
|
|
22077
|
+
// The bookkeeping the two meta-tools that load what the client ASKED for
|
|
22078
|
+
// share -- handleActivate (by name) and handleDispatch (by intent). One
|
|
22079
|
+
// copy, so a new per-namespace flag or notify condition cannot reach one of
|
|
22080
|
+
// them and miss the other, which is how two hand-kept "mirrors
|
|
22081
|
+
// handleActivate" loops drift. autoLoadRecurringPack and discover's
|
|
22082
|
+
// auto-warm also add to sessionActivated but are deliberately not routed
|
|
22083
|
+
// through here: they report no cap/error split and no isError. What each
|
|
22084
|
+
// handler does beyond this -- activate's filter rollback and upstream
|
|
22085
|
+
// `instructions`, dispatch's scored result lines, and the list of loaded
|
|
22086
|
+
// namespaces each passes to execHintForNonRelistingClient -- stays in the
|
|
22087
|
+
// handler.
|
|
22088
|
+
//
|
|
22089
|
+
// Gateway mode advertises a namespace only on a signal of what the user
|
|
22090
|
+
// wants -- by name or by intent here, by discover's auto-warm and by replay
|
|
22091
|
+
// of their recurring pack at those two sites -- never in activateOne, which
|
|
22092
|
+
// the deferred first-call path and prewarm also route through: surfacing a
|
|
22093
|
+
// whole namespace off those would grow the tool list as a side effect of
|
|
22094
|
+
// one call. So the sessionActivated add lives here, on success only. A cap
|
|
22095
|
+
// refusal is booked apart from every other refusal (its message says what
|
|
22096
|
+
// to unload); explicitLoadIsError says what each means for the reply.
|
|
22097
|
+
recordExplicitLoad(tally, namespace, r) {
|
|
22098
|
+
if (r.isChanged) tally.anyChanged = true;
|
|
22099
|
+
if (r.ok) {
|
|
22100
|
+
if (!this.sessionActivated.has(namespace)) tally.advertisedGrew = true;
|
|
22101
|
+
this.sessionActivated.add(namespace);
|
|
22102
|
+
} else if (r.capped) {
|
|
22103
|
+
tally.anyCapped = true;
|
|
22104
|
+
} else {
|
|
22105
|
+
tally.anyError = true;
|
|
22106
|
+
}
|
|
22107
|
+
}
|
|
22108
|
+
// After the batch: a new connection needs the routes rebuilt AND the
|
|
22109
|
+
// client told. An advertised set that grew with no new connection (a
|
|
22110
|
+
// winner already connected but never advertised) -- or, for activate, a
|
|
22111
|
+
// `tools` filter change on a connected server -- leaves the routes current
|
|
22112
|
+
// but moves the tools/list surface, so the client still has to re-list.
|
|
22113
|
+
// Without that arm a gateway client is told tools are "now callable" while
|
|
22114
|
+
// its tools/list never learns they exist.
|
|
22115
|
+
async announceExplicitLoads(tally, surfaceMoved = false) {
|
|
22116
|
+
if (tally.anyChanged) {
|
|
22117
|
+
await this.refreshRoutesAndNotify();
|
|
22118
|
+
} else if (surfaceMoved || tally.advertisedGrew) {
|
|
22119
|
+
await this.notifyAllListsChanged();
|
|
22120
|
+
}
|
|
22121
|
+
}
|
|
21366
22122
|
async handleActivate(namespaces, progress, toolsFilter) {
|
|
21367
22123
|
if (namespaces.length === 0) {
|
|
21368
22124
|
return {
|
|
@@ -21400,10 +22156,7 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21400
22156
|
}
|
|
21401
22157
|
const results = [];
|
|
21402
22158
|
const upstreamInstructions = [];
|
|
21403
|
-
|
|
21404
|
-
let anyError = false;
|
|
21405
|
-
let anyCapped = false;
|
|
21406
|
-
let advertisedGrew = false;
|
|
22159
|
+
const tally = newExplicitLoadTally();
|
|
21407
22160
|
const total = namespaces.length;
|
|
21408
22161
|
const loadedOk = [];
|
|
21409
22162
|
let i = 0;
|
|
@@ -21412,11 +22165,9 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21412
22165
|
progress?.(`Loading ${namespace} (${i}/${total})`, i - 1, total);
|
|
21413
22166
|
const r = await this.activateOne(namespace, progress);
|
|
21414
22167
|
results.push(r.message);
|
|
21415
|
-
|
|
22168
|
+
this.recordExplicitLoad(tally, namespace, r);
|
|
21416
22169
|
if (r.ok) loadedOk.push(namespace);
|
|
21417
22170
|
if (r.ok) {
|
|
21418
|
-
if (!this.sessionActivated.has(namespace)) advertisedGrew = true;
|
|
21419
|
-
this.sessionActivated.add(namespace);
|
|
21420
22171
|
const captured = this.connections.get(namespace)?.instructions;
|
|
21421
22172
|
if (captured && !this.instructionsShown.has(namespace)) {
|
|
21422
22173
|
this.instructionsShown.add(namespace);
|
|
@@ -21424,8 +22175,6 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21424
22175
|
}
|
|
21425
22176
|
}
|
|
21426
22177
|
if (!r.ok) {
|
|
21427
|
-
if (r.capped) anyCapped = true;
|
|
21428
|
-
else anyError = true;
|
|
21429
22178
|
if (installedFilter && installedFilter.namespace === namespace) {
|
|
21430
22179
|
if (installedFilter.prev) this.toolFilters.set(namespace, installedFilter.prev);
|
|
21431
22180
|
else this.toolFilters.delete(namespace);
|
|
@@ -21435,11 +22184,7 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21435
22184
|
}
|
|
21436
22185
|
}
|
|
21437
22186
|
}
|
|
21438
|
-
|
|
21439
|
-
await this.refreshRoutesAndNotify();
|
|
21440
|
-
} else if (filtersChanged || advertisedGrew) {
|
|
21441
|
-
await this.notifyAllListsChanged();
|
|
21442
|
-
}
|
|
22187
|
+
await this.announceExplicitLoads(tally, filtersChanged);
|
|
21443
22188
|
if (filterRequestedFor) {
|
|
21444
22189
|
const ns = filterRequestedFor;
|
|
21445
22190
|
const unmatched = this.unmatchedFilterNames(ns);
|
|
@@ -21457,7 +22202,7 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21457
22202
|
results.push(...upstreamInstructions);
|
|
21458
22203
|
return {
|
|
21459
22204
|
content: [{ type: "text", text: results.join("\n") }],
|
|
21460
|
-
isError:
|
|
22205
|
+
isError: explicitLoadIsError(tally)
|
|
21461
22206
|
};
|
|
21462
22207
|
}
|
|
21463
22208
|
/** Filter names for `namespace` that match no tool the server actually
|
|
@@ -21468,7 +22213,14 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21468
22213
|
const filter = this.toolFilters.get(namespace);
|
|
21469
22214
|
if (!filter || filter.size === 0) return [];
|
|
21470
22215
|
const conn = this.connections.get(namespace);
|
|
21471
|
-
|
|
22216
|
+
let known;
|
|
22217
|
+
if (conn && conn.status === "connected") {
|
|
22218
|
+
known = conn.tools.map((t) => t.name);
|
|
22219
|
+
} else {
|
|
22220
|
+
const config = this.config?.servers.find((s) => s.namespace === namespace);
|
|
22221
|
+
const cache = config ? this.mergeToolCache(config).toolCache : this.toolCache.get(namespace);
|
|
22222
|
+
known = (cache ?? []).map((t) => t.name);
|
|
22223
|
+
}
|
|
21472
22224
|
if (known.length === 0) return [];
|
|
21473
22225
|
const have = new Set(known);
|
|
21474
22226
|
return [...filter].filter((n) => !have.has(n)).sort();
|
|
@@ -21508,9 +22260,9 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21508
22260
|
//
|
|
21509
22261
|
// The three empty-state messages below are the fresh-install path (dispatch
|
|
21510
22262
|
// is the documented first call), so each names the LOCAL fix -- `yaw-mcp
|
|
21511
|
-
// add <slug>`, `"isActive": true` in
|
|
21512
|
-
// the retired hosted add/enable UI at yaw.sh/mcp that
|
|
21513
|
-
// were already migrated away from.
|
|
22263
|
+
// add <slug>`, `"isActive": true` in the bundles.json that defines the
|
|
22264
|
+
// server -- rather than the retired hosted add/enable UI at yaw.sh/mcp that
|
|
22265
|
+
// discover and bundles were already migrated away from.
|
|
21514
22266
|
async handleDispatch(intent, budget, progress, routeEffortOverride) {
|
|
21515
22267
|
const trimmed = intent?.trim?.() ?? "";
|
|
21516
22268
|
if (trimmed.length === 0) {
|
|
@@ -21554,7 +22306,8 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21554
22306
|
if (safeBudget === 1 && shouldSample(ranked, effort)) {
|
|
21555
22307
|
progress?.("Top candidates close \u2014 asking LLM to pick\u2026");
|
|
21556
22308
|
const serversByNamespace = new Map(activeServers.map((s) => [s.namespace, s]));
|
|
21557
|
-
const
|
|
22309
|
+
const mergedTools = new Map(activeServers.map((s) => [s.namespace, s.toolCache ?? []]));
|
|
22310
|
+
const candidates = buildCandidates(ranked.slice(0, 3), serversByNamespace, mergedTools);
|
|
21558
22311
|
const samples = sampleCountForEffort(effort);
|
|
21559
22312
|
const picked = await bestOfNViaSampling(this.server, trimmed, candidates, samples);
|
|
21560
22313
|
if (picked) {
|
|
@@ -21590,10 +22343,7 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21590
22343
|
}
|
|
21591
22344
|
}
|
|
21592
22345
|
const results = [];
|
|
21593
|
-
|
|
21594
|
-
let anyError = false;
|
|
21595
|
-
let anyCapped = false;
|
|
21596
|
-
let advertisedGrew = false;
|
|
22346
|
+
const tally = newExplicitLoadTally();
|
|
21597
22347
|
const dispatchedOk = [];
|
|
21598
22348
|
let i = 0;
|
|
21599
22349
|
for (const winner of winners) {
|
|
@@ -21601,36 +22351,25 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21601
22351
|
progress?.(`Loading ${winner.namespace} (${i}/${winners.length})`, i - 1, winners.length);
|
|
21602
22352
|
const r = await this.activateOne(winner.namespace, progress);
|
|
21603
22353
|
results.push(`${winner.namespace} (score ${winner.score.toFixed(2)}): ${r.message}`);
|
|
21604
|
-
|
|
21605
|
-
if (r.ok)
|
|
21606
|
-
if (!this.sessionActivated.has(winner.namespace)) advertisedGrew = true;
|
|
21607
|
-
this.sessionActivated.add(winner.namespace);
|
|
21608
|
-
dispatchedOk.push(winner.namespace);
|
|
21609
|
-
}
|
|
21610
|
-
if (!r.ok) {
|
|
21611
|
-
if (r.capped) anyCapped = true;
|
|
21612
|
-
else anyError = true;
|
|
21613
|
-
}
|
|
21614
|
-
}
|
|
21615
|
-
if (anyChanged) {
|
|
21616
|
-
await this.refreshRoutesAndNotify();
|
|
21617
|
-
} else if (advertisedGrew) {
|
|
21618
|
-
await this.notifyAllListsChanged();
|
|
22354
|
+
this.recordExplicitLoad(tally, winner.namespace, r);
|
|
22355
|
+
if (r.ok) dispatchedOk.push(winner.namespace);
|
|
21619
22356
|
}
|
|
22357
|
+
await this.announceExplicitLoads(tally);
|
|
21620
22358
|
const execHint = this.execHintForNonRelistingClient(dispatchedOk);
|
|
21621
22359
|
if (execHint) results.push(execHint);
|
|
21622
22360
|
const header = `Dispatched "${trimmed}" \u2014 loaded top ${winners.length} of ${ranked.length} matching server${ranked.length === 1 ? "" : "s"}.
|
|
21623
22361
|
`;
|
|
21624
22362
|
return {
|
|
21625
22363
|
content: [{ type: "text", text: header + results.join("\n") }],
|
|
21626
|
-
isError:
|
|
22364
|
+
isError: explicitLoadIsError(tally)
|
|
21627
22365
|
};
|
|
21628
22366
|
}
|
|
21629
22367
|
// Drop every per-namespace bit of session state after its connection has
|
|
21630
|
-
// been closed. Called by
|
|
21631
|
-
// idle reaper
|
|
21632
|
-
//
|
|
21633
|
-
//
|
|
22368
|
+
// been closed. Called by all three teardown sites -- explicit deactivate,
|
|
22369
|
+
// the idle reaper, and reconcileConfig's unload of a server a bundles.json
|
|
22370
|
+
// reload changed or removed. The first two used to carry identical copies
|
|
22371
|
+
// of this list, so a new piece of per-namespace state had to be remembered
|
|
22372
|
+
// in each place to avoid leaking into the next load of the same server.
|
|
21634
22373
|
//
|
|
21635
22374
|
// Deliberately NOT cleared here: toolCache / toolCacheLearnedAt (what the
|
|
21636
22375
|
// server offers survives an unload -- that is what makes it deferred
|
|
@@ -21811,7 +22550,7 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21811
22550
|
content: [
|
|
21812
22551
|
{
|
|
21813
22552
|
type: "text",
|
|
21814
|
-
text: `"${serverArg}" is not in
|
|
22553
|
+
text: `"${serverArg}" is not in ${bundlesFileHint("in-effect")}.${hint}`
|
|
21815
22554
|
}
|
|
21816
22555
|
],
|
|
21817
22556
|
isError: true
|
|
@@ -21842,8 +22581,7 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
21842
22581
|
};
|
|
21843
22582
|
}
|
|
21844
22583
|
progress?.(`Inspecting "${serverArg}" (transient \u2014 not loading into session)\u2026`);
|
|
21845
|
-
const
|
|
21846
|
-
const transientConfig = elicitedForTransient ? { ...serverConfig, env: { ...serverConfig.env, ...elicitedForTransient } } : serverConfig;
|
|
22584
|
+
const transientConfig = this.effectiveEntry(serverConfig);
|
|
21847
22585
|
try {
|
|
21848
22586
|
return await withTransientUpstream(
|
|
21849
22587
|
transientConfig,
|
|
@@ -21988,10 +22726,6 @@ Cross-session reliability (dormant, <${flakyPct}% success):`);
|
|
|
21988
22726
|
}
|
|
21989
22727
|
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
21990
22728
|
}
|
|
21991
|
-
// Pack suggestion. Surfaces recurring multi-server tool-call sequences
|
|
21992
|
-
// observed in this session. Observation only — never activates
|
|
21993
|
-
// anything. Ranked by frequency primarily, with recency as a tiebreak
|
|
21994
|
-
// so the hottest-most-recent pattern sits at the top.
|
|
21995
22729
|
/** Cap on what find_tool returns when the caller names no limit.
|
|
21996
22730
|
*
|
|
21997
22731
|
* A number, not "everything that matched": the point of the tool is to
|
|
@@ -22081,6 +22815,11 @@ Cross-session reliability (dormant, <${flakyPct}% success):`);
|
|
|
22081
22815
|
);
|
|
22082
22816
|
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
22083
22817
|
}
|
|
22818
|
+
// Pack suggestion. Surfaces recurring multi-server tool-call sequences from
|
|
22819
|
+
// the pack history, which persists across restarts (see persistence.ts).
|
|
22820
|
+
// Observation only — never activates anything. Ranked by frequency
|
|
22821
|
+
// primarily, with recency as a tiebreak so the hottest-most-recent pattern
|
|
22822
|
+
// sits at the top.
|
|
22084
22823
|
handleSuggest() {
|
|
22085
22824
|
const detected = this.packDetector.detectChains();
|
|
22086
22825
|
if (detected.length === 0) {
|
|
@@ -22524,7 +23263,7 @@ function registerShutdownTriggers(shutdown, targets) {
|
|
|
22524
23263
|
// src/status-cmd.ts
|
|
22525
23264
|
import { existsSync as existsSync10 } from "fs";
|
|
22526
23265
|
import { homedir as homedir23 } from "os";
|
|
22527
|
-
var VERSION2 = true ? "1.0.
|
|
23266
|
+
var VERSION2 = true ? "1.0.16" : "dev";
|
|
22528
23267
|
var STATUS_SCHEMA_VERSION = 1;
|
|
22529
23268
|
var STATUS_USAGE = `Usage: yaw-mcp status [--json]
|
|
22530
23269
|
|
|
@@ -22880,6 +23619,11 @@ if (subcommand === "compliance") {
|
|
|
22880
23619
|
aggregator into the client; it does NOT add a
|
|
22881
23620
|
server (for that, see \`add\` below). <client> is
|
|
22882
23621
|
one of: ${wrapHelpList(clientChoices("install"))}.
|
|
23622
|
+
For codex-cli it also adds
|
|
23623
|
+
mcp_optional_startup_grace_ms = 0 to config.toml
|
|
23624
|
+
when the file lacks it, even on a re-run over an
|
|
23625
|
+
entry that is already correct, and leaves a value
|
|
23626
|
+
you set alone (\`install --help\` has the rest).
|
|
22883
23627
|
install --list Show every MCP client config location on this
|
|
22884
23628
|
machine and whether yaw-mcp is wired into each.
|
|
22885
23629
|
The STATUS column is about YAW-MCP, not about the
|
|
@@ -22903,8 +23647,14 @@ if (subcommand === "compliance") {
|
|
|
22903
23647
|
\`installed\` or \`legacy\` row can add \`(other
|
|
22904
23648
|
drive case)\`, for a Claude Code local-scope entry
|
|
22905
23649
|
an older version left under the other
|
|
22906
|
-
drive-letter spelling of this directory
|
|
22907
|
-
|
|
23650
|
+
drive-letter spelling of this directory. An
|
|
23651
|
+
\`installed\` row can also add \`(setting
|
|
23652
|
+
missing)\` or \`(setting refused)\`: its file
|
|
23653
|
+
lacks a top-level setting install adds (Codex
|
|
23654
|
+
CLI's mcp_optional_startup_grace_ms), or sets it
|
|
23655
|
+
to a value the client will not load, and a note
|
|
23656
|
+
under the table says what to do. Read-only; no
|
|
23657
|
+
writes.
|
|
22908
23658
|
install --all Install into every client yaw-mcp supports on this
|
|
22909
23659
|
OS. It plans from that list, not from a probe of
|
|
22910
23660
|
what you have installed (--list is the detecting
|
|
@@ -22925,8 +23675,10 @@ if (subcommand === "compliance") {
|
|
|
22925
23675
|
you already had instead of starting empty. The
|
|
22926
23676
|
client keeps launching them itself until you say
|
|
22927
23677
|
otherwise, so this offers to remove the originals
|
|
22928
|
-
(never silently).
|
|
22929
|
-
|
|
23678
|
+
(never silently). A server bundles.json already
|
|
23679
|
+
has in another form is asked about first, and
|
|
23680
|
+
off a terminal needs --force. --dry-run, --scope,
|
|
23681
|
+
--remove-originals, --keep-originals, --force.
|
|
22930
23682
|
remove <slug> Remove a server (by slug, namespace or name) from
|
|
22931
23683
|
bundles.json. Shows the server and the command it
|
|
22932
23684
|
launches, then confirms; --force skips the prompt
|
|
@@ -23304,7 +24056,7 @@ if (subcommand === "compliance") {
|
|
|
23304
24056
|
`);
|
|
23305
24057
|
process.exitCode = 0;
|
|
23306
24058
|
} else if (subcommand === "--version" || subcommand === "-V") {
|
|
23307
|
-
process.stdout.write(`yaw-mcp ${true ? "1.0.
|
|
24059
|
+
process.stdout.write(`yaw-mcp ${true ? "1.0.16" : "dev"}
|
|
23308
24060
|
`);
|
|
23309
24061
|
process.exitCode = 0;
|
|
23310
24062
|
} else if (subcommand !== void 0 && !subcommand.startsWith("-")) {
|