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

@zhushanwen/pi-pending-notifications

v0.8.2

Published

Cross-extension async operation registration/query mechanism for Pi.

Readme

@zhushanwen/pi-pending-notifications

跨 extension 的异步操作注册/查询机制:workflow / subagent / bash 后台任务等长耗时异步操作在启动与结束时经 Pi EventBus 广播事件,本扩展监听事件并将注册/注销落盘为 session entries,同时提供 pending_notifications 工具供 LLM 查询当前活跃的异步操作(数量或列表)。

提供的工具

pending_notifications

| 参数 | 类型 | 说明 | |------|------|------| | action | "count" | "list" | count 返回活跃操作数量;list 返回列表(类型 / 名称 / id) |

list 返回文本示例:

2 pending operation(s):
- [subagent] 审查登录模块 (id=sa-xxxx)
- [workflow] 重构数据层 (id=run-xxxx)

核心机制

  • 事件契约:异步操作的宿主扩展经 Pi EventBus 广播:
    • pending:register { id, type, name } —— 操作启动(type ∈ workflow / subagent / bash)
    • pending:unregister { id, reason } —— 操作结束(reason 映射为终态 status)
    • 发送方:subagent-core(subagent 与 workflow run 生命周期:启动注册 / 结束注销 / 崩溃恢复 sweep 补注销)、base-tool-enhance(bash 后台任务)、subagent-workflow(仅崩溃恢复补注销)
  • session entries 唯一状态源:register/unregister 经 appendEntry 落盘,无内存第二份状态;活跃集合 = register − unregister 差集,工具投影与写侧去重对同一份 entries 现算,结构上不可分歧
  • 写侧幂等:重复 register、未知/已注销 id 的 unregister 均忽略,天然不重复落盘
  • 无 TTL:三类操作均按进程存活口径处理,长任务(>1h)仍视为活跃
  • 跨 session 残留过滤:查询按当前 session id 过滤 fork 继承的父级注册残留
  • 跨扩展导出:countActiveFromEntries() 供 goal(continuation 守卫)、subagent-workflow(后代存活判定)直接复用差集计算;差集本体单点在 @zhushanwen/extension-protocol

安装

# npm 方式(正式)
pi install npm:@zhushanwen/pi-pending-notifications

本地开发可用 --extension 直接加载:

pi --extension <repo>/extensions/universal/pending-notifications/index.ts "<prompt>"

使用示例

LLM 在决定「继续推进还是等待异步操作」前主动查询:

{ "action": "count" }
{ "action": "list" }

典型场景:agent 想确认是否真有后台任务在跑(workflow run / subagent / bash 后台命令),避免在异步操作未收口时提前下结论或重复派发。

文件结构

pending-notifications/
├── index.ts            # 入口 — re-export src/index.ts
├── mocks/
│   └── typebox.ts      # 测试用 typebox mock
└── src/
    ├── index.ts        # 工厂入口(EventBus 监听 + session 基准 + pending_notifications 工具注册)
    ├── state.ts        # PendingEntry 类型 + 差集/写侧判断纯函数(countActiveFromEntries / hasPendingId / isPendingActive)
    └── __tests__/
        └── pending-notifications.test.ts