@cydm/magic-shell-agent-node 0.1.11 → 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,15 +1,45 @@
1
1
  import { spawn } from "node-pty";
2
- import { existsSync } from "node:fs";
3
- import { dirname } from "path";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import path, { dirname } from "node:path";
4
5
  import { fileURLToPath } from "url";
5
6
  const __filename = fileURLToPath(import.meta.url);
6
7
  const __dirname = dirname(__filename);
7
- function resolveExecutableCommand(command) {
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) {
8
29
  if (!command || process.platform !== "win32") {
9
- return command;
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
+ }
10
40
  }
11
41
  if (command.includes("\\") || command.includes("/") || /^[a-zA-Z]:/.test(command)) {
12
- return command;
42
+ return { command, args };
13
43
  }
14
44
  const pathEntries = (process.env.PATH || "").split(";").filter(Boolean);
15
45
  const pathext = (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD")
@@ -19,20 +49,20 @@ function resolveExecutableCommand(command) {
19
49
  for (const entry of pathEntries) {
20
50
  const bareCandidate = `${entry}\\${command}`;
21
51
  if (existsSync(bareCandidate)) {
22
- return bareCandidate;
52
+ return { command: bareCandidate, args };
23
53
  }
24
54
  for (const ext of pathext) {
25
55
  const candidate = `${entry}\\${command}${ext.toLowerCase()}`;
26
56
  if (existsSync(candidate)) {
27
- return candidate;
57
+ return { command: candidate, args };
28
58
  }
29
59
  const candidateUpper = `${entry}\\${command}${ext.toUpperCase()}`;
30
60
  if (existsSync(candidateUpper)) {
31
- return candidateUpper;
61
+ return { command: candidateUpper, args };
32
62
  }
33
63
  }
34
64
  }
35
- return command;
65
+ return { command, args };
36
66
  }
37
67
  export class PtyAdapter {
38
68
  name = "pty";
@@ -47,8 +77,8 @@ export class PtyAdapter {
47
77
  }
48
78
  async start(config) {
49
79
  const agentId = `pty-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
50
- const resolvedCommand = resolveExecutableCommand(config.command);
51
- const pty = spawn(resolvedCommand, config.args || [], {
80
+ const resolved = resolveWindowsCommand(config.command, config.args || []);
81
+ const pty = spawn(resolved.command, resolved.args, {
52
82
  name: "xterm-256color",
53
83
  cols: 80,
54
84
  rows: 24,
@@ -86,7 +116,7 @@ export class PtyAdapter {
86
116
  this.agents.delete(agentId);
87
117
  });
88
118
  this.agents.set(agentId, agent);
89
- console.log(`[PtyAdapter] Started ${agentId}: ${resolvedCommand}`);
119
+ console.log(`[PtyAdapter] Started ${agentId}: ${resolved.command}`);
90
120
  return agentId;
91
121
  }
92
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.11",
3
+ "version": "0.1.12",
4
4
  "description": "Magic Shell Agent Node - Local agent connector",
5
5
  "homepage": "https://magicshell.ai",
6
6
  "keywords": [