@mwillbanks/ast-mcp 0.1.1 → 0.1.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.
package/package.json CHANGED
@@ -84,5 +84,5 @@
84
84
  "dprint"
85
85
  ],
86
86
  "type": "module",
87
- "version": "0.1.1"
87
+ "version": "0.1.2"
88
88
  }
package/src/installer.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  import os from "node:os";
11
11
  import path from "node:path";
12
12
  import { isManagedHook } from "./managed-hook";
13
+ import { assertAstBroAvailable } from "./runtime/dependencies";
13
14
 
14
15
  const packageRoot = path.resolve(import.meta.dir, "..");
15
16
  const cliEntry = path.join(packageRoot, "dist/ast-mcp.js");
@@ -223,6 +224,7 @@ async function hasLocalInstallation(root: string) {
223
224
  }
224
225
 
225
226
  export interface InstallOptions {
227
+ astBroBinary?: string;
226
228
  home?: string;
227
229
  root: string;
228
230
  scope: "local" | "global";
@@ -299,6 +301,7 @@ function changedFiles(before: Map<string, string>, after: Map<string, string>) {
299
301
  }
300
302
 
301
303
  async function reconcile(options: InstallOptions) {
304
+ assertAstBroAvailable(options.astBroBinary);
302
305
  const root = path.resolve(options.root);
303
306
  const home = options.home ?? os.homedir();
304
307
  const global = options.scope === "global";
@@ -462,9 +465,10 @@ export async function runInstallerCli(
462
465
  args = process.argv.slice(2),
463
466
  ): Promise<void> {
464
467
  const tokens = [...args];
465
- let operation: "install" | "update" | "uninstall" = "install";
468
+ type Operation = "install" | "update" | "uninstall";
469
+ let operation: Operation = "install";
466
470
  if (["install", "update", "uninstall"].includes(tokens[0] ?? ""))
467
- operation = tokens.shift() as typeof operation;
471
+ operation = tokens.shift() as Operation;
468
472
  let scope: "local" | "global" = "local";
469
473
  let root = process.cwd();
470
474
  let selected: Target[] = [...targets];
@@ -12,9 +12,43 @@ const astBroInstaller = createRequire(import.meta.url)(
12
12
  path.join(path.dirname(realpathSync(astBroWrapper)), "install.js"),
13
13
  ) as { getBinaryPath: () => string };
14
14
 
15
+ export const AST_BRO_VERSION = "3.0.0";
15
16
  export const AST_BRO_BINARY =
16
17
  process.env.AST_BRO_BINARY ?? astBroInstaller.getBinaryPath();
17
18
 
19
+ export function assertAstBroAvailable(
20
+ binary = AST_BRO_BINARY,
21
+ platform: NodeJS.Platform = process.platform,
22
+ arch = process.arch,
23
+ ): void {
24
+ let version = "";
25
+ let cause = "binary not found";
26
+ try {
27
+ const result = Bun.spawnSync([binary, "--version"], {
28
+ stderr: "pipe",
29
+ stdout: "pipe",
30
+ });
31
+ version = result.stdout.toString().trim();
32
+ if (result.exitCode === 0 && version === `ast-bro ${AST_BRO_VERSION}`)
33
+ return;
34
+ cause = result.stderr.toString().trim() || version || cause;
35
+ } catch (error) {
36
+ cause = error instanceof Error ? error.message : String(error);
37
+ }
38
+ const environment =
39
+ platform === "win32"
40
+ ? `$env:AST_BRO_BINARY = "$HOME\\.cargo\\bin\\ast-bro.exe"\n[Environment]::SetEnvironmentVariable("AST_BRO_BINARY", "$HOME\\.cargo\\bin\\ast-bro.exe", "User")`
41
+ : `export AST_BRO_BINARY="$HOME/.cargo/bin/ast-bro"\nprintf '%s\\n' 'export AST_BRO_BINARY="$HOME/.cargo/bin/ast-bro"' >> "$HOME/.profile"\n# For zsh login shells, persist the same line in "$HOME/.zprofile" instead.`;
42
+ const packageRecovery =
43
+ platform === "darwin" && arch === "arm64"
44
+ ? "The npm package includes a macOS Apple Silicon binary. If Bun blocked its installer, run:\n bun pm trust @ast-bro/cli\nThen rerun ast-mcp install."
45
+ : `No precompiled ast-bro ${AST_BRO_VERSION} binary is published for ${platform}-${arch}. Install Rust from https://rustup.rs, then run:`;
46
+
47
+ throw new Error(
48
+ `ast-bro ${AST_BRO_VERSION} is required before ast-mcp can configure a host.\nResolved binary: ${binary}\nFailure: ${cause}\n\n${packageRecovery}\n cargo install ast-bro --version ${AST_BRO_VERSION} --locked\n\nSet AST_BRO_BINARY before rerunning the installer and persist it for the host process:\n${environment}\n\nRestart the host after installation so it receives the environment variable. GUI-launched hosts must be started from that configured environment or receive AST_BRO_BINARY through their launcher.`,
49
+ );
50
+ }
51
+
18
52
  export const DPRINT_BINARY =
19
53
  process.env.DPRINT_BINARY ??
20
54
  path.join(PACKAGE_ROOT, "node_modules/.bin/dprint");
@@ -36,6 +36,8 @@ If the package is not already installed, obtain user authorization before allowi
36
36
 
37
37
  For a global host surface, use `bun add --global --trust @ast-bro/cli dprint @mwillbanks/ast-mcp` followed by `ast-mcp install --scope global --target codex`. Bun blocks transitive lifecycle scripts by default; explicitly trusting `@ast-bro/cli` and `dprint` runs their pinned native installers instead of leaving stale or missing cache paths. Do not use an ephemeral package executor for host installation because its temporary package path can disappear after configuration is written. The installer records the stable installed CLI and uses its `mcp` and `hook` subcommands. For a local installation, run `./node_modules/.bin/ast-mcp update` to refresh managed surfaces and `./node_modules/.bin/ast-mcp uninstall` to remove them; global installations use `ast-mcp update` and `ast-mcp uninstall`.
38
38
 
39
+ The pinned `@ast-bro/cli@3.0.0` package has a precompiled binary only for macOS Apple Silicon. On Linux or macOS Intel, install it with `cargo install ast-bro --version 3.0.0 --locked`, set `AST_BRO_BINARY="$HOME/.cargo/bin/ast-bro"`, and persist that export in `~/.profile` or `~/.zprofile`. On Windows, use the same Cargo command and persist `AST_BRO_BINARY` as `$HOME\.cargo\bin\ast-bro.exe` in the user environment. GUI-launched hosts must inherit that variable from their launcher. The ast-mcp installer verifies the binary before modifying host configuration and returns these commands when manual setup is required.
40
+
39
41
  ## Activate and verify
40
42
 
41
43
  1. Restart or reconnect MCP servers in the host; a skill file alone cannot make MCP tools callable. A supervised ast-mcp process may receive `SIGHUP`, which performs graceful cleanup and exits 0 so the host can restart it from refreshed code and configuration.