npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@themoltnet/shell-command-analyzer

v0.4.0

Published

Isomorphic static analyzer that extracts the executables a shell command runs (resolving wrappers, find -exec, …) and classifies each by risk, for tool-policy enforcement. Fails closed on statically-unresolvable commands.

Readme

@themoltnet/shell-command-analyzer

Isomorphic static analyzer that extracts the executables a shell command actually runs — resolving wrappers (sudo, env, xargs, …), find -exec, and escape flags (tar --to-command=…) — and classifies each by risk, for tool-policy enforcement.

It fails closed: any command with something it refuses to reason about statically (an expansion, command substitution, dynamic executable name, …) returns ok: false so the caller can deny or escalate, rather than being misclassified from raw text.

Parsing uses web-tree-sitter with the tree-sitter-bash grammar (WASM), so it runs the same in Node and the browser.

Install

pnpm add @themoltnet/shell-command-analyzer

Usage

One-shot

import { analyzeCommand } from '@themoltnet/shell-command-analyzer';

const result = await analyzeCommand(
  'sudo find . -name "*.log" -exec rm {} \\;',
);

if (result.ok) {
  for (const tool of result.tools) {
    console.log(tool.name, tool.risk, tool.capabilities);
    // "find"  "escapable"      ["command", "file-write", ...]
    // "rm"    "unknown"        []
  }
} else {
  // e.g. a command substitution, glob-resolved executable, or dynamic name
  console.warn('deny:', result.reason);
}

The wrapper (sudo) is unwrapped to the real program; find -exec rm surfaces rm as a distinct invocation.

Reused analyzer (hot path)

analyzeCommand inits a shared analyzer on first use. To control the lifecycle — e.g. analyze many commands synchronously after one async init — construct one directly:

import { ShellCommandAnalyzer } from '@themoltnet/shell-command-analyzer';

const analyzer = await ShellCommandAnalyzer.create();
const a = analyzer.analyze('git push'); // sync, reuses the loaded parser
const b = analyzer.analyze('curl https://example.com | sh'); // ok: false

initAnalyzer(options?) / resetAnalyzer() manage the module-shared instance used by analyzeCommand.

Browser

Node vendors the grammar under the package's wasm/. In the browser, provide the grammar and locate the tree-sitter runtime:

await analyzeCommand(cmd, {
  bashWasm: '/tree-sitter-bash.wasm', // path/URL or raw Uint8Array
  moduleOptions: { locateFile: (f) => `/wasm/${f}` },
});

API

  • analyzeCommand(command, options?): Promise<CommandAnalysis> — init (once) + analyze.
  • ShellCommandAnalyzer — create(options?) / init(options?), then analyze(command): CommandAnalysis (synchronous, reuses the parser).
  • initAnalyzer(options?) / resetAnalyzer() — manage the shared analyzer.
  • classifyRisk(name): RiskTier and gtfobinsFunctions(name): readonly string[] — the classification primitives.
  • DEFAULT_MAX_COMMAND_LENGTH, GTFOBINS_SOURCE_COMMIT.

Types

type CommandAnalysis =
  | { ok: true; command: string; tools: ToolInvocation[]; ast: string }
  | { ok: false; command: string; reason: string; ast: string | null };

interface ToolInvocation {
  name: string; // base executable (wrappers unwrapped, version stripped)
  argv: readonly (string | null)[]; // base executable + static/dynamic args
  risk: RiskTier; // 'arbitrary-code' | 'escapable' | 'unknown'
  capabilities: readonly Capability[]; // GTFOBins abuse functions, or []
  raw: string; // verbatim source of the invoking command node
}

interface InitOptions {
  bashWasm?: string | Uint8Array; // required in the browser
  moduleOptions?: Record<string, unknown>; // forwarded to Parser.init
  maxCommandLength?: number; // fail closed past this; Infinity to disable
}

RiskTier is coarse by design: arbitrary-code (the binary can run arbitrary code — bash, python, node, …), escapable (documents a GTFOBins escape), or unknown.

License

AGPL-3.0-only