@sliday/tamp 0.3.13 → 0.4.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.
Files changed (4) hide show
  1. package/README.md +39 -2
  2. package/bin/tamp.js +101 -1
  3. package/config.js +63 -17
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -113,7 +113,27 @@ That's it. Use your agent as normal — Tamp compresses silently in the backgrou
113
113
 
114
114
  ## Configuration
115
115
 
116
- All configuration via environment variables:
116
+ ### Config file
117
+
118
+ Run `tamp init` to create a persistent config file:
119
+
120
+ ```bash
121
+ tamp init
122
+ # Creates ~/.config/tamp/config
123
+ ```
124
+
125
+ Edit the file to set your defaults. All `TAMP_*` variables are supported. Environment variables still override the config file.
126
+
127
+ ```bash
128
+ # ~/.config/tamp/config
129
+ TAMP_PORT=7778
130
+ TAMP_UPSTREAM=https://api.anthropic.com
131
+ TAMP_STAGES=minify,toon,strip-lines,whitespace,dedup,diff,prune
132
+ ```
133
+
134
+ ### Environment variables
135
+
136
+ All configuration also works via environment variables (override config file):
117
137
 
118
138
  | Variable | Default | Description |
119
139
  |----------|---------|-------------|
@@ -168,6 +188,23 @@ cd tamp && npm install
168
188
  node bin/tamp.js
169
189
  ```
170
190
 
191
+ ### Systemd service (Ubuntu/Linux)
192
+
193
+ ```bash
194
+ npm i -g @sliday/tamp
195
+ tamp init # create config file
196
+ tamp install-service # install + start systemd user service
197
+ ```
198
+
199
+ Manages itself via `systemctl --user`. Starts on login, restarts on crash.
200
+
201
+ ```bash
202
+ tamp status # check if running
203
+ systemctl --user status tamp
204
+ journalctl --user -u tamp -f
205
+ tamp uninstall-service # remove
206
+ ```
207
+
171
208
  ### One-line installer
172
209
 
173
210
  ```bash
@@ -198,7 +235,7 @@ index.js HTTP proxy server
198
235
  providers.js API format adapters (Anthropic, OpenAI, Gemini) + auto-detection
199
236
  compress.js Compression pipeline (compressRequest, compressText)
200
237
  detect.js Content classification (classifyContent, tryParseJSON, stripLineNumbers)
201
- config.js Environment-based configuration
238
+ config.js Configuration (env vars + ~/.config/tamp/config)
202
239
  stats.js Session statistics and request logging
203
240
  setup.sh One-line installer script
