@yawlabs/mcp 0.75.4 → 0.76.1
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 +32 -0
- package/dist/auto-upgrade-CIO76Z6V.js +14 -0
- package/dist/chunk-C3AQHLOR.js +15 -0
- package/dist/{chunk-VHPGG3GN.js → chunk-CNEMSMQD.js} +387 -53
- package/dist/chunk-U3KC5QAD.js +552 -0
- package/dist/index.js +802 -992
- package/dist/{oam-spawn-Z5CASEBY.js → oam-spawn-VPVBHI7B.js} +12 -1
- package/package.json +2 -2
|
@@ -1,72 +1,354 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
log
|
|
4
|
+
} from "./chunk-C3AQHLOR.js";
|
|
2
5
|
|
|
3
6
|
// src/oam-spawn.ts
|
|
4
7
|
import { spawn } from "child_process";
|
|
5
8
|
import { accessSync, constants, existsSync, readdirSync, readFileSync, statSync } from "fs";
|
|
6
|
-
import { homedir as
|
|
7
|
-
import { dirname, isAbsolute, join, sep } from "path";
|
|
9
|
+
import { homedir as homedir3 } from "os";
|
|
10
|
+
import { dirname, isAbsolute as isAbsolute2, join as join2, sep } from "path";
|
|
8
11
|
import { fileURLToPath } from "url";
|
|
9
12
|
|
|
10
|
-
// src/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
// src/install-targets.ts
|
|
14
|
+
import { homedir } from "os";
|
|
15
|
+
import { isAbsolute, join, resolve } from "path";
|
|
16
|
+
var CURRENT_OS = process.platform === "darwin" ? "macos" : process.platform === "win32" ? "windows" : "linux";
|
|
17
|
+
var INSTALL_TARGETS = [
|
|
18
|
+
{
|
|
19
|
+
clientId: "claude-code",
|
|
20
|
+
label: "Claude Code",
|
|
21
|
+
jsonShape: "mcpServers",
|
|
22
|
+
availableOn: ["macos", "linux", "windows"],
|
|
23
|
+
scopes: [
|
|
24
|
+
{
|
|
25
|
+
scope: "user",
|
|
26
|
+
label: "User (global)",
|
|
27
|
+
description: "Private to this machine; applies to every project.",
|
|
28
|
+
requiresProjectDir: false
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
scope: "project",
|
|
32
|
+
label: "Project",
|
|
33
|
+
description: "Commit to share with your team.",
|
|
34
|
+
requiresProjectDir: true
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
scope: "local",
|
|
38
|
+
label: "Local",
|
|
39
|
+
description: "Per-project override; typically gitignored.",
|
|
40
|
+
requiresProjectDir: true
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
clientId: "claude-desktop",
|
|
46
|
+
label: "Claude Desktop",
|
|
47
|
+
jsonShape: "mcpServers",
|
|
48
|
+
availableOn: ["macos", "windows"],
|
|
49
|
+
notes: "Claude Desktop reads one file per OS \u2014 no project scope. Restart the app after editing.",
|
|
50
|
+
scopes: [
|
|
51
|
+
{
|
|
52
|
+
scope: "user",
|
|
53
|
+
label: "User",
|
|
54
|
+
description: "The only config file Claude Desktop reads.",
|
|
55
|
+
requiresProjectDir: false
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
clientId: "cursor",
|
|
61
|
+
label: "Cursor",
|
|
62
|
+
jsonShape: "mcpServers",
|
|
63
|
+
availableOn: ["macos", "linux", "windows"],
|
|
64
|
+
scopes: [
|
|
65
|
+
{
|
|
66
|
+
scope: "user",
|
|
67
|
+
label: "User (global)",
|
|
68
|
+
description: "Private to this machine; applies to every Cursor project.",
|
|
69
|
+
requiresProjectDir: false
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
scope: "project",
|
|
73
|
+
label: "Project",
|
|
74
|
+
description: "Commit to share with your team.",
|
|
75
|
+
requiresProjectDir: true
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
clientId: "vscode",
|
|
81
|
+
label: "VS Code",
|
|
82
|
+
jsonShape: "servers",
|
|
83
|
+
availableOn: ["macos", "linux", "windows"],
|
|
84
|
+
notes: "VS Code uses `servers` (not `mcpServers`) as the top-level key in .vscode/mcp.json.",
|
|
85
|
+
scopes: [
|
|
86
|
+
{
|
|
87
|
+
scope: "project",
|
|
88
|
+
label: "Workspace",
|
|
89
|
+
description: "Per-project config; commit to share.",
|
|
90
|
+
requiresProjectDir: true
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
];
|
|
95
|
+
function resolveInstallPath(opts) {
|
|
96
|
+
const home = opts.home ?? homedir();
|
|
97
|
+
const appData = opts.appData ?? process.env.APPDATA ?? join(home, "AppData", "Roaming");
|
|
98
|
+
const { clientId, scope, os, projectDir, claudeConfigDir } = opts;
|
|
99
|
+
const target = INSTALL_TARGETS.find((t) => t.clientId === clientId);
|
|
100
|
+
if (!target) throw new Error(`Unknown client: ${clientId}`);
|
|
101
|
+
const scopeSpec = target.scopes.find((s) => s.scope === scope);
|
|
102
|
+
if (!scopeSpec) throw new Error(`Client ${clientId} does not support scope ${scope}`);
|
|
103
|
+
if (!target.availableOn.includes(os)) {
|
|
104
|
+
throw new Error(`${target.label} is not available on ${os}`);
|
|
105
|
+
}
|
|
106
|
+
if (scopeSpec.requiresProjectDir && !projectDir) {
|
|
107
|
+
throw new Error(`Scope ${scope} for ${clientId} requires a project directory`);
|
|
108
|
+
}
|
|
109
|
+
const absoluteProjectDir = projectDir && !isAbsolute(projectDir) ? resolve(projectDir) : projectDir;
|
|
110
|
+
const p = pathFor(clientId, scope, os, {
|
|
111
|
+
home,
|
|
112
|
+
appData,
|
|
113
|
+
projectDir: absoluteProjectDir ?? "",
|
|
114
|
+
claudeConfigDir: claudeConfigDir && claudeConfigDir.length > 0 ? claudeConfigDir : void 0
|
|
115
|
+
});
|
|
116
|
+
return p;
|
|
117
|
+
}
|
|
118
|
+
function claudeCodeProjectKey(projectDir) {
|
|
119
|
+
return /^(?:[A-Za-z]:[\\/]|\\\\)/.test(projectDir) ? projectDir.replace(/\\/g, "/") : projectDir;
|
|
120
|
+
}
|
|
121
|
+
function pathFor(client, scope, os, base) {
|
|
122
|
+
const { home, appData, projectDir, claudeConfigDir } = base;
|
|
123
|
+
const sep2 = os === "windows" ? "\\" : "/";
|
|
124
|
+
const joinPath = (...parts) => parts.join(sep2);
|
|
125
|
+
if (client === "claude-code") {
|
|
126
|
+
if (scope === "user") {
|
|
127
|
+
if (claudeConfigDir) {
|
|
128
|
+
const absolute = join(claudeConfigDir, ".claude.json");
|
|
129
|
+
return { absolute, display: absolute, containerPath: ["mcpServers"] };
|
|
130
|
+
}
|
|
131
|
+
const display = os === "windows" ? "%USERPROFILE%\\.claude.json" : "~/.claude.json";
|
|
132
|
+
return { absolute: join(home, ".claude.json"), display, containerPath: ["mcpServers"] };
|
|
133
|
+
}
|
|
134
|
+
if (scope === "project") {
|
|
135
|
+
return {
|
|
136
|
+
absolute: join(projectDir, ".mcp.json"),
|
|
137
|
+
display: joinPath("<project folder>", ".mcp.json"),
|
|
138
|
+
containerPath: ["mcpServers"]
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const projectKey = claudeCodeProjectKey(projectDir);
|
|
142
|
+
if (claudeConfigDir) {
|
|
143
|
+
const absolute = join(claudeConfigDir, ".claude.json");
|
|
144
|
+
return { absolute, display: absolute, containerPath: ["projects", projectKey, "mcpServers"] };
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
absolute: join(home, ".claude.json"),
|
|
148
|
+
display: os === "windows" ? "%USERPROFILE%\\.claude.json" : "~/.claude.json",
|
|
149
|
+
containerPath: ["projects", projectKey, "mcpServers"]
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
if (client === "claude-desktop") {
|
|
153
|
+
if (os === "macos") {
|
|
154
|
+
return {
|
|
155
|
+
absolute: join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json"),
|
|
156
|
+
display: "~/Library/Application Support/Claude/claude_desktop_config.json",
|
|
157
|
+
containerPath: ["mcpServers"]
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (os === "windows") {
|
|
161
|
+
return {
|
|
162
|
+
absolute: join(appData, "Claude", "claude_desktop_config.json"),
|
|
163
|
+
display: "%APPDATA%\\Claude\\claude_desktop_config.json",
|
|
164
|
+
containerPath: ["mcpServers"]
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
throw new Error("Claude Desktop is not available on Linux");
|
|
168
|
+
}
|
|
169
|
+
if (client === "cursor") {
|
|
170
|
+
if (scope === "user") {
|
|
171
|
+
const display = os === "windows" ? "%USERPROFILE%\\.cursor\\mcp.json" : "~/.cursor/mcp.json";
|
|
172
|
+
return { absolute: join(home, ".cursor", "mcp.json"), display, containerPath: ["mcpServers"] };
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
absolute: join(projectDir, ".cursor", "mcp.json"),
|
|
176
|
+
display: joinPath("<project folder>", ".cursor", "mcp.json"),
|
|
177
|
+
containerPath: ["mcpServers"]
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
if (client === "vscode") {
|
|
181
|
+
return {
|
|
182
|
+
absolute: join(projectDir, ".vscode", "mcp.json"),
|
|
183
|
+
display: joinPath("<project folder>", ".vscode", "mcp.json"),
|
|
184
|
+
containerPath: ["servers"]
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
throw new Error(`Unhandled client: ${client}`);
|
|
188
|
+
}
|
|
189
|
+
var CMD_METACHARS = /[&|<>^()]/g;
|
|
190
|
+
var HAS_CMD_METACHAR = /[&|<>^()]/;
|
|
191
|
+
var KNOWN_CMD_SHIM_LAUNCHERS = /* @__PURE__ */ new Set(["npx", "uvx", "pipx", "npm", "pnpm", "yarn", "bunx"]);
|
|
192
|
+
var KNOWN_DIRECT_BINARIES = /* @__PURE__ */ new Set([
|
|
193
|
+
"node",
|
|
194
|
+
"deno",
|
|
195
|
+
"bun",
|
|
196
|
+
"python",
|
|
197
|
+
"python3",
|
|
198
|
+
"py",
|
|
199
|
+
"ruby",
|
|
200
|
+
"php",
|
|
201
|
+
"docker",
|
|
202
|
+
"dotnet",
|
|
203
|
+
"java",
|
|
204
|
+
"go"
|
|
205
|
+
]);
|
|
206
|
+
function isCmdShimLauncher(command) {
|
|
207
|
+
const base = command.replace(/^.*[\\/]/, "").toLowerCase();
|
|
208
|
+
if (/\.(?:cmd|bat)$/.test(base)) return true;
|
|
209
|
+
if (/\.(?:exe|com)$/.test(base)) return false;
|
|
210
|
+
const stem = base.replace(/\.[^.]*$/, "");
|
|
211
|
+
if (KNOWN_CMD_SHIM_LAUNCHERS.has(stem)) return true;
|
|
212
|
+
if (KNOWN_DIRECT_BINARIES.has(stem)) return false;
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
function escapeCmdArg(arg, opts) {
|
|
216
|
+
if (arg.includes('"')) {
|
|
217
|
+
if (HAS_CMD_METACHAR.test(arg)) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`Cannot safely encode an argument that contains BOTH a double-quote and a cmd.exe metacharacter (& | < > ^ ( )) for the Windows cmd /c launcher: ${arg} -- passing it through cmd.exe risks a command injection at client-spawn time. Rework the server's args to drop one of the two.`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
return arg;
|
|
223
|
+
}
|
|
224
|
+
if (/[ \t]/.test(arg)) return arg;
|
|
225
|
+
const caret = opts.shim ? "^^^" : "^";
|
|
226
|
+
return arg.replace(CMD_METACHARS, (m) => caret + m);
|
|
227
|
+
}
|
|
228
|
+
function buildLaunchEntry(opts) {
|
|
229
|
+
if (opts.upstream) {
|
|
230
|
+
const { command, args, env } = opts.upstream;
|
|
231
|
+
if (opts.os === "windows") {
|
|
232
|
+
const shim = isCmdShimLauncher(command);
|
|
233
|
+
const wrapped = {
|
|
234
|
+
command: "cmd",
|
|
235
|
+
args: ["/c", escapeCmdArg(command, { shim: false }), ...args.map((a) => escapeCmdArg(a, { shim }))]
|
|
236
|
+
};
|
|
237
|
+
if (env && Object.keys(env).length > 0) wrapped.env = { ...env };
|
|
238
|
+
return wrapped;
|
|
239
|
+
}
|
|
240
|
+
const entry = { command, args: [...args] };
|
|
241
|
+
if (env && Object.keys(env).length > 0) entry.env = { ...env };
|
|
242
|
+
return entry;
|
|
243
|
+
}
|
|
244
|
+
const pkg = opts.pkg ?? "@yawlabs/mcp@latest";
|
|
245
|
+
if (opts.oamBinPath && isAbsolute(opts.oamBinPath) && opts.oamEntry && !opts.pkg) {
|
|
246
|
+
return { command: opts.oamBinPath, args: ["run", "--no-check", opts.oamEntry] };
|
|
247
|
+
}
|
|
248
|
+
return opts.os === "windows" ? { command: "cmd", args: ["/c", "npx", "-y", pkg] } : { command: "npx", args: ["-y", pkg] };
|
|
249
|
+
}
|
|
250
|
+
function isProjectLocalEntry(entryPath, cwd) {
|
|
251
|
+
const norm = (p) => p.replace(/\\/g, "/").replace(/\/+$/, "").toLowerCase();
|
|
252
|
+
const entry = norm(entryPath);
|
|
253
|
+
const here = norm(cwd);
|
|
254
|
+
const idx = entry.indexOf("/node_modules/");
|
|
255
|
+
if (idx <= 0) return false;
|
|
256
|
+
const root = entry.slice(0, idx);
|
|
257
|
+
return here === root || here.startsWith(`${root}/`);
|
|
258
|
+
}
|
|
259
|
+
var ENTRY_NAME = "mcp";
|
|
260
|
+
var LEGACY_ENTRY_NAMES = ["mcp.hosting", "mcph", "yaw-mcp"];
|
|
261
|
+
function findLegacyEntry(container) {
|
|
262
|
+
return LEGACY_ENTRY_NAMES.find((n) => n in container) ?? null;
|
|
263
|
+
}
|
|
264
|
+
var CLAUDE_CODE_ALLOW_PATTERN = "mcp__mcp__*";
|
|
265
|
+
function resolveClaudeCodeSettingsPath(scope, opts) {
|
|
266
|
+
const { home, projectDir, claudeConfigDir } = opts;
|
|
267
|
+
const cfgDir = claudeConfigDir && claudeConfigDir.length > 0 ? claudeConfigDir : null;
|
|
268
|
+
if (scope === "user") return cfgDir ? join(cfgDir, "settings.json") : join(home, ".claude", "settings.json");
|
|
269
|
+
if (scope === "project" && projectDir) return join(projectDir, ".claude", "settings.json");
|
|
270
|
+
if (scope === "local" && projectDir) return join(projectDir, ".claude", "settings.local.json");
|
|
271
|
+
return null;
|
|
18
272
|
}
|
|
19
273
|
|
|
20
274
|
// src/paths.ts
|
|
21
|
-
import { access } from "fs/promises";
|
|
22
|
-
import { homedir } from "os";
|
|
275
|
+
import { access, realpath, stat } from "fs/promises";
|
|
276
|
+
import { homedir as homedir2 } from "os";
|
|
23
277
|
import path from "path";
|
|
24
278
|
function cacheDir() {
|
|
25
279
|
if (process.platform === "win32") {
|
|
26
280
|
const localAppData = process.env.LOCALAPPDATA;
|
|
27
|
-
const base = localAppData && localAppData.length > 0 ? localAppData : path.join(
|
|
281
|
+
const base = localAppData && localAppData.length > 0 ? localAppData : path.join(homedir2(), "AppData", "Local");
|
|
28
282
|
return path.join(base, "yaw-mcp", "Cache");
|
|
29
283
|
}
|
|
30
284
|
if (process.platform === "darwin") {
|
|
31
|
-
return path.join(
|
|
285
|
+
return path.join(homedir2(), "Library", "Caches", "yaw-mcp");
|
|
32
286
|
}
|
|
33
287
|
const xdg = process.env.XDG_CACHE_HOME;
|
|
34
|
-
return path.join(xdg && xdg.length > 0 ? xdg : path.join(
|
|
288
|
+
return path.join(xdg && xdg.length > 0 ? xdg : path.join(homedir2(), ".cache"), "yaw-mcp");
|
|
35
289
|
}
|
|
36
290
|
var CONFIG_DIRNAME = ".yaw-mcp";
|
|
37
291
|
var SIDECARS_DIRNAME = "sidecars";
|
|
38
|
-
function sidecarsRoot(home =
|
|
292
|
+
function sidecarsRoot(home = homedir2()) {
|
|
39
293
|
return path.join(userConfigDir(home), SIDECARS_DIRNAME);
|
|
40
294
|
}
|
|
41
|
-
function sidecarsNodeModules(home =
|
|
295
|
+
function sidecarsNodeModules(home = homedir2()) {
|
|
42
296
|
return path.join(sidecarsRoot(home), "node_modules");
|
|
43
297
|
}
|
|
44
|
-
function userConfigDir(home =
|
|
298
|
+
function userConfigDir(home = homedir2()) {
|
|
45
299
|
return path.join(home, CONFIG_DIRNAME);
|
|
46
300
|
}
|
|
47
301
|
function normalizeForCompare(p) {
|
|
48
|
-
return process.platform === "win32" ? p.toLowerCase() : p;
|
|
302
|
+
return process.platform === "win32" || process.platform === "darwin" ? p.toLowerCase() : p;
|
|
303
|
+
}
|
|
304
|
+
async function realpathOrSelf(p) {
|
|
305
|
+
try {
|
|
306
|
+
return await realpath(p);
|
|
307
|
+
} catch {
|
|
308
|
+
return p;
|
|
309
|
+
}
|
|
49
310
|
}
|
|
50
311
|
function isUnderHome(dir, homeResolved) {
|
|
51
312
|
const dirKey = normalizeForCompare(dir);
|
|
52
313
|
const homeKey = normalizeForCompare(homeResolved);
|
|
53
314
|
if (dirKey === homeKey) return false;
|
|
54
|
-
const rel = path.relative(
|
|
315
|
+
const rel = path.relative(homeKey, dirKey);
|
|
55
316
|
if (rel === "" || path.isAbsolute(rel)) return false;
|
|
56
|
-
|
|
57
|
-
return relNorm !== ".." && !relNorm.startsWith(`..${path.sep}`);
|
|
317
|
+
return rel !== ".." && !rel.startsWith(`..${path.sep}`);
|
|
58
318
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
319
|
+
var ALLOW_UNOWNED_ENV = "YAW_MCP_ALLOW_UNOWNED_PROJECT_DIRS";
|
|
320
|
+
async function ownedByCurrentUser(candidate) {
|
|
321
|
+
const geteuid = process.geteuid;
|
|
322
|
+
if (typeof geteuid !== "function") return process.env[ALLOW_UNOWNED_ENV] === "1";
|
|
323
|
+
try {
|
|
324
|
+
const st = await stat(candidate);
|
|
325
|
+
return typeof st.uid === "number" && st.uid === geteuid.call(process);
|
|
326
|
+
} catch {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async function findProjectConfigDir(start, home = homedir2()) {
|
|
331
|
+
const homeFallback = home && home.length > 0 ? home : process.env.USERPROFILE || homedir2();
|
|
332
|
+
const homeResolved = path.resolve(await realpathOrSelf(path.resolve(homeFallback)));
|
|
333
|
+
let dir = path.resolve(await realpathOrSelf(path.resolve(start)));
|
|
334
|
+
const userConfigKey = normalizeForCompare(await realpathOrSelf(path.join(homeResolved, CONFIG_DIRNAME)));
|
|
335
|
+
const boundedByHome = isUnderHome(dir, homeResolved) || normalizeForCompare(dir) === normalizeForCompare(homeResolved);
|
|
63
336
|
let prev = "";
|
|
64
337
|
while (dir !== prev) {
|
|
65
|
-
if (!isUnderHome(dir, homeResolved)) return null;
|
|
338
|
+
if (boundedByHome && !isUnderHome(dir, homeResolved)) return null;
|
|
66
339
|
const candidate = path.join(dir, CONFIG_DIRNAME);
|
|
67
340
|
try {
|
|
68
341
|
await access(candidate);
|
|
69
|
-
|
|
342
|
+
if (normalizeForCompare(await realpathOrSelf(candidate)) === userConfigKey) {
|
|
343
|
+
log("debug", "Skipping a .yaw-mcp/ that resolves to the user-global config dir", { candidate });
|
|
344
|
+
} else if (boundedByHome || await ownedByCurrentUser(candidate)) {
|
|
345
|
+
return candidate;
|
|
346
|
+
} else {
|
|
347
|
+
log("warn", "Skipping an untrusted .yaw-mcp/ dir outside $HOME", {
|
|
348
|
+
candidate,
|
|
349
|
+
hint: `owned by another user, or ownership is unverifiable on this platform (set ${ALLOW_UNOWNED_ENV}=1 to trust it)`
|
|
350
|
+
});
|
|
351
|
+
}
|
|
70
352
|
} catch {
|
|
71
353
|
}
|
|
72
354
|
prev = dir;
|
|
@@ -111,12 +393,31 @@ function npxSpec(args) {
|
|
|
111
393
|
const spec = args[idx];
|
|
112
394
|
return spec.startsWith("-") ? null : spec;
|
|
113
395
|
}
|
|
114
|
-
var MIN_OAM_VERSION = "0.
|
|
396
|
+
var MIN_OAM_VERSION = "0.11.0";
|
|
115
397
|
var OAM_INSTALL_SH = "curl -fsSL https://oamjs.org/install.sh | sh";
|
|
116
398
|
var OAM_INSTALL_PS1 = "irm https://oamjs.org/install.ps1 | iex";
|
|
117
399
|
function oamInstallCommand(os) {
|
|
118
400
|
return os === "windows" ? OAM_INSTALL_PS1 : OAM_INSTALL_SH;
|
|
119
401
|
}
|
|
402
|
+
function oamPublishesBinaryFor(platform, arch) {
|
|
403
|
+
if (platform === "win32" || platform === "darwin") return arch === "x64" || arch === "arm64";
|
|
404
|
+
if (platform === "linux") return arch === "x64";
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
function oamPublishesBinaryForThisMachine() {
|
|
408
|
+
return oamPublishesBinaryFor(process.platform, process.arch);
|
|
409
|
+
}
|
|
410
|
+
function oamNoBinaryReason() {
|
|
411
|
+
return `no published oam binary for ${process.platform}-${process.arch} yet \u2014 build from source at https://oamjs.org`;
|
|
412
|
+
}
|
|
413
|
+
function oamInstallAdvice(os) {
|
|
414
|
+
if (os === CURRENT_OS && !oamPublishesBinaryForThisMachine()) return oamNoBinaryReason();
|
|
415
|
+
return oamInstallCommand(os);
|
|
416
|
+
}
|
|
417
|
+
function oamHeapOomHint(stderr) {
|
|
418
|
+
if (!stderr.includes("OAM-RT-OOM")) return null;
|
|
419
|
+
return `The oam-hosted child hit its V8 heap cap (oam defaults to 4 GiB). Raise it with OAM_MAX_HEAP_MB=<mb> in this server's env, or set "runtime": "node" for this server in bundles.json.`;
|
|
420
|
+
}
|
|
120
421
|
var warnedOamUnavailable = false;
|
|
121
422
|
function oamFailureLabel(failure) {
|
|
122
423
|
if (failure === "timeout") return "`oam --version` did not answer in time";
|
|
@@ -183,7 +484,7 @@ function isExecutableFile(candidate, platform) {
|
|
|
183
484
|
}
|
|
184
485
|
}
|
|
185
486
|
function resolveBinAbsolute(bin, env = process.env, platform = process.platform) {
|
|
186
|
-
if (
|
|
487
|
+
if (isAbsolute2(bin)) return isExecutableFile(bin, platform) ? winNormalize(bin, platform) : null;
|
|
187
488
|
const pathVar = env.PATH ?? env.Path ?? env.path ?? "";
|
|
188
489
|
if (!pathVar) return null;
|
|
189
490
|
const dirs = pathVar.split(platform === "win32" ? ";" : ":").filter(Boolean);
|
|
@@ -191,8 +492,8 @@ function resolveBinAbsolute(bin, env = process.env, platform = process.platform)
|
|
|
191
492
|
for (const dir of dirs) {
|
|
192
493
|
const clean = dir.replace(/^"|"$/g, "");
|
|
193
494
|
for (const ext of exts) {
|
|
194
|
-
const candidate =
|
|
195
|
-
if (!
|
|
495
|
+
const candidate = join2(clean, bin + ext);
|
|
496
|
+
if (!isAbsolute2(candidate)) continue;
|
|
196
497
|
if (isExecutableFile(candidate, platform)) return winNormalize(candidate, platform);
|
|
197
498
|
}
|
|
198
499
|
}
|
|
@@ -232,7 +533,7 @@ function createProbeCollector(max = OAM_PROBE_MAX_OUTPUT) {
|
|
|
232
533
|
};
|
|
233
534
|
}
|
|
234
535
|
function spawnVersionProbe(bin) {
|
|
235
|
-
return new Promise((
|
|
536
|
+
return new Promise((resolve2, reject) => {
|
|
236
537
|
let settled = false;
|
|
237
538
|
let timer;
|
|
238
539
|
const settle = (fn) => {
|
|
@@ -261,7 +562,7 @@ function spawnVersionProbe(bin) {
|
|
|
261
562
|
"close",
|
|
262
563
|
(code, signal) => settle(() => {
|
|
263
564
|
if (code === 0) {
|
|
264
|
-
|
|
565
|
+
resolve2(collector.result());
|
|
265
566
|
return;
|
|
266
567
|
}
|
|
267
568
|
const err = new Error(`oam exited ${code ?? signal}`);
|
|
@@ -444,7 +745,7 @@ function npxCacheNodeModules(fromUrl = import.meta.url) {
|
|
|
444
745
|
if (idx === -1) return [];
|
|
445
746
|
const npxRoot = here.slice(0, idx + NPX_CACHE_MARKER.length - sep.length);
|
|
446
747
|
try {
|
|
447
|
-
return readdirSync(npxRoot, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) =>
|
|
748
|
+
return readdirSync(npxRoot, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => join2(npxRoot, e.name, "node_modules"));
|
|
448
749
|
} catch {
|
|
449
750
|
return [];
|
|
450
751
|
}
|
|
@@ -492,7 +793,7 @@ function npmrcCache(file) {
|
|
|
492
793
|
if (!m) continue;
|
|
493
794
|
const value = npmrcValue(m[1]);
|
|
494
795
|
if (!value) continue;
|
|
495
|
-
return value.startsWith("~/") ?
|
|
796
|
+
return value.startsWith("~/") ? join2(homedir3(), value.slice(2)) : value;
|
|
496
797
|
}
|
|
497
798
|
return null;
|
|
498
799
|
}
|
|
@@ -510,36 +811,36 @@ function resetNpmCacheDir() {
|
|
|
510
811
|
function resolveNpmCacheDir(fromUrl) {
|
|
511
812
|
const fromEnv = process.env.npm_config_cache;
|
|
512
813
|
if (fromEnv) return fromEnv;
|
|
513
|
-
const candidates = [
|
|
814
|
+
const candidates = [join2(homedir3(), ".npmrc")];
|
|
514
815
|
for (const nodeModules of ownNodeModules(fromUrl)) {
|
|
515
816
|
candidates.push(
|
|
516
|
-
|
|
817
|
+
join2(dirname(nodeModules), "etc", "npmrc"),
|
|
517
818
|
// <prefix>/node_modules (Windows)
|
|
518
|
-
|
|
819
|
+
join2(dirname(dirname(nodeModules)), "etc", "npmrc"),
|
|
519
820
|
// <prefix>/lib/node_modules (POSIX)
|
|
520
|
-
|
|
821
|
+
join2(nodeModules, "npm", "npmrc")
|
|
521
822
|
// builtin, beside npm itself
|
|
522
823
|
);
|
|
523
824
|
}
|
|
524
825
|
const nodeDir = dirname(process.execPath);
|
|
525
826
|
candidates.push(
|
|
526
|
-
|
|
827
|
+
join2(nodeDir, "node_modules", "npm", "npmrc"),
|
|
527
828
|
// Windows layout
|
|
528
|
-
|
|
829
|
+
join2(nodeDir, "..", "lib", "node_modules", "npm", "npmrc")
|
|
529
830
|
// POSIX layout
|
|
530
831
|
);
|
|
531
832
|
for (const file of candidates) {
|
|
532
833
|
const cache = npmrcCache(file);
|
|
533
834
|
if (cache) return cache;
|
|
534
835
|
}
|
|
535
|
-
const fallback = process.platform === "win32" ? process.env.LOCALAPPDATA &&
|
|
836
|
+
const fallback = process.platform === "win32" ? process.env.LOCALAPPDATA && join2(process.env.LOCALAPPDATA, "npm-cache") : join2(homedir3(), ".npm");
|
|
536
837
|
return fallback && existsSync(fallback) ? fallback : null;
|
|
537
838
|
}
|
|
538
839
|
function npmCacheNpxNodeModules(cacheDir2) {
|
|
539
840
|
if (!cacheDir2) return [];
|
|
540
|
-
const npxRoot =
|
|
841
|
+
const npxRoot = join2(cacheDir2, "_npx");
|
|
541
842
|
try {
|
|
542
|
-
return readdirSync(npxRoot, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) =>
|
|
843
|
+
return readdirSync(npxRoot, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => join2(npxRoot, e.name, "node_modules"));
|
|
543
844
|
} catch {
|
|
544
845
|
return [];
|
|
545
846
|
}
|
|
@@ -557,7 +858,7 @@ function ownNodeModules(fromUrl = import.meta.url) {
|
|
|
557
858
|
return [here.slice(0, idx + seg.length - sep.length)];
|
|
558
859
|
}
|
|
559
860
|
function packageEntry(pkgDir, pkg) {
|
|
560
|
-
const pjPath =
|
|
861
|
+
const pjPath = join2(pkgDir, "package.json");
|
|
561
862
|
if (!existsSync(pjPath)) return null;
|
|
562
863
|
let j;
|
|
563
864
|
try {
|
|
@@ -574,7 +875,7 @@ function packageEntry(pkgDir, pkg) {
|
|
|
574
875
|
}
|
|
575
876
|
if (!rel && typeof j.main === "string") rel = j.main;
|
|
576
877
|
if (!rel) return null;
|
|
577
|
-
const entry =
|
|
878
|
+
const entry = isAbsolute2(rel) ? rel : join2(pkgDir, rel);
|
|
578
879
|
if (!existsSync(entry)) return null;
|
|
579
880
|
return {
|
|
580
881
|
entry,
|
|
@@ -596,7 +897,7 @@ function resolveNpmEntry(pkg, fromUrl = import.meta.url, npmCache = npmCacheDir(
|
|
|
596
897
|
}))
|
|
597
898
|
];
|
|
598
899
|
for (const { nodeModules, source } of durable) {
|
|
599
|
-
const hit = packageEntry(
|
|
900
|
+
const hit = packageEntry(join2(nodeModules, ...parts), pkg);
|
|
600
901
|
if (!hit) continue;
|
|
601
902
|
if (wantVersion !== null && !satisfiesExactPin(hit.version, wantVersion)) continue;
|
|
602
903
|
notePinnedSidecar(pkg, hit.version, source, nodeModules);
|
|
@@ -607,7 +908,7 @@ function resolveNpmEntry(pkg, fromUrl = import.meta.url, npmCache = npmCacheDir(
|
|
|
607
908
|
let bestRoot = null;
|
|
608
909
|
let bestParsed = null;
|
|
609
910
|
for (const nodeModules of roots) {
|
|
610
|
-
const hit = packageEntry(
|
|
911
|
+
const hit = packageEntry(join2(nodeModules, ...parts), pkg);
|
|
611
912
|
if (!hit) continue;
|
|
612
913
|
if (wantVersion !== null && !satisfiesExactPin(hit.version, wantVersion)) continue;
|
|
613
914
|
const parsed = hit.version === null ? null : parseSemver(hit.version);
|
|
@@ -624,7 +925,22 @@ function resolveNpmEntry(pkg, fromUrl = import.meta.url, npmCache = npmCacheDir(
|
|
|
624
925
|
var REFRESH_COMMAND = {
|
|
625
926
|
managed: () => "yaw-mcp sidecars install",
|
|
626
927
|
durable: (pkg) => `npm install ${pkg}@latest`,
|
|
627
|
-
|
|
928
|
+
// No trailing flag. `npx -y <pkg>@latest` re-resolves the tag and refreshes
|
|
929
|
+
// the cache tree BEFORE it execs the binary, which is all the refresh
|
|
930
|
+
// needs -- and stdio MCP servers ignore flags like `--help` and simply
|
|
931
|
+
// start, so tacking one on turns "runs briefly" into "hangs the terminal
|
|
932
|
+
// on a server waiting for stdin" (measured on
|
|
933
|
+
// @modelcontextprotocol/server-memory). `npm cache add` is no substitute:
|
|
934
|
+
// it only fills _cacache, never the _npx install tree this resolver reads.
|
|
935
|
+
// No inline `#` comment either: that is comment syntax only in sh and
|
|
936
|
+
// PowerShell -- cmd.exe hands `#` and everything after it to npx as literal
|
|
937
|
+
// argv for the spawned server, which arg-parsing servers fail on. The
|
|
938
|
+
// Ctrl-C guidance rides in REFRESH_NOTE instead, so the command itself is
|
|
939
|
+
// copy-paste safe in all three shells.
|
|
940
|
+
"npx-cache": (pkg) => `npx -y ${pkg}@latest`
|
|
941
|
+
};
|
|
942
|
+
var REFRESH_NOTE = {
|
|
943
|
+
"npx-cache": "then Ctrl-C -- the cache is refreshed before the server starts"
|
|
628
944
|
};
|
|
629
945
|
var pinnedReported = /* @__PURE__ */ new Set();
|
|
630
946
|
function resetPinnedSidecarLog() {
|
|
@@ -645,14 +961,17 @@ function notePinnedSidecar(pkg, version, source, from) {
|
|
|
645
961
|
// the command differs -- so this is what makes the advice actionable
|
|
646
962
|
// rather than something to run in whatever cwd the user happens to be.
|
|
647
963
|
from,
|
|
648
|
-
refreshWith: REFRESH_COMMAND[source](pkg)
|
|
964
|
+
refreshWith: REFRESH_COMMAND[source](pkg),
|
|
965
|
+
// Only npx-cache has one today; JSON.stringify drops the field entirely
|
|
966
|
+
// for the sources that do not, rather than printing "undefined".
|
|
967
|
+
refreshNote: REFRESH_NOTE[source]
|
|
649
968
|
}
|
|
650
969
|
);
|
|
651
970
|
}
|
|
652
971
|
function resolveStableNpmEntry(pkg, fromUrl = import.meta.url) {
|
|
653
972
|
for (const nodeModules of ownNodeModules(fromUrl)) {
|
|
654
973
|
if (nodeModules.includes(NPX_CACHE_MARKER)) continue;
|
|
655
|
-
const hit = packageEntry(
|
|
974
|
+
const hit = packageEntry(join2(nodeModules, ...pkg.split("/")), pkg);
|
|
656
975
|
if (hit) return hit.entry;
|
|
657
976
|
}
|
|
658
977
|
return null;
|
|
@@ -715,14 +1034,24 @@ function isOamLaunch(command, args = []) {
|
|
|
715
1034
|
}
|
|
716
1035
|
|
|
717
1036
|
export {
|
|
718
|
-
log,
|
|
719
1037
|
cacheDir,
|
|
720
1038
|
CONFIG_DIRNAME,
|
|
721
1039
|
sidecarsRoot,
|
|
722
1040
|
sidecarsNodeModules,
|
|
723
1041
|
userConfigDir,
|
|
1042
|
+
isUnderHome,
|
|
724
1043
|
findProjectConfigDir,
|
|
725
1044
|
guidePath,
|
|
1045
|
+
CURRENT_OS,
|
|
1046
|
+
INSTALL_TARGETS,
|
|
1047
|
+
resolveInstallPath,
|
|
1048
|
+
buildLaunchEntry,
|
|
1049
|
+
isProjectLocalEntry,
|
|
1050
|
+
ENTRY_NAME,
|
|
1051
|
+
LEGACY_ENTRY_NAMES,
|
|
1052
|
+
findLegacyEntry,
|
|
1053
|
+
CLAUDE_CODE_ALLOW_PATTERN,
|
|
1054
|
+
resolveClaudeCodeSettingsPath,
|
|
726
1055
|
packageName,
|
|
727
1056
|
specConstraint,
|
|
728
1057
|
isRegistrySpec,
|
|
@@ -732,6 +1061,11 @@ export {
|
|
|
732
1061
|
OAM_INSTALL_SH,
|
|
733
1062
|
OAM_INSTALL_PS1,
|
|
734
1063
|
oamInstallCommand,
|
|
1064
|
+
oamPublishesBinaryFor,
|
|
1065
|
+
oamPublishesBinaryForThisMachine,
|
|
1066
|
+
oamNoBinaryReason,
|
|
1067
|
+
oamInstallAdvice,
|
|
1068
|
+
oamHeapOomHint,
|
|
735
1069
|
oamFailureLabel,
|
|
736
1070
|
parseOamVersion,
|
|
737
1071
|
compareVersions,
|