@yawlabs/mcp 1.0.2 → 1.0.4
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 +18 -4
- package/README.md +1 -1
- package/dist/{auto-upgrade-A3WTRVGV.js → auto-upgrade-HYJENL2G.js} +1 -1
- package/dist/{chunk-PAUBVL2N.js → chunk-YYZYSCOI.js} +200 -89
- package/dist/index.js +385 -447
- package/package.json +1 -1
|
@@ -17,6 +17,100 @@ import {
|
|
|
17
17
|
import { tmpdir } from "os";
|
|
18
18
|
import { dirname as dirname2, join as join11, sep as sep2 } from "path";
|
|
19
19
|
|
|
20
|
+
// src/atomic-write.ts
|
|
21
|
+
import { chmod, lstat, mkdir, realpath, rename, stat, unlink, writeFile } from "fs/promises";
|
|
22
|
+
import path from "path";
|
|
23
|
+
import { setTimeout as delay } from "timers/promises";
|
|
24
|
+
var WIN32_TRANSIENT_CODES = /* @__PURE__ */ new Set(["EPERM", "EBUSY", "EACCES"]);
|
|
25
|
+
var RENAME_RETRY_DELAYS_MS = [10, 50, 100];
|
|
26
|
+
function isWin32TransientFsError(err) {
|
|
27
|
+
if (process.platform !== "win32") return false;
|
|
28
|
+
const code = err?.code;
|
|
29
|
+
return code !== void 0 && WIN32_TRANSIENT_CODES.has(code);
|
|
30
|
+
}
|
|
31
|
+
async function renameWithRetry(tmp, target) {
|
|
32
|
+
if (process.platform !== "win32") {
|
|
33
|
+
await rename(tmp, target);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
for (const ms of RENAME_RETRY_DELAYS_MS) {
|
|
37
|
+
try {
|
|
38
|
+
await rename(tmp, target);
|
|
39
|
+
return;
|
|
40
|
+
} catch (err) {
|
|
41
|
+
if (!isWin32TransientFsError(err)) throw err;
|
|
42
|
+
await delay(ms);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
await rename(tmp, target);
|
|
46
|
+
}
|
|
47
|
+
var tmpSeq = 0;
|
|
48
|
+
async function atomicWriteFile(filePath, contents, encoding = "utf8", mode, dirMode) {
|
|
49
|
+
const target = await resolveSymlinkTarget(filePath);
|
|
50
|
+
const dir = path.dirname(target);
|
|
51
|
+
const tmp = `${target}.tmp-${process.pid}-${Date.now()}-${++tmpSeq}`;
|
|
52
|
+
await mkdirpWithMode(dir, dirMode);
|
|
53
|
+
let preserved;
|
|
54
|
+
if (mode === void 0 && process.platform !== "win32") {
|
|
55
|
+
try {
|
|
56
|
+
preserved = (await stat(target)).mode & 511;
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const birthMode = mode ?? preserved;
|
|
61
|
+
try {
|
|
62
|
+
await writeFile(tmp, contents, birthMode === void 0 ? { encoding } : { encoding, mode: birthMode });
|
|
63
|
+
if (preserved !== void 0) {
|
|
64
|
+
try {
|
|
65
|
+
await chmod(tmp, preserved);
|
|
66
|
+
} catch {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
await renameWithRetry(tmp, target);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
await unlink(tmp).catch(() => void 0);
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function resolveSymlinkTarget(filePath) {
|
|
76
|
+
try {
|
|
77
|
+
if (!(await lstat(filePath)).isSymbolicLink()) return filePath;
|
|
78
|
+
return await realpath(filePath);
|
|
79
|
+
} catch {
|
|
80
|
+
return filePath;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function mkdirpWithMode(dir, dirMode) {
|
|
84
|
+
if (dirMode === void 0 || process.platform === "win32") {
|
|
85
|
+
await mkdir(dir, { recursive: true });
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const resolved = path.resolve(dir);
|
|
89
|
+
const toCreate = [];
|
|
90
|
+
let cursor = resolved;
|
|
91
|
+
while (true) {
|
|
92
|
+
let exists = true;
|
|
93
|
+
try {
|
|
94
|
+
await stat(cursor);
|
|
95
|
+
} catch {
|
|
96
|
+
exists = false;
|
|
97
|
+
}
|
|
98
|
+
if (exists) break;
|
|
99
|
+
toCreate.unshift(cursor);
|
|
100
|
+
const parent = path.dirname(cursor);
|
|
101
|
+
if (parent === cursor) break;
|
|
102
|
+
cursor = parent;
|
|
103
|
+
}
|
|
104
|
+
if (toCreate.length === 0) return;
|
|
105
|
+
await mkdir(resolved, { recursive: true, mode: dirMode });
|
|
106
|
+
for (const created of toCreate) {
|
|
107
|
+
try {
|
|
108
|
+
await chmod(created, dirMode);
|
|
109
|
+
} catch {
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
20
114
|
// src/internal-secret-env.ts
|
|
21
115
|
var INTERNAL_SECRET_ENV_KEYS = /* @__PURE__ */ new Set([
|
|
22
116
|
"YAW_MCP_TOKEN",
|
|
@@ -436,11 +530,11 @@ function replaceValue(text, container, node, value) {
|
|
|
436
530
|
);
|
|
437
531
|
return { offset: node.offset, length: node.length, content };
|
|
438
532
|
}
|
|
439
|
-
function spliceEdits(text,
|
|
533
|
+
function spliceEdits(text, path3, value) {
|
|
440
534
|
const errors = [];
|
|
441
535
|
const root = parseTree(text, errors, { allowTrailingComma: true });
|
|
442
536
|
if (root === void 0 || errors.length > 0) return null;
|
|
443
|
-
const remaining =
|
|
537
|
+
const remaining = path3.slice();
|
|
444
538
|
let toWrite = value;
|
|
445
539
|
let parent;
|
|
446
540
|
let key;
|
|
@@ -466,8 +560,8 @@ function spliceEdits(text, path2, value) {
|
|
|
466
560
|
}
|
|
467
561
|
return null;
|
|
468
562
|
}
|
|
469
|
-
function computeEdits(text,
|
|
470
|
-
return spliceEdits(text,
|
|
563
|
+
function computeEdits(text, path3, value) {
|
|
564
|
+
return spliceEdits(text, path3, value) ?? modify(text, path3, value, { formattingOptions: FORMATTING_OPTIONS });
|
|
471
565
|
}
|
|
472
566
|
function editJsoncEntry(src, containerPath, entryName, value) {
|
|
473
567
|
if (entryName === "") {
|
|
@@ -485,40 +579,40 @@ function removeJsoncEntry(src, containerPath, entryName) {
|
|
|
485
579
|
if (edits.length === 0) return src;
|
|
486
580
|
return applyEdits(debommed, edits);
|
|
487
581
|
}
|
|
488
|
-
function editJsoncPath(src,
|
|
489
|
-
if (
|
|
582
|
+
function editJsoncPath(src, path3, value) {
|
|
583
|
+
if (path3.length === 0) {
|
|
490
584
|
throw new Error("editJsoncPath: path must not be empty");
|
|
491
585
|
}
|
|
492
|
-
if (
|
|
586
|
+
if (path3.some((seg) => seg === "")) {
|
|
493
587
|
throw new Error("editJsoncPath: path segments must be non-empty");
|
|
494
588
|
}
|
|
495
589
|
const debommed = src.charCodeAt(0) === 65279 ? src.slice(1) : src;
|
|
496
|
-
const edits = computeEdits(debommed,
|
|
590
|
+
const edits = computeEdits(debommed, path3, value);
|
|
497
591
|
if (edits.length === 0) return src;
|
|
498
592
|
return applyEdits(debommed, edits);
|
|
499
593
|
}
|
|
500
594
|
function elementValue(child) {
|
|
501
595
|
return getNodeValue(child);
|
|
502
596
|
}
|
|
503
|
-
function arrayNodeAt(text,
|
|
597
|
+
function arrayNodeAt(text, path3) {
|
|
504
598
|
const errors = [];
|
|
505
599
|
const root = parseTree(text, errors, { allowTrailingComma: true });
|
|
506
600
|
if (root === void 0 || errors.length > 0) return null;
|
|
507
|
-
const node = findNodeAtLocation(root,
|
|
601
|
+
const node = findNodeAtLocation(root, path3);
|
|
508
602
|
return node !== void 0 && node.type === "array" ? node : null;
|
|
509
603
|
}
|
|
510
|
-
function addJsoncArrayElement(src,
|
|
511
|
-
if (
|
|
604
|
+
function addJsoncArrayElement(src, path3, value) {
|
|
605
|
+
if (path3.length === 0) throw new Error("addJsoncArrayElement: path must not be empty");
|
|
512
606
|
const debommed = src.charCodeAt(0) === 65279 ? src.slice(1) : src;
|
|
513
|
-
const array = arrayNodeAt(debommed,
|
|
607
|
+
const array = arrayNodeAt(debommed, path3);
|
|
514
608
|
if (array === null) {
|
|
515
609
|
const errors = [];
|
|
516
610
|
const root = parseTree(debommed, errors, { allowTrailingComma: true });
|
|
517
|
-
const existing = root === void 0 ? void 0 : findNodeAtLocation(root,
|
|
611
|
+
const existing = root === void 0 ? void 0 : findNodeAtLocation(root, path3);
|
|
518
612
|
if (existing !== void 0) {
|
|
519
|
-
throw new Error(`addJsoncArrayElement: ${
|
|
613
|
+
throw new Error(`addJsoncArrayElement: ${path3.join(".")} is a ${existing.type}, not an array`);
|
|
520
614
|
}
|
|
521
|
-
return editJsoncPath(debommed,
|
|
615
|
+
return editJsoncPath(debommed, path3, [value]);
|
|
522
616
|
}
|
|
523
617
|
const wanted = JSON.stringify(value);
|
|
524
618
|
for (const child of array.children ?? []) {
|
|
@@ -527,26 +621,26 @@ function addJsoncArrayElement(src, path2, value) {
|
|
|
527
621
|
const edits = insertMember(debommed, array, null, value);
|
|
528
622
|
if (edits === null) {
|
|
529
623
|
const next = [...(array.children ?? []).map(elementValue), value];
|
|
530
|
-
return editJsoncPath(debommed,
|
|
624
|
+
return editJsoncPath(debommed, path3, next);
|
|
531
625
|
}
|
|
532
626
|
return applyEdits(debommed, edits);
|
|
533
627
|
}
|
|
534
|
-
function removeJsoncArrayElements(src,
|
|
535
|
-
if (
|
|
628
|
+
function removeJsoncArrayElements(src, path3, matches) {
|
|
629
|
+
if (path3.length === 0) throw new Error("removeJsoncArrayElements: path must not be empty");
|
|
536
630
|
const debommed = src.charCodeAt(0) === 65279 ? src.slice(1) : src;
|
|
537
|
-
const array = arrayNodeAt(debommed,
|
|
631
|
+
const array = arrayNodeAt(debommed, path3);
|
|
538
632
|
if (array === null) return src;
|
|
539
633
|
const doomed = (array.children ?? []).filter((child) => matches(elementValue(child)));
|
|
540
634
|
if (doomed.length === 0) return src;
|
|
541
635
|
let text = debommed;
|
|
542
636
|
for (let i = 0; i < doomed.length; i++) {
|
|
543
|
-
const current = arrayNodeAt(text,
|
|
637
|
+
const current = arrayNodeAt(text, path3);
|
|
544
638
|
if (current === null) break;
|
|
545
639
|
const member = (current.children ?? []).find((child) => matches(elementValue(child)));
|
|
546
640
|
if (member === void 0) break;
|
|
547
641
|
text = applyEdits(text, removeMember(text, current, member));
|
|
548
642
|
}
|
|
549
|
-
const emptied = arrayNodeAt(text,
|
|
643
|
+
const emptied = arrayNodeAt(text, path3);
|
|
550
644
|
if (emptied !== null && (emptied.children ?? []).length === 0) {
|
|
551
645
|
const open = emptied.offset + 1;
|
|
552
646
|
const close = emptied.offset + emptied.length - 1;
|
|
@@ -986,7 +1080,7 @@ function siteAt(site, containerPath) {
|
|
|
986
1080
|
return { ...site, resolved: { ...site.resolved, containerPath: [...containerPath] } };
|
|
987
1081
|
}
|
|
988
1082
|
async function readClientConfigFile(site, opts = {}) {
|
|
989
|
-
const load = opts.readFile ?? ((
|
|
1083
|
+
const load = opts.readFile ?? ((path3) => readFile(path3, "utf8"));
|
|
990
1084
|
let raw;
|
|
991
1085
|
try {
|
|
992
1086
|
raw = await load(site.resolved.absolute);
|
|
@@ -1474,7 +1568,7 @@ function decodeBasicBody(body) {
|
|
|
1474
1568
|
return out;
|
|
1475
1569
|
}
|
|
1476
1570
|
function readKeyPath(text, i) {
|
|
1477
|
-
const
|
|
1571
|
+
const path3 = [];
|
|
1478
1572
|
let pos = i;
|
|
1479
1573
|
for (; ; ) {
|
|
1480
1574
|
while (isHorizontalSpace2(text[pos])) pos++;
|
|
@@ -1482,17 +1576,17 @@ function readKeyPath(text, i) {
|
|
|
1482
1576
|
if (c === '"') {
|
|
1483
1577
|
const body = readQuoted(text, pos, '"');
|
|
1484
1578
|
if (body === null) break;
|
|
1485
|
-
|
|
1579
|
+
path3.push(decodeBasicBody(body.body));
|
|
1486
1580
|
pos = body.end;
|
|
1487
1581
|
} else if (c === "'") {
|
|
1488
1582
|
const body = readQuoted(text, pos, "'");
|
|
1489
1583
|
if (body === null) break;
|
|
1490
|
-
|
|
1584
|
+
path3.push(body.body);
|
|
1491
1585
|
pos = body.end;
|
|
1492
1586
|
} else if (isBareKeyChar(c)) {
|
|
1493
1587
|
let j = pos;
|
|
1494
1588
|
while (isBareKeyChar(text[j])) j++;
|
|
1495
|
-
|
|
1589
|
+
path3.push(text.slice(pos, j));
|
|
1496
1590
|
pos = j;
|
|
1497
1591
|
} else {
|
|
1498
1592
|
break;
|
|
@@ -1506,7 +1600,7 @@ function readKeyPath(text, i) {
|
|
|
1506
1600
|
pos = after;
|
|
1507
1601
|
break;
|
|
1508
1602
|
}
|
|
1509
|
-
return { path:
|
|
1603
|
+
return { path: path3, end: pos };
|
|
1510
1604
|
}
|
|
1511
1605
|
function readQuoted(text, pos, quote) {
|
|
1512
1606
|
let i = pos + 1;
|
|
@@ -1688,7 +1782,7 @@ function scanSpan(text, from, to, state, depth) {
|
|
|
1688
1782
|
if (state === "basic" || state === "literal") state = "normal";
|
|
1689
1783
|
return { state, depth };
|
|
1690
1784
|
}
|
|
1691
|
-
var pathStartsWith = (
|
|
1785
|
+
var pathStartsWith = (path3, prefix) => prefix.length <= path3.length && prefix.every((seg, i) => path3[i] === seg);
|
|
1692
1786
|
var pathEquals = (a, b) => a.length === b.length && a.every((seg, i) => seg === b[i]);
|
|
1693
1787
|
function tomlKey(key) {
|
|
1694
1788
|
return /^[A-Za-z0-9_-]+$/.test(key) ? key : tomlString(key);
|
|
@@ -2498,7 +2592,7 @@ var TYPED_TARGET = defineTarget({
|
|
|
2498
2592
|
markers: ['"mcp.json"', "'mcp.json'"],
|
|
2499
2593
|
warning: staleTypedCliWarning
|
|
2500
2594
|
},
|
|
2501
|
-
notes: "typed reads ~/.config/typed/mcp.json when a session starts, ahead of the user-scope files it shares with Claude Code, so this entry wins over an \"mcp\" entry Yaw Terminal manages in ~/.claude.json; a project's .mcp.json still wins over it. On a Yaw Terminal machine that means an npx entry here replaces Yaw Terminal's local launch for typed, and npx resolves @latest on every typed start, which can outlast typed's MCP connect timeout -- `npm i -g @yawlabs/mcp` with oam installed, then re-run install, writes a fast absolute-path entry instead, or raise MCP_TIMEOUT. The file is strict JSON: no comments, no trailing commas. The mcp__mcp__* grant goes in Claude Code's user settings.json, which typed reads too; under a set CLAUDE_CONFIG_DIR that is <CLAUDE_CONFIG_DIR>/settings.json
|
|
2595
|
+
notes: "typed reads ~/.config/typed/mcp.json when a session starts, ahead of the user-scope files it shares with Claude Code, so this entry wins over an \"mcp\" entry Yaw Terminal manages in ~/.claude.json; a project's .mcp.json still wins over it. On a Yaw Terminal machine that means an npx entry here replaces Yaw Terminal's local launch for typed, and npx resolves @latest on every typed start, which can outlast typed's MCP connect timeout -- `npm i -g @yawlabs/mcp` with oam installed, then re-run install, writes a fast absolute-path entry instead, or raise MCP_TIMEOUT. The file is strict JSON: no comments, no trailing commas. The mcp__mcp__* grant goes in Claude Code's user settings.json, which typed reads too; under a set CLAUDE_CONFIG_DIR that is <CLAUDE_CONFIG_DIR>/settings.json. There is no project scope here: <project>/.mcp.json is Claude Code's project file, which typed also reads -- use `yaw-mcp install mcp` for it. Needs a typed CLI newer than 1.5.0; older typed reads only Claude Code's files, so use `yaw-mcp install claude-code` there. typed picks the change up in its next session.",
|
|
2502
2596
|
resolvePath: resolveTypedPath,
|
|
2503
2597
|
scopes: [
|
|
2504
2598
|
{
|
|
@@ -2582,7 +2676,7 @@ var ZED_TARGET = defineTarget({
|
|
|
2582
2676
|
});
|
|
2583
2677
|
|
|
2584
2678
|
// src/claude-code-settings.ts
|
|
2585
|
-
import { readFile as readFile2, stat } from "fs/promises";
|
|
2679
|
+
import { readFile as readFile2, stat as stat2 } from "fs/promises";
|
|
2586
2680
|
import { basename, join as join7, resolve as resolve4 } from "path";
|
|
2587
2681
|
var CLAUDE_CODE_ALLOW_PATTERN = "mcp__mcp__*";
|
|
2588
2682
|
function resolveClaudeCodeSettingsPath(scope, opts) {
|
|
@@ -2629,27 +2723,27 @@ function patchPermissionsAllowText(raw, patterns, op) {
|
|
|
2629
2723
|
}
|
|
2630
2724
|
return text;
|
|
2631
2725
|
}
|
|
2632
|
-
async function settingsFingerprint(
|
|
2726
|
+
async function settingsFingerprint(path3) {
|
|
2633
2727
|
try {
|
|
2634
|
-
const st = await
|
|
2728
|
+
const st = await stat2(path3);
|
|
2635
2729
|
return { mtimeMs: st.mtimeMs, size: st.size };
|
|
2636
2730
|
} catch {
|
|
2637
2731
|
return null;
|
|
2638
2732
|
}
|
|
2639
2733
|
}
|
|
2640
2734
|
async function prepareClaudeCodeSettingsPatch(opts) {
|
|
2641
|
-
const
|
|
2735
|
+
const path3 = resolveClaudeCodeSettingsPath(opts.scope, {
|
|
2642
2736
|
home: opts.home,
|
|
2643
2737
|
projectDir: opts.projectDir,
|
|
2644
2738
|
claudeConfigDir: opts.claudeConfigDir
|
|
2645
2739
|
});
|
|
2646
|
-
if (!
|
|
2740
|
+
if (!path3) return null;
|
|
2647
2741
|
let existing = {};
|
|
2648
2742
|
let rawSettings = null;
|
|
2649
|
-
const fingerprint = await settingsFingerprint(
|
|
2743
|
+
const fingerprint = await settingsFingerprint(path3);
|
|
2650
2744
|
if (fingerprint !== null) {
|
|
2651
2745
|
try {
|
|
2652
|
-
const raw = await readFile2(
|
|
2746
|
+
const raw = await readFile2(path3, "utf8");
|
|
2653
2747
|
if (raw.trim().length > 0) {
|
|
2654
2748
|
const parsed = parseJsonc(raw);
|
|
2655
2749
|
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
@@ -2657,7 +2751,7 @@ async function prepareClaudeCodeSettingsPatch(opts) {
|
|
|
2657
2751
|
rawSettings = raw;
|
|
2658
2752
|
} else {
|
|
2659
2753
|
return {
|
|
2660
|
-
path:
|
|
2754
|
+
path: path3,
|
|
2661
2755
|
nextJson: "",
|
|
2662
2756
|
changed: false,
|
|
2663
2757
|
added: [],
|
|
@@ -2670,7 +2764,7 @@ async function prepareClaudeCodeSettingsPatch(opts) {
|
|
|
2670
2764
|
}
|
|
2671
2765
|
} catch (e) {
|
|
2672
2766
|
return {
|
|
2673
|
-
path:
|
|
2767
|
+
path: path3,
|
|
2674
2768
|
nextJson: "",
|
|
2675
2769
|
changed: false,
|
|
2676
2770
|
added: [],
|
|
@@ -2685,7 +2779,7 @@ async function prepareClaudeCodeSettingsPatch(opts) {
|
|
|
2685
2779
|
const merged = op === "remove" ? removePermissionsAllow(existing, [CLAUDE_CODE_ALLOW_PATTERN]) : mergePermissionsAllow(existing, [CLAUDE_CODE_ALLOW_PATTERN]);
|
|
2686
2780
|
const before = JSON.stringify(existing);
|
|
2687
2781
|
const after = JSON.stringify(merged);
|
|
2688
|
-
if (before === after) return { path:
|
|
2782
|
+
if (before === after) return { path: path3, nextJson: "", changed: false, added: [], removed: [], fingerprint };
|
|
2689
2783
|
const prevAllow = existing.permissions?.allow;
|
|
2690
2784
|
const prevAllowList = Array.isArray(prevAllow) ? prevAllow : [];
|
|
2691
2785
|
const added = op === "add" ? [CLAUDE_CODE_ALLOW_PATTERN].filter((p) => !prevAllowList.includes(p)) : [];
|
|
@@ -2694,7 +2788,7 @@ async function prepareClaudeCodeSettingsPatch(opts) {
|
|
|
2694
2788
|
const perms = existing.permissions;
|
|
2695
2789
|
if (perms !== void 0 && (typeof perms !== "object" || perms === null || Array.isArray(perms))) {
|
|
2696
2790
|
return {
|
|
2697
|
-
path:
|
|
2791
|
+
path: path3,
|
|
2698
2792
|
nextJson: "",
|
|
2699
2793
|
changed: false,
|
|
2700
2794
|
added: [],
|
|
@@ -2706,11 +2800,11 @@ async function prepareClaudeCodeSettingsPatch(opts) {
|
|
|
2706
2800
|
}
|
|
2707
2801
|
try {
|
|
2708
2802
|
const next = patchPermissionsAllowText(rawSettings, [CLAUDE_CODE_ALLOW_PATTERN], op);
|
|
2709
|
-
return { path:
|
|
2803
|
+
return { path: path3, nextJson: next.endsWith("\n") ? next : `${next}
|
|
2710
2804
|
`, changed: true, added, removed, fingerprint };
|
|
2711
2805
|
} catch (e) {
|
|
2712
2806
|
return {
|
|
2713
|
-
path:
|
|
2807
|
+
path: path3,
|
|
2714
2808
|
nextJson: "",
|
|
2715
2809
|
changed: false,
|
|
2716
2810
|
added: [],
|
|
@@ -2721,7 +2815,7 @@ async function prepareClaudeCodeSettingsPatch(opts) {
|
|
|
2721
2815
|
};
|
|
2722
2816
|
}
|
|
2723
2817
|
}
|
|
2724
|
-
return { path:
|
|
2818
|
+
return { path: path3, nextJson: `${JSON.stringify(merged, null, 2)}
|
|
2725
2819
|
`, changed: true, added, removed, fingerprint };
|
|
2726
2820
|
}
|
|
2727
2821
|
|
|
@@ -3226,52 +3320,52 @@ function blockedContainerFix(then) {
|
|
|
3226
3320
|
}
|
|
3227
3321
|
|
|
3228
3322
|
// src/paths.ts
|
|
3229
|
-
import { realpath, stat as
|
|
3323
|
+
import { realpath as realpath2, stat as stat3 } from "fs/promises";
|
|
3230
3324
|
import { homedir as homedir3 } from "os";
|
|
3231
|
-
import
|
|
3325
|
+
import path2 from "path";
|
|
3232
3326
|
function cacheDir() {
|
|
3233
3327
|
if (process.platform === "win32") {
|
|
3234
3328
|
const localAppData = process.env.LOCALAPPDATA;
|
|
3235
|
-
const base = localAppData && localAppData.length > 0 ? localAppData :
|
|
3236
|
-
return
|
|
3329
|
+
const base = localAppData && localAppData.length > 0 ? localAppData : path2.join(homedir3(), "AppData", "Local");
|
|
3330
|
+
return path2.join(base, "yaw-mcp", "Cache");
|
|
3237
3331
|
}
|
|
3238
3332
|
if (process.platform === "darwin") {
|
|
3239
|
-
return
|
|
3333
|
+
return path2.join(homedir3(), "Library", "Caches", "yaw-mcp");
|
|
3240
3334
|
}
|
|
3241
3335
|
const xdg = process.env.XDG_CACHE_HOME;
|
|
3242
|
-
return
|
|
3336
|
+
return path2.join(xdg && xdg.length > 0 ? xdg : path2.join(homedir3(), ".cache"), "yaw-mcp");
|
|
3243
3337
|
}
|
|
3244
3338
|
var CONFIG_DIRNAME = ".yaw-mcp";
|
|
3245
3339
|
var SIDECARS_DIRNAME = "sidecars";
|
|
3246
3340
|
function sidecarsRoot(home = homedir3()) {
|
|
3247
|
-
return
|
|
3341
|
+
return path2.join(userConfigDir(home), SIDECARS_DIRNAME);
|
|
3248
3342
|
}
|
|
3249
3343
|
function sidecarsNodeModules(home = homedir3()) {
|
|
3250
|
-
return
|
|
3344
|
+
return path2.join(sidecarsRoot(home), "node_modules");
|
|
3251
3345
|
}
|
|
3252
3346
|
function userConfigDir(home = homedir3()) {
|
|
3253
|
-
return
|
|
3347
|
+
return path2.join(home, CONFIG_DIRNAME);
|
|
3254
3348
|
}
|
|
3255
3349
|
function normalizeForCompare(p) {
|
|
3256
3350
|
return process.platform === "win32" || process.platform === "darwin" ? p.toLowerCase() : p;
|
|
3257
3351
|
}
|
|
3258
3352
|
function tildePath(abs, home, sep3) {
|
|
3259
|
-
if (!home || !
|
|
3260
|
-
const absResolved =
|
|
3261
|
-
const homeResolved =
|
|
3353
|
+
if (!home || !path2.isAbsolute(abs)) return abs;
|
|
3354
|
+
const absResolved = path2.resolve(abs);
|
|
3355
|
+
const homeResolved = path2.resolve(home);
|
|
3262
3356
|
const head = absResolved.slice(0, homeResolved.length);
|
|
3263
3357
|
if (normalizeForCompare(head) !== normalizeForCompare(homeResolved)) return abs;
|
|
3264
3358
|
const rest = absResolved.slice(homeResolved.length);
|
|
3265
3359
|
if (rest === "") return "~";
|
|
3266
3360
|
let tail;
|
|
3267
|
-
if (homeResolved.endsWith(
|
|
3268
|
-
else if (rest.startsWith(
|
|
3361
|
+
if (homeResolved.endsWith(path2.sep)) tail = rest;
|
|
3362
|
+
else if (rest.startsWith(path2.sep)) tail = rest.slice(path2.sep.length);
|
|
3269
3363
|
else return abs;
|
|
3270
|
-
return `~${sep3}${tail.split(
|
|
3364
|
+
return `~${sep3}${tail.split(path2.sep).join(sep3)}`;
|
|
3271
3365
|
}
|
|
3272
3366
|
async function realpathOrSelf(p) {
|
|
3273
3367
|
try {
|
|
3274
|
-
return await
|
|
3368
|
+
return await realpath2(p);
|
|
3275
3369
|
} catch {
|
|
3276
3370
|
return p;
|
|
3277
3371
|
}
|
|
@@ -3280,9 +3374,9 @@ function isUnderHome(dir, homeResolved) {
|
|
|
3280
3374
|
const dirKey = normalizeForCompare(dir);
|
|
3281
3375
|
const homeKey = normalizeForCompare(homeResolved);
|
|
3282
3376
|
if (dirKey === homeKey) return false;
|
|
3283
|
-
const rel =
|
|
3284
|
-
if (rel === "" ||
|
|
3285
|
-
return rel !== ".." && !rel.startsWith(`..${
|
|
3377
|
+
const rel = path2.relative(homeKey, dirKey);
|
|
3378
|
+
if (rel === "" || path2.isAbsolute(rel)) return false;
|
|
3379
|
+
return rel !== ".." && !rel.startsWith(`..${path2.sep}`);
|
|
3286
3380
|
}
|
|
3287
3381
|
var ALLOW_UNOWNED_ENV = "YAW_MCP_ALLOW_UNOWNED_PROJECT_DIRS";
|
|
3288
3382
|
var warnedUntrustedDirs = /* @__PURE__ */ new Set();
|
|
@@ -3293,16 +3387,16 @@ function ownedByCurrentUser(st, env) {
|
|
|
3293
3387
|
}
|
|
3294
3388
|
async function findProjectConfigDir(start, home = homedir3(), env = process.env) {
|
|
3295
3389
|
const homeFallback = home && home.length > 0 ? home : homedir3();
|
|
3296
|
-
const homeResolved =
|
|
3297
|
-
let dir =
|
|
3298
|
-
const userConfigKey = normalizeForCompare(await realpathOrSelf(
|
|
3390
|
+
const homeResolved = path2.resolve(await realpathOrSelf(path2.resolve(homeFallback)));
|
|
3391
|
+
let dir = path2.resolve(await realpathOrSelf(path2.resolve(start)));
|
|
3392
|
+
const userConfigKey = normalizeForCompare(await realpathOrSelf(path2.join(homeResolved, CONFIG_DIRNAME)));
|
|
3299
3393
|
const boundedByHome = isUnderHome(dir, homeResolved) || normalizeForCompare(dir) === normalizeForCompare(homeResolved);
|
|
3300
3394
|
let prev = "";
|
|
3301
3395
|
while (dir !== prev) {
|
|
3302
3396
|
if (boundedByHome && !isUnderHome(dir, homeResolved)) return null;
|
|
3303
|
-
const candidate =
|
|
3397
|
+
const candidate = path2.join(dir, CONFIG_DIRNAME);
|
|
3304
3398
|
try {
|
|
3305
|
-
const st = await
|
|
3399
|
+
const st = await stat3(candidate);
|
|
3306
3400
|
if (!st.isDirectory()) {
|
|
3307
3401
|
log("debug", "Skipping a .yaw-mcp that exists but is not a directory", { candidate });
|
|
3308
3402
|
} else if (normalizeForCompare(await realpathOrSelf(candidate)) === userConfigKey) {
|
|
@@ -3321,13 +3415,13 @@ async function findProjectConfigDir(start, home = homedir3(), env = process.env)
|
|
|
3321
3415
|
} catch {
|
|
3322
3416
|
}
|
|
3323
3417
|
prev = dir;
|
|
3324
|
-
dir =
|
|
3418
|
+
dir = path2.dirname(dir);
|
|
3325
3419
|
}
|
|
3326
3420
|
return null;
|
|
3327
3421
|
}
|
|
3328
3422
|
var GUIDE_FILENAME = "YAW-MCP.md";
|
|
3329
3423
|
function guidePath(configDir) {
|
|
3330
|
-
return
|
|
3424
|
+
return path2.join(configDir, GUIDE_FILENAME);
|
|
3331
3425
|
}
|
|
3332
3426
|
|
|
3333
3427
|
// src/oam-spawn.ts
|
|
@@ -4068,13 +4162,13 @@ ${UPGRADE_USAGE}` };
|
|
|
4068
4162
|
}
|
|
4069
4163
|
return { ok: true, options: opts };
|
|
4070
4164
|
}
|
|
4071
|
-
function detectInstallMethod(argvPath,
|
|
4165
|
+
function detectInstallMethod(argvPath, realpath3 = realpathSync, resolveWhen = ["unknown"]) {
|
|
4072
4166
|
if (!argvPath) return "unknown";
|
|
4073
4167
|
const literal = classifyEntrypoint(argvPath);
|
|
4074
4168
|
if (!resolveWhen.includes(literal)) return literal;
|
|
4075
4169
|
let resolved;
|
|
4076
4170
|
try {
|
|
4077
|
-
resolved =
|
|
4171
|
+
resolved = realpath3(argvPath);
|
|
4078
4172
|
} catch {
|
|
4079
4173
|
return literal;
|
|
4080
4174
|
}
|
|
@@ -4100,12 +4194,12 @@ function localInstallRoot(argvPath) {
|
|
|
4100
4194
|
const idx = argvPath.replace(/\\/g, "/").indexOf("/node_modules/");
|
|
4101
4195
|
return idx > 0 ? argvPath.slice(0, idx) : null;
|
|
4102
4196
|
}
|
|
4103
|
-
function runningPackageDir(argvPath,
|
|
4197
|
+
function runningPackageDir(argvPath, realpath3 = realpathSync) {
|
|
4104
4198
|
if (!argvPath) return null;
|
|
4105
4199
|
const literal = packageDirOf(argvPath);
|
|
4106
4200
|
if (literal !== null) return literal;
|
|
4107
4201
|
try {
|
|
4108
|
-
return packageDirOf(
|
|
4202
|
+
return packageDirOf(realpath3(argvPath));
|
|
4109
4203
|
} catch {
|
|
4110
4204
|
return null;
|
|
4111
4205
|
}
|
|
@@ -4293,7 +4387,7 @@ async function oamFloorLines(probe) {
|
|
|
4293
4387
|
}
|
|
4294
4388
|
async function defaultRunningPrefix(argvPath) {
|
|
4295
4389
|
if (process.env.VITEST) return null;
|
|
4296
|
-
const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-
|
|
4390
|
+
const { detectRunningInstallPrefix: detectRunningInstallPrefix2 } = await import("./auto-upgrade-HYJENL2G.js");
|
|
4297
4391
|
return detectRunningInstallPrefix2(argvPath);
|
|
4298
4392
|
}
|
|
4299
4393
|
async function defaultSpawn(cmd, args, cwd) {
|
|
@@ -4354,7 +4448,7 @@ async function runUpgrade(opts = {}) {
|
|
|
4354
4448
|
if (method === "global-npm") {
|
|
4355
4449
|
const rawPrefix = await (opts.runningPrefix ?? defaultRunningPrefix)(argvPath);
|
|
4356
4450
|
if (rawPrefix !== null) {
|
|
4357
|
-
const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-
|
|
4451
|
+
const { quoteArgForDisplay: quoteArgForDisplay2, quoteShellArgIfNeeded: quoteShellArgIfNeeded2 } = await import("./auto-upgrade-HYJENL2G.js");
|
|
4358
4452
|
const spawnForm = quoteShellArgIfNeeded2(rawPrefix, opts.platform);
|
|
4359
4453
|
const displayForm = quoteArgForDisplay2(rawPrefix, opts.platform);
|
|
4360
4454
|
if (spawnForm !== null && displayForm !== null) {
|
|
@@ -4471,7 +4565,7 @@ async function runUpgrade(opts = {}) {
|
|
|
4471
4565
|
return { exitCode: 3, lines };
|
|
4472
4566
|
}
|
|
4473
4567
|
function readCurrentVersion() {
|
|
4474
|
-
return true ? "1.0.
|
|
4568
|
+
return true ? "1.0.4" : "dev";
|
|
4475
4569
|
}
|
|
4476
4570
|
|
|
4477
4571
|
// src/auto-upgrade.ts
|
|
@@ -4514,6 +4608,21 @@ async function compareWithNpmPrefix(detected, probe = npmGlobalPrefix) {
|
|
|
4514
4608
|
var UPGRADE_LOCK_NAME = ".yaw-mcp-upgrade.lock";
|
|
4515
4609
|
var UPGRADE_LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
4516
4610
|
var UPGRADE_LOCK_FUTURE_SKEW_MS = 5 * 1e3;
|
|
4611
|
+
var LOCK_CREATE_RETRY_DELAYS_MS = [1, 5, 20];
|
|
4612
|
+
function sleepSync(ms) {
|
|
4613
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
4614
|
+
}
|
|
4615
|
+
function openLockSync(path3) {
|
|
4616
|
+
for (const ms of LOCK_CREATE_RETRY_DELAYS_MS) {
|
|
4617
|
+
try {
|
|
4618
|
+
return openSync(path3, "wx");
|
|
4619
|
+
} catch (err) {
|
|
4620
|
+
if (!isWin32TransientFsError(err)) throw err;
|
|
4621
|
+
sleepSync(ms);
|
|
4622
|
+
}
|
|
4623
|
+
}
|
|
4624
|
+
return openSync(path3, "wx");
|
|
4625
|
+
}
|
|
4517
4626
|
function lockHolderAlive(lockPath) {
|
|
4518
4627
|
let pid;
|
|
4519
4628
|
try {
|
|
@@ -4532,11 +4641,11 @@ function lockHolderAlive(lockPath) {
|
|
|
4532
4641
|
}
|
|
4533
4642
|
function acquireUpgradeLock(dir, lockName = UPGRADE_LOCK_NAME, opts = {}) {
|
|
4534
4643
|
const lockPath = join11(dir, lockName);
|
|
4535
|
-
const holderAlive = (
|
|
4644
|
+
const holderAlive = (path3) => opts.probeHolder ? lockHolderAlive(path3) : true;
|
|
4536
4645
|
const mine = String(process.pid);
|
|
4537
4646
|
const take = () => {
|
|
4538
4647
|
try {
|
|
4539
|
-
const fd =
|
|
4648
|
+
const fd = openLockSync(lockPath);
|
|
4540
4649
|
try {
|
|
4541
4650
|
writeSync(fd, `${mine}
|
|
4542
4651
|
`);
|
|
@@ -4585,7 +4694,7 @@ function acquireUpgradeLock(dir, lockName = UPGRADE_LOCK_NAME, opts = {}) {
|
|
|
4585
4694
|
if (stoleLive) {
|
|
4586
4695
|
try {
|
|
4587
4696
|
const holder = readFileSync3(stolenPath, "utf8");
|
|
4588
|
-
const fd =
|
|
4697
|
+
const fd = openLockSync(lockPath);
|
|
4589
4698
|
try {
|
|
4590
4699
|
writeSync(fd, holder);
|
|
4591
4700
|
} finally {
|
|
@@ -4613,10 +4722,10 @@ function defaultAcquireLock(dir, lockName) {
|
|
|
4613
4722
|
}
|
|
4614
4723
|
var UPGRADE_CHECK_INTERVAL_MS = 60 * 60 * 1e3;
|
|
4615
4724
|
var UPGRADE_ATTEMPT_COOLDOWN_MS = 6 * 60 * 60 * 1e3;
|
|
4616
|
-
function readMemo(
|
|
4725
|
+
function readMemo(path3) {
|
|
4617
4726
|
let parsed;
|
|
4618
4727
|
try {
|
|
4619
|
-
parsed = JSON.parse(readFileSync3(
|
|
4728
|
+
parsed = JSON.parse(readFileSync3(path3, "utf8"));
|
|
4620
4729
|
} catch {
|
|
4621
4730
|
return null;
|
|
4622
4731
|
}
|
|
@@ -4626,9 +4735,9 @@ function readMemo(path2) {
|
|
|
4626
4735
|
const ageMs = Date.now() - memo.at;
|
|
4627
4736
|
return ageMs < -UPGRADE_LOCK_FUTURE_SKEW_MS ? null : { ageMs, memo };
|
|
4628
4737
|
}
|
|
4629
|
-
function writeMemo(
|
|
4738
|
+
function writeMemo(path3, fields) {
|
|
4630
4739
|
try {
|
|
4631
|
-
writeFileSync(
|
|
4740
|
+
writeFileSync(path3, `${JSON.stringify({ at: Date.now(), ...fields })}
|
|
4632
4741
|
`);
|
|
4633
4742
|
} catch {
|
|
4634
4743
|
}
|
|
@@ -4636,15 +4745,15 @@ function writeMemo(path2, fields) {
|
|
|
4636
4745
|
function checkMemoPath() {
|
|
4637
4746
|
return join11(tmpdir(), `.yaw-mcp-upgrade-check-${process.getuid?.() ?? "win"}.json`);
|
|
4638
4747
|
}
|
|
4639
|
-
function readCheckMemo(
|
|
4640
|
-
const read = readMemo(
|
|
4748
|
+
function readCheckMemo(path3) {
|
|
4749
|
+
const read = readMemo(path3);
|
|
4641
4750
|
if (read === null || read.ageMs >= UPGRADE_CHECK_INTERVAL_MS) return null;
|
|
4642
4751
|
const latest = read.memo.latest;
|
|
4643
4752
|
if (latest !== null && typeof latest !== "string") return null;
|
|
4644
4753
|
return { latest };
|
|
4645
4754
|
}
|
|
4646
|
-
function writeCheckMemo(
|
|
4647
|
-
writeMemo(
|
|
4755
|
+
function writeCheckMemo(path3, latest) {
|
|
4756
|
+
writeMemo(path3, { latest });
|
|
4648
4757
|
}
|
|
4649
4758
|
function attemptMemoPath(dir, lockName) {
|
|
4650
4759
|
return join11(dir, `${lockName}.attempt`);
|
|
@@ -4738,7 +4847,7 @@ function defaultSpawn2(cmd, args, onDone = () => {
|
|
|
4738
4847
|
async function maybeAutoUpgrade(deps = {}) {
|
|
4739
4848
|
const optOut = process.env.YAW_MCP_AUTO_UPGRADE;
|
|
4740
4849
|
if (optOut === "0" || optOut?.toLowerCase() === "false") return;
|
|
4741
|
-
const current = deps.currentVersion ?? (true ? "1.0.
|
|
4850
|
+
const current = deps.currentVersion ?? (true ? "1.0.4" : "dev");
|
|
4742
4851
|
if (current === "dev") return;
|
|
4743
4852
|
const argvPath = deps.argvPath ?? process.argv[1];
|
|
4744
4853
|
const method = (deps.isSeaImpl ? await deps.isSeaImpl() : await detectSea()) ? "binary" : detectInstallMethod(argvPath, realpathSync2, ["unknown", "local-node-modules"]);
|
|
@@ -4851,6 +4960,8 @@ export {
|
|
|
4851
4960
|
setLogSurface,
|
|
4852
4961
|
log,
|
|
4853
4962
|
createStreamWriter,
|
|
4963
|
+
isWin32TransientFsError,
|
|
4964
|
+
atomicWriteFile,
|
|
4854
4965
|
parseJsonc,
|
|
4855
4966
|
editJsoncPath,
|
|
4856
4967
|
cacheDir,
|