@webywz/context-diet 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +29 -18
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -42,13 +42,14 @@ cut:
42
42
  | --- | --- |
43
43
  | **Offline heuristics** | Strip ANSI/HTML chrome, drop boilerplate, dedupe, omit base64 blobs |
44
44
  | **Presets** | `logs`, `email`, `chat`, `html`, `code`, `json` — sensible keep/strip defaults |
45
- | **Budget** | `--max-tokens` drops low-value blocks first; `--keep` pins headings/code/lists |
45
+ | **Budget** | `--max-tokens` drops low-value blocks first (shared across files/dirs); `--keep` pins headings/code/lists |
46
46
  | **Secret redaction** | `--redact` scrubs PEM / JWT / `sk-` / `ghp_` / Slack / AWS / Bearer / Basic → `[redacted]` |
47
- | **CI token gate** | `--fail-over-tokens / --sarif <n>` exits `1` when output tokens still **>** n (no silent truncate); `--tap` for TAP 13; JSON `budget` field for Actions |
47
+ | **CI token gate** | `--fail-over-tokens <n>` exits `1` when **combined** output tokens still **>** n (shared multi-file budget; no silent truncate); `--sarif <path>` for Code Scanning; `--tap` for TAP 13; JSON `budget` field for Actions |
48
48
  | **Pipe-friendly** | Slimmed body → stdout; report → stderr |
49
49
  | **Bundled examples** | `--demo` / `examples/noisy.txt` in the published tarball |
50
50
  | **Optional deepen** | `--deepen` LLM second pass only when you opt in with a key |
51
51
  | **HTML report** | `--html <path>` writes a self-contained before/after report (offline, no CDN) |
52
+ | **Multi-file / dirs** | Pass several files or directories; they share one `--max-tokens` / `--fail-over-tokens` budget (`budget.shared`, `sources[]`) |
52
53
  | **Step summary** | `--github-summary` appends a short diet report to `$GITHUB_STEP_SUMMARY` |
53
54
 
54
55
  ### Install
@@ -74,6 +75,8 @@ context-diet input.txt --dry-run --diff
74
75
  context-diet --demo --html diet.html -q
75
76
  context-diet input.txt --json | jq '{tokens: .output.tokens, cuts}'
76
77
  context-diet dump.txt --redact --fail-over-tokens 2000
78
+ context-diet a.md b.md notes/ --max-tokens 2000 --fail-over-tokens 2500 --json
79
+ context-diet --demo --fail-over-tokens 1 --sarif over.sarif
77
80
  context-diet examples/noisy.txt --keep headings|code|lists
78
81
  ```
79
82
 
@@ -105,25 +108,26 @@ All offline unless you pass `--deepen`.
105
108
  | Drop quoted / chat chrome | Email quotes; reactions / join-leave |
106
109
  | Dedupe paragraphs | Exact and near-identical (Jaccard ≥ 0.84) |
107
110
  | Truncate | `--max-tokens` + `--keep` / presets |
108
- | Fail over tokens | `--fail-over-tokens` hard CI gate (after diet) |
111
+ | Fail over tokens | `--fail-over-tokens` hard CI gate on **combined** output tokens after diet (shared across inputs) |
109
112
  | TAP | `--tap` TAP version 13 (exit `1` when over `--fail-over-tokens`) |
110
- | JSON budget | `budget.failOverTokens` / `budget.outputTokens` / `budget.ok` in `--json` |
113
+ | JSON budget | `budget.failOverTokens` / `budget.outputTokens` / `budget.ok` / `budget.shared` / `sources[]` in `--json` |
111
114
 
112
115
  Token estimates are **cl100k-ish** (~4 chars/word, 1 CJK ≈ 1 token). Good enough to budget a prompt — not a billed tokenizer.
113
116
 
114
117
  ### CLI
115
118
 
116
119
  ```
