@sliday/tamp 0.3.5 → 0.3.7

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/bin/tamp.js +76 -79
  2. 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,54 +12,68 @@ 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
- bold: '\x1b[1m',
17
- dim: '\x1b[2m',
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 STAGE_INFO = {
29
- minify: 'Strip JSON whitespace (lossless)',
30
- toon: 'Columnar array encoding (lossless)',
31
- 'strip-lines':'Remove line-number prefixes from Read output',
32
- whitespace: 'Collapse blank lines, trim trailing spaces',
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',
37
- 'strip-comments': 'Remove code comments (lossy, opt-in)',
38
- textpress: 'LLM semantic compression via Ollama/OpenRouter (opt-in)',
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 ---
42
38
  const skipPrompt = process.argv.includes('-y') || process.argv.includes('--no-interactive') || !process.stdin.isTTY
43
39
  let selectedStages
44
40
 
45
- if (process.env.TAMP_STAGES) {
46
- selectedStages = process.env.TAMP_STAGES.split(',').map(s => s.trim()).filter(Boolean)
47
- } else if (skipPrompt) {
48
- selectedStages = Object.keys(STAGE_INFO).filter(s => s !== 'strip-comments' && s !== 'textpress')
41
+ // Determine pre-checked stages from env var (if set)
42
+ const envStages = process.env.TAMP_STAGES
43
+ ? new Set(process.env.TAMP_STAGES.split(',').map(s => s.trim()).filter(Boolean))
44
+ : null
45
+
46
+ if (skipPrompt) {
47
+ selectedStages = envStages ? [...envStages] : [...DEFAULT_STAGES]
49
48
  } else {
50
49
  log('')
51
- log(` ${c.bold}${c.cyan}Tamp${c.reset} ${c.dim}v${pkg.version}${c.reset} — Token compression proxy`)
50
+ log(` ${c.bold}${c.cyan}Tamp${c.reset} ${c.dim}v${pkg.version}${c.reset}`)
51
+ log(` ${c.dim}Token compression proxy for coding agents${c.reset}`)
52
52
  log('')
53
+
53
54
  selectedStages = await checkbox({
54
- message: 'Compression methods (space to toggle, enter to confirm):',
55
- choices: Object.entries(STAGE_INFO).map(([value, desc]) => ({
56
- name: `${value.padEnd(12)} ${c.dim}— ${desc}${c.reset}`,
57
- value,
58
- checked: value !== 'strip-comments' && value !== 'textpress',
59
- })),
55
+ message: 'Select compression stages:',
56
+ choices: [
57
+ new Separator(`${c.dim}── Default (lossless) ──${c.reset}`),
58
+ ...DEFAULT_STAGES.map(s => ({
59
+ name: `${c.cyan}${s.padEnd(15)}${c.reset} ${c.dim}${STAGE_DESC[s]}${c.reset}`,
60
+ value: s,
61
+ checked: envStages ? envStages.has(s) : true,
62
+ })),
63
+ new Separator(`${c.dim}── Extra (lossy, opt-in) ──${c.reset}`),
64
+ ...EXTRA_STAGES.map(s => ({
65
+ name: `${c.yellow}${s.padEnd(15)}${c.reset} ${c.dim}${STAGE_DESC[s]}${c.reset}`,
66
+ value: s,
67
+ checked: envStages ? envStages.has(s) : false,
68
+ })),
69
+ ],
70
+ pageSize: 15,
71
+ loop: false,
60
72
  })
73
+
61
74
  if (selectedStages.length === 0) {
62
- log(` ${c.yellow}No methods selected — running as passthrough proxy.${c.reset}`)
75
+ log(`\n ${c.red}No stages selected. At least one is required.${c.reset}`)
76
+ process.exit(1)
63
77
  }
64
78
  }
65
79
 
@@ -71,8 +85,7 @@ let sidecarProc = null
71
85
  async function checkPort(port) {
72
86
  return new Promise(resolve => {
73
87
  const req = http.get(`http://127.0.0.1:${port}/health`, (res) => {
74
- res.resume()
75
- resolve(res.statusCode === 200)
88
+ res.resume(); resolve(res.statusCode === 200)
76
89
  })
77
90
  req.on('error', () => resolve(false))
78
91
  req.setTimeout(1000, () => { req.destroy(); resolve(false) })
@@ -88,46 +101,37 @@ async function startSidecar() {
88
101
  const sidecarDir = join(root, 'sidecar')
89
102
  const serverPy = join(sidecarDir, 'server.py')
90
103
 
91
- // 1. Already running?
92
104
  if (await checkPort(sidecarPort)) {
93
- log(` ${c.green}✓${c.reset} LLMLingua-2 sidecar already running on port ${sidecarPort}`)
105
+ log(` ${c.green}✓${c.reset} LLMLingua-2 sidecar already running on :${sidecarPort}`)
94
106
  return `http://localhost:${sidecarPort}`
95
107
  }
96
-
97
- if (!existsSync(serverPy)) {
98
- return null
99
- }
108
+ if (!existsSync(serverPy)) return null
100
109
 
101
110
  log(` ${c.yellow}→${c.reset} Starting LLMLingua-2 sidecar ...`)
102
111
 
103
- // 2. Try uv run (no venv needed)
104
112
  if (hasCommand('uv')) {
105
113
  try {
106
114
  const proc = spawn('uv', [
107
115
  'run', '--with', 'fastapi', '--with', 'uvicorn', '--with', 'llmlingua', '--with', 'mlx',
108
116
  'uvicorn', 'server:app', '--host', '127.0.0.1', '--port', String(sidecarPort),
109
117
  ], { cwd: sidecarDir, stdio: ['ignore', 'pipe', 'pipe'] })
110
-
111
118
  const url = await waitForSidecar(proc, sidecarPort)
112
119
  if (url) { sidecarProc = proc; return url }
113
120
  proc.kill()
114
121
  } catch { /* try next */ }
115
122
  }
116
123
 
117
- // 3. Try existing venv
118
124
  const venvPython = join(sidecarDir, '.venv', 'bin', 'python')
119
125
  if (existsSync(venvPython)) {
120
126
  try {
121
127
  const proc = spawn(venvPython, [
122
128
  '-m', 'uvicorn', 'server:app', '--host', '127.0.0.1', '--port', String(sidecarPort),
123
129
  ], { cwd: sidecarDir, stdio: ['ignore', 'pipe', 'pipe'] })
124
-
125
130
  const url = await waitForSidecar(proc, sidecarPort)
126
131
  if (url) { sidecarProc = proc; return url }
127
132
  proc.kill()
128
133
  } catch { /* fall through */ }
129
134
  }
130
-
131
135
  return null
132
136
  }
133
137
 
@@ -137,7 +141,7 @@ function waitForSidecar(proc, port, timeout = 30000) {
137
141
  proc.stderr.on('data', (d) => {
138
142
  if (d.toString().includes('Uvicorn running')) {
139
143
  clearTimeout(timer)
140
- log(` ${c.green}✓${c.reset} LLMLingua-2 sidecar ready on port ${c.bold}${port}${c.reset}`)
144
+ log(` ${c.green}✓${c.reset} LLMLingua-2 ready on :${c.bold}${port}${c.reset}`)
141
145
  resolve(`http://localhost:${port}`)
142
146
  }
143
147
  })
@@ -145,18 +149,14 @@ function waitForSidecar(proc, port, timeout = 30000) {
145
149
  })
146
150
  }
147
151
 
148
- // Start sidecar if llmlingua is in selected stages
149
152
  if (selectedStages.includes('llmlingua')) {
150
153
  const sidecarUrl = await startSidecar()
151
154
  if (sidecarUrl) {
152
155
  process.env.TAMP_LLMLINGUA_URL = sidecarUrl
153
156
  } else {
154
- log(` ${c.yellow}!${c.reset} LLMLingua-2 sidecar not available`)
155
- if (!hasCommand('uv')) {
156
- log(` Install uv: ${c.cyan}curl -LsSf https://astral.sh/uv/install.sh | sh${c.reset}`)
157
- }
158
- log(` Continuing without neural compression.`)
159
- log('')
157
+ log(` ${c.yellow}!${c.reset} LLMLingua-2 not available`)
158
+ if (!hasCommand('uv')) log(` ${c.dim}Install uv: curl -LsSf https://astral.sh/uv/install.sh | sh${c.reset}`)
159
+ log(` ${c.dim}Continuing without neural compression.${c.reset}`)
160
160
  selectedStages = selectedStages.filter(s => s !== 'llmlingua')
161
161
  process.env.TAMP_STAGES = selectedStages.join(',')
162
162
  }
@@ -167,39 +167,36 @@ const { config, server } = createProxy()
167
167
 
168
168
  function printBanner() {
169
169
  const url = `http://localhost:${config.port}`
170
+ const active = config.stages
171
+ const defaultActive = active.filter(s => DEFAULT_STAGES.includes(s))
172
+ const extraActive = active.filter(s => EXTRA_STAGES.includes(s))
170
173
 
171
174
  log('')
172
- log(` ${c.bold}${c.cyan}┌─ Tamp ${c.dim}v${pkg.version}${c.reset}${c.bold}${c.cyan} ───────────────────────────────┐${c.reset}`)
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}`)
175
+ 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
176
  log('')
183
-
184
- log(` ${c.bold}Upstreams:${c.reset}`)
185
- log(` ${c.magenta}anthropic${c.reset} → ${c.dim}${config.upstreams.anthropic}${c.reset}`)
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}`)
177
+ log(` ${c.bold}Setup:${c.reset}`)
178
+ log(` ${c.dim}Claude Code:${c.reset} ANTHROPIC_BASE_URL=${c.yellow}${url}${c.reset}`)
179
+ log(` ${c.dim}Aider/Cursor:${c.reset} OPENAI_BASE_URL=${c.yellow}${url}${c.reset}`)
188
180
  log('')
189
181
 
190
- log(` ${c.bold}Compression:${c.reset}`)
191
- for (const [stage, desc] of Object.entries(STAGE_INFO)) {
192
- const active = config.stages.includes(stage)
193
- const icon = active ? `${c.green}✓${c.reset}` : `${c.dim}✗${c.reset}`
194
- const extra = stage === 'llmlingua' && active && config.llmLinguaUrl ? ` ${c.dim}(${config.llmLinguaUrl})${c.reset}` : ''
195
- log(` ${icon} ${active ? c.cyan : c.dim}${stage}${c.reset} — ${active ? desc : c.dim + desc + c.reset}${extra}`)
182
+ log(` ${c.bold}Stages${c.reset} ${c.dim}(${active.length} active)${c.reset}`)
183
+ for (const s of defaultActive) {
184
+ const extra = s === 'llmlingua' && config.llmLinguaUrl ? ` ${c.dim}(${config.llmLinguaUrl})${c.reset}` : ''
185
+ log(` ${c.green}✓${c.reset} ${c.cyan}${s}${c.reset}${extra}`)
186
+ }
187
+ if (extraActive.length) {
188
+ for (const s of extraActive) {
189
+ log(` ${c.yellow}✓${c.reset} ${c.yellow}${s}${c.reset} ${c.dim}(lossy)${c.reset}`)
190
+ }
191
+ }
192
+ const disabled = [...DEFAULT_STAGES, ...EXTRA_STAGES].filter(s => !active.includes(s))
193
+ if (disabled.length && disabled.length <= 4) {
194
+ log(` ${c.dim}✗ ${disabled.join(', ')}${c.reset}`)
196
195
  }
197
196
  log('')
198
197
  }
199
198
 
200
- server.listen(config.port, () => {
201
- printBanner()
202
- })
199
+ server.listen(config.port, () => { printBanner() })
203
200
 
204
201
  process.on('exit', () => sidecarProc?.kill())
205
202
  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.5",
12
+ "version": "0.3.7",
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",