@cydm/magic-shell-agent-node 0.1.10 → 0.1.12

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.
@@ -1,8 +1,69 @@
1
1
  import { spawn } from "node-pty";
2
- import { dirname } from "path";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import path, { dirname } from "node:path";
3
5
  import { fileURLToPath } from "url";
4
6
  const __filename = fileURLToPath(import.meta.url);
5
7
  const __dirname = dirname(__filename);
8
+ const require = createRequire(import.meta.url);
9
+ function resolvePackageBinScript(packageName, binName) {
10
+ try {
11
+ const packageJsonPath = require.resolve(`${packageName}/package.json`);
12
+ const packageDir = path.dirname(packageJsonPath);
13
+ const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));
14
+ const binField = typeof pkg.bin === "string"
15
+ ? pkg.bin
16
+ : pkg.bin && typeof pkg.bin[binName] === "string"
17
+ ? pkg.bin[binName]
18
+ : null;
19
+ if (!binField)
20
+ return null;
21
+ const entry = path.resolve(packageDir, binField);
22
+ return existsSync(entry) ? entry : null;
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ }
28
+ function resolveWindowsCommand(command, args) {
29
+ if (!command || process.platform !== "win32") {
30
+ return { command, args };
31
+ }
32
+ if (command === "pie") {
33
+ const pieEntry = resolvePackageBinScript("@cydm/pie", "pie");
34
+ if (pieEntry) {
35
+ return {
36
+ command: process.execPath,
37
+ args: [pieEntry, ...args],
38
+ };
39
+ }
40
+ }
41
+ if (command.includes("\\") || command.includes("/") || /^[a-zA-Z]:/.test(command)) {
42
+ return { command, args };
43
+ }
44
+ const pathEntries = (process.env.PATH || "").split(";").filter(Boolean);
45
+ const pathext = (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD")
46
+ .split(";")
47
+ .map((value) => value.trim())
48
+ .filter(Boolean);
49
+ for (const entry of pathEntries) {
50
+ const bareCandidate = `${entry}\\${command}`;
51
+ if (existsSync(bareCandidate)) {
52
+ return { command: bareCandidate, args };
53
+ }
54
+ for (const ext of pathext) {
55
+ const candidate = `${entry}\\${command}${ext.toLowerCase()}`;
56
+ if (existsSync(candidate)) {
57
+ return { command: candidate, args };
58
+ }
59
+ const candidateUpper = `${entry}\\${command}${ext.toUpperCase()}`;
60
+ if (existsSync(candidateUpper)) {
61
+ return { command: candidateUpper, args };
62
+ }
63
+ }
64
+ }
65
+ return { command, args };
66
+ }
6
67
  export class PtyAdapter {
7
68
  name = "pty";
8
69
  description = "PTY native terminal adapter (supports vim, tmux)";
@@ -16,7 +77,8 @@ export class PtyAdapter {
16
77
  }
17
78
  async start(config) {
18
79
  const agentId = `pty-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
19
- const pty = spawn(config.command, config.args || [], {
80
+ const resolved = resolveWindowsCommand(config.command, config.args || []);
81
+ const pty = spawn(resolved.command, resolved.args, {
20
82
  name: "xterm-256color",
21
83
  cols: 80,
22
84
  rows: 24,
@@ -54,7 +116,7 @@ export class PtyAdapter {
54
116
  this.agents.delete(agentId);
55
117
  });
56
118
  this.agents.set(agentId, agent);
57
- console.log(`[PtyAdapter] Started ${agentId}: ${config.command}`);
119
+ console.log(`[PtyAdapter] Started ${agentId}: ${resolved.command}`);
58
120
  return agentId;
59
121
  }
60
122
  async stop(agentId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cydm/magic-shell-agent-node",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Magic Shell Agent Node - Local agent connector",
5
5
  "homepage": "https://magicshell.ai",
6
6
  "keywords": [