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

@hardlydifficult/agent-tools

v1.0.1

Published

A utility package providing configuration-driven limits, path parsing for GitHub-style file references, and error-handling helpers for safe, predictable agent tool execution.

Readme

@hardlydifficult/agent-tools

A utility package providing configuration-driven limits, path parsing for GitHub-style file references, and error-handling helpers for safe, predictable agent tool execution.

Installation

npm install @hardlydifficult/agent-tools

Quick Start

import {
  parsePath,
  MAX_READ_BYTES,
  executeWithErrorHandling,
  toArray,
} from "@hardlydifficult/agent-tools";

// Parse a GitHub-style path with line range
const result = parsePath("src/index.ts#L10-L20");
// { filePath: "src/index.ts", startLine: 10, endLine: 20 }

// Normalize inputs to arrays
const items = toArray("single"); // ["single"]
const itemsArray = toArray(["a", "b"]); // ["a", "b"]

// Safely handle async operations with error messages
const safeRead = await executeWithErrorHandling(
  () => Promise.resolve("data"),
  "read_file failed"
);
// "data"

Path Parsing

Parses GitHub-style file paths with optional line ranges into structured objects.

parsePath(path: string): ParsedPath

Parses paths like file.ts, file.ts#L10, or file.ts#L10-L20.

Parameters:

| Name | Type | Description | |------|------|-------------| | path | string | GitHub-style file path with optional #L... line range |

Returns:

| Name | Type | Description | |------|------|-------------| | filePath | string | The path to the file | | startLine? | number | Starting line (1-indexed) | | endLine? | number | Ending line (inclusive) |

import { parsePath } from "@hardlydifficult/agent-tools";

parsePath("src/index.ts"); // { filePath: "src/index.ts" }
parsePath("src/index.ts#L5"); // { filePath: "src/index.ts", startLine: 5, endLine: 5 }
parsePath("src/index.ts#L5-L15"); // { filePath: "src/index.ts", startLine: 5, endLine: 15 }

Configuration Constants

Configuration values used to enforce safe limits in agent tool operations.

| Constant | Type | Default | Description | |----------|------|---------|-------------| | MAX_READ_BYTES | number | 100_000 | Max bytes to return from read operations before truncation | | MAX_GREP_FILE_SIZE | number | 102_400 | Max file size (bytes) to scan during content search | | MAX_SEARCH_RESULTS | number | 100 | Max total matches returned by search operations | | MAX_CONTEXT_LINES | number | 3 | Lines of context to show around each edit in write output | | VERIFY_TIMEOUT | number | 120_000 | Timeout (ms) for verify tool commands |

import {
  MAX_READ_BYTES,
  MAX_GREP_FILE_SIZE,
} from "@hardlydifficult/agent-tools";

// Max readable file size
console.log(MAX_READ_BYTES); // 100000

// Skip scanning files larger than this
console.log(MAX_GREP_FILE_SIZE); // 102400

Utility Helpers

Support functions for input normalization, error handling, and result formatting.

toArray<T>(input: T | T[]): T[]

Normalizes a value (single item or array) into an array.

import { toArray } from "@hardlydifficult/agent-tools";

toArray("single"); // ["single"]
toArray(["a", "b"]); // ["a", "b"]

executeWithErrorHandling<T>(operation: () => Promise<T>, errorPrefix: string): Promise<T \| string>

Wraps async operations in try-catch and returns either the result or an error string.

import { executeWithErrorHandling } from "@hardlydifficult/agent-tools";

const result = await executeWithErrorHandling(
  () => Promise.resolve("success"),
  "Operation failed"
);
// "success"

const errorResult = await executeWithErrorHandling(
  () => Promise.reject(new Error("Boom")),
  "Operation failed"
);
// "Operation failed: Boom"

formatArrayResult(items: string[], emptyMessage: string): string

Formats array results: joins items with newlines or returns a custom message if empty.

import { formatArrayResult } from "@hardlydifficult/agent-tools";

formatArrayResult(["a", "b"], "No items"); // "a\nb"
formatArrayResult([], "No items"); // "No items"