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

pi-usage-stats

v1.0.1

Published

Tool and command usage statistics for pi-coding-agent extensions

Downloads

317

Readme

📖 pi-atelier 实战指南 — 从零教会你使用 pi-atelier 扩展生态,包含完整示例和最佳实践。

pi-usage-stats

源码仓库 | npm

pi-coding-agent 扩展包工具使用次数统计。

功能

  • AI 工具调用统计:监听 tool_call / tool_result 事件,自动记录每次 AI 调用的工具名和错误次数
  • 用户命令统计:双轨机制
    • 已注册命令:通过 wrapCommand() 包装(需扩展主动接入)
    • 未注册命令:监听 input 事件自动识别(零配置)
  • 持久化存储~/.pi/agent/data/usage-stats.json,session_shutdown 时自动写入
  • 查询报告/usage 命令或 usage_stats 工具,支持 today / week / all 时间范围

使用

查看统计

/usage                     # 今天的统计
/usage week                # 近 7 天
/usage all                 # 全部历史
/usage today --tool bash   # 过滤工具名

AI 也可以调用 usage_stats 工具查询。

接入用户命令统计(扩展开发者)

pi 的已注册命令(/journal/usage 等)执行时 不触发 input 事件(pi 会直接执行命令 handler)。因此需要扩展主动用 wrapCommand 包装:

import { wrapCommand } from "@pi-atelier/usage-stats/lib/wrap-command";

// 替代 pi.registerCommand("journal", def)
wrapCommand(pi, "journal", {
  description: "生成日报",
  handler: async (ctx, args) => { ... },
});

数据模型

{
  "version": 1,
  "daily": {
    "2026-05-29": {
      "bash": { "ai": 42, "user": 0, "errors": 2 },
      "journal": { "ai": 3, "user": 1, "errors": 0 }
    }
  },
  "tools": {
    "bash": { "firstUsed": "...", "lastUsed": "...", "totalAi": 42, "totalUser": 0 }
  }
}
  • 天聚合,避免 history 无限增长
  • 超过 180 天的数据自动清理
  • 写入使用文件锁(proper-lockfile),避免竞态