@sliday/tamp 0.5.9 → 0.7.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.
@@ -0,0 +1,82 @@
1
+ // Targets:
2
+ // npm install [pkg...]
3
+ // npm i [pkg...]
4
+ // npm ci
5
+ // npm run <script>
6
+ //
7
+ // Strips: spinner frames, progress dots, "npm fund" / "npm audit" preamble
8
+ // lines when no vulnerabilities follow, repeated ".........." lines, leading
9
+ // "⠋ idealTree" style lines.
10
+ // Keeps: error/warn lines, final "added N packages in Ns", vulnerability
11
+ // counts, "up to date", package trees.
12
+
13
+ const SPINNER_CHARS = /[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]/;
14
+ const PROGRESS_LINE = /^\s*[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]\s+/;
15
+ const DOTS_ONLY = /^\s*\.{3,}\s*$/;
16
+ const NPM_SIG = /(^|\n)(npm (install|i|ci|run)\b|added \d+ packages?|up to date|changed \d+ packages?|removed \d+ packages?)/;
17
+
18
+ export default {
19
+ name: 'npm',
20
+
21
+ match(text) {
22
+ if (typeof text !== 'string' || text.length === 0) return false;
23
+ if (!NPM_SIG.test(text)) return false;
24
+ // Near-zero false positives: require either an npm invocation echo OR a
25
+ // characteristic npm summary line.
26
+ return (
27
+ /(^|\n)npm (install|i|ci|run)\b/.test(text) ||
28
+ /(^|\n)(added|removed|changed|up to date)/.test(text)
29
+ );
30
+ },
31
+
32
+ rewrite(text) {
33
+ if (!text) return text;
34
+ const lines = text.split('\n');
35
+ const out = [];
36
+ let lastWasDots = false;
37
+
38
+ for (let i = 0; i < lines.length; i++) {
39
+ const line = lines[i];
40
+
41
+ // Drop spinner lines and sole-dot lines.
42
+ if (PROGRESS_LINE.test(line) || SPINNER_CHARS.test(line)) continue;
43
+ if (DOTS_ONLY.test(line)) {
44
+ if (lastWasDots) continue;
45
+ lastWasDots = true;
46
+ continue; // drop dot-only lines entirely
47
+ }
48
+ lastWasDots = false;
49
+
50
+ // Drop the "run `npm fund` for details" preamble when no funding count follows.
51
+ if (/^\s*\d+ packages? are looking for funding\s*$/.test(line)) {
52
+ // Peek ahead — if next non-empty line is "run `npm fund`", drop both.
53
+ let j = i + 1;
54
+ while (j < lines.length && lines[j].trim() === '') j++;
55
+ if (j < lines.length && /run `npm fund`/.test(lines[j])) {
56
+ i = j; // skip the "run `npm fund`" line too
57
+ continue;
58
+ }
59
+ }
60
+ if (/^\s*run `npm fund` for details\s*$/.test(line)) continue;
61
+
62
+ // Drop "found 0 vulnerabilities" trailing audit preamble? Keep — it's signal.
63
+
64
+ out.push(line);
65
+ }
66
+
67
+ // Collapse runs of blank lines to max 1.
68
+ const collapsed = [];
69
+ let blank = 0;
70
+ for (const l of out) {
71
+ if (l.trim() === '') {
72
+ blank++;
73
+ if (blank > 1) continue;
74
+ } else {
75
+ blank = 0;
76
+ }
77
+ collapsed.push(l);
78
+ }
79
+
80
+ return collapsed.join('\n');
81
+ },
82
+ };
@@ -0,0 +1,58 @@
1
+ // Targets:
2
+ // pip install <pkg>
3
+ // pip install -r requirements.txt
4
+ //
5
+ // Strips: wheel download percentage lines, repeated "Collecting X" entries
6
+ // when the same package appears twice, "Using cached" blocks, progress bar
7
+ // block art.
8
+ // Keeps: "Successfully installed" summary, ERROR/WARNING lines, version pins.
9
+
10
+ const PROGRESS_BAR = /[█▏▎▍▌▋▊▉▐░▒▓|]{4,}/;
11
+ const PERCENT_LINE = /^\s*\|.*\|\s*\d+(\.\d+)?\s*[kKmMgG]?B\s/;
12
+ const DOWNLOADING = /^\s*Downloading\s+.*\([\d.]+\s*[kKmMgG]?B\)\s*$/;
13
+ const PIP_SIG = /(^|\n)(Collecting |Requirement already satisfied|Successfully installed|Installing collected packages)/;
14
+
15
+ export default {
16
+ name: 'pip',
17
+
18
+ match(text) {
19
+ if (typeof text !== 'string' || text.length === 0) return false;
20
+ return PIP_SIG.test(text);
21
+ },
22
+
23
+ rewrite(text) {
24
+ if (!text) return text;
25
+ const lines = text.split('\n');
26
+ const out = [];
27
+ const seenCollecting = new Set();
28
+
29
+ for (const line of lines) {
30
+ if (PROGRESS_BAR.test(line)) continue;
31
+ if (PERCENT_LINE.test(line)) continue;
32
+ if (DOWNLOADING.test(line)) continue;
33
+ if (/^\s*Using cached\s+\S+\.whl\s*\([^)]+\)\s*$/.test(line)) continue;
34
+
35
+ const m = /^\s*Collecting\s+([A-Za-z0-9_.\-]+)/.exec(line);
36
+ if (m) {
37
+ const key = m[1].toLowerCase();
38
+ if (seenCollecting.has(key)) continue;
39
+ seenCollecting.add(key);
40
+ }
41
+
42
+ out.push(line);
43
+ }
44
+
45
+ const collapsed = [];
46
+ let blank = 0;
47
+ for (const l of out) {
48
+ if (l.trim() === '') {
49
+ blank++;
50
+ if (blank > 1) continue;
51
+ } else {
52
+ blank = 0;
53
+ }
54
+ collapsed.push(l);
55
+ }
56
+ return collapsed.join('\n');
57
+ },
58
+ };
@@ -0,0 +1,50 @@
1
+ // Targets:
2
+ // prisma generate / prisma migrate / prisma db push
3
+ // npx prisma generate
4
+ //
5
+ // Strips: "Environment variables loaded from .env", "Prisma schema loaded
6
+ // from prisma/schema.prisma", spinner frames with "✔" replaced characters,
7
+ // braille spinner lines. Keeps: "Generated Prisma Client" success line,
8
+ // error blocks, migration summaries, query engine paths.
9
+
10
+ const ENV_LINE = /^Environment variables loaded from\s+\S+\s*$/;
11
+ const SCHEMA_LINE = /^Prisma schema loaded from\s+\S+\s*$/;
12
+ const DATASOURCE_LINE = /^Datasource "\w+":\s/;
13
+ const SPINNER = /^[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]\s+/;
14
+ const PRISMA_SIG = /(^|\n)(Prisma schema loaded from|Environment variables loaded from|Generated Prisma Client|Running generate|✔ Generated)/;
15
+
16
+ export default {
17
+ name: 'prisma',
18
+
19
+ match(text) {
20
+ if (typeof text !== 'string' || text.length === 0) return false;
21
+ return PRISMA_SIG.test(text);
22
+ },
23
+
24
+ rewrite(text) {
25
+ if (!text) return text;
26
+ const lines = text.split('\n');
27
+ const out = [];
28
+
29
+ for (const line of lines) {
30
+ if (ENV_LINE.test(line)) continue;
31
+ if (SCHEMA_LINE.test(line)) continue;
32
+ if (DATASOURCE_LINE.test(line)) continue;
33
+ if (SPINNER.test(line)) continue;
34
+ out.push(line);
35
+ }
36
+
37
+ const collapsed = [];
38
+ let blank = 0;
39
+ for (const l of out) {
40
+ if (l.trim() === '') {
41
+ blank++;
42
+ if (blank > 1) continue;
43
+ } else {
44
+ blank = 0;
45
+ }
46
+ collapsed.push(l);
47
+ }
48
+ return collapsed.join('\n');
49
+ },
50
+ };
@@ -0,0 +1,55 @@
1
+ // Targets:
2
+ // pytest / python -m pytest
3
+ //
4
+ // Strips: the "collected N items" banner line, the per-test dot-progress line
5
+ // ("tests/foo_test.py ........ [ 50%]"), and the session
6
+ // start banner "platform darwin -- Python 3.11.4 ...". Keeps: FAIL summaries,
7
+ // the short test summary info block, and the final "=== N passed in Xs ===".
8
+
9
+ const COLLECTED = /^collected\s+\d+\s+items?\b/;
10
+ const DOT_PROGRESS = /^\S.*\s+[.FsxE]{2,}\s*(\[\s*\d+%\s*\])?\s*$/;
11
+ const SESSION_START = /^platform\s+\S+\s+--\s+Python\s+\d/;
12
+ const ROOTDIR = /^rootdir:\s+/;
13
+ const PLUGINS = /^plugins:\s+/;
14
+ const CACHEDIR = /^cachedir:\s+/;
15
+ const PYTEST_SIG = /(^|\n)(={3,}\s+test session starts\s+={3,}|collected\s+\d+\s+items?|={3,}\s+\d+\s+(passed|failed|error)s?\b)/;
16
+
17
+ export default {
18
+ name: 'pytest',
19
+
20
+ match(text) {
21
+ if (typeof text !== 'string' || text.length === 0) return false;
22
+ return PYTEST_SIG.test(text);
23
+ },
24
+
25
+ rewrite(text) {
26
+ if (!text) return text;
27
+ const lines = text.split('\n');
28
+ const out = [];
29
+
30
+ for (const line of lines) {
31
+ if (COLLECTED.test(line)) continue;
32
+ if (SESSION_START.test(line)) continue;
33
+ if (ROOTDIR.test(line)) continue;
34
+ if (PLUGINS.test(line)) continue;
35
+ if (CACHEDIR.test(line)) continue;
36
+ // Drop dot-progress only if the line contains ONLY test status chars
37
+ // (not a traceback line that happens to end with dots).
38
+ if (DOT_PROGRESS.test(line) && !/error|FAILED|PASSED/.test(line)) continue;
39
+ out.push(line);
40
+ }
41
+
42
+ const collapsed = [];
43
+ let blank = 0;
44
+ for (const l of out) {
45
+ if (l.trim() === '') {
46
+ blank++;
47
+ if (blank > 1) continue;
48
+ } else {
49
+ blank = 0;
50
+ }
51
+ collapsed.push(l);
52
+ }
53
+ return collapsed.join('\n');
54
+ },
55
+ };
@@ -0,0 +1,49 @@
1
+ // Targets:
2
+ // terraform plan / terraform apply
3
+ //
4
+ // Strips: every "<resource>: Refreshing state... [id=...]" line under plan,
5
+ // repetitive "Still creating... [Xs elapsed]" progress lines during apply.
6
+ // Keeps: the "Plan: N to add, M to change, K to destroy." summary, all
7
+ // Warning:/Error: blocks, resource diff output, variable prompts.
8
+
9
+ const REFRESH_LINE = /^\S[\w.\-\[\]"]*:\s+Refreshing state\.\.\./;
10
+ const STILL_LINE = /:\s+Still (creating|destroying|modifying)\.\.\.\s+\[\d+[smh]\s+elapsed\]/;
11
+ const READING_LINE = /:\s+Reading\.\.\.\s*$/;
12
+ const READ_COMPLETE_LINE = /:\s+Read complete after\s+\d+[smh]/;
13
+ const TF_SIG = /(^|\n)(Refreshing state\.\.\.|Terraform will perform the following actions|Plan: \d+ to add|Apply complete!|Terraform used the selected providers|Initializing the backend)/;
14
+
15
+ export default {
16
+ name: 'terraform',
17
+
18
+ match(text) {
19
+ if (typeof text !== 'string' || text.length === 0) return false;
20
+ return TF_SIG.test(text);
21
+ },
22
+
23
+ rewrite(text) {
24
+ if (!text) return text;
25
+ const lines = text.split('\n');
26
+ const out = [];
27
+
28
+ for (const line of lines) {
29
+ if (REFRESH_LINE.test(line)) continue;
30
+ if (STILL_LINE.test(line)) continue;
31
+ if (READING_LINE.test(line)) continue;
32
+ if (READ_COMPLETE_LINE.test(line)) continue;
33
+ out.push(line);
34
+ }
35
+
36
+ const collapsed = [];
37
+ let blank = 0;
38
+ for (const l of out) {
39
+ if (l.trim() === '') {
40
+ blank++;
41
+ if (blank > 1) continue;
42
+ } else {
43
+ blank = 0;
44
+ }
45
+ collapsed.push(l);
46
+ }
47
+ return collapsed.join('\n');
48
+ },
49
+ };
@@ -0,0 +1,67 @@
1
+ // Targets:
2
+ // curl -O/-o <url>, curl <url>
3
+ // wget <url>
4
+ //
5
+ // Strips: the "% Total ... Time ... Current" header block and all mid-download
6
+ // percentage rows from curl; the tick-mark ASCII bar + per-line percentage
7
+ // rows from wget; leaves the final summary row / "100%" tail line intact.
8
+ // Keeps: final size/time summary, error lines, HTTP response headers if
9
+ // requested (-v / --verbose are untouched — we only match the download grid).
10
+
11
+ const CURL_HEADER = /^\s*%\s+Total\s+%\s+Received/;
12
+ const CURL_SECOND_HEADER = /^\s+Dload\s+Upload/;
13
+ const CURL_ROW = /^\s*\d{1,3}\s+\d[\d.kKMmGgTt]*\s+\d{1,3}\s+\d[\d.kKMmGgTt]*\s+\d+\s+\d+\s+\d[\d.kKMmGgTt]*\s+\d+\s+/;
14
+ const WGET_PROGRESS = /^\s*\d{1,3}%\s*\[[=> .]+\]/;
15
+ const WGET_TICKS = /^\s*[\d,]+[KMG]?\s+[.=]+\s+\d+%/;
16
+ const WGET_SIG = /(^|\n)(--\d{4}-\d{2}-\d{2}|Resolving |Connecting to |HTTP request sent|Length: |Saving to: )/;
17
+ const CURL_SIG = /(^|\n)\s*%\s+Total\s+%\s+Received/;
18
+
19
+ export default {
20
+ name: 'wget-curl',
21
+
22
+ match(text) {
23
+ if (typeof text !== 'string' || text.length === 0) return false;
24
+ return CURL_SIG.test(text) || WGET_SIG.test(text);
25
+ },
26
+
27
+ rewrite(text) {
28
+ if (!text) return text;
29
+ const lines = text.split('\n');
30
+ const out = [];
31
+ let lastCurlRow = null;
32
+
33
+ for (const line of lines) {
34
+ if (CURL_HEADER.test(line)) continue;
35
+ if (CURL_SECOND_HEADER.test(line)) continue;
36
+ if (WGET_PROGRESS.test(line)) continue;
37
+ if (WGET_TICKS.test(line)) continue;
38
+
39
+ if (CURL_ROW.test(line)) {
40
+ // Keep only the final row (last one seen) — buffer it.
41
+ lastCurlRow = line;
42
+ continue;
43
+ }
44
+
45
+ if (lastCurlRow !== null) {
46
+ // Flush the last curl row right before the next non-row line.
47
+ out.push(lastCurlRow);
48
+ lastCurlRow = null;
49
+ }
50
+ out.push(line);
51
+ }
52
+ if (lastCurlRow !== null) out.push(lastCurlRow);
53
+
54
+ const collapsed = [];
55
+ let blank = 0;
56
+ for (const l of out) {
57
+ if (l.trim() === '') {
58
+ blank++;
59
+ if (blank > 1) continue;
60
+ } else {
61
+ blank = 0;
62
+ }
63
+ collapsed.push(l);
64
+ }
65
+ return collapsed.join('\n');
66
+ },
67
+ };
@@ -0,0 +1,77 @@
1
+ // Per-command stdout rewriters for the `cmd-strip` stage.
2
+ // Each rewriter module lives in ./commands/<name>.js and exports:
3
+ // { name, match(text) -> bool, rewrite(text) -> string }
4
+ //
5
+ // Priority order is frozen — most specific signatures first so that a noisy
6
+ // output like `npm install` never gets eaten by a looser matcher.
7
+
8
+ import npm from './commands/npm.js';
9
+ import pip from './commands/pip.js';
10
+ import cargo from './commands/cargo.js';
11
+ import docker from './commands/docker.js';
12
+ import prisma from './commands/prisma.js';
13
+ import terraform from './commands/terraform.js';
14
+ import git from './commands/git.js';
15
+ import pytest from './commands/pytest.js';
16
+ import jest from './commands/jest.js';
17
+ import wgetCurl from './commands/wget-curl.js';
18
+
19
+ const REGISTRY = Object.freeze({
20
+ npm,
21
+ pip,
22
+ cargo,
23
+ docker,
24
+ prisma,
25
+ terraform,
26
+ git,
27
+ pytest,
28
+ jest,
29
+ 'wget-curl': wgetCurl,
30
+ });
31
+
32
+ export const PRIORITY = Object.freeze([
33
+ 'npm',
34
+ 'pip',
35
+ 'cargo',
36
+ 'docker',
37
+ 'prisma',
38
+ 'terraform',
39
+ 'git',
40
+ 'pytest',
41
+ 'jest',
42
+ 'wget-curl',
43
+ ]);
44
+
45
+ export function getRewriter(name) {
46
+ if (!name) return null;
47
+ return REGISTRY[name] || null;
48
+ }
49
+
50
+ export function rewriteCommandOutput(text) {
51
+ if (typeof text !== 'string' || text.length === 0) {
52
+ return { text: text ?? '', rewriter: null, savedBytes: 0 };
53
+ }
54
+ for (const name of PRIORITY) {
55
+ const mod = REGISTRY[name];
56
+ if (!mod) continue;
57
+ let hit = false;
58
+ try {
59
+ hit = !!mod.match(text);
60
+ } catch {
61
+ hit = false;
62
+ }
63
+ if (!hit) continue;
64
+ let out = text;
65
+ try {
66
+ out = mod.rewrite(text);
67
+ } catch {
68
+ out = text;
69
+ }
70
+ if (typeof out !== 'string') out = text;
71
+ const savedBytes = Math.max(0, Buffer.byteLength(text, 'utf8') - Buffer.byteLength(out, 'utf8'));
72
+ return { text: out, rewriter: mod.name || name, savedBytes };
73
+ }
74
+ return { text, rewriter: null, savedBytes: 0 };
75
+ }
76
+
77
+ export default { getRewriter, rewriteCommandOutput, PRIORITY };
@@ -25,6 +25,34 @@ const DANGEROUS_TASK_PATTERNS = [
25
25
  /test|spec|coverage/i,
26
26
  ]
27
27
 
28
+ /**
29
+ * Per-agent rule overrides. Keyed by `config.agent` (lowercased short name).
30
+ * Shape: { <agent>: { safe?: string, dangerous?: string, complex?: string, conservative?: string } }
31
+ *
32
+ * Hook: populate these tables to tune phrasing per agent. A missing entry
33
+ * falls through to the shared rules. Codex CLI's post-processor already
34
+ * strips explanations, so we use terser phrasing there — other agents get
35
+ * the default rules until we have evidence they benefit from variants.
36
+ */
37
+ export const PER_AGENT_OVERRIDES = Object.freeze({
38
+ codex: {
39
+ safe: `## Token-Efficient Output (Balanced / Codex)
40
+ - Code only. No prose, no preamble, no summary.
41
+ - Single-line status after the change (e.g., "done", "noop").
42
+ `,
43
+ complex: `## Token-Efficient Output (Balanced / Codex)
44
+ - Terse bullets. No filler sentences.
45
+ - Skip "Here's what I'll do" intros — just do it.
46
+ - Return code first; explanation only if non-obvious.
47
+ `,
48
+ },
49
+ // Intentionally empty — add overrides here if evidence warrants it.
50
+ cursor: {},
51
+ cline: {},
52
+ aider: {},
53
+ 'claude-code': {},
54
+ })
55
+
28
56
  /**
29
57
  * Detect task type from user message
30
58
  * @param {string} userMessage - User's input message
@@ -49,6 +77,15 @@ export function detectTaskType(userMessage) {
49
77
  return 'complex'
50
78
  }
51
79
 
80
+ /**
81
+ * True if the user's latest message matches a DANGEROUS_TASK_PATTERNS entry.
82
+ * Used by lossy stages (e.g., disclosure) to bypass when the task demands
83
+ * full fidelity (security/debug/refactor/test).
84
+ */
85
+ export function isDangerousTask(userMessage) {
86
+ return detectTaskType(userMessage) === 'dangerous'
87
+ }
88
+
52
89
  /**
53
90
  * Output compression intensity levels
54
91
  */
@@ -83,14 +120,16 @@ export const OUTPUT_MODES = Object.freeze({
83
120
  * Generate optimized CLAUDE.md rules for output compression
84
121
  * @param {string} mode - Output mode (conservative | balanced | aggressive)
85
122
  * @param {string} taskType - Task type (safe | dangerous | complex)
123
+ * @param {string} [agent] - Optional agent name for per-agent overrides
86
124
  * @returns {string} - Optimized CLAUDE.md rules text
87
125
  */
88
- export function generateOutputRules(mode = 'balanced', taskType = 'complex') {
126
+ export function generateOutputRules(mode = 'balanced', taskType = 'complex', agent) {
89
127
  const modeConfig = OUTPUT_MODES[mode] || OUTPUT_MODES.balanced
90
128
 
91
129
  // Conservative mode always generates minimal rules (for all task types)
92
130
  if (mode === 'conservative') {
93
- return generateConservativeRules()
131
+ const override = agent && PER_AGENT_OVERRIDES[agent]?.conservative
132
+ return override || generateConservativeRules()
94
133
  }
95
134
 
96
135
  // Determine if we should compress based on mode + task type
@@ -105,6 +144,10 @@ export function generateOutputRules(mode = 'balanced', taskType = 'complex') {
105
144
  return ''
106
145
  }
107
146
 
147
+ // Check per-agent override for this (agent, taskType) pair
148
+ const override = agent && PER_AGENT_OVERRIDES[agent]?.[taskType]
149
+ if (override) return override
150
+
108
151
  // Generate rules based on mode
109
152
  const rules = {
110
153
  balanced: generateBalancedRules(taskType),
package/metadata.js CHANGED
@@ -5,6 +5,7 @@ const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url),
5
5
  export const VERSION = pkg.version
6
6
 
7
7
  export const DEFAULT_STAGES = Object.freeze([
8
+ 'cmd-strip',
8
9
  'minify',
9
10
  'toon',
10
11
  'strip-lines',
@@ -12,6 +13,7 @@ export const DEFAULT_STAGES = Object.freeze([
12
13
  'llmlingua',
13
14
  'dedup',
14
15
  'diff',
16
+ 'read-diff',
15
17
  'prune',
16
18
  ])
17
19
 
@@ -20,6 +22,9 @@ export const EXTRA_STAGES = Object.freeze([
20
22
  'textpress',
21
23
  'foundation-models',
22
24
  'graph',
25
+ 'br-cache',
26
+ 'disclosure',
27
+ 'bm25-trim',
23
28
  ])
24
29
 
25
30
  export const ALL_STAGES = Object.freeze([
@@ -29,12 +34,18 @@ export const ALL_STAGES = Object.freeze([
29
34
 
30
35
  // Stages that can drop or paraphrase content (semantic/neural/comment removal).
31
36
  // `graph` is opt-in but fully lossless — it substitutes a reference marker for
32
- // content the model has already seen earlier in the same session.
37
+ // content the model has already seen earlier in the same session. `br-cache`
38
+ // is also lossless: it's a disk-backed store for large bodies, not a rewriter.
39
+ // `disclosure` IS lossy: it drops body content from the outgoing turn and
40
+ // relies on the model quoting the marker to trigger rehydration next turn.
41
+ // `bm25-trim` drops low-relevance lines from huge tool_results (lossy).
33
42
  export const LOSSY_STAGES = Object.freeze(new Set([
34
43
  'llmlingua',
35
44
  'foundation-models',
36
45
  'textpress',
37
46
  'strip-comments',
47
+ 'disclosure',
48
+ 'bm25-trim',
38
49
  ]))
39
50
 
40
51
  export function isLossy(stage) {
@@ -53,6 +64,10 @@ export const STAGE_HINTS = Object.freeze({
53
64
  summary: 'cross-request dedup, lossless, -99% on re-reads',
54
65
  setup: 'TAMP_STAGES=...,graph',
55
66
  },
67
+ 'read-diff': {
68
+ summary: 'replace re-reads with diffs, lossless, -80% on common flows',
69
+ setup: 'enabled by default in balanced preset',
70
+ },
56
71
  'strip-comments': {
57
72
  summary: 'remove code comments (lossy)',
58
73
  setup: null,
@@ -65,9 +80,22 @@ export const STAGE_HINTS = Object.freeze({
65
80
  summary: 'Apple Intelligence neural (macOS 15+, lossy)',
66
81
  setup: null,
67
82
  },
83
+ 'br-cache': {
84
+ summary: 'Brotli disk cache, persists across sessions, enables Phase 5 disclosure',
85
+ setup: 'TAMP_STAGES=...,br-cache',
86
+ },
87
+ disclosure: {
88
+ summary: 'progressive disclosure for >32KB tool_results, model can quote hash to expand',
89
+ setup: 'TAMP_STAGES=...,disclosure (requires br-cache)',
90
+ },
91
+ 'bm25-trim': {
92
+ summary: 'query-aware line ranking, preserves first+last, bypasses dangerous tasks',
93
+ setup: 'TAMP_STAGES=...,bm25-trim',
94
+ },
68
95
  })
69
96
 
70
97
  export const STAGE_DESCRIPTIONS = Object.freeze({
98
+ 'cmd-strip': 'Strip progress bars and spinners from command output (lossless)',
71
99
  minify: 'Strip JSON whitespace (lossless)',
72
100
  toon: 'Columnar array encoding (lossless)',
73
101
  'strip-lines': 'Remove line-number prefixes',
@@ -76,32 +104,36 @@ export const STAGE_DESCRIPTIONS = Object.freeze({
76
104
  'foundation-models': 'Apple Intelligence neural compression (macOS 15+, Apple Silicon, 100% local)',
77
105
  dedup: 'Deduplicate identical tool_results',
78
106
  diff: 'Replace similar re-reads with diffs',
107
+ 'read-diff': 'Session-scoped unified diff for re-reads (lossless, opt-in)',
79
108
  prune: 'Strip lockfile hashes & npm metadata',
80
109
  'strip-comments': 'Remove code comments (lossy)',
81
110
  textpress: 'LLM semantic compression (Ollama/OpenRouter)',
82
111
  graph: 'Session-scoped dedup across requests (lossless, opt-in)',
112
+ 'br-cache': 'Disk-backed Brotli store for large tool_results (lossless, opt-in)',
113
+ disclosure: '3-tier summary for huge tool_results with on-demand rehydration (lossy, aggressive-only)',
114
+ 'bm25-trim': 'Drop low-relevance lines from huge tool_results via BM25 (lossy, aggressive-only)',
83
115
  })
84
116
 
85
117
  export const COMPRESSION_PRESETS = Object.freeze({
86
118
  conservative: {
87
119
  name: 'Conservative',
88
120
  description: 'Safe, lossless compression only',
89
- stages: ['minify', 'toon', 'strip-lines', 'whitespace', 'dedup', 'diff'],
121
+ stages: ['cmd-strip', 'minify', 'toon', 'strip-lines', 'whitespace', 'dedup', 'diff'],
90
122
  expectedSavings: '45-50%',
91
123
  risk: 'None',
92
124
  },
93
125
  balanced: {
94
126
  name: 'Balanced',
95
127
  description: 'Default, includes semantic compression',
96
- stages: ['minify', 'toon', 'strip-lines', 'whitespace', 'llmlingua', 'dedup', 'diff', 'prune'],
128
+ stages: ['cmd-strip', 'minify', 'toon', 'strip-lines', 'whitespace', 'llmlingua', 'dedup', 'diff', 'read-diff', 'prune'],
97
129
  expectedSavings: '52-58%',
98
130
  risk: 'Low',
99
131
  },
100
132
  aggressive: {
101
133
  name: 'Aggressive',
102
134
  description: 'Maximum compression, lossy stages enabled',
103
- stages: ['minify', 'toon', 'strip-lines', 'whitespace', 'llmlingua', 'dedup', 'diff', 'prune', 'strip-comments', 'textpress'],
104
- expectedSavings: '60-68%',
135
+ stages: ['cmd-strip', 'minify', 'toon', 'strip-lines', 'whitespace', 'llmlingua', 'dedup', 'diff', 'read-diff', 'prune', 'strip-comments', 'textpress', 'br-cache', 'disclosure', 'bm25-trim'],
136
+ expectedSavings: '65-72%',
105
137
  risk: 'Medium (may lose comments, verbose text)',
106
138
  },
107
139
  })
package/package.json CHANGED
@@ -12,8 +12,8 @@
12
12
  "stats.js",
13
13
  "lib/"
14
14
  ],
15
- "version": "0.5.9",
16
- "description": "Token compression proxy for coding agents. Works with Claude Code, Aider, Cursor, Cline, Windsurf. 60-70% combined input+output savings with Caveman-integrated presets.",
15
+ "version": "0.7.0",
16
+ "description": "Token compression proxy for coding agents. Works with Claude Code, Aider, Cursor, Cline, Windsurf. 60-70% combined input+output savings with Caveman-integrated presets and per-command rewriters.",
17
17
  "type": "module",
18
18
  "main": "index.js",
19
19
  "bin": {