@cydm/magic-shell-agent-node 0.1.10 → 0.1.11
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/adapters/pty-adapter.js +34 -2
- package/package.json +1 -1
|
@@ -1,8 +1,39 @@
|
|
|
1
1
|
import { spawn } from "node-pty";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
2
3
|
import { dirname } from "path";
|
|
3
4
|
import { fileURLToPath } from "url";
|
|
4
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
5
6
|
const __dirname = dirname(__filename);
|
|
7
|
+
function resolveExecutableCommand(command) {
|
|
8
|
+
if (!command || process.platform !== "win32") {
|
|
9
|
+
return command;
|
|
10
|
+
}
|
|
11
|
+
if (command.includes("\\") || command.includes("/") || /^[a-zA-Z]:/.test(command)) {
|
|
12
|
+
return command;
|
|
13
|
+
}
|
|
14
|
+
const pathEntries = (process.env.PATH || "").split(";").filter(Boolean);
|
|
15
|
+
const pathext = (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD")
|
|
16
|
+
.split(";")
|
|
17
|
+
.map((value) => value.trim())
|
|
18
|
+
.filter(Boolean);
|
|
19
|
+
for (const entry of pathEntries) {
|
|
20
|
+
const bareCandidate = `${entry}\\${command}`;
|
|
21
|
+
if (existsSync(bareCandidate)) {
|
|
22
|
+
return bareCandidate;
|
|
23
|
+
}
|
|
24
|
+
for (const ext of pathext) {
|
|
25
|
+
const candidate = `${entry}\\${command}${ext.toLowerCase()}`;
|
|
26
|
+
if (existsSync(candidate)) {
|
|
27
|
+
return candidate;
|
|
28
|
+
}
|
|
29
|
+
const candidateUpper = `${entry}\\${command}${ext.toUpperCase()}`;
|
|
30
|
+
if (existsSync(candidateUpper)) {
|
|
31
|
+
return candidateUpper;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return command;
|
|
36
|
+
}
|
|
6
37
|
export class PtyAdapter {
|
|
7
38
|
name = "pty";
|
|
8
39
|
description = "PTY native terminal adapter (supports vim, tmux)";
|
|
@@ -16,7 +47,8 @@ export class PtyAdapter {
|
|
|
16
47
|
}
|
|
17
48
|
async start(config) {
|
|
18
49
|
const agentId = `pty-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
19
|
-
const
|
|
50
|
+
const resolvedCommand = resolveExecutableCommand(config.command);
|
|
51
|
+
const pty = spawn(resolvedCommand, config.args || [], {
|
|
20
52
|
name: "xterm-256color",
|
|
21
53
|
cols: 80,
|
|
22
54
|
rows: 24,
|
|
@@ -54,7 +86,7 @@ export class PtyAdapter {
|
|
|
54
86
|
this.agents.delete(agentId);
|
|
55
87
|
});
|
|
56
88
|
this.agents.set(agentId, agent);
|
|
57
|
-
console.log(`[PtyAdapter] Started ${agentId}: ${
|
|
89
|
+
console.log(`[PtyAdapter] Started ${agentId}: ${resolvedCommand}`);
|
|
58
90
|
return agentId;
|
|
59
91
|
}
|
|
60
92
|
async stop(agentId) {
|