@sliday/tamp 0.3.4 → 0.3.6
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/bin/tamp.js +70 -76
- package/package.json +1 -1
package/bin/tamp.js
CHANGED
|
@@ -4,7 +4,7 @@ import { existsSync, readFileSync } from 'node:fs'
|
|
|
4
4
|
import { spawn, execFileSync } from 'node:child_process'
|
|
5
5
|
import { fileURLToPath } from 'node:url'
|
|
6
6
|
import { dirname, join } from 'node:path'
|
|
7
|
-
import { checkbox } from '@inquirer/prompts'
|
|
7
|
+
import { checkbox, Separator } from '@inquirer/prompts'
|
|
8
8
|
import http from 'node:http'
|
|
9
9
|
|
|
10
10
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
@@ -12,30 +12,26 @@ const root = join(__dirname, '..')
|
|
|
12
12
|
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf-8'))
|
|
13
13
|
|
|
14
14
|
const c = {
|
|
15
|
-
reset: '\x1b[0m',
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
green: '\x1b[32m',
|
|
19
|
-
yellow: '\x1b[33m',
|
|
20
|
-
blue: '\x1b[34m',
|
|
21
|
-
magenta: '\x1b[35m',
|
|
22
|
-
cyan: '\x1b[36m',
|
|
23
|
-
bgGreen: '\x1b[42m',
|
|
15
|
+
reset: '\x1b[0m', bold: '\x1b[1m', dim: '\x1b[2m',
|
|
16
|
+
green: '\x1b[32m', yellow: '\x1b[33m', blue: '\x1b[34m',
|
|
17
|
+
magenta: '\x1b[35m', cyan: '\x1b[36m', bgGreen: '\x1b[42m', red: '\x1b[31m',
|
|
24
18
|
}
|
|
25
|
-
|
|
26
19
|
function log(msg = '') { console.error(msg) }
|
|
27
20
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
21
|
+
const DEFAULT_STAGES = ['minify', 'toon', 'strip-lines', 'whitespace', 'llmlingua', 'dedup', 'diff', 'prune']
|
|
22
|
+
const EXTRA_STAGES = ['strip-comments', 'textpress']
|
|
23
|
+
|
|
24
|
+
const STAGE_DESC = {
|
|
25
|
+
minify: 'Strip JSON whitespace (lossless)',
|
|
26
|
+
toon: 'Columnar array encoding (lossless)',
|
|
27
|
+
'strip-lines': 'Remove line-number prefixes',
|
|
28
|
+
whitespace: 'Collapse blank lines, trim trailing',
|
|
29
|
+
llmlingua: 'Neural compression via LLMLingua-2',
|
|
30
|
+
dedup: 'Deduplicate identical tool_results',
|
|
31
|
+
diff: 'Replace similar re-reads with diffs',
|
|
32
|
+
prune: 'Strip lockfile hashes & npm metadata',
|
|
33
|
+
'strip-comments': 'Remove code comments (lossy)',
|
|
34
|
+
textpress: 'LLM semantic compression (Ollama/OpenRouter)',
|
|
39
35
|
}
|
|
40
36
|
|
|
41
37
|
// --- Determine stages ---
|
|
@@ -45,21 +41,36 @@ let selectedStages
|
|
|
45
41
|
if (process.env.TAMP_STAGES) {
|
|
46
42
|
selectedStages = process.env.TAMP_STAGES.split(',').map(s => s.trim()).filter(Boolean)
|
|
47
43
|
} else if (skipPrompt) {
|
|
48
|
-
selectedStages =
|
|
44
|
+
selectedStages = [...DEFAULT_STAGES]
|
|
49
45
|
} else {
|
|
50
46
|
log('')
|
|
51
|
-
log(` ${c.bold}${c.cyan}Tamp${c.reset} ${c.dim}v${pkg.version}${c.reset}
|
|
47
|
+
log(` ${c.bold}${c.cyan}Tamp${c.reset} ${c.dim}v${pkg.version}${c.reset}`)
|
|
48
|
+
log(` ${c.dim}Token compression proxy for coding agents${c.reset}`)
|
|
52
49
|
log('')
|
|
50
|
+
|
|
53
51
|
selectedStages = await checkbox({
|
|
54
|
-
message: '
|
|
55
|
-
choices:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
message: 'Select compression stages:',
|
|
53
|
+
choices: [
|
|
54
|
+
new Separator(`${c.dim}── Default (lossless) ──${c.reset}`),
|
|
55
|
+
...DEFAULT_STAGES.map(s => ({
|
|
56
|
+
name: `${c.cyan}${s.padEnd(15)}${c.reset} ${c.dim}${STAGE_DESC[s]}${c.reset}`,
|
|
57
|
+
value: s,
|
|
58
|
+
checked: true,
|
|
59
|
+
})),
|
|
60
|
+
new Separator(`${c.dim}── Extra (lossy, opt-in) ──${c.reset}`),
|
|
61
|
+
...EXTRA_STAGES.map(s => ({
|
|
62
|
+
name: `${c.yellow}${s.padEnd(15)}${c.reset} ${c.dim}${STAGE_DESC[s]}${c.reset}`,
|
|
63
|
+
value: s,
|
|
64
|
+
checked: false,
|
|
65
|
+
})),
|
|
66
|
+
],
|
|
67
|
+
pageSize: 15,
|
|
68
|
+
loop: false,
|
|
60
69
|
})
|
|
70
|
+
|
|
61
71
|
if (selectedStages.length === 0) {
|
|
62
|
-
log(
|
|
72
|
+
log(`\n ${c.red}No stages selected. At least one is required.${c.reset}`)
|
|
73
|
+
process.exit(1)
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
|
|
@@ -71,8 +82,7 @@ let sidecarProc = null
|
|
|
71
82
|
async function checkPort(port) {
|
|
72
83
|
return new Promise(resolve => {
|
|
73
84
|
const req = http.get(`http://127.0.0.1:${port}/health`, (res) => {
|
|
74
|
-
res.resume()
|
|
75
|
-
resolve(res.statusCode === 200)
|
|
85
|
+
res.resume(); resolve(res.statusCode === 200)
|
|
76
86
|
})
|
|
77
87
|
req.on('error', () => resolve(false))
|
|
78
88
|
req.setTimeout(1000, () => { req.destroy(); resolve(false) })
|
|
@@ -88,46 +98,37 @@ async function startSidecar() {
|
|
|
88
98
|
const sidecarDir = join(root, 'sidecar')
|
|
89
99
|
const serverPy = join(sidecarDir, 'server.py')
|
|
90
100
|
|
|
91
|
-
// 1. Already running?
|
|
92
101
|
if (await checkPort(sidecarPort)) {
|
|
93
|
-
log(` ${c.green}✓${c.reset} LLMLingua-2 sidecar already running on
|
|
102
|
+
log(` ${c.green}✓${c.reset} LLMLingua-2 sidecar already running on :${sidecarPort}`)
|
|
94
103
|
return `http://localhost:${sidecarPort}`
|
|
95
104
|
}
|
|
96
|
-
|
|
97
|
-
if (!existsSync(serverPy)) {
|
|
98
|
-
return null
|
|
99
|
-
}
|
|
105
|
+
if (!existsSync(serverPy)) return null
|
|
100
106
|
|
|
101
107
|
log(` ${c.yellow}→${c.reset} Starting LLMLingua-2 sidecar ...`)
|
|
102
108
|
|
|
103
|
-
// 2. Try uv run (no venv needed)
|
|
104
109
|
if (hasCommand('uv')) {
|
|
105
110
|
try {
|
|
106
111
|
const proc = spawn('uv', [
|
|
107
112
|
'run', '--with', 'fastapi', '--with', 'uvicorn', '--with', 'llmlingua', '--with', 'mlx',
|
|
108
113
|
'uvicorn', 'server:app', '--host', '127.0.0.1', '--port', String(sidecarPort),
|
|
109
114
|
], { cwd: sidecarDir, stdio: ['ignore', 'pipe', 'pipe'] })
|
|
110
|
-
|
|
111
115
|
const url = await waitForSidecar(proc, sidecarPort)
|
|
112
116
|
if (url) { sidecarProc = proc; return url }
|
|
113
117
|
proc.kill()
|
|
114
118
|
} catch { /* try next */ }
|
|
115
119
|
}
|
|
116
120
|
|
|
117
|
-
// 3. Try existing venv
|
|
118
121
|
const venvPython = join(sidecarDir, '.venv', 'bin', 'python')
|
|
119
122
|
if (existsSync(venvPython)) {
|
|
120
123
|
try {
|
|
121
124
|
const proc = spawn(venvPython, [
|
|
122
125
|
'-m', 'uvicorn', 'server:app', '--host', '127.0.0.1', '--port', String(sidecarPort),
|
|
123
126
|
], { cwd: sidecarDir, stdio: ['ignore', 'pipe', 'pipe'] })
|
|
124
|
-
|
|
125
127
|
const url = await waitForSidecar(proc, sidecarPort)
|
|
126
128
|
if (url) { sidecarProc = proc; return url }
|
|
127
129
|
proc.kill()
|
|
128
130
|
} catch { /* fall through */ }
|
|
129
131
|
}
|
|
130
|
-
|
|
131
132
|
return null
|
|
132
133
|
}
|
|
133
134
|
|
|
@@ -137,7 +138,7 @@ function waitForSidecar(proc, port, timeout = 30000) {
|
|
|
137
138
|
proc.stderr.on('data', (d) => {
|
|
138
139
|
if (d.toString().includes('Uvicorn running')) {
|
|
139
140
|
clearTimeout(timer)
|
|
140
|
-
log(` ${c.green}✓${c.reset} LLMLingua-2
|
|
141
|
+
log(` ${c.green}✓${c.reset} LLMLingua-2 ready on :${c.bold}${port}${c.reset}`)
|
|
141
142
|
resolve(`http://localhost:${port}`)
|
|
142
143
|
}
|
|
143
144
|
})
|
|
@@ -145,18 +146,14 @@ function waitForSidecar(proc, port, timeout = 30000) {
|
|
|
145
146
|
})
|
|
146
147
|
}
|
|
147
148
|
|
|
148
|
-
// Start sidecar if llmlingua is in selected stages
|
|
149
149
|
if (selectedStages.includes('llmlingua')) {
|
|
150
150
|
const sidecarUrl = await startSidecar()
|
|
151
151
|
if (sidecarUrl) {
|
|
152
152
|
process.env.TAMP_LLMLINGUA_URL = sidecarUrl
|
|
153
153
|
} else {
|
|
154
|
-
log(` ${c.yellow}!${c.reset} LLMLingua-2
|
|
155
|
-
if (!hasCommand('uv')) {
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
log(` Continuing without neural compression.`)
|
|
159
|
-
log('')
|
|
154
|
+
log(` ${c.yellow}!${c.reset} LLMLingua-2 not available`)
|
|
155
|
+
if (!hasCommand('uv')) log(` ${c.dim}Install uv: curl -LsSf https://astral.sh/uv/install.sh | sh${c.reset}`)
|
|
156
|
+
log(` ${c.dim}Continuing without neural compression.${c.reset}`)
|
|
160
157
|
selectedStages = selectedStages.filter(s => s !== 'llmlingua')
|
|
161
158
|
process.env.TAMP_STAGES = selectedStages.join(',')
|
|
162
159
|
}
|
|
@@ -167,39 +164,36 @@ const { config, server } = createProxy()
|
|
|
167
164
|
|
|
168
165
|
function printBanner() {
|
|
169
166
|
const url = `http://localhost:${config.port}`
|
|
167
|
+
const active = config.stages
|
|
168
|
+
const defaultActive = active.filter(s => DEFAULT_STAGES.includes(s))
|
|
169
|
+
const extraActive = active.filter(s => EXTRA_STAGES.includes(s))
|
|
170
170
|
|
|
171
171
|
log('')
|
|
172
|
-
log(` ${c.bold}${c.
|
|
173
|
-
log(` ${c.cyan}│${c.reset} Proxy: ${c.bold}${c.green}${url}${c.reset}${c.cyan} │${c.reset}`)
|
|
174
|
-
log(` ${c.cyan}│${c.reset} Status: ${c.bgGreen}${c.bold} ● READY ${c.reset}${c.cyan} │${c.reset}`)
|
|
175
|
-
log(` ${c.cyan}│${c.reset} ${c.cyan}│${c.reset}`)
|
|
176
|
-
log(` ${c.cyan}│${c.reset} ${c.bold}Claude Code:${c.reset} ${c.cyan}│${c.reset}`)
|
|
177
|
-
log(` ${c.cyan}│${c.reset} ${c.dim}ANTHROPIC_BASE_URL=${c.reset}${c.yellow}${url}${c.reset} ${c.cyan}│${c.reset}`)
|
|
178
|
-
log(` ${c.cyan}│${c.reset} ${c.cyan}│${c.reset}`)
|
|
179
|
-
log(` ${c.cyan}│${c.reset} ${c.bold}Aider / Cursor / Cline:${c.reset} ${c.cyan}│${c.reset}`)
|
|
180
|
-
log(` ${c.cyan}│${c.reset} ${c.dim}OPENAI_BASE_URL=${c.reset}${c.yellow}${url}${c.reset} ${c.cyan}│${c.reset}`)
|
|
181
|
-
log(` ${c.cyan}└────────────────────────────────────────┘${c.reset}`)
|
|
172
|
+
log(` ${c.cyan}${c.bold}Tamp${c.reset} ${c.dim}v${pkg.version}${c.reset} ${c.bgGreen}${c.bold} READY ${c.reset} ${c.green}${url}${c.reset}`)
|
|
182
173
|
log('')
|
|
183
|
-
|
|
184
|
-
log(`
|
|
185
|
-
log(` ${c.
|
|
186
|
-
log(` ${c.magenta}openai${c.reset} → ${c.dim}${config.upstreams.openai}${c.reset}`)
|
|
187
|
-
log(` ${c.magenta}gemini${c.reset} → ${c.dim}${config.upstreams.gemini}${c.reset}`)
|
|
174
|
+
log(` ${c.bold}Setup:${c.reset}`)
|
|
175
|
+
log(` ${c.dim}Claude Code:${c.reset} ANTHROPIC_BASE_URL=${c.yellow}${url}${c.reset}`)
|
|
176
|
+
log(` ${c.dim}Aider/Cursor:${c.reset} OPENAI_BASE_URL=${c.yellow}${url}${c.reset}`)
|
|
188
177
|
log('')
|
|
189
178
|
|
|
190
|
-
log(` ${c.bold}
|
|
191
|
-
for (const
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
179
|
+
log(` ${c.bold}Stages${c.reset} ${c.dim}(${active.length} active)${c.reset}`)
|
|
180
|
+
for (const s of defaultActive) {
|
|
181
|
+
const extra = s === 'llmlingua' && config.llmLinguaUrl ? ` ${c.dim}(${config.llmLinguaUrl})${c.reset}` : ''
|
|
182
|
+
log(` ${c.green}✓${c.reset} ${c.cyan}${s}${c.reset}${extra}`)
|
|
183
|
+
}
|
|
184
|
+
if (extraActive.length) {
|
|
185
|
+
for (const s of extraActive) {
|
|
186
|
+
log(` ${c.yellow}✓${c.reset} ${c.yellow}${s}${c.reset} ${c.dim}(lossy)${c.reset}`)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const disabled = [...DEFAULT_STAGES, ...EXTRA_STAGES].filter(s => !active.includes(s))
|
|
190
|
+
if (disabled.length && disabled.length <= 4) {
|
|
191
|
+
log(` ${c.dim}✗ ${disabled.join(', ')}${c.reset}`)
|
|
196
192
|
}
|
|
197
193
|
log('')
|
|
198
194
|
}
|
|
199
195
|
|
|
200
|
-
server.listen(config.port, () => {
|
|
201
|
-
printBanner()
|
|
202
|
-
})
|
|
196
|
+
server.listen(config.port, () => { printBanner() })
|
|
203
197
|
|
|
204
198
|
process.on('exit', () => sidecarProc?.kill())
|
|
205
199
|
process.on('SIGINT', () => { sidecarProc?.kill(); process.exit() })
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"providers.js",
|
|
10
10
|
"stats.js"
|
|
11
11
|
],
|
|
12
|
-
"version": "0.3.
|
|
12
|
+
"version": "0.3.6",
|
|
13
13
|
"description": "Token compression proxy for coding agents. Works with Claude Code, Aider, Cursor, Cline, Windsurf. 52.6% fewer input tokens.",
|
|
14
14
|
"type": "module",
|
|
15
15
|
"main": "index.js",
|