@maintainer-pro/ai-bridge 0.1.4 → 0.1.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/daemon.mjs +37 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maintainer-pro/ai-bridge",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Local bridge daemon that pairs a machine to Maintainer Pro and configures multiple client sandboxes.",
5
5
  "keywords": [
6
6
  "maintainer-pro",
package/src/daemon.mjs CHANGED
@@ -1081,12 +1081,32 @@ function planHostJobs(dir, appUrl, hints = null) {
1081
1081
 
1082
1082
  function friendlyLaunchError(raw, title) {
1083
1083
  const text = String(raw || "").trim();
1084
- if (/ENOENT/i.test(text)) {
1084
+ if (/^spawn\b.*\bENOENT\b/i.test(text)) {
1085
1085
  return `Could not find a program to open a terminal for "${title}". ${text}`;
1086
1086
  }
1087
1087
  return text || `Could not open a terminal for "${title}".`;
1088
1088
  }
1089
1089
 
1090
+ function writeWinLaunchScript(folder, title, command, env) {
1091
+ const dir = path.join(folder, ".maintainer-pro");
1092
+ fs.mkdirSync(dir, { recursive: true });
1093
+ const safe = String(title || "app").replace(/[^a-zA-Z0-9._-]+/g, "-");
1094
+ const file = path.join(dir, `launch-${safe}.cmd`);
1095
+ const folderArg = String(folder).replace(/"/g, "");
1096
+ const lines = [
1097
+ "@echo off",
1098
+ `cd /d "${folderArg}"`,
1099
+ ...Object.entries(env).map(
1100
+ ([key, value]) => `set "${key}=${String(value).replace(/"/g, "")}"`
1101
+ ),
1102
+ `title ${String(title || "Maintainer Pro").replace(/["&<>|^]/g, " ")}`,
1103
+ command,
1104
+ "if errorlevel 1 pause",
1105
+ ];
1106
+ fs.writeFileSync(file, `${lines.join("\r\n")}\r\n`, "utf8");
1107
+ return file;
1108
+ }
1109
+
1090
1110
  function runLauncher(command, args, extra = {}) {
1091
1111
  return new Promise((resolve) => {
1092
1112
  let settled = false;
@@ -1100,6 +1120,7 @@ function runLauncher(command, args, extra = {}) {
1100
1120
  child = spawn(command, args, {
1101
1121
  stdio: ["ignore", "pipe", "pipe"],
1102
1122
  windowsHide: extra.windowsHide,
1123
+ windowsVerbatimArguments: Boolean(extra.windowsVerbatimArguments),
1103
1124
  });
1104
1125
  } catch (err) {
1105
1126
  done({
@@ -1152,9 +1173,6 @@ async function openInNewTerminal(opts) {
1152
1173
  title
1153
1174
  );
1154
1175
 
1155
- const envWin = Object.entries(env)
1156
- .map(([key, value]) => `set ${key}=${value}`)
1157
- .join("&& ");
1158
1176
  const envUnix = Object.entries(env)
1159
1177
  .map(([key, value]) => `export ${key}=${JSON.stringify(String(value))}`)
1160
1178
  .join(" && ");
@@ -1163,15 +1181,21 @@ async function openInNewTerminal(opts) {
1163
1181
 
1164
1182
  try {
1165
1183
  if (process.platform === "win32") {
1166
- const inner = `cd /d "${folder}" && ${envWin ? `${envWin}&& ` : ""}title ${title}&& ${command}`;
1167
- const opened = await runLauncher(process.env.ComSpec || "cmd.exe", [
1168
- "/c",
1169
- "start",
1170
- title,
1171
- "cmd.exe",
1172
- "/k",
1173
- inner,
1174
- ]);
1184
+ const safeTitle =
1185
+ String(title || "Maintainer Pro").replace(/["&<>|^]/g, " ").trim() ||
1186
+ "Maintainer Pro";
1187
+ const script = writeWinLaunchScript(folder, safeTitle, command, env);
1188
+ const scriptName = path.basename(script);
1189
+ const opened = await runLauncher(
1190
+ process.env.ComSpec || "cmd.exe",
1191
+ [
1192
+ "/d",
1193
+ "/s",
1194
+ "/c",
1195
+ `start "${safeTitle}" /D "${folder}" cmd.exe /k ".maintainer-pro\\${scriptName}"`,
1196
+ ],
1197
+ { windowsVerbatimArguments: true }
1198
+ );
1175
1199
  if (!opened.ok) {
1176
1200
  return { ok: false, error: friendlyLaunchError(opened.error, title) };
1177
1201
  }