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-subagent-workflow

v9.1.1

Published

Unified subagent execution and multi-agent workflow orchestration for Pi — spawned-process agent runtime with sync/background modes, stateful workflow management with persistence, state machine, and execution tracing.

Downloads

3,658

Readme

@zhushanwen/pi-subagent-workflow

Pi 的 subagent + workflow 合并包:任务委派 + 多 agent 编排(chain / parallel / scatter-gather / map-reduce),单包统一执行链 + 分层配额(ADR-030)。

工具面(3 tools)

| 工具 | action 集合 | 关键参数 | |------|------------|---------| | subagent | start / list / cancel / message / close / fork-from(6 个) | start:task + slug(≤35 字符)必填,agent(.md 绝对路径,缺省 general-purpose)、model、engine、fork、worktree、collect、maxTurns、idleTimeoutMs 等 16 字段拍平顶层;message / close / cancel / fork-from:subagentId 必填(message 另需 text) | | workflow | run / status / abort(3 个) | 见「Workflow 生命周期」节 | | workflow-script | generate / lint / save / delete / list(5 个) | generate:script + name(可选 description);save:name(可 newName 改名);lint / delete:name |

内置 Agents

按「读/写 × 视角」正交切分,10 个角色零重叠(C1 起随 @zhushanwen/subagent-core 的 agents/ 资产分发,<available_subagents> 的 <location> 指向 core 包 agents/ 内各 agent .md 的绝对路径):

| Agent | 角色 | 读/写 | |-------|------|-------| | explorer | 代码库侦查:找入口 / 追调用链 / 摸结构 | 只读 | | planner | 复杂任务拆解为有序实施计划(合并需求澄清) | 只读产文档 | | coder | 代码实现、修改、测试(唯一改代码的角色) | 可改 | | reviewer | 代码审查与需求验收(含 git diff) | 只读 | | doc-reviewer | 文档审查(四遍方法论,事实锚点核实;spec / 设计文档) | 只读 | | debugger | 运行时故障诊断,钉根因 | 只读* | | analyst | 深度项目分析,产出给人读的报告 | 只读 | | researcher | 外部资料调研(依赖 tavily skill) | 只读 | | orchestrator | 纯协调器:拆解 + 委派,不直接执行 | 只协调 | | general-purpose | 兜底,无角色假设 | 按需 |

* debugger 可加临时诊断日志,但必须诊断后恢复,不改业务代码(修复归 coder)。

日常调用链路:

陌生代码改动:  explorer → (planner) → coder → reviewer
修 bug:       debugger 定位 → coder 修复+补测试 → reviewer 验收
新功能开发:    planner → [coder 并行多包] → reviewer 验收
深度调研:      analyst (项目) / researcher (网页)

Orchestrator 协调器模式

orchestrator 是纯协调器角色:拆解任务 → 委派 subagent → 汇总结果,自身不做执行类工作。orchestrator agent 自身也可递归委派子 orchestrator,实现分层任务拆解(深度受 Depth: N/10 护栏保护)。

工具约束(C1/D-5):内置模板不携带 tools: frontmatter 白名单,subagent 不以 --tools 白名单启动——工具约束回归宿主默认工具面,orchestrator 靠角色职责(职责边界段)约束自身只做协调。想要白名单的用户在 <workspace>/.agents/agents/ 放同名 .md 覆写(发现优先级 project 级最高,稳定遮蔽内置),或临时用 pi CLI 的 --tools 白名单验证:

pi --tools todo,goal_control,workflow,subagent,ask_user

依赖:需先安装本包及相关扩展

pi install npm:@zhushanwen/pi-subagent-workflow
pi install npm:@zhushanwen/pi-todo
pi install npm:@zhushanwen/pi-goal

--tools 白名单按 tool 注册名匹配。注意 goal 扩展注册的 tool 名是 goal_control(非 goal)。

递归深度

系统内置 n = 10 深度护栏(MAX_FORK_DEPTH,fork 链与通用嵌套两个计数器共享上限、取严者生效):fork 链超限抛 ForkDepthExceededError,通用嵌套护栏报 nested_spawn_rejected。实测建议控制在 3-4 层以内——更深层会因上下文逐层压缩导致信息失真。

Workflow 生命周期

Workflow run 有两类结束形态:终局(done,outcome 区分 done / failed / cancelled / time_limited——成败已定)与中断(interrupted 暂停态——执行被打断但可续跑)。workflow tool 共 4 个 action:run / status / abort / resume。run 的 name 接受 <available_workflows> 列出的 workflow 名(内置 chain / parallel / map-reduce / scatter-gather / review-fix-loop 或已保存脚本)或 .js 绝对路径。

  • abort(主动取消):{"action":"abort","runId":"<id>"}(可选 "error":"<reason>")→ cancelled 终局。要新结果就重新 run
  • resume(断点续跑):{"action":"resume","runId":"<id>"}(可选 args 校验一致性与时间预算)——对 interrupted run 从断点恢复:已完成的调用回放缓存零 token、未完成的按三档恢复(会话完整 → 捞回结果;请求未完成 → 同会话续写;会话不在 → 整跑);/workflows resume <id> 同能力
  • session 切换/关闭时,所有 running run 转 interrupted 暂停态(被打断不记失败)——回原 session 可 resume 续跑
  • 持久化 = record 事件流(<runId>.record.jsonl,append-only 单一事实源):状态由事件流折叠得出;旧 wf-run-v1/wf-run-v2 快照文件为历史遗留,读取面不消费
  • worker 崩溃自动重建重试(默认 3 次):重建时在飞 agent 调用被清除重跑,已完成的调用保留 replay 缓存,不重复消耗 token

性能:sessions-index.json 持久化索引

冷启动首扫的 identity 探测结论持久化为 <enc>/sessions-index.json(<enc> = agentDir 下 subagents/ 内按 cwd 编码的目录段,索引落 sessions 目录同级;stat 戳自校验、tmp(pid+seq)+rename 原子写、60s 节流、损坏/版本不符静默回退全量探测),真实目录(1744 jsonl / 671MB)实测冷扫描中位数 972.8ms → 80.6ms(12.1x,预算 ≤300ms)。可复现验收脚本:bench/cold-scan.bench.ts(冷扫描计时 + 输出等价断言)、bench/concurrent-scan.bench.ts(3 实例并发 + 随机变异四判定)。

安装

pi install npm:@zhushanwen/pi-subagent-workflow

License

MIT