@cydm/magic-shell-agent-node 0.1.9 → 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.
@@ -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 pty = spawn(config.command, config.args || [], {
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}: ${config.command}`);
89
+ console.log(`[PtyAdapter] Started ${agentId}: ${resolvedCommand}`);
58
90
  return agentId;
59
91
  }
60
92
  async stop(agentId) {
package/dist/node.js CHANGED
@@ -642,6 +642,7 @@ export class AgentNode {
642
642
  const displayName = this.readString(payload.displayName) || message.displayName;
643
643
  const sessionId = this.readString(payload.sessionId) || message.target?.sessionId || generateSessionId();
644
644
  try {
645
+ console.log(`[AgentNode] spawn_worker request session=${sessionId} plugin=${pluginName} cwd=${cwd || ""}`);
645
646
  await this.spawnWorker({ sessionId, pluginName, cwd, displayName, taskSummary });
646
647
  if (taskSummary) {
647
648
  this.rememberNodeSpawn(taskSummary, sessionId);
@@ -654,8 +655,11 @@ export class AgentNode {
654
655
  });
655
656
  }
656
657
  catch (err) {
658
+ console.error(`[AgentNode] spawn_worker failed session=${sessionId} plugin=${pluginName}:`, err);
657
659
  this.sendControlResult(source, message.requestId, name, false, {
658
660
  error: err instanceof Error ? err.message : String(err),
661
+ sessionId,
662
+ pluginName,
659
663
  });
660
664
  }
661
665
  return;
@@ -134,6 +134,24 @@
134
134
  return true;
135
135
  }
136
136
 
137
+ if (msg.controlKind === "result" && msg.controlName === "spawn_worker") {
138
+ if (msg.ok === false) {
139
+ const requestedSessionId = msg.payload?.sessionId || msg.sessionId || ctx.pendingSpawnSessionId;
140
+ if (!requestedSessionId || requestedSessionId === ctx.pendingSpawnSessionId) {
141
+ ctx.pendingSpawnSessionId = null;
142
+ ctx.pendingSpawnAutoAttach = true;
143
+ ctx.resetSpawnButton();
144
+ }
145
+ ctx.writeSystemNotice(`WORKER SPAWN FAILED: ${msg.error || msg.payload?.error || "Unknown error"}`);
146
+ if (ctx.sessionId && ctx.sessionId === requestedSessionId) {
147
+ ctx.returnToPrimaryChat({ clearSession: true });
148
+ }
149
+ ctx.renderWorkers();
150
+ return true;
151
+ }
152
+ return true;
153
+ }
154
+
137
155
  if (msg.controlKind === "result" && msg.controlName === "get_worker_detail" && msg.payload && msg.payload.worker) {
138
156
  ctx.workerDetail = msg.payload.worker || null;
139
157
  ctx.renderWorkerDetailPanel();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cydm/magic-shell-agent-node",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Magic Shell Agent Node - Local agent connector",
5
5
  "homepage": "https://magicshell.ai",
6
6
  "keywords": [