@mwillbanks/ast-mcp 0.6.1 → 0.6.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.
@@ -195,7 +195,12 @@ export default function registerLifecycleTools(
195
195
  try {
196
196
  await applyFileChattr(
197
197
  filePath,
198
- snapshots.get(filePath)?.attributes,
198
+ process.platform === "win32"
199
+ ? {
200
+ chmod:
201
+ snapshots.get(filePath)?.attributes.chmod,
202
+ }
203
+ : snapshots.get(filePath)?.attributes,
199
204
  fence,
200
205
  );
201
206
  } catch (rollbackError) {
@@ -74,8 +74,12 @@ export function isExecutable(
74
74
  function commandOutput(command: string, args: string[]) {
75
75
  try {
76
76
  const result = Bun.spawnSync([command, ...args], {
77
+ stdin: "ignore",
77
78
  stderr: "ignore",
78
79
  stdout: "pipe",
80
+ timeout: 1000,
81
+ killSignal: "SIGKILL",
82
+ maxBuffer: 64 * 1024,
79
83
  });
80
84
  return result.exitCode === 0 ? result.stdout.toString().trim() : "";
81
85
  } catch {
@@ -87,12 +91,13 @@ export function globalBinDirectories(
87
91
  binaryName: string,
88
92
  platform: NodeJS.Platform,
89
93
  home = os.homedir(),
94
+ discover = true,
90
95
  ) {
91
96
  const directories = new Set<string>();
92
97
  const add = (value: string | undefined) => {
93
98
  if (value) directories.add(path.resolve(value));
94
99
  };
95
- const yarnBinary = commandOutput("yarn", ["bin", binaryName]);
100
+ const yarnBinary = discover ? commandOutput("yarn", ["bin", binaryName]) : "";
96
101
  if (yarnBinary) add(path.dirname(yarnBinary));
97
102
  add(process.env.BUN_INSTALL && path.join(process.env.BUN_INSTALL, "bin"));
98
103
  add(process.env.PNPM_HOME);
@@ -104,6 +109,7 @@ export function globalBinDirectories(
104
109
  );
105
110
  add(path.join(home, ".bun/bin"));
106
111
  add(path.join(home, ".bun/install/global/node_modules/.bin"));
112
+ if (!discover) return [...directories];
107
113
  add(commandOutput("bun", ["pm", "bin", "-g"]));
108
114
  add(commandOutput("pnpm", ["bin", "-g"]));
109
115
  add(commandOutput("yarn", ["global", "bin"]));
@@ -153,14 +159,22 @@ export function resolveGlobalBinaryAlias(
153
159
  options: GlobalBinaryResolutionOptions = {},
154
160
  ) {
155
161
  const platform = options.platform ?? process.platform;
162
+ const names = executableNames(binaryName, platform);
163
+ if (!options.globalBinDirectories) {
164
+ const known = executableCandidate(
165
+ directoryBinaryCandidates(
166
+ globalBinDirectories(binaryName, platform, options.home, false),
167
+ names,
168
+ ),
169
+ platform,
170
+ );
171
+ if (known) return known;
172
+ }
156
173
  const directories =
157
174
  options.globalBinDirectories ??
158
175
  globalBinDirectories(binaryName, platform, options.home);
159
176
  return executableCandidate(
160
- directoryBinaryCandidates(
161
- directories,
162
- executableNames(binaryName, platform),
163
- ),
177
+ directoryBinaryCandidates(directories, names),
164
178
  platform,
165
179
  );
166
180
  }
@@ -434,21 +434,27 @@ async function matchingSourceLaunch(
434
434
  return { command: receipt.runtime, args: [receipt.script, "mcp"] };
435
435
  }
436
436
 
437
+ function* installedBinaryCandidates(root: string | undefined, home: string) {
438
+ const names = executableNames("ast-mcp", process.platform);
439
+ for (const discover of root ? [false] : [false, true]) {
440
+ const directories = root
441
+ ? [path.join(root, "node_modules/.bin")]
442
+ : globalBinDirectories("ast-mcp", process.platform, home, discover);
443
+ for (const candidate of directoryBinaryCandidates(directories, names))
444
+ if (isExecutable(candidate, process.platform)) yield candidate;
445
+ }
446
+ }
447
+
437
448
  async function astMcpEntry(
438
449
  entry: unknown,
439
450
  root?: string,
440
451
  home = os.homedir(),
441
452
  ): Promise<boolean> {
442
453
  if (typeof entry !== "string") return false;
443
- const directories = root
444
- ? [path.join(root, "node_modules/.bin")]
445
- : globalBinDirectories("ast-mcp", process.platform, home);
446
- const expected = directoryBinaryCandidates(
447
- directories,
448
- executableNames("ast-mcp", process.platform),
449
- ).filter((candidate) => isExecutable(candidate, process.platform));
450
454
  const configured = root ? path.resolve(root, entry) : path.resolve(entry);
451
- return expected.some((candidate) => sameNativePath(configured, candidate));
455
+ for (const candidate of installedBinaryCandidates(root, home))
456
+ if (sameNativePath(configured, candidate)) return true;
457
+ return false;
452
458
  }
453
459
 
454
460
  function samePhysicalPath(left: string, right: string, filesOnly = false) {
@@ -638,14 +644,7 @@ async function matchingStdioBinary(
638
644
  home = os.homedir(),
639
645
  ) {
640
646
  if (!entry || !Array.isArray(entry.args)) return undefined;
641
- const directories = root
642
- ? [path.join(root, "node_modules/.bin")]
643
- : globalBinDirectories("ast-mcp", process.platform, home);
644
- const binaries = directoryBinaryCandidates(
645
- directories,
646
- executableNames("ast-mcp", process.platform),
647
- ).filter((candidate) => isExecutable(candidate, process.platform));
648
- for (const binary of binaries) {
647
+ for (const binary of installedBinaryCandidates(root, home)) {
649
648
  const configured = root
650
649
  ? `./${path.relative(root, binary).split(path.sep).join("/")}`
651
650
  : binary;