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

token-stats-timer

v1.1.2

Published

pi extension to display token usage and time spend. Persist preferred thinking level per model in pi

Readme

token-stats-timer

English | 简体中文(当前)

@liziy/token-stats 的修改版本。

一个扩展、一个 footer,同时提供 run 计时与 token 用量/配额监控。

功能

Footer 上行(左对齐):

↑12k ↓3.4k CH87% ⚡77.7 t/s 5.3%/1.0M | 5h: 87% W: 92% ⏱ 2h 15m
  • prev / max —— 上一次 run 耗时 / 本会话分支内最长 run 耗时(带 15 字 prompt 预览)
  • ↑ ↓ Σ CH —— 累计输入 / 输出 / 总量 / 缓存命中率
  • —— 实时速率(2s rolling window,无流时回落到平均速率)
  • 上下文占用(样式可配)
  • 5h: W: ⏱ —— 套餐剩余(MiniMax / GLM / Kimi / DeepSeek / OpenCode Go 内置套餐,需在 /stats 里为当前 provider 启用)

Footer 下行:cwd + git 分支 + 其他扩展状态。

按模型自动记忆思考强度(thinking-memory)

不用命令手动设置,手动切换思考强度时自动记录为当前模型的默认级别, 会话启动 / 切换模型时自动恢复。参考 @tifan/pi-preferred-thinking 的按模型偏好机制, 改为以实际切换行为作为记忆来源(默认开启):

  • 手动切换 thinking level(快捷键 / /thinking / 设置界面)→ 自动记录到当前模型

  • session_start / model_select → 自动应用该模型记忆的级别

  • 自身 setThinkingLevel 与模型切换引发的级别变化(如不支持 max 被 clamp)不会误记录

  • /auto-remember-thinking-level —— 无参查看状态;on / off 启用或禁用(默认开启)

配置:~/.pi/agent/extensions/token-stats/auto-remember-thinking-level.json

{
  "enabled": true,
  "levels": {
    "opencode-go/deepseek-v4-flash": "max"
  }
}

若同时安装原 @tifan/pi-preferred-thinking,其 session_start 自动应用会与本功能互相覆盖,建议二选一。

macOS 完成通知

每次 run(agent 任务)结束后弹系统通知,区分两种结果:

  • ✅ pi 执行完成 —— 正常结束(含耗时)
  • ⏹ pi 已中止 —— 用户 Esc 中止

会话关闭时另有 👋 提示(可关)。

投递通道(自动降级,优先用能送达的)

  1. OSC 终端协议 —— 向终端写转义序列,由终端应用自己弹系统通知,归属明确,无需 osascript:
    • iTerm2 → OSC 9ESC]9;内容,iTerm2 官方文档的通知序列,实测有效
    • Ghostty / WezTerm / Hyper / rxvt-unicode → OSC 777(ESC]777;notify;标题;内容

    ⚠️ 注意:OSC 777 在 iTerm2 3.5.x 上会静默忽略(3.6.9 才支持),官方 pi 示例(notify.ts)只发 OSC 777,在 iTerm2 上不生效——本插件已按终端选择序列。

  2. terminal-notifier —— 装了 brew install terminal-notifier 后自动使用,系统级最可靠(-sender 指定归属、-group 去重)。
  3. osascript —— 保底(无法用终端协议时的最后手段)。

为什么不用纯 osascript:macOS Sequoia 起通知按“调用进程”归属,pi 是 node 进程、无法在系统设置里授权,通知会被静默丢弃(脚本 exit 0 但没弹窗)。OSC 序列把归属改到终端 App,授权后即可正常弹。

配置

配置文件:~/.pi/agent/extensions/token-stats/notify-config.json(不存在时用默认值)

