@sliday/tamp 0.2.14 → 0.3.1

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tamp
2
2
 
3
- **Token compression proxy for coding agents.** 33.9% fewer input tokens, zero code changes. Works with Claude Code, Aider, Cursor, Cline, Windsurf, and any OpenAI-compatible agent.
3
+ **Token compression proxy for coding agents.** 50.5% fewer input tokens, zero code changes. Works with Claude Code, Aider, Cursor, Cline, Windsurf, and any OpenAI-compatible agent.
4
4
 
5
5
  ```
6
6
  npx @sliday/tamp
@@ -232,9 +232,26 @@ test/fixtures/ Sample API payloads
232
232
 
233
233
  Claude Code sends the full conversation history on every API call. As a session progresses, tool results accumulate — file contents, directory listings, command outputs — all re-sent as input tokens on each request.
234
234
 
235
- At $3/million input tokens (Sonnet 4), a 200-request session consuming 3M input tokens costs $9. If 60% of tool results are compressible JSON, and compression removes 30-50% of those tokens, that's $1.60-2.70 saved per session.
235
+ At $3/million input tokens (Sonnet 4.6), a 200-request session consuming 3M input tokens costs $9. With 32% compression on 60% compressible traffic, that's ~63K tokens and $0.19 saved per session. For Opus 4.6 ($5/MTok), savings are $0.32/session.
236
236
 
237
- For teams with 5 developers doing 2 sessions/day, that's $500-800/month in savings.
237
+ ### Claude Max subscribers
238
+
239
+ Max plans have fixed token budgets. With 32% fewer input tokens per request, you get **47% more requests** from the same budget:
240
+
241
+ | Plan | Without Tamp | With Tamp |
242
+ |------|-------------|-----------|
243
+ | Max 5× ($100/mo) | 5× Pro | **7.4×** Pro |
244
+ | Max 20× ($200/mo) | 20× Pro | **29.4×** Pro |
245
+
246
+ ### API cost savings
247
+
248
+ | Model | Per dev/month | 10-person team/year |
249
+ |-------|-------------|-------------------|
250
+ | Sonnet 4.6 ($3/MTok) | $28 | $3,400 |
251
+ | Opus 4.6 ($5/MTok) | $48 | $5,760 |
252
+ | Opus 4.6 extended ($10/MTok) | $96 | $11,520 |
253
+
254
+ Based on 5 sessions/day, 200 requests/session, 60% compressible traffic.
238
255
 
239
256
  ## License
240
257
 
package/bin/tamp.js CHANGED
@@ -31,6 +31,9 @@ const STAGE_INFO = {
31
31
  'strip-lines':'Remove line-number prefixes from Read output',
32
32
  whitespace: 'Collapse blank lines, trim trailing spaces',
33
33
  llmlingua: 'Neural text compression via LLMLingua-2',
34
+ dedup: 'Replace duplicate tool_results with references',
35
+ diff: 'Replace similar re-reads with unified diffs',
36
+ prune: 'Strip lockfile hashes, registry URLs, npm metadata',
34
37
  }
35
38
 
36
39
  // --- Determine stages ---
@@ -99,7 +102,7 @@ async function startSidecar() {
99
102
  if (hasCommand('uv')) {
100
103
  try {
101
104
  const proc = spawn('uv', [
102
- 'run', '--with', 'fastapi,uvicorn,llmlingua',
105
+ 'run', '--with', 'fastapi', '--with', 'uvicorn', '--with', 'llmlingua', '--with', 'mlx',
103
106
  'uvicorn', 'server:app', '--host', '127.0.0.1', '--port', String(sidecarPort),
104
107
  ], { cwd: sidecarDir, stdio: ['ignore', 'pipe', 'pipe'] })
105
108
 
package/compress.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { encode } from '@toon-format/toon'
2
2
  import { countTokens } from '@anthropic-ai/tokenizer'
3
+ import { createPatch } from 'diff'
3
4
  import { tryParseJSON, classifyContent, stripLineNumbers } from './detect.js'
4
5
  import { anthropic } from './providers.js'
5
6
 
@@ -19,6 +20,89 @@ function normalizeWhitespace(text) {
19
20
  .replace(/\n{3,}/g, '\n\n')
20
21
  }
21
22
 
23
+ // --- Stage: dedup ---
24
+ function deduplicateTargets(targets) {
25
+ const seen = new Map()
26
+ for (const target of targets) {
27
+ if (target.skip) continue
28
+ const key = cacheKey(target.text)
29
+ const prev = seen.get(key)
30
+ if (prev && prev.text === target.text) {
31
+ const ref = `[see tool_result in message ${prev.path[1]}, block ${prev.index} — identical content]`
32
+ target.compressed = ref
33
+ target.dedup = true
34
+ } else {
35
+ seen.set(key, target)
36
+ }
37
+ }
38
+ }
39
+
40
+ // --- Stage: diff ---
41
+ function diffTargets(targets) {
42
+ const seen = []
43
+ for (const target of targets) {
44
+ if (target.skip || target.dedup || target.compressed) continue
45
+ if (target.text.length < 200) { seen.push(target); continue }
46
+
47
+ for (const prev of seen) {
48
+ const sim = quickSimilarity(prev.text, target.text)
49
+ if (sim > 0.5 && sim < 1.0) {
50
+ const patch = createPatch('file', prev.text, target.text, '', '', { context: 1 })
51
+ // Strip the patch header (first 4 lines: ---, +++, index, etc.)
52
+ const lines = patch.split('\n')
53
+ const bodyStart = lines.findIndex(l => l.startsWith('@@'))
54
+ if (bodyStart === -1) continue
55
+ const diffBody = lines.slice(bodyStart).join('\n')
56
+ if (diffBody.length < target.text.length * 0.5) {
57
+ target.compressed = `[diff from tool_result in message ${prev.path[1]}, block ${prev.index}]:\n${diffBody}`
58
+ target.diffed = true
59
+ break
60
+ }
61
+ }
62
+ }
63
+ seen.push(target)
64
+ }
65
+ }
66
+
67
+ function quickSimilarity(a, b) {
68
+ if (Math.abs(a.length - b.length) > Math.max(a.length, b.length) * 0.5) return 0
69
+ const setA = new Set(a.split('\n'))
70
+ const setB = new Set(b.split('\n'))
71
+ const intersection = [...setA].filter(x => setB.has(x)).length
72
+ const union = new Set([...setA, ...setB]).size
73
+ return union > 0 ? intersection / union : 0
74
+ }
75
+
76
+ // --- Stage: prune ---
77
+ const PRUNE_KEYS = new Set(['integrity', 'shasum', '_id', '_from', '_resolved', '_integrity', '_nodeVersion', '_npmVersion', '_phantomChildren', '_requiredBy'])
78
+
79
+ function shouldPrune(key, val) {
80
+ if (PRUNE_KEYS.has(key)) return true
81
+ if (key === 'resolved' && typeof val === 'string' && val.startsWith('https://registry.')) return true
82
+ return false
83
+ }
84
+
85
+ function deepPrune(obj) {
86
+ if (Array.isArray(obj)) return obj.map(deepPrune)
87
+ if (obj === null || typeof obj !== 'object') return obj
88
+ const result = {}
89
+ for (const [key, val] of Object.entries(obj)) {
90
+ if (shouldPrune(key, val)) continue
91
+ result[key] = deepPrune(val)
92
+ }
93
+ return result
94
+ }
95
+
96
+ function pruneJSON(text) {
97
+ const { ok, value } = tryParseJSON(text)
98
+ if (!ok) return null
99
+ const pruned = deepPrune(value)
100
+ const result = JSON.stringify(pruned, null, 2)
101
+ if (result.length >= text.length * 0.95) return null
102
+ return result
103
+ }
104
+
105
+ // --- Core compression ---
22
106
  export function compressText(text, config) {
23
107
  if (text.length < config.minSize) return null
24
108
  const cls = classifyContent(text)
@@ -44,7 +128,14 @@ export function compressText(text, config) {
44
128
 
45
129
  if (cls !== 'json' && cls !== 'json-lined') return null
46
130
 
47
- const raw = cls === 'json-lined' ? stripLineNumbers(text) : text
131
+ let raw = cls === 'json-lined' ? stripLineNumbers(text) : text
132
+
133
+ // Prune low-value fields before minifying
134
+ if (config.stages.includes('prune')) {
135
+ const pruned = pruneJSON(raw)
136
+ if (pruned) raw = pruned
137
+ }
138
+
48
139
  const { ok, value } = tryParseJSON(raw)
49
140
  if (!ok) return null
50
141
 
@@ -106,9 +197,27 @@ async function compressBlock(text, config) {
106
197
 
107
198
  export async function compressRequest(body, config, provider) {
108
199
  const targets = provider.extract(body)
200
+
201
+ // Dedup: replace identical blocks with reference markers
202
+ if (config.stages.includes('dedup')) deduplicateTargets(targets)
203
+
204
+ // Diff: replace similar blocks with unified diffs
205
+ if (config.stages.includes('diff')) diffTargets(targets)
206
+
109
207
  const stats = []
110
208
  for (const target of targets) {
111
209
  if (target.skip) { stats.push({ index: target.index, skipped: target.skip }); continue }
210
+
211
+ // Dedup/diff already set .compressed — record stats and skip compression
212
+ if (target.dedup) {
213
+ stats.push({ index: target.index, method: 'dedup', originalLen: target.text.length, compressedLen: target.compressed.length, originalTokens: countTokens(target.text), compressedTokens: countTokens(target.compressed) })
214
+ continue
215
+ }
216
+ if (target.diffed) {
217
+ stats.push({ index: target.index, method: 'diff', originalLen: target.text.length, compressedLen: target.compressed.length, originalTokens: countTokens(target.text), compressedTokens: countTokens(target.compressed) })
218
+ continue
219
+ }
220
+
112
221
  const result = await compressBlock(target.text, config)
113
222
  if (result) {
114
223
  target.compressed = result.text
package/config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export function loadConfig(env = process.env) {
2
- const stages = (env.TAMP_STAGES || 'minify,toon,strip-lines,whitespace,llmlingua').split(',').map(s => s.trim()).filter(Boolean)
2
+ const stages = (env.TAMP_STAGES || 'minify,toon,strip-lines,whitespace,llmlingua,dedup,diff,prune').split(',').map(s => s.trim()).filter(Boolean)
3
3
  return Object.freeze({
4
4
  port: parseInt(env.TAMP_PORT, 10) || 7778,
5
5
  upstream: env.TAMP_UPSTREAM || 'https://api.anthropic.com',
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  "providers.js",
10
10
  "stats.js"
11
11
  ],
12
- "version": "0.2.14",
13
- "description": "Token compression proxy for coding agents. Works with Claude Code, Aider, Cursor, Cline, Windsurf. 33.9% fewer input tokens.",
12
+ "version": "0.3.1",
13
+ "description": "Token compression proxy for coding agents. Works with Claude Code, Aider, Cursor, Cline, Windsurf. 50.5% fewer input tokens.",
14
14
  "type": "module",
15
15
  "main": "index.js",
16
16
  "bin": {
@@ -20,7 +20,8 @@
20
20
  "start": "node bin/tamp.js",
21
21
  "test": "node --test test/*.test.js",
22
22
  "test:sidecar": "node test/capture-golden.js --verify",
23
- "bench:semantic": "node bench/semantic-eval.js"
23
+ "bench:semantic": "node bench/semantic-eval.js",
24
+ "test:quality": "node bench/quality-eval.js"
24
25
  },
25
26
  "keywords": [
26
27
  "claude",
@@ -41,6 +42,7 @@
41
42
  "@anthropic-ai/tokenizer": "^0.0.4",
42
43
  "@inquirer/prompts": "^8.3.2",
43
44
  "@toon-format/toon": "^2.1.0",
45
+ "diff": "^8.0.4",
44
46
  "fzstd": "^0.1.1"
45
47
  }
46
48
  }