117
- context-diet [file] [options]
120
+ context-diet [file|dir ...] [options]
118
121
  ```
119
122
 
120
123
  | Flag | Meaning |
121
124
  | --- | --- |
122
- | `[file]` | Path to read; omit or `-` for stdin |
125
+ | `[file\|dir ...]` | One or more paths; dirs expand top-level files; omit or `-` for stdin. Multi-input shares one token budget |
123
126
  | `-o, --output <file>` | Write slimmed text here instead of stdout |
124
127
  | `--html <path>` | Write self-contained HTML report (stats + capped previews) |
125
- | `--max-tokens <n>` | Cap estimated output tokens (truncates) |
126
- | `--fail-over-tokens <n>` | Exit `1` if output tokens still **>** n (CI gate; distinct from truncate) |
128
+ | `--max-tokens <n>` | Cap estimated output tokens (truncates; **shared** across files/dirs) |
129
+ | `--fail-over-tokens <n>` | Exit `1` if **combined** output tokens still **>** n (CI gate; shared; distinct from truncate) |
130
+ | `--sarif <path>` | Write SARIF 2.1.0 when over `--fail-over-tokens` (GitHub Code Scanning) |
127
131
  | `--tap` | TAP version 13 on stdout (CI; exit `1` if over `--fail-over-tokens`) |
128
132
  | `--redact` | Scrub common secret shapes → `[redacted]` (before diet heuristics) |
129
133
  | `--keep <cats>` | Prefer `headings`, `code`, `lists` when truncating (comma or `\|`) |
@@ -211,7 +215,9 @@ node dist/cli.js --demo --preset logs --max-tokens 400
211
215
  ---
212
216
 
213
217
 
214
- ### Multi-file budget + SARIF (0.9)
218
+ ### Multi-file budget + SARIF (0.9 / 0.10)
219
+
220
+ Documented in **Features** and **Quick start** above. Summary:
215
221
 
216
222
  ```bash
217
223
  context-diet a.md b.md notes/ --max-tokens 2000 --fail-over-tokens 2500 --json
@@ -220,14 +226,15 @@ context-diet --demo --fail-over-tokens 1 --sarif over.sarif
220
226
 
221
227
  - Multiple files/dirs share one `--max-tokens` / `--fail-over-tokens` budget (JSON `budget.shared`, `budget.maxTokens`, `sources[]`).
222
228
  - Directories expand to top-level files (non-recursive).
229
+ - `--fail-over-tokens` gates the **combined** dieted output, not each file alone.
223
230
  - `--sarif <path>` writes SARIF 2.1.0 when output exceeds `--fail-over-tokens`.
224
231
 
225
232
 
226
233
  ## 中文
227
234
 
228
- ### 多文件共享预算 + SARIF(0.9)
235
+ ### 多文件共享预算 + SARIF(0.9 / 0.10)
229
236
 
230
- 可传多个文件/目录,共享 `--max-tokens` / `--fail-over-tokens`;JSON 含 `budget.shared`、`sources[]`。`--sarif <path>` 在超 `--fail-over-tokens` 时写出 SARIF 2.1.0。
237
+ 详见上文 **功能** 与 **快速开始**。可传多个文件/目录,共享 `--max-tokens` / `--fail-over-tokens`(闸门看**合并后**输出);JSON 含 `budget.shared`、`sources[]`。`--sarif <path>` 在超 `--fail-over-tokens` 时写出 SARIF 2.1.0。
231
238
 
232
239
 
233
240
  ### 演示
@@ -244,13 +251,14 @@ npx @webywz/context-diet --demo --preset logs --max-tokens 400
244
251
  | --- | --- |
245
252
  | **离线启发式** | 剥 ANSI/HTML、去样板、去重、省略 base64 大块 |
246
253
  | **预设** | `logs` / `email` / `chat` / `html` / `code` / `json` |
247
- | **预算** | `--max-tokens` 优先丢掉低价值块;`--keep` 钉住标题/代码/列表 |
254
+ | **预算** | `--max-tokens` 优先丢掉低价值块(多文件/目录共享);`--keep` 钉住标题/代码/列表 |
248
255
  | **密钥脱敏** | `--redact` 擦除 PEM / JWT / `sk-` / `ghp_` / Slack / AWS / Bearer / Basic → `[redacted]` |
249
- | **CI token 闸门** | `--fail-over-tokens <n>`:输出 token 仍 **>** n 时退出码 `1`(不静默截断);`--tap` 输出 TAP 13;JSON `budget` 字段供 Actions 解析 |
256
+ | **CI token 闸门** | `--fail-over-tokens <n>`:**合并后**输出 token 仍 **>** n 时退出码 `1`(多文件共享预算;不静默截断);`--sarif <path>` 写 Code Scanning;`--tap` 输出 TAP 13;JSON `budget` 供 Actions |
250
257
  | **管道友好** | 正文 → stdout;报告 → stderr |
