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-smart-context

v0.3.5

Published

智能上下文压缩 pi extension:把 compact 时机交给 agent 自决,压缩生成用双模式接管(same-model KV 缓存命中 / cross-model 廉价模型),3 档阈值提醒不强制。

Readme

@zhushanwen/pi-smart-context

智能上下文压缩 pi extension:把 compact 时机交给 agent 自决,压缩生成用双模式接管(same-model KV 缓存命中 / cross-model 廉价模型),3 档阈值提醒不强制。

功能

  • compact_context 工具:agent 在「任务阶段性完成 && 压缩不影响后续 && 上下文超阈值」三条件同时满足时自决调用;带最低档阈值保护
  • 双模式生成接管(session_before_compact,覆盖工具 / /compact / 内建 auto 三条路径):
    • same-model:完整原始上下文 + 会话原 system prompt + tools + 末尾追加压缩指令——前缀缓存全命中,成本≈增量指令+输出,且模型看全量上下文(质量上限最高)
    • cross-model:调用 pi 原生 compact() 仅换模型与凭证——split-turn / fileOps / previousSummary 原生组装
  • 3 档阈值提醒(默认 400K/500K/600K):agent_settled 越档检查,每档一次、多档合并、压缩后重置,nextTurn 投递(随下一次 prompt 注入,不自起 run);已提醒档位经 pi.appendEntry 落在 session entries(smart-context:fired),reload / 进程重启后从 entries 重建,同一档不会重复提醒;措辞是数据投递不是指令
  • 排除模型(精准 provider/modelId 匹配):工具拒绝 + 不提醒 + 回落 pi 原生生成;切换跨界时注入一条可用性通知,downshift(切小窗模型将触线)时建议先压缩
  • 通知车道:压缩结果 / 阈值提醒 / 模型切换四类通知统一走 nextTurn(custom role 随下次 prompt 注入,不自起 run)——工具压缩掐断的 turn 由 taiji runtime 在 compaction_end 判定后经投递内核追加续跑投递(详情见仓库设计文档 delivery-ownership-kernel)
  • 健壮性:摘要收缩校验、max-tokens 截断 fail-closed、接管失败 3 次熔断(本 session 内停止接管)、transcript 回查指针、压缩后最近文件内容重注入(≤5 文件/50K)、多轮压缩降智提示(累计压缩 ≥2 次后附加)
  • subagent 进程自动静默(TAIJI_AGENT_SUBAGENT 标记)

行为门控

| 状态 | 工具 execute | 阈值提醒 | 压缩生成接管 | |---|---|---|---| | enabled,模型未排除 | 放行(低于最低档阈值时拒绝并返回用量建议) | 生效 | 生效(按双模式判定) | | enabled,模型命中排除列表 | 拒绝(返回原因) | 跳过 | 跳过(回落 pi 原生生成) | | enabled=false | 拒绝("可在设置页开启") | 跳过 | 跳过(回落 pi 原生) | | compactModel 未配置/无效 | 放行(same-model 不依赖该配置) | 生效 | same-model 生效;cross-model 回退当前模型,压缩不失败 | | 模型切换跨界(model_select) | 常驻不变 | 注入一条可用性变化通知(仅跨界时) | 按新模型即时重判 |

行为正确性由 execute / handler 现场校验兜底,每次事件回调重新读配置(热加载,改完下一次压缩 / 提醒 / 工具调用即生效,无需重启)。

安装

pi install npm:@zhushanwen/pi-smart-context

配置

<agentDir>/config/smart-context-ext-config.json(读时热加载)。schema 与示例见 skills/smart-context-ext-config/SKILL.md。taiji 桌面端在设置页(系统 → 智能上下文压缩)可视化配置。