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

@afu_context/afu-context

v0.1.10

Published

Local asynchronous context compression and diagnostics

Readme

AFU Context · 本地异步上下文压缩

English · 简体中文 · npm · 一键安装 · 评测效果 · Web 面板

长对话里,同一段工具输出可能随每次请求反复发送。AFU 用宿主当前的模型在后台整理已经结束的对话。摘要就绪后,下一次合适的请求可以用摘要替换旧历史,同时保留之后发生的工具调用和新消息。

AFU 如何压缩对话

| 时机 | AFU 的行为 | | --- | --- | | 达到压缩阈值 | 后台生成摘要,当前会话可以继续。 | | 下一次使用历史 | 检查摘要覆盖的对话前缀是否仍然匹配,匹配才替换。 | | 使用之后 | 记录模型请求成功回执或宿主提交结果,面板区分已生成与已应用。 |

快速开始

先安装并登录要使用的宿主,准备 npm、Node.js 22.19+(22.x)或 24+ 和 Python 3.11+(需在 PATH 中)。选一行,在终端执行安装命令,然后用最后一列的命令启动。

| 宿主 | 系统 | 一键安装 | 安装后启动 | | --- | --- | --- | --- | | Claude Code | macOS / Linux | npx --yes --registry=https://registry.npmjs.org @afu_context/[email protected] install claude | claude | | Codex CLI | macOS / Linux | npx --yes --registry=https://registry.npmjs.org @afu_context/[email protected] install codex | codex | | Codex CLI | Windows 10/11¹ | npx.cmd --yes --registry=https://registry.npmjs.org "@afu_context/[email protected]" install codex | codex | | Pi | macOS / Linux | npx --yes --registry=https://registry.npmjs.org @afu_context/[email protected] install pi | pi | | Pi | Windows 10/11¹ | npx.cmd --yes --registry=https://registry.npmjs.org "@afu_context/[email protected]" install pi | pi | | DSH | macOS / Linux | npx --yes --registry=https://registry.npmjs.org @afu_context/[email protected] install dsh --profile YOUR_PROFILE | dsh --profile YOUR_PROFILE | | DSH | Windows 10/11¹ | npx.cmd --yes --registry=https://registry.npmjs.org "@afu_context/[email protected]" install dsh --profile YOUR_PROFILE | dsh --profile YOUR_PROFILE |

支持 macOS(Apple Silicon)和 x64 Linux;安装后新开会话即可。

¹ Windows:Codex CLI、Pi、DSH 已实现,尚未在 Windows 实机验收。请在 PowerShell 中执行,命令里的 npx.cmd 和包名两侧的双引号都不能省。Claude Code 暂不支持 Windows。

验证范围、版本与镜像、重启后的启动方式、Pi / DSH 参数和已知问题见 安装说明。

评测效果

在 LongBench V2 的 39 道历史问答回放中(20 道 Agent 历史、19 道对话历史),AFU 异步压缩答对 23 道,平均上下文为 15.9k tokens。

| 回放策略 | 首次回答正确率 | 平均上下文 tokens | | --- | ---: | ---: | | 无压缩 | 19/39 (48.72%) | 72.6k | | Codex Compact Sync | 20/39 (51.28%) | 21.7k | | DSH Compact Sync | 18/39 (46.15%) | 26.1k | | Pi Compact Sync | 13/39 (33.33%) | 21.6k | | AFU Compact Async | 23/39 (58.97%) | 15.9k |

4.56× 是无压缩与 AFU 的平均上下文 token 之比。回放使用 DeepSeek-V3.2 回答和压缩,逻辑窗口为 131,072 tokens,AFU 在 20k 触发,摘要延迟一轮使用。同步策略按各自提示词和策略回放,比较上下文规模时至少压缩一次。此指标不含回答输出,也不能直接换算成 API 总费用或当前 npm 版本的线上收益。

Web 面板:查看压缩是否生效

打开面板

| 在哪里 | 输入 | | --- | --- | | Claude Code 会话里 | /afu:ctx-admin | | Codex 会话里 | $afu-ctx-admin | | 终端里 | afu-ctx-admin |

  • 面板在后台运行,不占用终端;再次打开会复用同一个面板,30 分钟没有页面打开时自动退出。
  • 默认暗色主题,右上角可切换亮色、跟随系统和中英文。
  • 终端命令由安装程序放在 ~/.local/bin(已在 PATH 中时才放,不改 shell 配置,不覆盖你已有的同名命令),移除最后一个接入时一并删除。

查看当前会话