204
241
  ```
package/bin/tamp.js CHANGED
@@ -1,11 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { createProxy } from '../index.js'
3
- import { existsSync } from 'node:fs'
3
+ import { existsSync, mkdirSync, writeFileSync, readFileSync, unlinkSync } 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 { homedir } from 'node:os'
7
8
  import http from 'node:http'
8
9
  import { DEFAULT_STAGES, EXTRA_STAGES, STAGE_DESCRIPTIONS, VERSION } from '../metadata.js'
10
+ import { CONFIG_PATH, CONFIG_TEMPLATE } from '../config.js'
9
11
 
10
12
  const __dirname = dirname(fileURLToPath(import.meta.url))
11
13
  const root = join(__dirname, '..')
@@ -77,6 +79,104 @@ export async function startSidecar() {
77
79
  return null
78
80
  }
79
81
 
82
+ // --- Subcommands ---
83
+ const subcommand = process.argv[2]
84
+
85
+ if (subcommand === 'init') {
86
+ const dir = dirname(CONFIG_PATH)
87
+ if (existsSync(CONFIG_PATH)) {
88
+ console.log(`Config file exists: ${CONFIG_PATH}\n`)
89
+ console.log(readFileSync(CONFIG_PATH, 'utf8'))
90
+ } else {
91
+ mkdirSync(dir, { recursive: true })
92
+ writeFileSync(CONFIG_PATH, CONFIG_TEMPLATE)
93
+ console.log(`Created config file: ${CONFIG_PATH}`)
94
+ console.log('Edit it to set your defaults. Environment variables still override.\n')
95
+ console.log(CONFIG_TEMPLATE)
96
+ }
97
+ process.exit(0)
98
+ }
99
+
100
+ if (subcommand === 'install-service') {
101
+ if (process.platform !== 'linux') {
102
+ console.error('Service installation requires Linux (systemd).')
103
+ process.exit(1)
104
+ }
105
+ const nodeBin = process.execPath
106
+ const tampBin = join(__dirname, 'tamp.js')
107
+ const unitDir = join(homedir(), '.config', 'systemd', 'user')
108
+ const unitPath = join(unitDir, 'tamp.service')
109
+ const unit = `[Unit]
110
+ Description=Tamp token compression proxy
111
+ After=network.target
112
+
113
+ [Service]
114
+ Type=simple
115
+ ExecStart=${nodeBin} ${tampBin} -y
116
+ Restart=always
117
+ RestartSec=5
118
+ EnvironmentFile=-${CONFIG_PATH}
119
+
120
+ [Install]
121
+ WantedBy=default.target
122
+ `
123
+ mkdirSync(unitDir, { recursive: true })
124
+ writeFileSync(unitPath, unit)
125
+ try {
126
+ execFileSync('systemctl', ['--user', 'daemon-reload'], { stdio: 'inherit' })
127
+ execFileSync('systemctl', ['--user', 'enable', '--now', 'tamp.service'], { stdio: 'inherit' })
128
+ console.log(`\nService installed: ${unitPath}`)
129
+ console.log(' Status: systemctl --user status tamp')
130
+ console.log(' Logs: journalctl --user -u tamp -f')
131
+ console.log(' Stop: systemctl --user stop tamp')
132
+ console.log(' Remove: tamp uninstall-service')
133
+ } catch (e) {
134
+ console.error('systemctl failed:', e.message)
135
+ process.exit(1)
136
+ }
137
+ process.exit(0)
138
+ }
139
+
140
+ if (subcommand === 'uninstall-service') {
141
+ if (process.platform !== 'linux') {
142
+ console.error('Service management requires Linux (systemd).')
143
+ process.exit(1)
144
+ }
145
+ const unitPath = join(homedir(), '.config', 'systemd', 'user', 'tamp.service')
146
+ try { execFileSync('systemctl', ['--user', 'stop', 'tamp.service'], { stdio: 'inherit' }) } catch {}
147
+ try { execFileSync('systemctl', ['--user', 'disable', 'tamp.service'], { stdio: 'inherit' }) } catch {}
148
+ try { unlinkSync(unitPath) } catch {}
149
+ try { execFileSync('systemctl', ['--user', 'daemon-reload'], { stdio: 'inherit' }) } catch {}
150
+ console.log('Service removed.')
151
+ process.exit(0)
152
+ }
153
+
154
+ if (subcommand === 'status') {
155
+ const port = process.env.TAMP_PORT || 7778
156
+ const healthy = await checkPort(port)
157
+ console.log(`Tamp v${VERSION}`)
158
+ console.log(` Health: ${healthy ? 'running' : 'not running'} (port ${port})`)
159
+ if (process.platform === 'linux') {
160
+ try { execFileSync('systemctl', ['--user', 'status', 'tamp.service', '--no-pager'], { stdio: 'inherit' }) } catch {}
161
+ }
162
+ process.exit(healthy ? 0 : 1)
163
+ }
164
+
165
+ if (subcommand === 'help' || subcommand === '--help' || subcommand === '-h') {
166
+ console.log(`Tamp v${VERSION} — Token compression proxy for coding agents\n`)
167
+ console.log('Usage: tamp [command] [options]\n')
168
+ console.log('Commands:')
169
+ console.log(' (default) Start proxy (interactive stage picker)')
170
+ console.log(' -y Start proxy (non-interactive, use defaults)')
171
+ console.log(' init Create config file (~/.config/tamp/config)')
172
+ console.log(' status Check if proxy is running')
173
+ console.log(' install-service Install systemd user service (Linux)')
174
+ console.log(' uninstall-service Remove systemd service')
175
+ console.log(' help Show this help')
176
+ console.log(`\nConfig: ${CONFIG_PATH}`)
177
+ process.exit(0)
178
+ }
179
+
80
180
  // --- Mode detection ---
81
181
  const skipPrompt = process.argv.includes('-y') || process.argv.includes('--no-interactive') || !process.stdin.isTTY
82
182
 
package/config.js CHANGED
@@ -1,3 +1,6 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import { homedir } from 'node:os'
3
+ import { join } from 'node:path'
1
4
  import { DEFAULT_STAGES, VERSION } from './metadata.js'
2
5
 
3
6
  function parseBoolean(value, defaultValue) {
@@ -7,28 +10,71 @@ function parseBoolean(value, defaultValue) {
7
10
  return defaultValue
8
11
  }
9
12
 
13
+ export const CONFIG_PATH = join(homedir(), '.config', 'tamp', 'config')
14
+
15
+ export function loadConfigFile(path) {
16
+ const filePath = path || process.env.TAMP_CONFIG || CONFIG_PATH
17
+ try {
18
+ const lines = readFileSync(filePath, 'utf8').split('\n')
19
+ const vars = {}
20
+ for (const raw of lines) {
21
+ const line = raw.trim()
22
+ if (!line || line.startsWith('#')) continue
23
+ const eq = line.indexOf('=')
24
+ if (eq < 1) continue
25
+ const key = line.slice(0, eq).trim()
26
+ let val = line.slice(eq + 1).trim()
27
+ if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
28
+ val = val.slice(1, -1)
29
+ }
30
+ vars[key] = val
31
+ }
32
+ return vars
33
+ } catch { return {} }
34
+ }
35
+
10
36
  export function loadConfig(env = process.env) {
11
- const stages = (env.TAMP_STAGES || DEFAULT_STAGES.join(',')).split(',').map(s => s.trim()).filter(Boolean)
37
+ const fileVars = (env === process.env) ? loadConfigFile() : {}
38
+ const get = (key) => env[key] !== undefined ? env[key] : fileVars[key]
39
+
40
+ const stages = (get('TAMP_STAGES') || DEFAULT_STAGES.join(',')).split(',').map(s => s.trim()).filter(Boolean)
12
41
  return Object.freeze({
13
42
  version: VERSION,
14
- port: parseInt(env.TAMP_PORT, 10) || 7778,
15
- upstream: env.TAMP_UPSTREAM || 'https://api.anthropic.com',
43
+ port: parseInt(get('TAMP_PORT'), 10) || 7778,
44
+ upstream: get('TAMP_UPSTREAM') || 'https://api.anthropic.com',
16
45
  upstreams: Object.freeze({
17
- anthropic: env.TAMP_UPSTREAM || 'https://api.anthropic.com',
18
- openai: env.TAMP_UPSTREAM_OPENAI || 'https://api.openai.com',
19
- gemini: env.TAMP_UPSTREAM_GEMINI || 'https://generativelanguage.googleapis.com',
46
+ anthropic: get('TAMP_UPSTREAM') || 'https://api.anthropic.com',
47
+ openai: get('TAMP_UPSTREAM_OPENAI') || 'https://api.openai.com',
48
+ gemini: get('TAMP_UPSTREAM_GEMINI') || 'https://generativelanguage.googleapis.com',
20
49
  }),
21
- minSize: parseInt(env.TAMP_MIN_SIZE, 10) || 200,
50
+ minSize: parseInt(get('TAMP_MIN_SIZE'), 10) || 200,
22
51
  stages,
23
- log: env.TAMP_LOG !== 'false',
24
- logFile: env.TAMP_LOG_FILE || null,
25
- maxBody: parseInt(env.TAMP_MAX_BODY, 10) || 10_485_760,
26
- cacheSafe: parseBoolean(env.TAMP_CACHE_SAFE, true),
27
- llmLinguaUrl: env.TAMP_LLMLINGUA_URL || null,
28
- textpressOllamaUrl: env.TAMP_TEXTPRESS_OLLAMA_URL || 'http://localhost:11434',
29
- textpressOllamaModel: env.TAMP_TEXTPRESS_OLLAMA_MODEL || 'qwen3.5:0.8b',
30
- textpressModel: env.TAMP_TEXTPRESS_MODEL || 'google/gemini-3.1-flash-lite-preview',
31
- textpressApiKey: env.TAMP_TEXTPRESS_API_KEY || env.OPENROUTER_API_KEY || null,
32
- tokenCost: parseFloat(env.TAMP_TOKEN_COST) || 3,
52
+ log: get('TAMP_LOG') !== 'false',
53
+ logFile: get('TAMP_LOG_FILE') || null,
54
+ maxBody: parseInt(get('TAMP_MAX_BODY'), 10) || 10_485_760,
55
+ cacheSafe: parseBoolean(get('TAMP_CACHE_SAFE'), true),
56
+ llmLinguaUrl: get('TAMP_LLMLINGUA_URL') || null,
57
+ textpressOllamaUrl: get('TAMP_TEXTPRESS_OLLAMA_URL') || 'http://localhost:11434',
58
+ textpressOllamaModel: get('TAMP_TEXTPRESS_OLLAMA_MODEL') || 'qwen3.5:0.8b',
59
+ textpressModel: get('TAMP_TEXTPRESS_MODEL') || 'google/gemini-3.1-flash-lite-preview',
60
+ textpressApiKey: get('TAMP_TEXTPRESS_API_KEY') || get('OPENROUTER_API_KEY') || null,
61
+ tokenCost: parseFloat(get('TAMP_TOKEN_COST')) || 3,
33
62
  })
34
63
  }
64
+
65
+ export const CONFIG_TEMPLATE = `# Tamp configuration
66
+ # Environment variables override these values
67
+ # https://github.com/sliday/tamp
68
+
69
+ # TAMP_PORT=7778
70
+ # TAMP_UPSTREAM=https://api.anthropic.com
71
+ # TAMP_UPSTREAM_OPENAI=https://api.openai.com
72
+ # TAMP_UPSTREAM_GEMINI=https://generativelanguage.googleapis.com
73
+ # TAMP_STAGES=minify,toon,strip-lines,whitespace,llmlingua,dedup,diff,prune
74
+ # TAMP_MIN_SIZE=200
75
+ # TAMP_LOG=true
76
+ # TAMP_LOG_FILE=
77
+ # TAMP_MAX_BODY=10485760
78
+ # TAMP_CACHE_SAFE=true
79
+ # TAMP_TOKEN_COST=3
80
+ `
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "providers.js",
11
11
  "stats.js"
12
12
  ],
13
- "version": "0.3.13",
13
+ "version": "0.4.0",
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",