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

@wxyhgk/snapcompact

v17.2.9

Published

Bitmap-frame context compression for vision-capable LLMs

Readme

@oh-my-pi/snapcompact

面向可看图的 LLM 的位图帧上下文压缩。

与其让 LLM 总结被丢弃的对话历史,snapcompact 会把历史序列化,并把文本渲染成密集的、由像素字体字形组成的 PNG 帧,让视觉模型直接读回。整个过程本地且确定——无需 LLM 调用、无需 API 密钥、除渲染外零延迟。栅格化与 PNG 编码在原生代码中完成(@oh-my-pi/pi-natives)。

oh-my-pi 的压缩管线而建,但渲染 API 可用于任意文本。

工作原理

  1. 被丢弃的历史序列化为紧凑文本(serializeConversation),带按工具结果与按参数的字符上限。
  2. 文本针对所选原生字体做归一化(normalize):剥离 ANSI 序列、折叠空白、把连续换行折成一个整块字形、把制表符画与兼容符号折成 ASCII、把语义 emoji 折成 ASCII 标签、丢弃装饰性 emoji;当所选字体或内嵌 Silver 回退能渲染时,保留非拉丁字形。
  3. 文本页栅格化为 PNG 帧(render / renderMany)。帧宽按形状固定;高度紧贴实际打印的行,因此未填满的帧不会按空像素行计费。
  4. 帧保存在压缩条目的 preserveData 中,并在每次上下文重建时重新附加到摘要消息。

帧形状按提供商感知,由针对真实提供商计费的 SQuAD 召回评测(见 research/)选定:

| 读取方 | 默认形状 | 说明 | | --- | --- | --- | | Anthropic | 11on16-bw | X.org 8x13 字形,11px 步进;高分辨率 Claude 行得到 1932px 帧 | | Google | 8on22-bw @2048 | X.org 8x13 字形,22px 间距;Gemini 按固定每图预算计费,因此更大的帧是免费字符 | | OpenAI | 8on22-bw | X.org 8x13 字形,22px 间距,以 detail: "original" 发送 | | 未知 | Anthropic 形状 | 按提供商的图像数量预算可防止网关静默丢弃帧 |

resolveShape({ api, id }) 匹配模型 id,而不只是 wire API——经 Vertex 或 OpenRouter 路由的 Claude 会保留其 Claude 形状,按实际承载请求的网关计价。

位图形状保留提供商调校的几何,缺失字形通过内嵌 Silver TrueType 回退逐字符绘制;东亚(CJK/Kana/Hangul)字形跨两个单元格全宽渲染,以便在狭窄的 ASCII 网格中保持可读。选择 silver16-bw 则整个帧都使用 Silver。

安装

bun add @oh-my-pi/snapcompact

直接发布 TypeScript 源码(无构建步骤);要求 Bun ≥ 1.3.14。

用法

把任意文本渲染成 LLM 图像块:

import { renderMany, frames, resolveShape } from "@oh-my-pi/snapcompact";

const images = renderMany(longText, { model }); // ImageContent[],第一页在前
const count = frames(longText, { model });      // 不渲染的帧计数
const shape = resolveShape(model);              // 面向读取方的评测最优 Shape

对准备好的消息运行一次完整压缩:

import { compact } from "@oh-my-pi/snapcompact";

const result = await compact(preparation, { model });
// result.summary        — 简短的"恢复先前对话"引导语、阅读指南与 FILES 区块
// result.preserveData   — 有界的归档来源 + 渲染后的图像中间部分

API 面

  • 压缩:compactCompactionPreparationCompactionResultgetPreservedArchiveimageshistoryBlocks
  • 渲染:renderrenderManyframesgeometry
  • 形状:SHAPESSHAPE_VARIANTSresolveShaperesolveShapeForTextidealShapeVariantisShapeisShapeVariantName
  • 文本:serializeConversationnormalizescanRenderabilityrenderabilityProbeTextdimStopwordswrap
  • 预算:providerImageBudgetMAX_FRAMES_DEFAULTFRAME_TOKEN_ESTIMATEHQ_EDGE_FRAMES
  • 文件操作:createFileOpscomputeFileListsupsertFileOperations

参考