@polterware/polter 0.4.0 → 0.4.2
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 +19 -2
- package/dist/{chunk-YNOZDU75.js → chunk-CWBIXRZP.js} +410 -55
- package/dist/chunk-XCCKD3RZ.js +108 -0
- package/dist/index.js +552 -334
- package/dist/mcp.js +100 -24
- package/package.json +1 -1
- package/dist/chunk-AGVTFYXU.js +0 -0
package/dist/mcp.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
createIpcClient
|
|
4
|
+
} from "./chunk-XCCKD3RZ.js";
|
|
3
5
|
import {
|
|
4
6
|
__export,
|
|
5
7
|
allCommands,
|
|
@@ -16,6 +18,7 @@ import {
|
|
|
16
18
|
getCommandsByTool,
|
|
17
19
|
getCurrentStatus,
|
|
18
20
|
getProcessOutput,
|
|
21
|
+
getSocketPath,
|
|
19
22
|
getToolInfo,
|
|
20
23
|
listProcesses,
|
|
21
24
|
parsePolterYaml,
|
|
@@ -27,7 +30,7 @@ import {
|
|
|
27
30
|
startProcess,
|
|
28
31
|
stopProcess,
|
|
29
32
|
translateCommand
|
|
30
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-CWBIXRZP.js";
|
|
31
34
|
|
|
32
35
|
// src/mcp.ts
|
|
33
36
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
@@ -13806,6 +13809,19 @@ import crypto from "crypto";
|
|
|
13806
13809
|
import { readFileSync, existsSync } from "fs";
|
|
13807
13810
|
import { join } from "path";
|
|
13808
13811
|
var TOOL_IDS = ["supabase", "gh", "vercel", "git", "pkg"];
|
|
13812
|
+
async function withTuiConnection(method, params, fallback) {
|
|
13813
|
+
const socketPath = getSocketPath();
|
|
13814
|
+
if (!socketPath) return fallback();
|
|
13815
|
+
try {
|
|
13816
|
+
const client = createIpcClient(socketPath);
|
|
13817
|
+
await client.connect();
|
|
13818
|
+
const result = await client.call(method, params);
|
|
13819
|
+
client.disconnect();
|
|
13820
|
+
return result;
|
|
13821
|
+
} catch {
|
|
13822
|
+
return fallback();
|
|
13823
|
+
}
|
|
13824
|
+
}
|
|
13809
13825
|
var server = new McpServer({
|
|
13810
13826
|
name: "polter",
|
|
13811
13827
|
version: "0.1.0"
|
|
@@ -14150,29 +14166,47 @@ server.tool(
|
|
|
14150
14166
|
const mgr = detectPkgManager(cwd);
|
|
14151
14167
|
try {
|
|
14152
14168
|
const translated = translateCommand(["run", script, ...extraArgs ?? []], mgr.id);
|
|
14153
|
-
const existing =
|
|
14169
|
+
const existing = await withTuiConnection(
|
|
14170
|
+
"ps.find_running",
|
|
14171
|
+
{ cwd, command: mgr.command, args: translated.args },
|
|
14172
|
+
() => findRunningByCommand(cwd, mgr.command, translated.args)
|
|
14173
|
+
);
|
|
14154
14174
|
if (existing) {
|
|
14175
|
+
const output2 = await withTuiConnection(
|
|
14176
|
+
"ps.logs",
|
|
14177
|
+
{ id: existing.id, tail: 20 },
|
|
14178
|
+
() => getProcessOutput(existing.id, 20)
|
|
14179
|
+
);
|
|
14155
14180
|
return {
|
|
14156
14181
|
content: [{
|
|
14157
14182
|
type: "text",
|
|
14158
14183
|
text: JSON.stringify({
|
|
14159
14184
|
alreadyRunning: true,
|
|
14160
14185
|
process: existing,
|
|
14161
|
-
output:
|
|
14186
|
+
output: output2
|
|
14162
14187
|
}, null, 2)
|
|
14163
14188
|
}]
|
|
14164
14189
|
};
|
|
14165
14190
|
}
|
|
14166
14191
|
const id = generateProcessId(mgr.command, translated.args);
|
|
14167
|
-
const info =
|
|
14192
|
+
const info = await withTuiConnection(
|
|
14193
|
+
"ps.start",
|
|
14194
|
+
{ command: mgr.command, args: translated.args, cwd, id },
|
|
14195
|
+
() => startProcess(id, mgr.command, translated.args, cwd)
|
|
14196
|
+
);
|
|
14168
14197
|
await new Promise((r) => setTimeout(r, 500));
|
|
14198
|
+
const output = await withTuiConnection(
|
|
14199
|
+
"ps.logs",
|
|
14200
|
+
{ id, tail: 20 },
|
|
14201
|
+
() => getProcessOutput(id, 20)
|
|
14202
|
+
);
|
|
14169
14203
|
return {
|
|
14170
14204
|
content: [{
|
|
14171
14205
|
type: "text",
|
|
14172
14206
|
text: JSON.stringify({
|
|
14173
14207
|
success: true,
|
|
14174
14208
|
process: info,
|
|
14175
|
-
output
|
|
14209
|
+
output,
|
|
14176
14210
|
packageManager: mgr.id
|
|
14177
14211
|
}, null, 2)
|
|
14178
14212
|
}]
|
|
@@ -14310,7 +14344,7 @@ server.tool(
|
|
|
14310
14344
|
"List all tracked background processes with their status, PID, uptime, and exit info.",
|
|
14311
14345
|
{},
|
|
14312
14346
|
async () => {
|
|
14313
|
-
const processes = listProcesses();
|
|
14347
|
+
const processes = await withTuiConnection("ps.list", {}, () => listProcesses());
|
|
14314
14348
|
return {
|
|
14315
14349
|
content: [{ type: "text", text: JSON.stringify(processes, null, 2) }]
|
|
14316
14350
|
};
|
|
@@ -14330,7 +14364,11 @@ server.tool(
|
|
|
14330
14364
|
const processId = id ?? generateProcessId(command, processArgs);
|
|
14331
14365
|
const processCwd = cwd ?? process.cwd();
|
|
14332
14366
|
try {
|
|
14333
|
-
const info =
|
|
14367
|
+
const info = await withTuiConnection(
|
|
14368
|
+
"ps.start",
|
|
14369
|
+
{ command, args: processArgs, cwd: processCwd, id: processId },
|
|
14370
|
+
() => startProcess(processId, command, processArgs, processCwd)
|
|
14371
|
+
);
|
|
14334
14372
|
return {
|
|
14335
14373
|
content: [{ type: "text", text: JSON.stringify({ success: true, process: info }, null, 2) }]
|
|
14336
14374
|
};
|
|
@@ -14352,7 +14390,11 @@ server.tool(
|
|
|
14352
14390
|
},
|
|
14353
14391
|
async ({ id, tail, stream }) => {
|
|
14354
14392
|
try {
|
|
14355
|
-
const output =
|
|
14393
|
+
const output = await withTuiConnection(
|
|
14394
|
+
"ps.logs",
|
|
14395
|
+
{ id, ...tail !== void 0 ? { tail } : {}, ...stream !== void 0 ? { stream } : {} },
|
|
14396
|
+
() => getProcessOutput(id, tail, stream)
|
|
14397
|
+
);
|
|
14356
14398
|
return {
|
|
14357
14399
|
content: [{ type: "text", text: JSON.stringify(output, null, 2) }]
|
|
14358
14400
|
};
|
|
@@ -14372,7 +14414,11 @@ server.tool(
|
|
|
14372
14414
|
},
|
|
14373
14415
|
async ({ id }) => {
|
|
14374
14416
|
try {
|
|
14375
|
-
const info = await
|
|
14417
|
+
const info = await withTuiConnection(
|
|
14418
|
+
"ps.stop",
|
|
14419
|
+
{ id },
|
|
14420
|
+
() => stopProcess(id)
|
|
14421
|
+
);
|
|
14376
14422
|
return {
|
|
14377
14423
|
content: [{ type: "text", text: JSON.stringify({ success: true, process: info }, null, 2) }]
|
|
14378
14424
|
};
|
|
@@ -14416,30 +14462,48 @@ server.tool(
|
|
|
14416
14462
|
}
|
|
14417
14463
|
const mgr = detectPkgManager(cwd);
|
|
14418
14464
|
const runArgs = ["run", script];
|
|
14419
|
-
const existing =
|
|
14465
|
+
const existing = await withTuiConnection(
|
|
14466
|
+
"ps.find_running",
|
|
14467
|
+
{ cwd, command: mgr.command, args: runArgs },
|
|
14468
|
+
() => findRunningByCommand(cwd, mgr.command, runArgs)
|
|
14469
|
+
);
|
|
14420
14470
|
if (existing) {
|
|
14471
|
+
const output = await withTuiConnection(
|
|
14472
|
+
"ps.logs",
|
|
14473
|
+
{ id: existing.id, tail },
|
|
14474
|
+
() => getProcessOutput(existing.id, tail)
|
|
14475
|
+
);
|
|
14421
14476
|
return {
|
|
14422
14477
|
content: [{
|
|
14423
14478
|
type: "text",
|
|
14424
14479
|
text: JSON.stringify({
|
|
14425
14480
|
alreadyRunning: true,
|
|
14426
14481
|
process: existing,
|
|
14427
|
-
output
|
|
14482
|
+
output
|
|
14428
14483
|
}, null, 2)
|
|
14429
14484
|
}]
|
|
14430
14485
|
};
|
|
14431
14486
|
}
|
|
14432
14487
|
try {
|
|
14433
14488
|
const id = generateProcessId(mgr.command, runArgs);
|
|
14434
|
-
const info =
|
|
14489
|
+
const info = await withTuiConnection(
|
|
14490
|
+
"ps.start",
|
|
14491
|
+
{ command: mgr.command, args: runArgs, cwd, id },
|
|
14492
|
+
() => startProcess(id, mgr.command, runArgs, cwd)
|
|
14493
|
+
);
|
|
14435
14494
|
await new Promise((r) => setTimeout(r, 500));
|
|
14495
|
+
const output = await withTuiConnection(
|
|
14496
|
+
"ps.logs",
|
|
14497
|
+
{ id, tail },
|
|
14498
|
+
() => getProcessOutput(id, tail)
|
|
14499
|
+
);
|
|
14436
14500
|
return {
|
|
14437
14501
|
content: [{
|
|
14438
14502
|
type: "text",
|
|
14439
14503
|
text: JSON.stringify({
|
|
14440
14504
|
alreadyRunning: false,
|
|
14441
14505
|
process: info,
|
|
14442
|
-
output
|
|
14506
|
+
output,
|
|
14443
14507
|
packageManager: mgr.id
|
|
14444
14508
|
}, null, 2)
|
|
14445
14509
|
}]
|
|
@@ -14462,19 +14526,31 @@ server.tool(
|
|
|
14462
14526
|
},
|
|
14463
14527
|
async ({ cwd: cwdArg, filter, tail }) => {
|
|
14464
14528
|
const cwd = cwdArg ?? process.cwd();
|
|
14465
|
-
|
|
14466
|
-
|
|
14467
|
-
|
|
14468
|
-
|
|
14469
|
-
|
|
14529
|
+
const processes = await withTuiConnection(
|
|
14530
|
+
"ps.find_by_cwd",
|
|
14531
|
+
{ cwd, ...filter ? { filter } : {} },
|
|
14532
|
+
() => {
|
|
14533
|
+
let procs = findProcessesByCwd(cwd);
|
|
14534
|
+
if (filter) {
|
|
14535
|
+
const f = filter.toLowerCase();
|
|
14536
|
+
procs = procs.filter(
|
|
14537
|
+
(proc) => (proc.command + " " + proc.args.join(" ")).toLowerCase().includes(f)
|
|
14538
|
+
);
|
|
14539
|
+
}
|
|
14540
|
+
return procs;
|
|
14541
|
+
}
|
|
14542
|
+
);
|
|
14543
|
+
const results = [];
|
|
14544
|
+
for (const proc of processes) {
|
|
14545
|
+
const output = await withTuiConnection(
|
|
14546
|
+
"ps.logs",
|
|
14547
|
+
{ id: proc.id, tail },
|
|
14548
|
+
() => getProcessOutput(proc.id, tail)
|
|
14470
14549
|
);
|
|
14550
|
+
results.push({ process: proc, output });
|
|
14471
14551
|
}
|
|
14472
|
-
const result = processes.map((proc) => ({
|
|
14473
|
-
process: proc,
|
|
14474
|
-
output: getProcessOutput(proc.id, tail)
|
|
14475
|
-
}));
|
|
14476
14552
|
return {
|
|
14477
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
14553
|
+
content: [{ type: "text", text: JSON.stringify(results, null, 2) }]
|
|
14478
14554
|
};
|
|
14479
14555
|
}
|
|
14480
14556
|
);
|
package/package.json
CHANGED
package/dist/chunk-AGVTFYXU.js
DELETED
|
File without changes
|