@whenlabs/when 0.8.0 → 0.8.1

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.
@@ -2,15 +2,18 @@
2
2
 
3
3
  // src/utils/mcp-config.ts
4
4
  import { execSync } from "child_process";
5
+ import { existsSync, readFileSync, writeFileSync } from "fs";
6
+ import { resolve } from "path";
5
7
  function registerServer(name, command) {
8
+ try {
9
+ execSync(`claude mcp remove -s user ${name}`, { stdio: "pipe" });
10
+ } catch {
11
+ }
6
12
  try {
7
13
  execSync(`claude mcp add -s user ${name} -- ${command}`, { stdio: "pipe" });
8
- return { success: true, message: `MCP server "${name}" registered successfully.` };
14
+ return { success: true, message: `MCP server "${name}" registered.` };
9
15
  } catch (err) {
10
16
  const output = err instanceof Error && "stderr" in err ? err.stderr?.toString() ?? "" : "";
11
- if (output.includes("already exists") || output.includes("already registered")) {
12
- return { success: true, message: `MCP server "${name}" is already registered.` };
13
- }
14
17
  return {
15
18
  success: false,
16
19
  message: `Failed to register "${name}": ${output || (err instanceof Error ? err.message : String(err))}`
@@ -32,12 +35,36 @@ function unregisterServer(name) {
32
35
  };
33
36
  }
34
37
  }
38
+ function cleanLegacyMcpJson() {
39
+ let dir = process.cwd();
40
+ const root = resolve("/");
41
+ while (dir !== root) {
42
+ const mcpJson = resolve(dir, ".mcp.json");
43
+ if (existsSync(mcpJson)) {
44
+ try {
45
+ const data = JSON.parse(readFileSync(mcpJson, "utf-8"));
46
+ if (data?.mcpServers?.["velocity-mcp"]) {
47
+ delete data.mcpServers["velocity-mcp"];
48
+ writeFileSync(mcpJson, JSON.stringify(data, null, 2) + "\n", "utf-8");
49
+ return mcpJson;
50
+ }
51
+ } catch {
52
+ }
53
+ }
54
+ dir = resolve(dir, "..");
55
+ }
56
+ return null;
57
+ }
35
58
  function registerMcpServer() {
36
59
  const whenlabs = registerServer("whenlabs", "npx @whenlabs/when when-mcp");
37
60
  const legacyCleanup = unregisterServer("velocity-mcp");
61
+ const cleanedFile = cleanLegacyMcpJson();
38
62
  const messages = [whenlabs.message];
39
63
  if (legacyCleanup.success && !legacyCleanup.message.includes("was not registered")) {
40
- messages.push("Removed legacy standalone velocity-mcp (now bundled in whenlabs)");
64
+ messages.push("Removed legacy velocity-mcp from user config (now bundled in whenlabs)");
65
+ }
66
+ if (cleanedFile) {
67
+ messages.push(`Removed legacy velocity-mcp from ${cleanedFile}`);
41
68
  }
42
69
  return {
43
70
  success: whenlabs.success,
@@ -60,7 +87,7 @@ function unregisterMcpServer() {
60
87
  // src/utils/editor-config.ts
61
88
  import { join } from "path";
62
89
  import { homedir } from "os";
63
- import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
90
+ import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2, mkdirSync } from "fs";
64
91
  var MCP_SERVERS = {
65
92
  "velocity-mcp": { command: "npx", args: ["@whenlabs/velocity-mcp"] },
66
93
  whenlabs: { command: "when-mcp", args: [] }
@@ -77,16 +104,16 @@ function getConfigPath(editor) {
77
104
  }
78
105
  }
79
106
  function readJsonFile(filePath) {
80
- if (!existsSync(filePath)) return {};
107
+ if (!existsSync2(filePath)) return {};
81
108
  try {
82
- return JSON.parse(readFileSync(filePath, "utf-8"));
109
+ return JSON.parse(readFileSync2(filePath, "utf-8"));
83
110
  } catch {
84
111
  return {};
85
112
  }
86
113
  }
87
114
  function ensureDir(filePath) {
88
115
  const dir = filePath.substring(0, filePath.lastIndexOf("/"));
89
- if (!existsSync(dir)) {
116
+ if (!existsSync2(dir)) {
90
117
  mkdirSync(dir, { recursive: true });
91
118
  }
92
119
  }
@@ -102,7 +129,7 @@ function installCursorOrWindsurf(editor) {
102
129
  }
103
130
  };
104
131
  ensureDir(configPath);
105
- writeFileSync(configPath, JSON.stringify(updated, null, 2) + "\n", "utf-8");
132
+ writeFileSync2(configPath, JSON.stringify(updated, null, 2) + "\n", "utf-8");
106
133
  return { editor, success: true, message: `${capitalize(editor)}: MCP servers registered at ${configPath}` };
107
134
  }
108
135
  function installVSCode() {
@@ -121,12 +148,12 @@ function installVSCode() {
121
148
  }
122
149
  };
123
150
  ensureDir(configPath);
124
- writeFileSync(configPath, JSON.stringify(updated, null, 2) + "\n", "utf-8");
151
+ writeFileSync2(configPath, JSON.stringify(updated, null, 2) + "\n", "utf-8");
125
152
  return { editor: "vscode", success: true, message: `VS Code: MCP servers registered at ${configPath}` };
126
153
  }
127
154
  function uninstallCursorOrWindsurf(editor) {
128
155
  const configPath = getConfigPath(editor);
129
- if (!existsSync(configPath)) {
156
+ if (!existsSync2(configPath)) {
130
157
  return { editor, success: true, message: `${capitalize(editor)}: config not found, nothing to remove` };
131
158
  }
132
159
  const existing = readJsonFile(configPath);
@@ -135,12 +162,12 @@ function uninstallCursorOrWindsurf(editor) {
135
162
  delete mcpServers[key];
136
163
  }
137
164
  const updated = { ...existing, mcpServers };
138
- writeFileSync(configPath, JSON.stringify(updated, null, 2) + "\n", "utf-8");
165
+ writeFileSync2(configPath, JSON.stringify(updated, null, 2) + "\n", "utf-8");
139
166
  return { editor, success: true, message: `${capitalize(editor)}: MCP servers removed from ${configPath}` };
140
167
  }
141
168
  function uninstallVSCode() {
142
169
  const configPath = getConfigPath("vscode");
143
- if (!existsSync(configPath)) {
170
+ if (!existsSync2(configPath)) {
144
171
  return { editor: "vscode", success: true, message: "VS Code: config not found, nothing to remove" };
145
172
  }
146
173
  const existing = readJsonFile(configPath);
@@ -153,7 +180,7 @@ function uninstallVSCode() {
153
180
  ...existing,
154
181
  mcp: { ...mcpSection, servers }
155
182
  };
156
- writeFileSync(configPath, JSON.stringify(updated, null, 2) + "\n", "utf-8");
183
+ writeFileSync2(configPath, JSON.stringify(updated, null, 2) + "\n", "utf-8");
157
184
  return { editor: "vscode", success: true, message: `VS Code: MCP servers removed from ${configPath}` };
158
185
  }
159
186
  function capitalize(s) {
package/dist/index.js CHANGED
@@ -495,11 +495,11 @@ function createInitCommand() {
495
495
  var program = new Command4();
496
496
  program.name("when").version("0.1.0").description("The WhenLabs developer toolkit \u2014 6 tools, one install");
497
497
  program.command("install").description("Install all WhenLabs tools globally (MCP server + CLAUDE.md instructions)").option("--cursor", "Install MCP servers into Cursor (~/.cursor/mcp.json)").option("--vscode", "Install MCP servers into VS Code (settings.json)").option("--windsurf", "Install MCP servers into Windsurf (~/.codeium/windsurf/mcp_config.json)").option("--all", "Install MCP servers into all supported editors").action(async (options) => {
498
- const { install } = await import("./install-JRDDTX6Y.js");
498
+ const { install } = await import("./install-HPF26YW2.js");
499
499
  await install(options);
500
500
  });
501
501
  program.command("uninstall").description("Remove all WhenLabs tools").option("--cursor", "Remove MCP servers from Cursor").option("--vscode", "Remove MCP servers from VS Code").option("--windsurf", "Remove MCP servers from Windsurf").option("--all", "Remove MCP servers from all supported editors").action(async (options) => {
502
- const { uninstall } = await import("./uninstall-QQ2Y3AQ3.js");
502
+ const { uninstall } = await import("./uninstall-X5NO3Z6I.js");
503
503
  await uninstall(options);
504
504
  });
505
505
  program.command("status").description("Show installation status and velocity stats").action(async () => {
@@ -3,7 +3,7 @@ import {
3
3
  ALL_EDITORS,
4
4
  installForEditor,
5
5
  registerMcpServer
6
- } from "./chunk-2Y7YZAIR.js";
6
+ } from "./chunk-3PDLNC63.js";
7
7
  import {
8
8
  injectBlock
9
9
  } from "./chunk-NYUYV3UL.js";
@@ -3,7 +3,7 @@ import {
3
3
  ALL_EDITORS,
4
4
  uninstallForEditor,
5
5
  unregisterMcpServer
6
- } from "./chunk-2Y7YZAIR.js";
6
+ } from "./chunk-3PDLNC63.js";
7
7
  import {
8
8
  removeBlock
9
9
  } from "./chunk-NYUYV3UL.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whenlabs/when",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "The WhenLabs developer toolkit — 6 tools, one install",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",