versionmeta

package
v1.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 DpkgPackageVersion added in v1.17.0

func DpkgPackageVersion(exec executor.Executor, pkg string, paths ...string) string

DpkgPackageVersion returns the installed version of the Debian package pkg when that package's own file manifest lists one of paths, "" otherwise. It is versionFromDpkg with the package name supplied by the caller instead of derived from the binary's basename, for ladders that already know which package they are proving (kiro-cli, whose binary and package share a name but whose PATH aliases `kiro` and `q` do not).

func FromBinary

func FromBinary(ctx context.Context, exec executor.Executor, binaryPath string) string

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:

  1. 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).
  2. <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.
  3. 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).
  4. dpkg (Linux): the version of the package whose own file manifest lists this path. A binary dpkg still owns but that self-updated in place reports the packaged version; rules 1-3 claim the layouts where that happens before this is reached.
  5. snap (Linux): the `version` field of the snap manifest, which the path rules can't reach (/snap/bin/<name> symlinks to the snap wrapper).
  6. AppImage (Linux): the version in the filename, the only static source a single-file install has.
  7. macOS app bundle: CFBundleShortVersionString of the enclosing .app.

func IsVersionLike added in v1.17.0

func IsVersionLike(s string) bool

IsVersionLike reports whether s looks like a version: optional "v", then a digit, at least one dot, and only [0-9A-Za-z.+_-] throughout. Rejects Caskroom "version,build" composites — callers fall back to exec for those.

func NPMPackageName

func NPMPackageName(exec executor.Executor, binaryPath string) string

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

func NPMShimPackageRoot(exec executor.Executor, path string) string

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

func NodeModulesPackageRoot(path string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL