@mwillbanks/ast-mcp 0.2.0 → 0.2.2

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.
@@ -96,23 +96,13 @@ const instructionsBegin = "<!-- ast-mcp:begin -->";
96
96
  const instructionsEnd = "<!-- ast-mcp:end -->";
97
97
 
98
98
  async function astMcpEntry(entry: unknown): Promise<boolean> {
99
- if (typeof entry !== "string" || path.basename(entry) !== "ast-mcp.js")
99
+ if (entry === "./node_modules/.bin/ast-mcp") return true;
100
+ if (typeof entry !== "string" || path.basename(entry) !== "ast-mcp")
100
101
  return false;
101
- let folder = path.dirname(path.resolve(entry));
102
- while (true) {
103
- try {
104
- const manifest = JSON.parse(
105
- await readFile(path.join(folder, "package.json"), "utf8"),
106
- );
107
- return (
108
- manifest.name === "@mwillbanks/ast-mcp" &&
109
- path.resolve(entry) === path.join(folder, "dist/ast-mcp.js")
110
- );
111
- } catch {}
112
- const parent = path.dirname(folder);
113
- if (parent === folder) return false;
114
- folder = parent;
115
- }
102
+ const bin = path.dirname(entry);
103
+ return (
104
+ path.basename(bin) === "bin" && path.basename(path.dirname(bin)) === ".bun"
105
+ );
116
106
  }
117
107
 
118
108
  async function expectedReference(
@@ -173,7 +163,7 @@ async function hookCurrent(
173
163
  );
174
164
  for (const command of commands) {
175
165
  if (typeof command !== "string") continue;
176
- const match = command.match(/^bun (.+) hook$/);
166
+ const match = command.match(/^(.+) hook$/);
177
167
  if (!match) continue;
178
168
  try {
179
169
  if (await astMcpEntry(JSON.parse(match[1]))) return true;
@@ -203,10 +193,10 @@ function httpJsonMcpCurrent(
203
193
  }
204
194
  async function stdioCommandCurrent(entry: McpEntry | undefined) {
205
195
  return (
206
- entry?.command === "bun" &&
207
- Array.isArray(entry.args) &&
208
- entry.args[1] === "mcp" &&
209
- (await astMcpEntry(entry.args[0]))
196
+ (await astMcpEntry(entry?.command)) &&
197
+ Array.isArray(entry?.args) &&
198
+ entry.args.length === 1 &&
199
+ entry.args[0] === "mcp"
210
200
  );
211
201
  }
212
202
 
@@ -266,12 +256,12 @@ function codexHttpMcpCurrent(block: string, url: string | undefined) {
266
256
  );
267
257
  }
268
258
  async function codexStdioMcpCurrent(block: string, root: string | undefined) {
269
- const args = block.match(/args = \[(".*"), "mcp"\]/);
259
+ const command = block.match(/command = (".*")/);
270
260
  if (
271
261
  !block.includes("[mcp_servers.ast-mcp]") ||
272
- !block.includes('command = "bun"') ||
273
- !args ||
274
- !(await astMcpEntry(JSON.parse(args[1])))
262
+ !block.includes('args = ["mcp"]') ||
263
+ !command ||
264
+ !(await astMcpEntry(JSON.parse(command[1])))
275
265
  )
276
266
  return false;
277
267
  return root