{
  "enabled": true,
  "minDurationSec": 0,
  "sound": "Glass",
  "onSuccess": true,
  "onFailure": true,
  "onAbort": true,
  "onSessionEnd": true
}
  • enabled —— 总开关(也可用 /notify on|off 切换)
  • minDurationSec —— 耗时低于该秒数的 run 不通知(设为 30 可避免秒回打扰)
  • sound —— 通知声音(macOS 内置:Glass/Ping/Sosumi/Hero/Funk 等,"" 静音;注意仅 osascript/terminal-notifier 通道有声,OSC 777 无声音参数)
  • onSuccess/onFailure/onAbort/onSessionEnd —— 各类通知开关

/notify —— 无参查看当前状态;on/off 开关;test 立即发一条测试通知验证通道是否可达。

任务计时(step-timer)

  • 任务执行中:工作指示器(spinner 文案)显示 Working... 01:02(整体已耗时,每秒刷新)

  • 完成后:会话末尾插入一条汇总,仅显示总耗时:

    总耗时 01:23

    appendEntry 持久化、不进入 LLM 上下文,/resume 后仍在。

无独立开关,随包启用;计时口径与 run-timer 一致(一次 run = 首个 agent_start → agent_settled,含重试/压缩/排队提示)。

命令

  • /stats —— 无参默认显示当天 token 统计(等价 /stats day
  • /stats day [YYYY-MM-DD] / hour / week / month [YYYY-MM] —— 统计查询
  • /stats limit —— 套餐配置(为当前 provider 选择/关闭配额套餐;选 GLM 后会继续询问是否配置团队套餐凭证)
  • /stats config —— 显示样式 / 显示内容 / 配额刷新时间 / GLM 团队凭证
  • /notify [on|off|test] —— 通知开关 / 测试(无参查看状态)
  • /auto-remember-thinking-level [on|off] —— 自动记忆思考强度开关(无参查看状态)

GLM 团队套餐(Team Plan)

个人版与团队版共用 GET /api/monitor/usage/quota/limit,区别在请求头:团队版需额外携带 Bigmodel-Organization / Bigmodel-Project 两个请求头并加 ?type=2(api_key + 组织 ID + 项目 ID 三者缺一不可,仅国内站 open.bigmodel.cn 有团队档)。

本插件在组织 ID 与项目 ID 都配置时才走团队查询,否则回退个人版查询:

  • 启用 GLM 套餐后(/stats limit 选 GLM)会自动弹出团队凭证配置询问,可「✏️ 配置/修改」或「跳过」
  • 随时可通过 /stats config → 「GLM 团队凭证」修改或清除
  • 凭证保存在 ~/.pi/agent/extensions/token-stats/config.jsonteamCredential 字段:
{
  "providerPlans": { "zai-coding-cn": "glm" },
  "teamCredential": { "organization": "your-org-id", "project": "your-project-id" },
  "ttl": 60
}

组织 ID / 项目 ID 在 GLM Coding Plan 团队版后台「团队编程套餐」页面获取;如果你同时使用 Claude Code / Cursor 等工具并已在环境变量里配置,也可以在 config.json 里直接填上同名值。

OpenCode Go 余额

OpenCode Go 订阅(opencode-go provider,baseUrl https://opencode.ai/zen/go/v1)使用官方配额接口 GET /zen/go/v1/usageAuthorization: Bearer <key>,即 auth.json 里 opencode-gokey 或环境变量 OPENCODE_API_KEY),返回三个滚动窗口的已用百分比:5 小时 / 周 / 月。

footer 显示 5h: X% W: Y% M: Z% ⏱ ...(剩余比例 = 100 - 已用),后三个子项可分别用 /stats config → 显示内容 的「5h额度 / 周额度 / 月额度 / 刷新时间」开关控制。

与原包的兼容性

  • 显示/套餐配置沿用 ~/.pi/agent/extensions/token-stats/(原 token-stats 的配置直接生效)
  • 统计日志沿用 ~/.pi/agent/extensions/token-stats-logs/(历史数据 /stats 可直接查询)

安装(替换原包)

pi remove npm:@liziy/token-stats
pi install npm:token-stats-timer

/reload 或重启 pi 生效。