@polterware/polter 0.4.0 → 0.4.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/dist/api.js +9 -2
- package/dist/chunk-VYHW3UNY.js +108 -0
- package/dist/{chunk-YNOZDU75.js → chunk-ZHVOYB5M.js} +249 -54
- package/dist/index.js +259 -184
- package/dist/mcp.js +100 -24
- package/package.json +1 -1
- package/dist/chunk-AGVTFYXU.js +0 -0
package/dist/api.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
createIpcClient
|
|
3
|
+
} from "./chunk-VYHW3UNY.js";
|
|
2
4
|
import {
|
|
3
5
|
allCommands,
|
|
4
6
|
applyActions,
|
|
7
|
+
createIpcServer,
|
|
5
8
|
deletePipeline,
|
|
6
9
|
detectPkgManager,
|
|
7
10
|
executePipeline,
|
|
@@ -19,6 +22,7 @@ import {
|
|
|
19
22
|
getFlagsForTool,
|
|
20
23
|
getMcpStatusInfo,
|
|
21
24
|
getProcessOutput,
|
|
25
|
+
getSocketPath,
|
|
22
26
|
getToolDisplayName,
|
|
23
27
|
getToolInfo,
|
|
24
28
|
installMcpServerSilent,
|
|
@@ -36,10 +40,12 @@ import {
|
|
|
36
40
|
stopProcess,
|
|
37
41
|
toolFlags,
|
|
38
42
|
translateCommand
|
|
39
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-ZHVOYB5M.js";
|
|
40
44
|
export {
|
|
41
45
|
allCommands,
|
|
42
46
|
applyActions,
|
|
47
|
+
createIpcClient,
|
|
48
|
+
createIpcServer,
|
|
43
49
|
deletePipeline,
|
|
44
50
|
detectPkgManager,
|
|
45
51
|
executePipeline,
|
|
@@ -57,6 +63,7 @@ export {
|
|
|
57
63
|
getFlagsForTool,
|
|
58
64
|
getMcpStatusInfo,
|
|
59
65
|
getProcessOutput,
|
|
66
|
+
getSocketPath,
|
|
60
67
|
getToolDisplayName,
|
|
61
68
|
getToolInfo,
|
|
62
69
|
installMcpServerSilent,
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseMessages,
|
|
3
|
+
serializeMessage
|
|
4
|
+
} from "./chunk-ZHVOYB5M.js";
|
|
5
|
+
|
|
6
|
+
// src/lib/ipcClient.ts
|
|
7
|
+
import net from "net";
|
|
8
|
+
var DEFAULT_TIMEOUT = 5e3;
|
|
9
|
+
function createIpcClient(socketPath) {
|
|
10
|
+
let socket = null;
|
|
11
|
+
let connected = false;
|
|
12
|
+
let nextId = 1;
|
|
13
|
+
let buffer = "";
|
|
14
|
+
const pending = /* @__PURE__ */ new Map();
|
|
15
|
+
function handleData(data) {
|
|
16
|
+
buffer += data.toString();
|
|
17
|
+
const { messages, remainder } = parseMessages(buffer);
|
|
18
|
+
buffer = remainder;
|
|
19
|
+
for (const msg of messages) {
|
|
20
|
+
if ("id" in msg && !("method" in msg)) {
|
|
21
|
+
const resp = msg;
|
|
22
|
+
const entry = pending.get(resp.id);
|
|
23
|
+
if (entry) {
|
|
24
|
+
pending.delete(resp.id);
|
|
25
|
+
if (resp.error) {
|
|
26
|
+
entry.reject(new Error(resp.error.message));
|
|
27
|
+
} else {
|
|
28
|
+
entry.resolve(resp.result);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
connect() {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
socket = net.createConnection(socketPath);
|
|
38
|
+
socket.on("connect", () => {
|
|
39
|
+
connected = true;
|
|
40
|
+
resolve();
|
|
41
|
+
});
|
|
42
|
+
socket.on("data", handleData);
|
|
43
|
+
socket.on("close", () => {
|
|
44
|
+
connected = false;
|
|
45
|
+
for (const entry of pending.values()) {
|
|
46
|
+
entry.reject(new Error("Connection closed"));
|
|
47
|
+
}
|
|
48
|
+
pending.clear();
|
|
49
|
+
});
|
|
50
|
+
socket.on("error", (err) => {
|
|
51
|
+
connected = false;
|
|
52
|
+
if (!connected) {
|
|
53
|
+
reject(err);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
disconnect() {
|
|
59
|
+
if (socket) {
|
|
60
|
+
socket.destroy();
|
|
61
|
+
socket = null;
|
|
62
|
+
connected = false;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
isConnected() {
|
|
66
|
+
return connected;
|
|
67
|
+
},
|
|
68
|
+
call(method, params) {
|
|
69
|
+
if (!socket || !connected) {
|
|
70
|
+
return Promise.reject(new Error("Not connected"));
|
|
71
|
+
}
|
|
72
|
+
const id = nextId++;
|
|
73
|
+
const request = {
|
|
74
|
+
jsonrpc: "2.0",
|
|
75
|
+
id,
|
|
76
|
+
method,
|
|
77
|
+
...params !== void 0 ? { params } : {}
|
|
78
|
+
};
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
const timer = setTimeout(() => {
|
|
81
|
+
pending.delete(id);
|
|
82
|
+
reject(new Error(`RPC call "${method}" timed out after ${DEFAULT_TIMEOUT}ms`));
|
|
83
|
+
}, DEFAULT_TIMEOUT);
|
|
84
|
+
pending.set(id, {
|
|
85
|
+
resolve: (v) => {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
resolve(v);
|
|
88
|
+
},
|
|
89
|
+
reject: (e) => {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
reject(e);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
socket.write(serializeMessage(request));
|
|
96
|
+
} catch (err) {
|
|
97
|
+
clearTimeout(timer);
|
|
98
|
+
pending.delete(id);
|
|
99
|
+
reject(err);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export {
|
|
107
|
+
createIpcClient
|
|
108
|
+
};
|
|
@@ -989,6 +989,7 @@ function runCommand(execution, args, cwd = process.cwd(), options) {
|
|
|
989
989
|
cwd,
|
|
990
990
|
env: resolvedExecution.env,
|
|
991
991
|
shell: true,
|
|
992
|
+
detached: true,
|
|
992
993
|
stdio: [options?.quiet ? "pipe" : "inherit", "pipe", "pipe"]
|
|
993
994
|
});
|
|
994
995
|
if (options?.quiet) {
|
|
@@ -1022,7 +1023,14 @@ function runCommand(execution, args, cwd = process.cwd(), options) {
|
|
|
1022
1023
|
});
|
|
1023
1024
|
return {
|
|
1024
1025
|
promise,
|
|
1025
|
-
abort: () =>
|
|
1026
|
+
abort: () => {
|
|
1027
|
+
if (child.pid) {
|
|
1028
|
+
try {
|
|
1029
|
+
process.kill(-child.pid, "SIGTERM");
|
|
1030
|
+
} catch {
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1026
1034
|
};
|
|
1027
1035
|
}
|
|
1028
1036
|
function runInteractiveCommand(execution, args, cwd = process.cwd()) {
|
|
@@ -1337,6 +1345,31 @@ function getToolLinkInfo(toolId, cwd = process.cwd()) {
|
|
|
1337
1345
|
|
|
1338
1346
|
// src/lib/processManager.ts
|
|
1339
1347
|
import { spawn as spawn2 } from "child_process";
|
|
1348
|
+
import { join as join5 } from "path";
|
|
1349
|
+
|
|
1350
|
+
// src/lib/packageRoot.ts
|
|
1351
|
+
import { existsSync as existsSync4 } from "fs";
|
|
1352
|
+
import { dirname as dirname3, join as join4, resolve as resolve2 } from "path";
|
|
1353
|
+
var rootCache = /* @__PURE__ */ new Map();
|
|
1354
|
+
function findNearestPackageRoot(startDir = process.cwd()) {
|
|
1355
|
+
const resolvedStart = resolve2(startDir);
|
|
1356
|
+
if (rootCache.has(resolvedStart)) return rootCache.get(resolvedStart);
|
|
1357
|
+
let currentDir = resolvedStart;
|
|
1358
|
+
while (true) {
|
|
1359
|
+
if (existsSync4(join4(currentDir, "package.json"))) {
|
|
1360
|
+
rootCache.set(resolvedStart, currentDir);
|
|
1361
|
+
return currentDir;
|
|
1362
|
+
}
|
|
1363
|
+
const parentDir = dirname3(currentDir);
|
|
1364
|
+
if (parentDir === currentDir) {
|
|
1365
|
+
rootCache.set(resolvedStart, void 0);
|
|
1366
|
+
return void 0;
|
|
1367
|
+
}
|
|
1368
|
+
currentDir = parentDir;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
// src/lib/processManager.ts
|
|
1340
1373
|
var DEFAULT_BUFFER_CAP = 1e3;
|
|
1341
1374
|
function createRingBuffer(cap = DEFAULT_BUFFER_CAP) {
|
|
1342
1375
|
return { lines: [], cap, totalLines: 0 };
|
|
@@ -1536,6 +1569,188 @@ function toProcessInfo(proc) {
|
|
|
1536
1569
|
uptime: end - start
|
|
1537
1570
|
};
|
|
1538
1571
|
}
|
|
1572
|
+
function getSocketPath(cwd) {
|
|
1573
|
+
const root = findNearestPackageRoot(cwd);
|
|
1574
|
+
if (!root) return void 0;
|
|
1575
|
+
return join5(root, ".polter", "polter.sock");
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
// src/lib/ipcServer.ts
|
|
1579
|
+
import net from "net";
|
|
1580
|
+
import { mkdirSync, unlinkSync, existsSync as existsSync5 } from "fs";
|
|
1581
|
+
import { dirname as dirname4 } from "path";
|
|
1582
|
+
|
|
1583
|
+
// src/lib/ipcProtocol.ts
|
|
1584
|
+
var DELIMITER = "\n";
|
|
1585
|
+
function serializeMessage(msg) {
|
|
1586
|
+
return JSON.stringify(msg) + DELIMITER;
|
|
1587
|
+
}
|
|
1588
|
+
function parseMessages(buffer) {
|
|
1589
|
+
const messages = [];
|
|
1590
|
+
let remainder = buffer;
|
|
1591
|
+
let idx;
|
|
1592
|
+
while ((idx = remainder.indexOf(DELIMITER)) !== -1) {
|
|
1593
|
+
const line = remainder.slice(0, idx);
|
|
1594
|
+
remainder = remainder.slice(idx + 1);
|
|
1595
|
+
if (line.length === 0) continue;
|
|
1596
|
+
try {
|
|
1597
|
+
messages.push(JSON.parse(line));
|
|
1598
|
+
} catch {
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
return { messages, remainder };
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
// src/lib/ipcServer.ts
|
|
1605
|
+
var handlers = {
|
|
1606
|
+
"ps.list": () => listProcesses(),
|
|
1607
|
+
"ps.start": (params) => {
|
|
1608
|
+
const { command, args, cwd, id } = params;
|
|
1609
|
+
const processArgs = args ?? [];
|
|
1610
|
+
const processId = id ?? generateProcessId(command, processArgs);
|
|
1611
|
+
const processCwd = cwd ?? process.cwd();
|
|
1612
|
+
return startProcess(processId, command, processArgs, processCwd);
|
|
1613
|
+
},
|
|
1614
|
+
"ps.stop": async (params) => {
|
|
1615
|
+
const { id } = params;
|
|
1616
|
+
return stopProcess(id);
|
|
1617
|
+
},
|
|
1618
|
+
"ps.logs": (params) => {
|
|
1619
|
+
const { id, tail, stream } = params;
|
|
1620
|
+
return getProcessOutput(id, tail, stream);
|
|
1621
|
+
},
|
|
1622
|
+
"ps.remove": (params) => {
|
|
1623
|
+
const { id } = params;
|
|
1624
|
+
removeProcess(id);
|
|
1625
|
+
return null;
|
|
1626
|
+
},
|
|
1627
|
+
"ps.find_by_cwd": (params) => {
|
|
1628
|
+
const { cwd, filter } = params;
|
|
1629
|
+
let processes = findProcessesByCwd(cwd);
|
|
1630
|
+
if (filter) {
|
|
1631
|
+
const f = filter.toLowerCase();
|
|
1632
|
+
processes = processes.filter(
|
|
1633
|
+
(p) => (p.command + " " + p.args.join(" ")).toLowerCase().includes(f)
|
|
1634
|
+
);
|
|
1635
|
+
}
|
|
1636
|
+
return processes;
|
|
1637
|
+
},
|
|
1638
|
+
"ps.find_running": (params) => {
|
|
1639
|
+
const { cwd, command, args } = params;
|
|
1640
|
+
return findRunningByCommand(cwd, command, args) ?? null;
|
|
1641
|
+
},
|
|
1642
|
+
"ps.generate_id": (params) => {
|
|
1643
|
+
const { command, args } = params;
|
|
1644
|
+
return generateProcessId(command, args);
|
|
1645
|
+
},
|
|
1646
|
+
status: () => ({ tui: true, pid: process.pid })
|
|
1647
|
+
};
|
|
1648
|
+
async function handleRequest(req) {
|
|
1649
|
+
const handler = handlers[req.method];
|
|
1650
|
+
if (!handler) {
|
|
1651
|
+
return {
|
|
1652
|
+
jsonrpc: "2.0",
|
|
1653
|
+
id: req.id,
|
|
1654
|
+
error: { code: -32601, message: `Method not found: ${req.method}` }
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
try {
|
|
1658
|
+
const result = await handler(req.params ?? {});
|
|
1659
|
+
return { jsonrpc: "2.0", id: req.id, result };
|
|
1660
|
+
} catch (err) {
|
|
1661
|
+
return {
|
|
1662
|
+
jsonrpc: "2.0",
|
|
1663
|
+
id: req.id,
|
|
1664
|
+
error: { code: -32e3, message: err.message }
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
function createIpcServer(socketPath) {
|
|
1669
|
+
let server = null;
|
|
1670
|
+
const connections = /* @__PURE__ */ new Set();
|
|
1671
|
+
function handleConnection(socket) {
|
|
1672
|
+
connections.add(socket);
|
|
1673
|
+
let buffer = "";
|
|
1674
|
+
socket.on("data", async (data) => {
|
|
1675
|
+
buffer += data.toString();
|
|
1676
|
+
const { messages, remainder } = parseMessages(buffer);
|
|
1677
|
+
buffer = remainder;
|
|
1678
|
+
for (const msg of messages) {
|
|
1679
|
+
if ("method" in msg) {
|
|
1680
|
+
const response = await handleRequest(msg);
|
|
1681
|
+
try {
|
|
1682
|
+
socket.write(serializeMessage(response));
|
|
1683
|
+
} catch {
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1688
|
+
socket.on("close", () => {
|
|
1689
|
+
connections.delete(socket);
|
|
1690
|
+
});
|
|
1691
|
+
socket.on("error", () => {
|
|
1692
|
+
connections.delete(socket);
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
async function cleanStaleSocket() {
|
|
1696
|
+
if (!existsSync5(socketPath)) return;
|
|
1697
|
+
return new Promise((resolve3) => {
|
|
1698
|
+
const probe = net.createConnection(socketPath);
|
|
1699
|
+
probe.on("connect", () => {
|
|
1700
|
+
probe.destroy();
|
|
1701
|
+
resolve3();
|
|
1702
|
+
});
|
|
1703
|
+
probe.on("error", () => {
|
|
1704
|
+
try {
|
|
1705
|
+
unlinkSync(socketPath);
|
|
1706
|
+
} catch {
|
|
1707
|
+
}
|
|
1708
|
+
resolve3();
|
|
1709
|
+
});
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
return {
|
|
1713
|
+
async start() {
|
|
1714
|
+
mkdirSync(dirname4(socketPath), { recursive: true });
|
|
1715
|
+
await cleanStaleSocket();
|
|
1716
|
+
return new Promise((resolve3, reject) => {
|
|
1717
|
+
server = net.createServer(handleConnection);
|
|
1718
|
+
server.on("error", (err) => {
|
|
1719
|
+
if (err.code === "EADDRINUSE") {
|
|
1720
|
+
try {
|
|
1721
|
+
unlinkSync(socketPath);
|
|
1722
|
+
} catch {
|
|
1723
|
+
}
|
|
1724
|
+
server.listen(socketPath, () => resolve3());
|
|
1725
|
+
} else {
|
|
1726
|
+
reject(err);
|
|
1727
|
+
}
|
|
1728
|
+
});
|
|
1729
|
+
server.listen(socketPath, () => resolve3());
|
|
1730
|
+
});
|
|
1731
|
+
},
|
|
1732
|
+
async stop() {
|
|
1733
|
+
for (const conn of connections) {
|
|
1734
|
+
conn.destroy();
|
|
1735
|
+
}
|
|
1736
|
+
connections.clear();
|
|
1737
|
+
return new Promise((resolve3) => {
|
|
1738
|
+
if (!server) {
|
|
1739
|
+
resolve3();
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
server.close(() => {
|
|
1743
|
+
try {
|
|
1744
|
+
unlinkSync(socketPath);
|
|
1745
|
+
} catch {
|
|
1746
|
+
}
|
|
1747
|
+
server = null;
|
|
1748
|
+
resolve3();
|
|
1749
|
+
});
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1539
1754
|
|
|
1540
1755
|
// src/pipeline/engine.ts
|
|
1541
1756
|
async function executePipeline(pipeline, onProgress, cwd = process.cwd()) {
|
|
@@ -1590,32 +1805,8 @@ async function executePipeline(pipeline, onProgress, cwd = process.cwd()) {
|
|
|
1590
1805
|
}
|
|
1591
1806
|
|
|
1592
1807
|
// src/config/projectConfig.ts
|
|
1593
|
-
import { existsSync as
|
|
1594
|
-
import { join as
|
|
1595
|
-
|
|
1596
|
-
// src/lib/packageRoot.ts
|
|
1597
|
-
import { existsSync as existsSync4 } from "fs";
|
|
1598
|
-
import { dirname as dirname3, join as join4, resolve as resolve2 } from "path";
|
|
1599
|
-
var rootCache = /* @__PURE__ */ new Map();
|
|
1600
|
-
function findNearestPackageRoot(startDir = process.cwd()) {
|
|
1601
|
-
const resolvedStart = resolve2(startDir);
|
|
1602
|
-
if (rootCache.has(resolvedStart)) return rootCache.get(resolvedStart);
|
|
1603
|
-
let currentDir = resolvedStart;
|
|
1604
|
-
while (true) {
|
|
1605
|
-
if (existsSync4(join4(currentDir, "package.json"))) {
|
|
1606
|
-
rootCache.set(resolvedStart, currentDir);
|
|
1607
|
-
return currentDir;
|
|
1608
|
-
}
|
|
1609
|
-
const parentDir = dirname3(currentDir);
|
|
1610
|
-
if (parentDir === currentDir) {
|
|
1611
|
-
rootCache.set(resolvedStart, void 0);
|
|
1612
|
-
return void 0;
|
|
1613
|
-
}
|
|
1614
|
-
currentDir = parentDir;
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
|
-
// src/config/projectConfig.ts
|
|
1808
|
+
import { existsSync as existsSync6, readFileSync as readFileSync2, writeFileSync, mkdirSync as mkdirSync2 } from "fs";
|
|
1809
|
+
import { join as join6 } from "path";
|
|
1619
1810
|
var CONFIG_DIR = ".polter";
|
|
1620
1811
|
var CONFIG_FILE = "config.json";
|
|
1621
1812
|
function defaultConfig() {
|
|
@@ -1628,13 +1819,13 @@ function defaultConfig() {
|
|
|
1628
1819
|
function getProjectConfigPath(startDir) {
|
|
1629
1820
|
const root = findNearestPackageRoot(startDir);
|
|
1630
1821
|
if (!root) return void 0;
|
|
1631
|
-
const dir =
|
|
1632
|
-
return { dir, file:
|
|
1822
|
+
const dir = join6(root, CONFIG_DIR);
|
|
1823
|
+
return { dir, file: join6(dir, CONFIG_FILE) };
|
|
1633
1824
|
}
|
|
1634
1825
|
function readProjectConfig(startDir) {
|
|
1635
1826
|
const paths = getProjectConfigPath(startDir);
|
|
1636
1827
|
if (!paths) return void 0;
|
|
1637
|
-
if (!
|
|
1828
|
+
if (!existsSync6(paths.file)) return void 0;
|
|
1638
1829
|
try {
|
|
1639
1830
|
const raw = readFileSync2(paths.file, "utf-8");
|
|
1640
1831
|
return JSON.parse(raw);
|
|
@@ -1645,7 +1836,7 @@ function readProjectConfig(startDir) {
|
|
|
1645
1836
|
function writeProjectConfig(config2, startDir) {
|
|
1646
1837
|
const paths = getProjectConfigPath(startDir);
|
|
1647
1838
|
if (!paths) return false;
|
|
1648
|
-
|
|
1839
|
+
mkdirSync2(paths.dir, { recursive: true });
|
|
1649
1840
|
writeFileSync(paths.file, JSON.stringify(config2, null, 2) + "\n", "utf-8");
|
|
1650
1841
|
return true;
|
|
1651
1842
|
}
|
|
@@ -1735,8 +1926,8 @@ function findPipelineByName(name, startDir) {
|
|
|
1735
1926
|
}
|
|
1736
1927
|
|
|
1737
1928
|
// src/declarative/parser.ts
|
|
1738
|
-
import { existsSync as
|
|
1739
|
-
import { join as
|
|
1929
|
+
import { existsSync as existsSync7, readFileSync as readFileSync3 } from "fs";
|
|
1930
|
+
import { join as join7 } from "path";
|
|
1740
1931
|
var YAML_FILE = "polter.yaml";
|
|
1741
1932
|
function parseSimpleYaml(content) {
|
|
1742
1933
|
const lines = content.split("\n");
|
|
@@ -1808,8 +1999,8 @@ function parseValue(raw) {
|
|
|
1808
1999
|
return raw;
|
|
1809
2000
|
}
|
|
1810
2001
|
function findPolterYaml(startDir = process.cwd()) {
|
|
1811
|
-
const filePath =
|
|
1812
|
-
return
|
|
2002
|
+
const filePath = join7(startDir, YAML_FILE);
|
|
2003
|
+
return existsSync7(filePath) ? filePath : void 0;
|
|
1813
2004
|
}
|
|
1814
2005
|
function parsePolterYaml(startDir = process.cwd()) {
|
|
1815
2006
|
const filePath = findPolterYaml(startDir);
|
|
@@ -1955,16 +2146,16 @@ async function applyActions(actions, cwd = process.cwd(), onProgress) {
|
|
|
1955
2146
|
|
|
1956
2147
|
// src/lib/mcpInstaller.ts
|
|
1957
2148
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
1958
|
-
import { readFileSync as readFileSync4, writeFileSync as writeFileSync2, mkdirSync as
|
|
1959
|
-
import { join as
|
|
2149
|
+
import { readFileSync as readFileSync4, writeFileSync as writeFileSync2, mkdirSync as mkdirSync3, existsSync as existsSync8 } from "fs";
|
|
2150
|
+
import { join as join8, dirname as dirname5 } from "path";
|
|
1960
2151
|
import { fileURLToPath } from "url";
|
|
1961
2152
|
import { homedir } from "os";
|
|
1962
2153
|
import pc from "picocolors";
|
|
1963
|
-
var __dirname =
|
|
2154
|
+
var __dirname = dirname5(fileURLToPath(import.meta.url));
|
|
1964
2155
|
function readPkgVersion() {
|
|
1965
2156
|
for (const rel of ["../../package.json", "../package.json"]) {
|
|
1966
|
-
const p =
|
|
1967
|
-
if (
|
|
2157
|
+
const p = join8(__dirname, rel);
|
|
2158
|
+
if (existsSync8(p)) {
|
|
1968
2159
|
const pkg = JSON.parse(readFileSync4(p, "utf-8"));
|
|
1969
2160
|
return pkg.version;
|
|
1970
2161
|
}
|
|
@@ -1987,15 +2178,15 @@ function tryClaudeCli(scope) {
|
|
|
1987
2178
|
}
|
|
1988
2179
|
function getSettingsPath(scope) {
|
|
1989
2180
|
if (scope === "project") {
|
|
1990
|
-
return
|
|
2181
|
+
return join8(process.cwd(), ".mcp.json");
|
|
1991
2182
|
}
|
|
1992
|
-
return
|
|
2183
|
+
return join8(homedir(), ".claude", "settings.json");
|
|
1993
2184
|
}
|
|
1994
2185
|
function tryManualInstall(scope) {
|
|
1995
2186
|
const settingsPath = getSettingsPath(scope);
|
|
1996
|
-
const dir =
|
|
2187
|
+
const dir = join8(settingsPath, "..");
|
|
1997
2188
|
let settings = {};
|
|
1998
|
-
if (
|
|
2189
|
+
if (existsSync8(settingsPath)) {
|
|
1999
2190
|
try {
|
|
2000
2191
|
settings = JSON.parse(readFileSync4(settingsPath, "utf-8"));
|
|
2001
2192
|
} catch {
|
|
@@ -2004,7 +2195,7 @@ function tryManualInstall(scope) {
|
|
|
2004
2195
|
return false;
|
|
2005
2196
|
}
|
|
2006
2197
|
} else {
|
|
2007
|
-
|
|
2198
|
+
mkdirSync3(dir, { recursive: true });
|
|
2008
2199
|
}
|
|
2009
2200
|
const mcpServers = settings.mcpServers ?? {};
|
|
2010
2201
|
mcpServers.polter = {
|
|
@@ -2056,7 +2247,7 @@ async function removeMcpServer(scope) {
|
|
|
2056
2247
|
process.stdout.write(pc.yellow(" 'claude mcp remove' failed, falling back to manual removal...\n\n"));
|
|
2057
2248
|
}
|
|
2058
2249
|
const settingsPath = getSettingsPath(scope);
|
|
2059
|
-
if (!
|
|
2250
|
+
if (!existsSync8(settingsPath)) {
|
|
2060
2251
|
process.stdout.write(pc.yellow(" No settings file found. Nothing to remove.\n"));
|
|
2061
2252
|
return;
|
|
2062
2253
|
}
|
|
@@ -2082,11 +2273,11 @@ async function removeMcpServer(scope) {
|
|
|
2082
2273
|
function getMcpStatusInfo() {
|
|
2083
2274
|
const version = readPkgVersion();
|
|
2084
2275
|
const scopeDefs = [
|
|
2085
|
-
{ label: "Project (.mcp.json)", path:
|
|
2086
|
-
{ label: "User (~/.claude/settings.json)", path:
|
|
2276
|
+
{ label: "Project (.mcp.json)", path: join8(process.cwd(), ".mcp.json"), scope: "project" },
|
|
2277
|
+
{ label: "User (~/.claude/settings.json)", path: join8(homedir(), ".claude", "settings.json"), scope: "user" }
|
|
2087
2278
|
];
|
|
2088
2279
|
const scopes = scopeDefs.map((s) => {
|
|
2089
|
-
if (!
|
|
2280
|
+
if (!existsSync8(s.path)) {
|
|
2090
2281
|
return { label: s.label, scope: s.scope, registered: false };
|
|
2091
2282
|
}
|
|
2092
2283
|
try {
|
|
@@ -2133,7 +2324,7 @@ async function removeMcpServerSilent(scope) {
|
|
|
2133
2324
|
messages.push("'claude mcp remove' failed, falling back to manual removal...");
|
|
2134
2325
|
}
|
|
2135
2326
|
const settingsPath = getSettingsPath(scope);
|
|
2136
|
-
if (!
|
|
2327
|
+
if (!existsSync8(settingsPath)) {
|
|
2137
2328
|
messages.push("No settings file found. Nothing to remove.");
|
|
2138
2329
|
return { success: true, message: messages.join("\n") };
|
|
2139
2330
|
}
|
|
@@ -2172,11 +2363,11 @@ async function mcpStatus() {
|
|
|
2172
2363
|
}
|
|
2173
2364
|
process.stdout.write("\n");
|
|
2174
2365
|
const scopes = [
|
|
2175
|
-
{ label: "Project (.mcp.json)", path:
|
|
2176
|
-
{ label: "User (~/.claude/settings.json)", path:
|
|
2366
|
+
{ label: "Project (.mcp.json)", path: join8(process.cwd(), ".mcp.json"), key: "project" },
|
|
2367
|
+
{ label: "User (~/.claude/settings.json)", path: join8(homedir(), ".claude", "settings.json"), key: "user" }
|
|
2177
2368
|
];
|
|
2178
2369
|
for (const scope of scopes) {
|
|
2179
|
-
if (!
|
|
2370
|
+
if (!existsSync8(scope.path)) {
|
|
2180
2371
|
process.stdout.write(` ${scope.label}: ${pc.dim("not found")}
|
|
2181
2372
|
`);
|
|
2182
2373
|
continue;
|
|
@@ -2220,6 +2411,7 @@ export {
|
|
|
2220
2411
|
resolveToolCommand,
|
|
2221
2412
|
getToolInfo,
|
|
2222
2413
|
getToolLinkInfo,
|
|
2414
|
+
findNearestPackageRoot,
|
|
2223
2415
|
generateProcessId,
|
|
2224
2416
|
startProcess,
|
|
2225
2417
|
stopProcess,
|
|
@@ -2229,8 +2421,11 @@ export {
|
|
|
2229
2421
|
removeProcess,
|
|
2230
2422
|
findProcessesByCwd,
|
|
2231
2423
|
findRunningByCommand,
|
|
2424
|
+
getSocketPath,
|
|
2425
|
+
serializeMessage,
|
|
2426
|
+
parseMessages,
|
|
2427
|
+
createIpcServer,
|
|
2232
2428
|
executePipeline,
|
|
2233
|
-
findNearestPackageRoot,
|
|
2234
2429
|
getProjectConfigPath,
|
|
2235
2430
|
writeProjectConfig,
|
|
2236
2431
|
getOrCreateProjectConfig,
|