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.17

Published

A small wrapper around OpenCode for two things:

Readme

@hardlydifficult/agent-tools

A small wrapper around OpenCode for two things:

  • running one agent task with a concise, stream-friendly API
  • parsing GitHub-style file references into a shape that reads well in client code

Installation

npm install @hardlydifficult/agent-tools

Quick Start

import {
  parseFileReference,
  runAgent,
} from "@hardlydifficult/agent-tools";

const file = parseFileReference("src/index.ts#L10-L20");
// { path: "src/index.ts", lines: { start: 10, end: 20 } }

const result = await runAgent({
  task: "Explain why the tests are failing.",
  directory: process.cwd(),
  model: "openai/o3",
  onEvent(event) {
    if (event.type === "text") {
      process.stdout.write(event.text);
    }
  },
});

console.log(result.output);

runAgent()

runAgent() is the package's main entrypoint. It starts or reuses an OpenCode server, creates a session, sends one task, and streams back text/tool events through a single callback.

runAgent(options: RunAgentOptions): Promise<RunAgentResult>

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

const result = await runAgent({
  task: "Review the latest diff and suggest one small cleanup.",
  directory: "/Users/nick/Documents/code/typescript",
  model: "o3",
  instructions: "Be concise and actionable.",
  mode: "read",
  onEvent(event) {
    switch (event.type) {
      case "text":
        process.stdout.write(event.text);
        break;
      case "tool-start":
        console.log(`\n[tool:start] ${event.tool}`);
        break;
      case "tool-finish":
        console.log(`\n[tool:end] ${event.tool} ok=${event.ok}`);
        break;
    }
  },
});

console.log(result.ok, result.output, result.error);

Options

| Field | Type | Description | |------|------|-------------| | task | string | What the agent should do | | directory | string | Working directory for the run | | model? | string | provider/model or just model | | instructions? | string | Extra top-level instructions | | mode? | "edit" \| "read" | read restricts the run to read-only file tools | | signal? | AbortSignal | Cancels the run | | onEvent? | (event) => void | Receives streamed text and tool events |

Model resolution

  • If model is omitted, OPENCODE_MODEL is used.
  • If model is just a model name such as "o3", OPENCODE_PROVIDER is used when present.
  • If OPENCODE_PROVIDER is not set, the provider defaults to "anthropic".

Result

| Field | Type | Description | |------|------|-------------| | ok | boolean | true when the run completed without a session error | | output | string | Collected assistant text | | error? | string | Session error message, when one occurred | | durationMs | number | Total wall-clock duration | | sessionId | string | OpenCode session identifier |

parseFileReference()

Parses GitHub-style file references into a structured shape:

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

parseFileReference("src/index.ts");
// { path: "src/index.ts" }

parseFileReference("src/index.ts#L5");
// { path: "src/index.ts", lines: { start: 5, end: 5 } }

parseFileReference("src/index.ts#L15-L5");
// { path: "src/index.ts", lines: { start: 5, end: 15 } }

parseFileReference("src/index.ts#L0");
// { path: "src/index.ts#L0" }

Shutdown

If you keep a worker process alive and want to clean up the shared OpenCode subprocess explicitly:

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

shutdownAgentServer();