Claude Code 输入 /afu:status,Codex 输入 $afu-status,终端里运行 afu status。会显示 AFU 是否已接入、当前上下文距离压缩触发线还有多少,以及已经生效的压缩次数。

没有上面的终端命令时(例如 ~/.local/bin 不在 PATH 中),可以用完整的 npx 命令。以 Codex 为例,其它宿主将 codex 换成 claude、pi 或 dsh:

npx --yes --registry=https://registry.npmjs.org @afu_context/[email protected] status codex --brief
npx --yes --registry=https://registry.npmjs.org @afu_context/[email protected] ui

面板内容

  • 总览:节省的 token 和生效的压缩次数,以及对话输入、缓存命中率、压缩消耗和活跃会话;下方每个对话一行,显示标题、压缩状态,以及距离触发压缩还差多少的进度条。
  • 会话详情:上下文在每次压缩后的回落、每次压缩的耗时和节省量,以及缓存命中率。宿主把一个对话分成多段时(子代理、起标题请求、宿主自己压缩后),这里会列出各段。
  • 运行状态:接入情况、版本和异常记录。

每次压缩分三步记录:请求已接入 → 摘要已生成 → 摘要已应用。Claude Code 和 Codex 的“已应用”表示替换历史后的请求已收到完整成功响应;Pi 表示已有模型请求用摘要替换了它覆盖的历史;DSH 表示宿主已把摘要写入会话历史。摘要在后台生成,不影响对话。模型未返回的缓存用量显示为未知;节省量按模型服务对未压缩请求报告的实际 token 数校准,与费用一样都是估算,不是供应商账单。需要估算费用时,可按会话提供输入、输出和缓存单价,见面板与费用。

AFU 本地面板的总览页(暗色)

截图为演示数据。

模型与压缩阈值

四个平台都复用主对话的模型和认证。上下文超过触发线时,AFU 在后台用当前模型生成摘要,之后的请求改用压缩后的历史。触发线 = 模型窗口 × 触发比例,默认如下:

| 模型窗口 | 默认触发比例 | 触发线示例 | | --- | --- | --- | | 1,000,000 tokens 及以上 | 50% | 1,000,000 窗口 → 500,000 | | 小于 1,000,000 tokens | 60% | 272,000 窗口 → 163,200;200,000 窗口 → 120,000 |

模型窗口自动获取,不需要手动配置:

| 宿主 | 窗口从哪来 | | --- | --- | | Claude Code | Claude Code 传给状态栏命令的模型窗口。AFU 包装这条命令来读取,你原来的状态栏照常运行、显示不变 | | Codex | Codex 本地的模型目录缓存 | | Pi / DSH | 宿主当前选择的模型和窗口 |

窗口仍未知时聊天照常进行,/afu:status 或 $afu-status 会提示。

手动指定窗口和调整比例

用同一条安装命令加参数即可,改完后新开会话生效。下面以 Codex 为例,其它宿主将 codex 换成 claude、pi 或 dsh。

| 想做的事 | 参数 | | --- | --- | | 提前或推迟压缩 | --ratio 0.3(取值 0 到 1 之间) | | 手动指定模型窗口 | --context-window 200000 | | 恢复自动 | --context-window auto --ratio auto |

# 在 30% 触发,并手动指定 200,000 的窗口(即 60,000 触发)
npx --yes --registry=https://registry.npmjs.org @afu_context/[email protected] install codex --context-window 200000 --ratio 0.3
# 恢复自动设置
npx --yes --registry=https://registry.npmjs.org @afu_context/[email protected] install codex --context-window auto --ratio auto

如果经常使用 AFU,可运行 npm install -g --registry=https://registry.npmjs.org @afu_context/[email protected],以后用 afu 代替完整的 npx 命令。例如,afu ui --prices ./afu-prices.json 用自己的单价文件打开面板估算费用。

升级与移除

升级 Claude Code 或 Codex 接入后,新开会话即可使用新版网关。需要移除时,先撤销对应宿主的接入,再重启宿主。以下两条命令分别用于升级和移除。

npx --yes --registry=https://registry.npmjs.org @afu_context/[email protected] upgrade codex
npx --yes --registry=https://registry.npmjs.org @afu_context/[email protected] remove codex

Pi 和 DSH 可分别用 remove pi 或 remove dsh 撤销。Windows PowerShell 请使用 npx.cmd 并将包名放在双引号中。

本地面板只监听回环地址。日志记录用量和回执,Pi/DSH 的本地会话状态还会保存摘要。生成摘要本身会调用模型,节省多少取决于后续复用和实际缓存命中。

Apache-2.0