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

@toddzheng024/pi-ouroboros

v0.2.0

Published

Play snake in pi's TUI while the agent works; the snake eats the conversation.

Readme

🐍 pi-ouroboros

English | 简体中文

一条吃掉你对话的蛇。pi 编程 agent 准备的 Chrome 小恐龙式摸鱼游戏:agent 埋头干活的时候,弹出一局贪吃蛇——而游戏场地, 正是你当前屏幕上的对话文字。

npm version npm downloads license node

demo

🤔 为什么

agent 长跑时,你只能盯着转圈圈。Ouroboros 把等待变成游戏,还顺手打破第四面墙: 蛇从底部出发,一路吃掉你正在看的对话——你的提问是青色,assistant 的回复是普通文字, 代码块变暗,标题加粗。每个字符都是食物。

✨ 特性

  • 吃掉屏幕 — 游戏场地由当前对话的尾部内容铺成,保留原有换行和角色配色
  • 变色蛇 — 身体颜色随长度变化:绿 → 青 → 黄 → 品红 → 红
  • 越吃越快 — 每吃 10 个字符,节奏加快一档(120ms → 60ms 下限)
  • 奖励词errorbugTODOfix 等词红色高亮,值 5 倍分数
  • 死亡动画 — 撞死后蛇从尾巴开始逐节消散,然后才出现 GAME OVER
  • 胃里有什么 — 标题栏下一行滚动显示最近吃掉的字符
  • 高分持久化 — 保存在 ~/.pi/agent/ouroboros.json,重启不丢
  • agent 状态实时显示 — 底部两行展示当前工具、调用次数和耗时; agent 完成时触发 🎉 庆祝
  • 自适应场地 — 随终端大小调整(最大 80×28 格)
  • 零门槛操作 — 小恐龙式:游戏等你按第一个键才开始,esc 直接回到对话
  • 转向缓冲 — 快速按键按队列逐拍执行,不会因为手速快而 180° 自杀
  • CJK/emoji 安全 — 宽度处理走 pi-tui 的 visibleWidth(),不会渲染崩溃

📦 安装

需要 pi 0.80+

从 npm 安装(最简单):

pi install npm:@toddzheng024/pi-ouroboros

然后重启 pi(或执行 /reload)即可。

本地开发用软链(自动发现):

git clone https://github.com/qiz029/pi-ouroboros.git
ln -s "$PWD/pi-ouroboros" ~/.pi/agent/extensions/pi-ouroboros

或者在 pi 的 settings.json 里指过来:

{
  "extensions": ["/path/to/pi-ouroboros"]
}

无运行时依赖——扩展只使用 pi 自带的包。

🎮 玩法

agent 干活时(其实任何时候都行):

| 按键 | 作用 | | --- | --- | | /snakealt+s | 打开游戏 | | space / 任意方向键 | 开始移动 | | ↑↓←→ / wasd | 转向 | | space / p | 暂停 / 继续 | | r | 游戏结束后重开 | | esc / q | 退出,回到对话 |

吃字符变长——红色奖励词每个值 5 分。撞墙和咬到自己都是致命的。蛇会等你, pi 不会。

⚙️ 实现原理

  • index.ts 注册 /snake 命令和 alt+s 快捷键,通过 agent_start / tool_execution_* / agent_settled 事件跟踪 agent 进度, 并从会话中提取最近约 64 行对话(带角色和代码围栏感知的样式)。
  • game.ts 是一个自包含的 pi-tui 组件,通过 ctx.ui.custom() 渲染: setTimeout 游戏循环随进食加速(120ms → 60ms),文字行之间留出空车道, 转向输入缓冲,尾部消散的死亡动画,以及按终端宽度截断的 ANSI 渲染。

🛠 开发

npm install          # 仅开发依赖:typescript + pi 类型包
npx tsc --noEmit     # 类型检查
npx tsx smoke.mts    # 无头冒烟测试(渲染、tick、增长不变量)

改完代码后在 pi 里执行 /reload 热重载扩展。

重新生成 docs/demo.gif(在 PTY 里驱动真实 pi 会话录制;先执行一次 python3 -m venv .venv && .venv/bin/pip install pyte pillow):

.venv/bin/python scripts/record_demo.py

可调参数都在 game.ts 顶部:BASE_TICK_MS / MIN_TICK_MS / SPEEDUP_EVERY (速度曲线)、MAX_FIELD_WIDTH / MAX_FIELD_HEIGHT(场地上限)、REFILL_THRESHOLDBONUS_WORDS / BONUS_POINTS(奖励计分)、BELLY_MAXCELEBRATION_TICKS

📄 许可证

MIT