来源与定位:本仓库是基于
teamchong/pxpipe(MIT)的实验性衍生研究分支,不是 pxpipe 的官方发布仓库。仓库保留了上游 Git 历史和上游 package 元数据;当前这里的package.json仍为 0.8.0,而上游仍在持续演进。若要安装、使用或跟踪 pxpipe 的当前正式版本,请以上游仓库为准。本分支的主要实验增量集中在
src/rehydrate/、src/classifier/precision.ts、src/memory/ARCHITECTURE.md及对应测试/规格,探索 Rehydrate · Precision Classifier · Agent Memory。这些实验组件并不改变上游项目的作者归属,其中部分仍处于集成阶段。
将 Claude Code 的大量上下文渲染为图像,大幅削减输入 token —— 同样的系统提示、工具文档、历史记录,只需一小部分 token。
图像的 token 成本由像素尺寸决定,与内容无关。密集内容(代码、JSON、工具输出)在真实 Claude Code 流量下约 3.1 字符/图像 token vs ~1 字符/文本 token。pxpipe 是一个本地代理,利用这个差距:在请求离开你的机器之前,将大块文本重写为紧凑的 PNG。按当前 Fable 定价,端到端账单节省约 59–70%。
这是模型看到的内容(替代文本):
~48k 字符的系统提示 + 工具文档:文本约 25k token,作为此图像约 2.7k 图像 token。
npx pxpipe-proxy # 代理运行在 127.0.0.1:47821
ANTHROPIC_BASE_URL=http://127.0.0.1:47821 claude # 将 Claude Code 指向代理仪表盘:http://127.0.0.1:47821/ — token 节省量、文本→图像对比、开关控制。
- 有损压缩。 密集图像中的精确 12 字符 hex:Fable 5 得 13/15,Opus 得 0/15 —— 失败是静默 confabulation,不是错误。精确值(ID、哈希、密钥)必须保持文本。
- 真实测试: SWE-bench Lite 10/10 双臂通过,请求大小 −65%;SWE-bench Pro 14/19 ON vs 15/19 OFF,−60%。
- 工作负载相关。 对 token 密集内容(~1 字符/token)有收益,对稀疏散文(~3.5 字符/token)亏损。
- 模型范围: 默认
PXPIPE_MODELS=claude-fable-5,gpt-5.6。Opus 4.7/4.8 误读率约 7%,需手动启用。
| 测试 | N | 文本 | pxpipe(图像) | token |
|---|---|---|---|---|
新颖算术,claude-fable-5 |
100 | 100% | 100% | −38% |
新颖算术,claude-opus-4-8 |
100 | 100% | 93% | −38% |
| gist 回忆 A/B,Fable 5 | 98/arm | 98/98 | 98/98 | - |
| 状态跟踪,Fable 5 | 18/arm | 18/18 | 18/18 | - |
| verbatim 12 字符 hex,Fable 5 | 15 | - | 13/15 | - |
详细收据:eval/swe-bench/ · eval/gist-recall/ · FINDINGS.md
基于两条已实证的公理:
- A1(gist 无损):模型从图像做语义级回忆可靠(98/98)
- A2(verbatim 静默失败):模型从图像转写精确字节不可靠(Fable 13/15,Opus 0/15)
由此推出核心不变量:INV-1 — 任何需要 byte-exact 消费的内容,不得只存在于图像层。
| 组件 | 职责 | 状态 |
|---|---|---|
RehydrateStore (src/rehydrate/store.ts) |
字节存储层:被图像化块的原始字节落盘,模型可通过 rehydrate(id) 按需取回 |
✅ 已实现 |
rehydrate 工具 (src/rehydrate/tool.ts) |
模型可调用的合成工具:proxy 注入定义、本地短路、<rehydrated untrusted> 包裹 |
✅ 已实现 |
Precision Classifier (src/classifier/precision.ts) |
事前判定:图像化前识别块中的 verbatim 风险,输出决策(keep_text/image/factsheet/rehydrate) | ✅ 已实现 |
集成层 (src/rehydrate/integration.ts) |
集成胶水:classifier ↔ store ↔ transform 管道 | ✅ 已实现 |
架构文档 (src/memory/ARCHITECTURE.md) |
L0–L4 分层模型 + 守恒律 | ✅ 已完成 |
| 任务 | 描述 | 优先级 |
|---|---|---|
| 接入 proxy 管道 | 在 proxy.ts 中拦截 rehydrate tool_use 调用、注入 abstention prompt 到 system field、注入 rehydrate 工具定义到 tools[] |
高 |
| 接入 transform 管道 | 在 transform.ts 中,图像化每个块前调用 classifier;recordRecoverable 后写入 store;image_with_rehydrate 块的 banner 追加 rec_id 标注 |
高 |
| SWE-bench 反事实成本回归 | 三组件全开 vs 上游基线:同一 SWE-bench Lite 子集(≥5 题双臂),账单差 ≤ +5% | 中 |
| 密度阈值校准 | D > 0.15 阈值用真实 production events.jsonl 回放校准,当前短文本过于敏感 |
中 |
| Opus abstention 率测量 | 如果 abstention prompt 让 Opus abstention 率 >90%,可考虑将 Opus 加回 allowlist | 低 |
| CJK 混淆矩阵补测 | 中文场景下形近字(己/已/巳、未/末)的像素距离,压缩率低于英文基准 | 低 |
pnpm install && pnpm test
pnpm run build # 重新生成 dist/pnpm test # 运行全部测试
pnpm test -- tests/rehydrate.store.test.ts # M1 测试
pnpm test -- tests/rehydrate.e2e.test.ts # M2 测试
pnpm test -- tests/classifier.precision.test.ts # M3 测试
pnpm test -- tests/rehydrate.integration.test.ts # 集成测试新内容 ──► classifier ──┬─ keep_text ────────► L0/L1(文本层)
├─ image ────────────► L2(图像 gist 层)
├─ image_with_factsheet ► L2 + L1(factsheet)
└─ image_with_rehydrate ► L2 + L3(字节存储)+ banner(rec_id)
模型需要精确字节 ──► rehydrate(id) ──► 从 L3 取回 ──► 进入 L0(keepSharp 钉住)
- 有损(见上);图像的 verbatim 回忆不可靠
- PNG 编码增加大请求的延迟
- ASCII/Latin-1 测试充分;CJK 可用但保守
MIT
