docdex 0.2.7 → 0.2.9

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Changelog
2
2
 
3
- ## 0.2.7
3
+ ## 0.2.9
4
4
  - Added glama support
5
5
 
6
6
  ## 0.1.10
package/lib/install.js CHANGED
@@ -427,6 +427,15 @@ async function installFromLocalBinary({
427
427
  if (!isWin32) {
428
428
  await fsModule.promises.chmod(destPath, 0o755).catch(() => {});
429
429
  }
430
+ const mcpName = isWin32 ? "docdex-mcp-server.exe" : "docdex-mcp-server";
431
+ const mcpSource = pathModule.join(pathModule.dirname(binaryPath), mcpName);
432
+ if (fsModule.existsSync(mcpSource)) {
433
+ const mcpDest = pathModule.join(distDir, mcpName);
434
+ await fsModule.promises.copyFile(mcpSource, mcpDest);
435
+ if (!isWin32) {
436
+ await fsModule.promises.chmod(mcpDest, 0o755).catch(() => {});
437
+ }
438
+ }
430
439
  const binarySha256 = await sha256FileFn(destPath);
431
440
  const metadata = {
432
441
  schemaVersion: INSTALL_METADATA_SCHEMA_VERSION,
@@ -1063,6 +1063,49 @@ function shouldSkipSetup(env = process.env) {
1063
1063
  return parseEnvBool(env.DOCDEX_SETUP_SKIP) === true;
1064
1064
  }
1065
1065
 
1066
+ function commandExists(cmd, spawnSyncFn) {
1067
+ const result = spawnSyncFn(cmd, ["--version"], { stdio: "ignore" });
1068
+ if (result?.error?.code === "ENOENT") return false;
1069
+ return true;
1070
+ }
1071
+
1072
+ function launchMacTerminal({ binaryPath, args, spawnSyncFn, logger }) {
1073
+ const command = [binaryPath, ...args].join(" ");
1074
+ const script = [
1075
+ 'tell application "Terminal" to activate',
1076
+ `tell application "Terminal" to do script ${JSON.stringify(command)}`
1077
+ ].join("\n");
1078
+ const result = spawnSyncFn("osascript", ["-e", script]);
1079
+ if (result.status === 0) return true;
1080
+ logger?.warn?.(`[docdex] osascript launch failed: ${result.stderr || "unknown error"}`);
1081
+ return false;
1082
+ }
1083
+
1084
+ function launchLinuxTerminal({ binaryPath, args, spawnFn, spawnSyncFn }) {
1085
+ const candidates = [
1086
+ { cmd: "x-terminal-emulator", args: ["-e", binaryPath, ...args] },
1087
+ { cmd: "gnome-terminal", args: ["--", binaryPath, ...args] },
1088
+ { cmd: "konsole", args: ["-e", binaryPath, ...args] },
1089
+ { cmd: "xfce4-terminal", args: ["-e", binaryPath, ...args] },
1090
+ { cmd: "xterm", args: ["-e", binaryPath, ...args] },
1091
+ { cmd: "kitty", args: ["-e", binaryPath, ...args] },
1092
+ { cmd: "alacritty", args: ["-e", binaryPath, ...args] },
1093
+ { cmd: "wezterm", args: ["start", "--", binaryPath, ...args] }
1094
+ ];
1095
+ for (const candidate of candidates) {
1096
+ if (!commandExists(candidate.cmd, spawnSyncFn)) continue;
1097
+ const child = spawnFn(candidate.cmd, candidate.args, {
1098
+ stdio: "ignore",
1099
+ detached: true
1100
+ });
1101
+ if (child?.pid) {
1102
+ child.unref?.();
1103
+ return true;
1104
+ }
1105
+ }
1106
+ return false;
1107
+ }
1108
+
1066
1109
  function launchSetupWizard({
1067
1110
  binaryPath,
1068
1111
  logger,
@@ -1078,26 +1121,18 @@ function launchSetupWizard({
1078
1121
  if (shouldSkipSetup(env)) return { ok: false, reason: "skipped" };
1079
1122
 
1080
1123
  const args = ["setup"];
1081
- if (platform === "linux") {
1124
+ if (platform === "linux" || platform === "darwin") {
1082
1125
  if (!canPrompt(stdin, stdout)) {
1083
1126
  return { ok: false, reason: "non_interactive" };
1084
1127
  }
1085
- const child = spawnFn(binaryPath, args, { stdio: "inherit" });
1086
- if (child.pid) return { ok: true };
1087
- return { ok: false, reason: "spawn_failed" };
1088
- }
1089
-
1090
- if (platform === "darwin") {
1091
- const command = `${binaryPath} ${args.join(" ")}`;
1092
- const osa = [
1093
- "osascript",
1094
- "-e",
1095
- `tell application \"Terminal\" to do script \"${command.replace(/"/g, '\\"')}\"`
1096
- ];
1097
- const result = spawnSyncFn(osa[0], osa.slice(1));
1098
- if (result.status === 0) return { ok: true };
1099
- logger?.warn?.(`[docdex] osascript failed: ${result.stderr || "unknown error"}`);
1100
- return { ok: false, reason: "terminal_launch_failed" };
1128
+ if (platform === "darwin") {
1129
+ return launchMacTerminal({ binaryPath, args, spawnSyncFn, logger })
1130
+ ? { ok: true }
1131
+ : { ok: false, reason: "terminal_launch_failed" };
1132
+ }
1133
+ return launchLinuxTerminal({ binaryPath, args, spawnFn, spawnSyncFn })
1134
+ ? { ok: true }
1135
+ : { ok: false, reason: "terminal_launch_failed" };
1101
1136
  }
1102
1137
 
1103
1138
  if (platform === "win32") {
package/lib/uninstall.js CHANGED
@@ -206,9 +206,68 @@ function removeCodexConfig(pathname, name = "docdex") {
206
206
  return output.join("\n");
207
207
  };
208
208
 
209
+ const removeLooseEntry = (text) => {
210
+ const lines = text.split(/\r?\n/);
211
+ const output = [];
212
+ let changed = false;
213
+ for (const line of lines) {
214
+ if (/^\s*docdex\s*=/.test(line)) {
215
+ changed = true;
216
+ continue;
217
+ }
218
+ output.push(line);
219
+ }
220
+ return { text: output.join("\n"), changed };
221
+ };
222
+
223
+ const removeEmptyMcpServersTable = (text) => {
224
+ const lines = text.split(/\r?\n/);
225
+ const output = [];
226
+ let inTable = false;
227
+ let tableHasEntries = false;
228
+ let buffer = [];
229
+
230
+ const flushTable = () => {
231
+ if (!inTable) return;
232
+ if (tableHasEntries) output.push(...buffer);
233
+ inTable = false;
234
+ tableHasEntries = false;
235
+ buffer = [];
236
+ };
237
+
238
+ for (const line of lines) {
239
+ const section = line.match(/^\s*\[([^\]]+)\]\s*$/);
240
+ if (section) {
241
+ flushTable();
242
+ if (section[1].trim() === "mcp_servers") {
243
+ inTable = true;
244
+ buffer = [line];
245
+ continue;
246
+ }
247
+ output.push(line);
248
+ continue;
249
+ }
250
+
251
+ if (inTable) {
252
+ if (line.trim() && !line.trim().startsWith("#")) {
253
+ if (/=/.test(line)) tableHasEntries = true;
254
+ }
255
+ buffer.push(line);
256
+ continue;
257
+ }
258
+
259
+ output.push(line);
260
+ }
261
+ flushTable();
262
+ return output.join("\n");
263
+ };
264
+
209
265
  contents = removeArrayBlocks(contents);
210
266
  contents = removeNestedSection(contents);
211
267
  contents = removeTableEntry(contents);
268
+ const loose = removeLooseEntry(contents);
269
+ contents = loose.text;
270
+ contents = removeEmptyMcpServersTable(contents);
212
271
 
213
272
  if (contents !== original) {
214
273
  fs.writeFileSync(pathname, contents.endsWith("\n") ? contents : `${contents}\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docdex",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "mcpName": "io.github.bekirdag/docdex",
5
5
  "description": "Docdex CLI as an npm-installable binary wrapper.",
6
6
  "bin": {