Skip to content

fix(compress): remove JSON-string content form (array-only) per #273 - #274

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-01_compress-remove-json-format
Open

fix(compress): remove JSON-string content form (array-only) per #273#274
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-01_compress-remove-json-format

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

背景

Issue #273:压缩彻底取消 json 格式。

compress 工具的 content 参数此前是一个 union:既接受数组,也接受「JSON 编码的字符串」(当初为兼容非严格工具 provider 把数组参数字符串化而加的兜底,见 session 01a00a38 / #253)。本 PR 彻底移除该 JSON 字符串形式。

改动

  • src/compress-tool.ts
    • CompressParams.contentType.Union([Array, String])Type.Array(RangeSpec)
    • normalizeRanges:改为纯数组校验;非数组 content(含 JSON 编码的数组字符串)现在直接抛错(pi 标 isError:true,计入失败上限)
    • 删除 tailRepair / repairContentTail / jsonParseError / describeDiagnostics,以及不再使用的 parseCompressArgs + CompressParseDiagnostics 导入
  • tests/compress-tail-repair.test.ts:整体删除(测的是被移除的字符串兜底)
  • tests/compress-retry.test.ts:删掉「接受 JSON 字符串」用例;保留并改写「非数组 → 抛错」用例,现在喂一个合法的 JSON 数组字符串以证明它同样被拒
  • CHANGELOG.md:Unreleased 段记录本次移除

权衡(已在 issue 里跟 @ranxianglei 确认方向)

移除后,会把数组参数字符串化的非严格工具 provider(如 vLLM openai-completions)会在 pi 的 schema 校验层被拒(content 必须是 array),不再进兜底解析。按「彻底取消」的字面要求这么做。

验证

  • npm run typecheck
  • npm test ✅ 450 pass / 0 fail / 3 skipped
  • npm run build ✅(dist 已无 tailRepair 等残留)

The compress tool's content param accepted a JSON-encoded string as a fallback for non-strict-tool providers that stringify array arguments. Per #273, remove it entirely:

- CompressParams.content: Type.Union([Array, String]) -> Type.Array(RangeSpec)
- normalizeRanges: pure array validation; non-array content (incl. a JSON-encoded array string) now throws a clear 'must be an ARRAY' error
- drop tailRepair / repairContentTail / jsonParseError / describeDiagnostics and the now-unused parseCompressArgs + CompressParseDiagnostics imports
- tests: remove compress-tail-repair.test.ts; compress-retry.test.ts now asserts a well-formed JSON-string is rejected (isError:true)
- CHANGELOG: note the removal under Unreleased

Tradeoff: non-strict providers that stringify the array arg are now rejected at pi's schema layer instead of being parsed by the fallback.
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

📦 Built Extension Artifact

Branch: 2026-09-01_compress-remove-json-format (d94a4d4)

Option A — Install from npm PR tag (recommended)

pi install npm:billion-context-pi@pr-274

Each push to this PR publishes a new version under the pr-274 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pi-pr274.tgz
pi install ./package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 ework agent · qwen3.8-27b

[bot] 🏷 收到,正在 review 这个 PR(2026-09-01_compress-remove-json-format @ d94a4d4)。我会核对 diff、跑 typecheck/test/build,确认「非数组 content(含合法 JSON 数组字符串)都被拒」的行为后回复结论。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 ework agent · qwen3.8-27b

[bot] 🏷 Review 完成,结论:LGTM,建议合并(merge 按规则由人来操作)。

验证(本地全跑过)

  • npm run typecheck ✅ 无错
  • npm test ✅ 450 pass / 0 fail / 3 skipped(与 issue 描述完全一致)
  • npm run build ✅(dist/index.js 531.79 KB)
  • dist 残留检查:tailRepair / repairContentTail / jsonParseError / describeDiagnostics / parseCompressArgs 在 dist 中 0 处;新错误文案 JSON-encoded string arrays are no longer accepted 已在 dist 中
  • 源码全仓 grep:被删标识符仅剩 CHANGELOG.md 里的说明性引用(预期内),无悬空引用

逻辑核对(src/compress-tool.ts)

  • schema:contentType.Union([Array, String])Type.Array(RangeSpec)
  • normalizeRanges(src/compress-tool.ts:68)改为纯数组校验:非数组直接返回错误串 → handleCompress throw → pi 标 isError:true 计入失败上限 ✅;空数组返回 [],调用点仍走 "No ranges provided." ✅;逐条校验 startId/endId/summary 均为 string ✅
  • 删除 repairContentTail/tailRepair/describeDiagnostics/jsonParseErrorparseCompressArgs+CompressParseDiagnostics 导入,无残留 ✅

测试改动

  • tests/compress-tail-repair.test.ts 整体删除(测的就是被移除的字符串兜底)✅
  • tests/compress-retry.test.ts:删「接受 JSON 字符串」用例;改写后的「非数组 → 抛错」用例现在喂一个合法 JSON 数组字符串并断言被拒(/Invalid compress content[\s\S]*ARRAY/)——正好证明「合法 JSON 数组字符串同样被拒」✅

一处行为取舍(已在 issue 确认方向)
非严格 provider(如 vLLM openai-completions 把数组参数字符串化的)现在会在 pi 的 typebox 校验层被拒(content 必须是 array),不再进兜底解析。这是 #273「彻底取消」的字面要求,CHANGELOG 已记录。
补充一点精确性:改写后的单测走的是 execute() 直调(绕过 typebox),验证的是 normalizeRanges 这层防御;pi schema 层的拒绝由 Type.Array 定义本身保证(未被单测直接覆盖,但由 schema 语义保证)。两层都拒,结论一致。

可选 nit(非阻塞,pre-existing)
src/compress-tool.ts:54 的 throw-log 里 typeof (params as CompressArgs).content === "string" ? "string" : ... 仍对 string 形式做了特判。content 现在已是 array-only,这个三元已冗余,可简化为直接取 content?.length ?? 0。不影响正确性,纯清理,可留到后续。

综上:改动干净、验证齐全、行为符合预期,建议合并。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant