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

@tjamescouch/niki

v0.5.5

Published

Deterministic process supervisor for AI agents — token budgets, rate limits, and abort control

Readme


Niki wraps any AI agent command and enforces hard limits. When the agent exceeds its budget, timeout, or rate limit, niki kills it. No negotiation.

Install

npm install -g @tjamescouch/niki

Usage

niki [options] -- <command> [args...]

The -- separator is required. Everything before it is niki config, everything after is the command to supervise.

Examples

# Basic: 500k token budget, 1 hour timeout
niki --budget 500000 --timeout 3600 -- claude -p "your prompt" --verbose

# Strict: rate-limit sends and tool calls
niki --budget 1000000 --max-sends 5 --max-tool-calls 20 -- claude -p "..." --verbose

# With external abort file (touch this file to kill the agent)
niki --budget 500000 --abort-file /tmp/niki-12345.abort -- claude -p "..." --verbose

# With logging and state output
niki --budget 500000 --log /tmp/niki.log --state /tmp/niki-state.json -- claude -p "..."

Options

| Flag | Default | Description | |------|---------|-------------| | --budget <tokens> | 1000000 | Max total tokens (input+output) before SIGTERM | | --timeout <seconds> | 3600 | Max wall-clock runtime before SIGTERM | | --max-sends <n> | 10 | Max agentchat_send calls per minute | | --max-tool-calls <n> | 30 | Max total tool calls per minute | | --log <file> | none | Append diagnostics to file | | --state <file> | none | Write exit-state JSON on completion | | --metrics <file> | none | Append session metrics as JSONL on exit (cumulative across runs) | | --cooldown <seconds> | 5 | Grace period after SIGTERM before SIGKILL | | --abort-file <path> | none | Poll this file for external abort signal | | --poll-interval <ms> | 1000 | Base poll interval for abort file (±30% jitter) |

How it works

  1. Niki spawns the child command, inheriting stdin and stdout
  2. Stderr is captured and parsed for token counts and tool calls
  3. Token usage is tracked via high-water-mark (monotonically increasing)
  4. Tool calls and sends are rate-limited with a sliding 60-second window
  5. When any limit is exceeded, niki sends SIGTERM, waits the cooldown period, then SIGKILL
  6. On exit, niki writes a state summary and exits with the child's exit code

State file

When --state is provided, niki writes a JSON snapshot on exit:

{
  "startedAt": "2026-02-09T12:00:00.000Z",
  "pid": 12345,
  "tokensIn": 45000,
  "tokensOut": 12000,
  "tokensTotal": 57000,
  "toolCalls": 42,
  "sendCalls": 8,
  "exitCode": 0,
  "killedBy": null,
  "duration": 1234
}

Metrics file

When --metrics is provided, niki appends one JSON line per session exit. The file grows across restarts, giving you a full history:

# View last 5 sessions
tail -5 /tmp/niki-metrics.jsonl | jq .

# Total tokens across all sessions
cat /tmp/niki-metrics.jsonl | jq -s '[.[].tokensTotal] | add'

# Sessions killed by reason
cat /tmp/niki-metrics.jsonl | jq -s 'group_by(.killedBy) | map({reason: .[0].killedBy, count: length})'

Each line contains the full session state plus endedAt, budget, and timeoutS for context.

killedBy is one of: "budget", "timeout", "rate-sends", "rate-tools", "abort", or null (clean exit).

Security

  • Never logs API tokens, environment variables, or message content
  • Diagnostics contain only counters and timestamps
  • Credentials flow through inherited env, never in CLI args
  • State file contains only operational metrics

Kill reasons

| Reason | Trigger | |--------|---------| | budget | tokensTotal > --budget | | timeout | Wall-clock time exceeds --timeout | | rate-sends | More than --max-sends agentchat_send calls in 60s | | rate-tools | More than --max-tool-calls tool calls in 60s | | abort | External abort file detected at --abort-file path |

License

MIT


Photo: Unsplash (stylized)