Documentation
¶
Overview ¶
Package versionmeta resolves installed-tool versions from on-disk metadata — npm package manifests, version-encoded install layouts (<tool>/versions/<v>, Homebrew Cellar/Caskroom), and macOS app bundles — so detectors can avoid launching third-party binaries.
Running `<tool> --version` is the detection path that popped macOS Gatekeeper "could not verify … free of malware" dialogs on customer machines: cursor-agent eagerly dlopens an un-notarized native addon (merkle-tree-napi.darwin-arm64.node) on any invocation. Metadata reads can't trigger that class of problem, so callers try FromBinary first and fall back to exec'ing the binary only when it returns "".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromBinary ¶
FromBinary returns the version of the tool installed at binaryPath, derived purely from filesystem metadata, or "" when no trustworthy source exists. It never executes the target binary; the only subprocess it may spawn is Apple's own PlistBuddy (an OS utility) to read an app-bundle Info.plist.
A "" result is not a failure — it means the caller should fall back to its existing version command. Sources are tried most- to least-authoritative:
- npm package manifest: binary resolves into node_modules/<pkg>/, and the manifest's package name matches the tool (rejects e.g. corepack's yarn shim, whose manifest version would be corepack's, not yarn's).
- <tool>/versions/<version>/ install layouts (cursor-agent, claude native installer). The directory holding "versions" must match the tool name so runtime-manager layouts (~/.pyenv/versions/3.12.1/bin/poetry) don't misattribute the runtime's version to the tool.
- Homebrew Cellar/Caskroom: physical containment in Cellar/<formula>/<v>/ means the formula owns the binary, so <v> is its version (npm-installed binaries under a brew node live in node_modules and are claimed or rejected by rule 1 before this can misfire).
- macOS app bundle: CFBundleShortVersionString of the enclosing .app.
func NPMPackageName ¶
NPMPackageName returns the full npm package name (e.g. "@github/copilot") that owns binaryPath, or "" when the binary doesn't resolve into an npm package. Lets detectors verify a tool's identity without executing it.
func NPMShimPackageRoot ¶
NPMShimPackageRoot reads a Windows-style npm shim (`<bin>.cmd`, `<bin>.ps1`, `<bin>.bat`) and returns the install root of the package the shim invokes, by locating the first `node_modules\<...>` reference in the shim body. Returns "" when path isn't a shim, can't be read, or contains no node_modules reference.
npm's Windows shim, generated by cmd-shim, looks like:
"%_prog%" "%dp0%\node_modules\@anthropic-ai\claude-code\cli.js" %*
We extract the node_modules path, resolve it relative to the shim's own directory (cmd-shim's `%dp0%`), and feed the absolute path through NodeModulesPackageRoot.
func NodeModulesPackageRoot ¶
NodeModulesPackageRoot walks up `path` looking for a `node_modules` directory; if found, returns the package root (one or two levels deeper depending on whether the package is scoped). Returns "" when the path isn't inside a node_modules tree.
Separator-agnostic: handles both `/` and `\` paths regardless of the host OS. The returned path uses the same separator style as the input — Windows paths preserve backslashes, Unix paths preserve forward slashes.
Examples:
/usr/local/lib/node_modules/@anthropic-ai/claude-code/bin/claude.exe -> /usr/local/lib/node_modules/@anthropic-ai/claude-code C:\Users\u\AppData\Roaming\npm\node_modules\@scope\name\cli.js -> C:\Users\u\AppData\Roaming\npm\node_modules\@scope\name
Types ¶
This section is empty.