@sliday/tamp 0.4.3 → 0.4.5
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 +9 -29
- package/compress.js +3 -2
- package/index.js +47 -2
- package/package.json +1 -1
- package/stats.js +2 -1
package/README.md
CHANGED
|
@@ -84,43 +84,23 @@ All 8 default stages are enabled by default. Two additional lossy stages are ava
|
|
|
84
84
|
|
|
85
85
|
## Quick Start
|
|
86
86
|
|
|
87
|
-
###
|
|
87
|
+
### Option A: One-line installer
|
|
88
88
|
|
|
89
89
|
```bash
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
```
|
|
94
|
-
┌─ Tamp ─────────────────────────────────┐
|
|
95
|
-
│ Proxy: http://localhost:7778 │
|
|
96
|
-
│ Status: ● Ready │
|
|
97
|
-
│ │
|
|
98
|
-
│ Claude Code: │
|
|
99
|
-
│ ANTHROPIC_BASE_URL=http://localhost:7778
|
|
100
|
-
│ │
|
|
101
|
-
│ Aider / Cursor / Cline: │
|
|
102
|
-
│ OPENAI_API_BASE=http://localhost:7778
|
|
103
|
-
└────────────────────────────────────────┘
|
|
90
|
+
curl -fsSL https://tamp.dev/setup.sh | bash
|
|
104
91
|
```
|
|
105
92
|
|
|
106
|
-
|
|
93
|
+
Installs via npm, sets `ANTHROPIC_BASE_URL` and `OPENAI_API_BASE` in your shell profile. Then just run `tamp` in one terminal and your agent in another.
|
|
107
94
|
|
|
108
|
-
|
|
109
|
-
```bash
|
|
110
|
-
export ANTHROPIC_BASE_URL=http://localhost:7778
|
|
111
|
-
claude
|
|
112
|
-
```
|
|
95
|
+
### Option B: Manual
|
|
113
96
|
|
|
114
|
-
**Aider:**
|
|
115
97
|
```bash
|
|
116
|
-
|
|
117
|
-
|
|
98
|
+
npx @sliday/tamp # start proxy
|
|
99
|
+
export ANTHROPIC_BASE_URL=http://localhost:7778 # Claude Code
|
|
100
|
+
export OPENAI_API_BASE=http://localhost:7778 # Aider, Cursor, Cline
|
|
118
101
|
```
|
|
119
102
|
|
|
120
|
-
|
|
121
|
-
Set the API base URL to `http://localhost:7778` in your editor's settings.
|
|
122
|
-
|
|
123
|
-
That's it. Use your agent as normal — Tamp compresses silently in the background.
|
|
103
|
+
Use your agent as normal — Tamp compresses silently in the background.
|
|
124
104
|
|
|
125
105
|
## Configuration
|
|
126
106
|
|
|
@@ -222,7 +202,7 @@ tamp uninstall-service # remove
|
|
|
222
202
|
curl -fsSL https://tamp.dev/setup.sh | bash
|
|
223
203
|
```
|
|
224
204
|
|
|
225
|
-
|
|
205
|
+
Installs `@sliday/tamp` globally via npm and adds `ANTHROPIC_BASE_URL` + `OPENAI_API_BASE` to your shell profile.
|
|
226
206
|
|
|
227
207
|
## What Gets Compressed
|
|
228
208
|
|
package/compress.js
CHANGED
|
@@ -195,9 +195,9 @@ async function textpressCompress(text, config) {
|
|
|
195
195
|
|
|
196
196
|
// --- Core compression ---
|
|
197
197
|
export function compressText(text, config) {
|
|
198
|
-
if (text.length < config.minSize) return null
|
|
198
|
+
if (text.length < config.minSize) { if (config.log !== false) process.stderr.write(`[tamp] skip: too small (${text.length} < ${config.minSize})\n`); return null }
|
|
199
199
|
const cls = classifyContent(text)
|
|
200
|
-
if (cls === 'toon') return null
|
|
200
|
+
if (cls === 'toon') { if (config.log !== false) process.stderr.write(`[tamp] skip: classified as toon (first 80: ${text.slice(0, 80).replace(/\n/g, '\\n')})\n`); return null }
|
|
201
201
|
|
|
202
202
|
if (cls === 'text') {
|
|
203
203
|
let processed = text
|
|
@@ -220,6 +220,7 @@ export function compressText(text, config) {
|
|
|
220
220
|
if (config.stages.includes('textpress')) {
|
|
221
221
|
return { async: true, asyncMethod: 'textpress', text: processed, cls }
|
|
222
222
|
}
|
|
223
|
+
if (config.log !== false) process.stderr.write(`[tamp] skip: text not compressible (${config.stages.includes('llmlingua') && !config.llmLinguaUrl ? 'no llmlingua sidecar' : 'whitespace savings < 10%'})\n`)
|
|
223
224
|
return null
|
|
224
225
|
}
|
|
225
226
|
|
package/index.js
CHANGED
|
@@ -88,10 +88,29 @@ function pipeRequest(req, res, upstreamUrl, prefixChunks) {
|
|
|
88
88
|
|
|
89
89
|
return http.createServer(async (req, res) => {
|
|
90
90
|
// Health check endpoint
|
|
91
|
-
if (req.url === '/health' && (req.method === 'GET' || req.method === 'HEAD')) {
|
|
91
|
+
if ((req.url === '/health' || req.url === '/health?text') && (req.method === 'GET' || req.method === 'HEAD')) {
|
|
92
92
|
const totals = session.getTotals()
|
|
93
|
+
if (req.url === '/health?text') {
|
|
94
|
+
const ratio = totals.totalOriginal > 0 ? (totals.totalSaved * 100 / totals.totalOriginal).toFixed(1) + '%' : 'n/a'
|
|
95
|
+
const sidecarStatus = config.stages.includes('llmlingua') ? (sidecarAvailable ? 'ok' : 'not running') : 'n/a'
|
|
96
|
+
const lines = [`Tamp v${config.version} | ${config.stages.length} stages active | sidecar: ${sidecarStatus}`]
|
|
97
|
+
if (totals.requestCount === 0) {
|
|
98
|
+
lines.push('No requests yet this session')
|
|
99
|
+
} else {
|
|
100
|
+
lines.push(`Requests: ${totals.requestCount} | Blocks: ${totals.compressionCount}`)
|
|
101
|
+
lines.push(`Tokens saved: ${totals.totalTokensSaved} | Chars: ${totals.totalSaved}/${totals.totalOriginal} (${ratio})`)
|
|
102
|
+
if (totals.totalTokensSaved > 0) {
|
|
103
|
+
const son = (totals.totalTokensSaved * 3 / 1e6).toFixed(4)
|
|
104
|
+
const opus = (totals.totalTokensSaved * 15 / 1e6).toFixed(4)
|
|
105
|
+
lines.push(`Est. savings: $${son} (Sonnet $3/Mtok) | $${opus} (Opus $15/Mtok)`)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const body = lines.join('\n') + '\n'
|
|
109
|
+
res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': Buffer.byteLength(body) })
|
|
110
|
+
return res.end(req.method === 'HEAD' ? undefined : body)
|
|
111
|
+
}
|
|
93
112
|
const body = JSON.stringify({
|
|
94
|
-
status: 'ok', version: config.version, stages: config.stages,
|
|
113
|
+
status: 'ok', version: config.version, stages: config.stages, sidecar: sidecarAvailable,
|
|
95
114
|
session: {
|
|
96
115
|
requests: totals.requestCount,
|
|
97
116
|
tokensSaved: totals.totalTokensSaved,
|
|
@@ -217,6 +236,28 @@ function createRequestLogger(config) {
|
|
|
217
236
|
}
|
|
218
237
|
}
|
|
219
238
|
|
|
239
|
+
const SIDECAR_PORT = 8788
|
|
240
|
+
const SIDECAR_URL = `http://localhost:${SIDECAR_PORT}`
|
|
241
|
+
|
|
242
|
+
let sidecarAvailable = false
|
|
243
|
+
|
|
244
|
+
function probeSidecar(config) {
|
|
245
|
+
const req = http.get(`${SIDECAR_URL}/health`, { timeout: 2000 }, (res) => {
|
|
246
|
+
if (res.statusCode === 200) {
|
|
247
|
+
sidecarAvailable = true
|
|
248
|
+
if (!config.llmLinguaUrl) config.llmLinguaUrl = SIDECAR_URL
|
|
249
|
+
console.error(`[tamp] llmlingua sidecar: ok (${config.llmLinguaUrl})`)
|
|
250
|
+
}
|
|
251
|
+
res.resume()
|
|
252
|
+
})
|
|
253
|
+
req.on('error', () => {
|
|
254
|
+
sidecarAvailable = false
|
|
255
|
+
console.error('[tamp] \u26a0 llmlingua stage enabled but sidecar not running \u2014 text blocks won\u2019t compress')
|
|
256
|
+
console.error('[tamp] start with: uv run --with fastapi --with uvicorn --with llmlingua --with mlx uvicorn server:app --host 0.0.0.0 --port 8788 --app-dir sidecar')
|
|
257
|
+
})
|
|
258
|
+
req.on('timeout', () => { req.destroy() })
|
|
259
|
+
}
|
|
260
|
+
|
|
220
261
|
const isMain = !process.argv[1]?.includes('node_modules') && process.argv[1] === new URL(import.meta.url).pathname
|
|
221
262
|
|
|
222
263
|
if (isMain) {
|
|
@@ -225,5 +266,9 @@ if (isMain) {
|
|
|
225
266
|
console.error(`[tamp] proxy listening on http://localhost:${config.port}`)
|
|
226
267
|
console.error(`[tamp] upstream: ${config.upstream}`)
|
|
227
268
|
console.error(`[tamp] stages: ${config.stages.join(', ')}`)
|
|
269
|
+
|
|
270
|
+
if (config.stages.includes('llmlingua')) {
|
|
271
|
+
probeSidecar(config)
|
|
272
|
+
}
|
|
228
273
|
})
|
|
229
274
|
}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"providers.js",
|
|
11
11
|
"stats.js"
|
|
12
12
|
],
|
|
13
|
-
"version": "0.4.
|
|
13
|
+
"version": "0.4.5",
|
|
14
14
|
"description": "Token compression proxy for coding agents. Works with Claude Code, Aider, Cursor, Cline, Windsurf. 52.6% fewer input tokens.",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"main": "index.js",
|
package/stats.js
CHANGED
|
@@ -22,7 +22,8 @@ export function formatRequestLog(stats, session, providerName, url, bodySize, to
|
|
|
22
22
|
if (!compressed.length) {
|
|
23
23
|
const skipCount = stats.filter(s => s.skipped).length
|
|
24
24
|
const n = stats.length
|
|
25
|
-
const
|
|
25
|
+
const reasons = [...new Set(stats.filter(s => s.skipped).map(s => s.skipped))].join(', ')
|
|
26
|
+
const reason = skipCount ? `${skipCount} skipped (${reasons})` : 'nothing to compress'
|
|
26
27
|
return `[tamp] ${c.cyan}${label}${c.reset} ${path}${sizeInfo} ${c.dim}— ${n} block${n !== 1 ? 's' : ''}, ${reason}${c.reset}`
|
|
27
28
|
}
|
|
28
29
|
|