251
258
  | **示例随包** | `--demo` / `examples/noisy.txt` 在发布 tarball 里 |
252
259
  | **可选 deepen** | `--deepen` 仅在有 key 且你主动开启时走 LLM |
253
260
  | **HTML 报告** | `--html <path>`:写出自包含前后对比报告(离线、无 CDN) |
261
+ | **多文件 / 目录** | 可传多个文件或目录,共享一份 `--max-tokens` / `--fail-over-tokens`(`budget.shared`、`sources[]`) |
254
262
  | **Step Summary** | `--github-summary`:把精简饮食报告追加到 `$GITHUB_STEP_SUMMARY` |
255
263
 
256
264
  ### 安装
@@ -272,6 +280,8 @@ context-diet input.txt --dry-run --diff
272
280
  context-diet --demo --html diet.html -q
273
281
  context-diet input.txt --json | jq '{tokens: .output.tokens, cuts}'
274
282
  context-diet dump.txt --redact --fail-over-tokens 2000
283
+ context-diet a.md b.md notes/ --max-tokens 2000 --fail-over-tokens 2500 --json
284
+ context-diet --demo --fail-over-tokens 1 --sarif over.sarif
275
285
  context-diet examples/noisy.txt --keep headings|code|lists
276
286
  ```
277
287
 
@@ -303,9 +313,9 @@ context-diet examples/noisy.txt --keep headings|code|lists
303
313
  | 去引用 / 聊天 chrome | 邮件引用;反应 / 进出房 |
304
314
  | 段落去重 | 精确与近似(Jaccard ≥ 0.84) |
305
315
  | 截断 | `--max-tokens` + `--keep` / 预设 |
306
- | Token 闸门 | `--fail-over-tokens`:饮食后的硬失败 CI 闸 |
316
+ | Token 闸门 | `--fail-over-tokens`:饮食后对**合并输出** token 的硬失败 CI 闸(多输入共享) |
307
317
  | TAP | `--tap`:TAP version 13(超过 `--fail-over-tokens` 则退出 `1`) |
308
- | JSON budget | `--json` 中的 `budget.failOverTokens` / `budget.outputTokens` / `budget.ok` |
318
+ | JSON budget | `--json` 中的 `budget.failOverTokens` / `budget.outputTokens` / `budget.ok` / `budget.shared` / `sources[]` |
309
319
 
310
320
  Token 估算为 **cl100k 近似**(约 4 字符/词,1 个 CJK ≈ 1 token)。够用来做预算,不是计费 tokenizer。
311
321
 
@@ -313,11 +323,12 @@ Token 估算为 **cl100k 近似**(约 4 字符/词,1 个 CJK ≈ 1 token)
313
323
 
314
324
  | 参数 | 含义 |
315
325
  | --- | --- |
316
- | `[file]` | 读取路径;省略或 `-` 读 stdin |
326
+ | `[file\|dir ...]` | 一个或多个路径;目录展开顶层文件;省略或 `-` 读 stdin。多输入共享一份 token 预算 |
317
327
  | `-o, --output <file>` | 把瘦身正文写到文件 |
318
328
  | `--html <path>` | 写入自包含 HTML 报告(统计 + 截断预览) |
319
- | `--max-tokens <n>` | 估算输出 token 上限(会截断) |
320
- | `--fail-over-tokens <n>` | 输出 token 仍 **>** n 时退出 `1`(CI 闸;与截断不同) |
329
+ | `--max-tokens <n>` | 估算输出 token 上限(会截断;**多文件/目录共享**) |
330
+ | `--fail-over-tokens <n>` | **合并后**输出 token 仍 **>** n 时退出 `1`(CI 闸;共享;与截断不同) |
331
+ | `--sarif <path>` | 超过 `--fail-over-tokens` 时写出 SARIF 2.1.0(GitHub Code Scanning) |
321
332
  | `--tap` | 向 stdout 输出 TAP version 13(超过 `--fail-over-tokens` 则退出 `1`) |
322
333
  | `--redact` | 擦除常见密钥形态 → `[redacted]`(在饮食启发式之前) |
323
334
  | `--keep <cats>` | 截断时优先保留 `headings` / `code` / `lists` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webywz/context-diet",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Slim LLM context before you send it — drop noise, keep the signal, estimate tokens.",
5
5
  "keywords": [
6
6
  "llm",