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

@cnife/pi-prune-context

v0.2.0

Published

确定性上下文裁剪:零 LLM 开销的 prune→format 管线替代 LLM 摘要压缩

Readme

@cnife/pi-prune-context

确定性上下文裁剪:零 LLM 开销的 prune→format 管线替代 LLM 摘要压缩。

功能

  • /prune 命令:手动触发确定性裁剪,产出结构化 Markdown summary 替代原始消息流
  • session_before_compact 钩子:pi 自动阈值压缩时介入,用确定性裁剪替代默认 LLM 摘要
  • /compact 不受影响:保持 pi 原生 LLM 摘要行为

裁剪规则(最小管线)

  • user / assistant text:全留
  • thinking / toolCall / toolResult 等:跳过

本地测试

pi -ne -ns -e packages/prune-context/extensions/prune-context.ts

单元测试

npx tsx --test packages/prune-context/test/pipeline.test.ts

已知问题

/prune 后 TUI 显示两个 [compaction]

这是 pi 上游 TUI 的显示 bug,不是本扩展的问题。 session jsonl 只写入 1 个 compaction entry,但 TUI 渲染了 2 个完全相同的 [compaction] 块(同 summary、同 tokensBefore)。

根因:pi packages/coding-agent/src/modes/interactive/interactive-mode.tscompaction_end 事件处理(约 3104-3113 行):

  1. rebuildChatFromMessages() —— buildContextEntries 把 compaction entry 作为首元素返回,sessionEntryToContextMessages 将其转成 compactionSummary,渲染在历史位置(顶部)。
  2. 紧接着 addMessageToChat(createCompactionSummaryMessage(...)) 又在底部渲染一个。

两者重复。

为何 /prune 特别明显/prune 是 compact-all(firstKeptEntryId=""),无 kept messages,两个块紧挨。/compact/pi-vcc 等保留 tail 的压缩,两个块被 kept messages 分隔在顶/底,重复不易察觉——但同样存在(已实测)。

上游历史

  • #2617(commit 161ad182,2026-03-27)曾修复:移除 synthetic addMessageToChat,只 rebuildChatFromMessages,CHANGELOG 写明“manual compaction no longer duplicates the summary block”。
  • f456a7a4d(同日,#2617 后约 46 分钟,无 issue/PR、直接 push main)又加回 addMessageToChat,CHANGELOG 写明“so the latest compaction remains visible at the bottom”——为让最新 compaction 固定显示在底部,重新引入重复。
  • 测试因 vi.fn() mock 了 rebuildChatFromMessages,未发现 rebuild 也渲染了 compactionSummary,重复被掩盖。此后无 issue 再讨论。

Workaround:无。扩展无法控制 compaction_end 的 TUI 渲染。prune-context 逻辑正确,无需改动。