@sliday/tamp 0.7.0 โ†’ 0.8.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
@@ -6,16 +6,19 @@
6
6
  npx @sliday/tamp
7
7
  ```
8
8
 
9
- ### Claude Code plugin
10
-
11
- Auto-start on every session:
9
+ ### Claude Code
12
10
 
13
11
  ```bash
12
+ # Install the plugin (auto-starts Tamp each session)
14
13
  claude plugin marketplace add sliday/claude-plugins
15
14
  claude plugin install tamp@sliday
16
15
  ```
17
16
 
18
- Adds `/tamp:status` and `/tamp:config` commands.
17
+ The plugin adds `/tamp:status` and `/tamp:config` commands. It auto-starts Tamp but does not route traffic. Point Claude Code at Tamp once by adding to `~/.claude/settings.json`:
18
+
19
+ ```json
20
+ { "env": { "ANTHROPIC_BASE_URL": "http://localhost:7778" } }
21
+ ```
19
22
 
20
23
  ### ๐Ÿฆž OpenClaw
21
24
 
@@ -51,6 +54,22 @@ Auto-detects API format, compresses tool output, forwards upstream. Error result
51
54
 
52
55
  Opt-in stages: `strip-comments`, `textpress` (LLM semantic compression), `graph` (session-scoped dedup โ€” works on any coding agent: Codex, Claude Code, Aider โ€” anywhere the same file is read twice, up to -99% per repeat block)
53
56
 
57
+ ### LLMLingua sidecar
58
+
59
+ The `llmlingua` stage is enabled by default but requires a Python sidecar running on port 8788.
60
+
61
+ Tamp auto-starts the sidecar when [`uv`](https://docs.astral.sh/uv/) is installed. Manual starts for all other cases:
62
+
63
+ ```bash
64
+ uv run --with fastapi --with uvicorn --with llmlingua \
65
+ uvicorn server:app --host 127.0.0.1 --port 8788 \
66
+ --app-dir "$(npm root -g)/@sliday/tamp/sidecar"
67
+
68
+ curl -s http://localhost:8788/health # Verify: {"status":"ok","model_loaded":true}
69
+
70
+ tamp stop && tamp -y # restart Tamp, health endpoint will show `sidecar: ok`
71
+ ```
72
+
54
73
  ## Quick Start
55
74
 
56
75
  ```bash
@@ -60,14 +79,14 @@ curl -fsSL https://tamp.dev/setup.sh | bash
60
79
  # Option B: Manual
61
80
  npx @sliday/tamp
62
81
  export ANTHROPIC_BASE_URL=http://localhost:7778 # Claude Code
63
- export OPENAI_API_BASE=http://localhost:7778/v1 # Aider, Cursor, Cline
82
+ export OPENAI_API_BASE=http://localhost:7778/v1 # Aider, Cline
64
83
  ```
65
84
 
66
85
  Use your agent as normal โ€” Tamp compresses silently.
67
86
 
68
87
  ### Codex CLI
69
88
 
70
- Codex CLI reads its upstream from `~/.codex/config.toml`, not `OPENAI_API_BASE`. Add a custom provider:
89
+ Codex CLI reads its upstream from `~/.codex/config.toml`, not an env var. Add a custom provider:
71
90
 
72
91
  ```toml
73
92
  model_provider = "tamp"
@@ -81,6 +100,14 @@ wire_api = "responses"
81
100
 
82
101
  Then `export OPENAI_API_KEY=sk-...` and run `codex` or `codex exec "..."` as usual. Tamp routes `/v1/responses` through the `openai-responses` adapter and compresses every `function_call_output` block.
83
102
 
103
+ **ChatGPT Plus / Pro subscription.** If you sign in with `codex login` instead of using an API key, add this line to `~/.codex/config.toml`:
104
+
105
+ ```toml
106
+ openai_base_url = "http://localhost:7778/v1"
107
+ ```
108
+
109
+ Tamp detects OAuth bearer tokens and routes them to `chatgpt.com/backend-api/codex` automatically, so your ChatGPT Plus/Pro subscription keeps paying for inference while Tamp compresses every tool result in flight.
110
+
84
111
  ### Cursor
85
112
 
86
113
  1. Start Tamp: `npx @sliday/tamp -y`
@@ -90,7 +117,24 @@ Then `export OPENAI_API_KEY=sk-...` and run `codex` or `codex exec "..."` as usu
90
117
  5. Click **Verify**, then enable any OpenAI-family model (`gpt-4o`, `gpt-5-codex`, etc.)
91
118
  6. Use Cursor as normal โ€” Tamp compresses every tool call
92
119
 
93
- > Cursor's bundled `cursor-*` and `claude-*` models go through Cursor's own servers and bypass the override. Pick an OpenAI model to route through Tamp.
120
+ > **Cursor Pro subscription caveat.** Cursor's bundled `cursor-*`, `composer-*`, `claude-*`, and `gpt-*` models are routed through Cursor's own servers (`api2.cursor.sh`) regardless of the "Override OpenAI Base URL" setting โ€” Tamp cannot intercept them. Compression only applies when you (a) bring your own OpenAI key and (b) select a model Cursor treats as external (e.g. an unbundled `gpt-4o` with BYOK, or a custom model name via a public tunnel).
121
+
122
+ ### opencode
123
+
124
+ opencode **silently ignores** `OPENAI_API_BASE` / `OPENAI_BASE_URL`. Configure base URLs per provider in `~/.config/opencode/opencode.json`:
125
+
126
+ ```json
127
+ {
128
+ "provider": {
129
+ "anthropic": { "options": { "baseURL": "http://localhost:7778" } },
130
+ "openai": { "options": { "baseURL": "http://localhost:7778/v1" } },
131
+ "openrouter": { "options": { "baseURL": "http://localhost:7778/v1/openrouter" } },
132
+ "opencode": { "options": { "baseURL": "http://localhost:7778/v1/zen" } }
133
+ }
134
+ }
135
+ ```
136
+
137
+ Restart opencode. Tamp's adapter table routes each provider to the correct upstream.
94
138
 
95
139
  ### VS Code
96
140
 
@@ -134,15 +178,41 @@ Copilot does not expose a base URL setting and routes everything through GitHub'
134
178
 
135
179
  Run `tamp init` to create `~/.config/tamp/config`. All variables work via env or config file.
136
180
 
137
- ### Compression Presets (New!)
181
+ ### Compression levels
182
+
183
+ One knob, nine stops. The 1โ€“9 ladder is prefix-preserving (each level adds stages on top of the previous), so you can dial compression up or down without reasoning about individual stages.
138
184
 
139
- Simplify configuration with three intensity levels:
185
+ | Level | Stages (cumulative) | Lossy | Expected savings | Preset alias |
186
+ |---|---|---|---|---|
187
+ | 1 | minify | โ€” | ~15% | โ€” |
188
+ | 2 | + whitespace, strip-lines | โ€” | ~25% | โ€” |
189
+ | 3 | + cmd-strip | โ€” | ~35% | โ€” |
190
+ | 4 | + toon, dedup, diff | โ€” | ~45% | `conservative` |
191
+ | 5 | + llmlingua, read-diff, prune | yes | ~53% | **`balanced` (default)** |
192
+ | 6 | + strip-comments | yes | ~58% | โ€” |
193
+ | 7 | + textpress, br-cache | yes | ~62% | โ€” |
194
+ | 8 | + disclosure, bm25-trim | yes | ~67% | `aggressive` |
195
+ | 9 | + graph, foundation-models | yes | ~72% | `max` |
140
196
 
141
- | Preset | Savings | Description |
142
- |--------|---------|-------------|
143
- | `conservative` | 45-50% | Lossless only (no neural) |
144
- | `balanced` (default) | 52-58% | Recommended, includes LLMLingua |
145
- | `aggressive` | 60-68% | Maximum, lossy stages enabled |
197
+ Three interchangeable ways to pick a level:
198
+
199
+ ```bash
200
+ tamp --level 7 # CLI flag
201
+ TAMP_LEVEL=7 tamp # Environment variable
202
+ tamp settings # Interactive slider (+ advanced stage picker)
203
+ ```
204
+
205
+ Precedence: `--level` > `TAMP_LEVEL` > config file > preset alias > default (`balanced` / L5). Setting `TAMP_STAGES` explicitly still wins over any level โ€” the banner will show the full stage list instead of the Level line.
206
+
207
+ ### Compression Presets
208
+
209
+ The named presets are aliases of levels and still work unchanged:
210
+
211
+ | Preset | Level | Savings | Description |
212
+ |--------|-------|---------|-------------|
213
+ | `conservative` | L4 | 45-50% | Lossless only (no neural) |
214
+ | `balanced` (default) | L5 | 52-58% | Recommended, includes LLMLingua |
215
+ | `aggressive` | L8 | 60-68% | Maximum, lossy stages enabled |
146
216
 
147
217
  ```bash
148
218
  # Use a preset
@@ -181,19 +251,19 @@ Supported on all providers: Anthropic, OpenAI Chat, OpenAI Responses (Codex), Ge
181
251
  | `TAMP_MIN_SIZE` | `200` | Min content size (chars) |
182
252
  | `TAMP_LOG` | `true` | Enable logging |
183
253
  | `TAMP_CACHE_SAFE` | `true` | Compress newest only (prompt-cache safe) |
184
- | `TAMP_LLMLINGUA_URL` | *(none)* | LLMLingua sidecar URL |
254
+ | `TAMP_LLMLINGUA_URL` | *(none)* | LLMLingua sidecar URL. Set to `http://localhost:8788` to skip the auto-probe (avoids startup race if sidecar is still loading the model) |
185
255
 
186
256
  **Recommended setups:**
187
257
 
188
258
  ```bash
189
- # Default (balanced preset)
259
+ # Default (balanced preset = L5)
190
260
  npx @sliday/tamp
191
261
 
192
262
  # Conservative (no Python, lossless only)
193
- TAMP_COMPRESSION_PRESET=conservative npx @sliday/tamp -y
263
+ TAMP_LEVEL=4 npx @sliday/tamp -y
194
264
 
195
265
  # Aggressive (maximum compression)
196
- TAMP_COMPRESSION_PRESET=aggressive npx @sliday/tamp -y
266
+ TAMP_LEVEL=8 npx @sliday/tamp -y
197
267
  ```
198
268
 
199
269
  ## CLI Tools
@@ -242,6 +312,22 @@ tamp install-service
242
312
  tamp status
243
313
  ```
244
314
 
315
+ ## Monitoring
316
+
317
+ Check session stats any time via the health endpoint via browser or terminal:
318
+
319
+ ```bash
320
+ curl -s 'http://localhost:7778/health?text' # Human-readable
321
+ # Tamp v0.5.9 | 7 stages active | sidecar: n/a
322
+ # Requests: 63 | Blocks: 2
323
+ # Tokens saved: 1136 | Chars: 3482/61528 (5.7%)
324
+ # Est. savings: $0.0034 (Sonnet $3/Mtok) | $0.0170 (Opus $15/Mtok)
325
+
326
+ curl -s http://localhost:7778/health # JSON (for scripts/dashboards)
327
+ ```
328
+
329
+ Inside Claude Code, run `/tamp:status`.
330
+
245
331
  ## Token Savings
246
332
 
247
333
  Claude Code sends full conversation history on every API call. Tool results accumulate โ€” files, listings, outputs โ€” all re-sent as input tokens.
@@ -252,6 +338,29 @@ Claude Code sends full conversation history on every API call. Tool results accu
252
338
 
253
339
  **Combined impact:** With new Caveman-integrated features, Tamp achieves 60-70% total token savings (input + output) in balanced mode.
254
340
 
341
+ ### Did v0.8 headline % improve over v0.5?
342
+
343
+ Short answer: **not much on the micro-benchmark, a lot on real sessions.**
344
+
345
+ On the short single-request fixtures in `bench/`, the headline percentage barely moves โ€” v0.5 baseline lands at 45.1%, L5 (balanced) at 45.3%, L9 (max) at 45.4%. The fixtures are too small to exercise the new stages: they don't contain re-reads, don't cross the disclosure threshold (>32 KB tool_result bodies), don't include the noisy CLI streams `cmd-strip` targets, and fit entirely inside a single request so cross-request session dedup (`graph`) is a no-op.
346
+
347
+ Where v0.8 actually pays off is **session-scoped work**, which is what coding agents do all day:
348
+
349
+ - `read-diff` (L5) and `graph` (L9) eliminate the cost of re-reading the same file โ€” a dominant pattern in multi-turn debugging sessions.
350
+ - `disclosure` (L8) keeps `tool_result` payloads over 32 KB from burning input tokens a second time when the agent references them later.
351
+ - `cmd-strip` (L3) removes per-command stdout noise (spinners, progress bars from `npm`, `pip`, `cargo`, `docker`) that the synthetic fixtures don't contain.
352
+ - `br-cache` (L7) and `bm25-trim` (L8) shave long-tail content the fixtures don't exercise.
353
+
354
+ The real win in v0.8 is **the level knob itself** โ€” a zip-like 1โ€“9 dial that lets you trade compression aggressiveness for risk without memorizing stage names. To reproduce the numbers above, run `node bench/runner.js --sweep` (set `OPENROUTER_API_KEY` for the live A/B pass).
355
+
356
+ ## Security
357
+
358
+ Tamp runs on `localhost` and forwards to the upstream you configure. Most stages are local-only: `llmlingua` talks to a sidecar on `127.0.0.1`, `foundation-models` stays on-device. The one stage that sends content off-box is `textpress` (opt-in, level 7+), which posts to OpenRouter when `OPENROUTER_API_KEY` is set โ€” leave it off if your tool output is sensitive.
359
+
360
+ **Secret redaction** is on the roadmap ([#6](https://github.com/sliday/tamp/issues/6)): a `redact` stage that masks API keys, tokens, and `.env` values before anything leaves the machine, running ahead of every other stage. Until it lands, Tamp forwards file contents verbatim โ€” treat your upstream's data policy as the boundary.
361
+
362
+ This repo ships an agent harness (built with [harn.app](https://harn.app)): `AGENTS.md` plus PreToolUse / Stop hooks under `scripts/harness/` that block dangerous shell commands and gate completion on `npm test`. See `.claude/settings.json`.
363
+
255
364
  ## Development
256
365
 
257
366
  ```bash
@@ -259,6 +368,10 @@ npm test
259
368
  node smoke.js
260
369
  ```
261
370
 
371
+ ## Star History
372
+
373
+ [![Star History Chart](https://api.star-history.com/svg?repos=sliday/tamp&type=Date)](https://star-history.com/#sliday/tamp&Date)
374
+
262
375
  ## License
263
376
 
264
377
  MIT ยฉ [Stas Kulesh](https://sliday.com)
package/bin/tamp.js CHANGED
@@ -5,8 +5,8 @@ import { spawn, execFileSync } from 'node:child_process'
5
5
  import { fileURLToPath } from 'node:url'
6
6
  import { dirname, join } from 'node:path'
7
7
  import { homedir } from 'node:os'
8
- import { DEFAULT_STAGES, EXTRA_STAGES, STAGE_DESCRIPTIONS, STAGE_HINTS, VERSION, isLossy } from '../metadata.js'
9
- import { CONFIG_PATH, CONFIG_TEMPLATE } from '../config.js'
8
+ import { DEFAULT_STAGES, EXTRA_STAGES, STAGE_DESCRIPTIONS, STAGE_HINTS, VERSION, isLossy, DEFAULT_LEVEL } from '../metadata.js'
9
+ import { CONFIG_PATH, CONFIG_TEMPLATE, loadConfig } from '../config.js'
10
10
  import {
11
11
  checkPort,
12
12
  diagnoseBindConflict,
@@ -79,9 +79,83 @@ export async function startSidecar() {
79
79
  return null
80
80
  }
81
81
 
82
+ // Write (or update) a single scalar field in the config file. Preserves
83
+ // unrelated lines verbatim. Creates the file (seeded from CONFIG_TEMPLATE)
84
+ // if missing. Shared by `init` and `settings` โ€” the single writer.
85
+ function writeConfigField(field, value) {
86
+ const dir = dirname(CONFIG_PATH)
87
+ mkdirSync(dir, { recursive: true })
88
+ const stringified = String(value)
89
+ let body
90
+ if (existsSync(CONFIG_PATH)) {
91
+ body = readFileSync(CONFIG_PATH, 'utf8')
92
+ } else {
93
+ body = CONFIG_TEMPLATE
94
+ }
95
+ const lines = body.split('\n')
96
+ const activeRe = new RegExp(`^\\s*${field}\\s*=`)
97
+ const commentedRe = new RegExp(`^\\s*#\\s*${field}\\s*=`)
98
+ let replaced = false
99
+ for (let i = 0; i < lines.length; i++) {
100
+ if (activeRe.test(lines[i])) {
101
+ lines[i] = `${field}=${stringified}`
102
+ replaced = true
103
+ break
104
+ }
105
+ }
106
+ if (!replaced) {
107
+ for (let i = 0; i < lines.length; i++) {
108
+ if (commentedRe.test(lines[i])) {
109
+ lines[i] = `${field}=${stringified}`
110
+ replaced = true
111
+ break
112
+ }
113
+ }
114
+ }
115
+ if (!replaced) {
116
+ if (lines.length && lines[lines.length - 1] !== '') lines.push('')
117
+ lines.push(`${field}=${stringified}`)
118
+ }
119
+ writeFileSync(CONFIG_PATH, lines.join('\n'))
120
+ }
121
+
82
122
  // --- Subcommands ---
83
123
  const subcommand = process.argv[2]
84
124
 
125
+ // --- Global --level flag parsing ---
126
+ // Supports '--level N', '--level=N'. Accepts integers 1..9 or alias strings
127
+ // (conservative, balanced, aggressive, max). Invalid values: print a friendly
128
+ // error and exit(2). Threaded into loadConfig via options.levelOverride so the
129
+ // precedence rules (stages-env > level-flag > level-env > preset-env > file > default)
130
+ // live entirely in config.js.
131
+ function parseLevelArgv(argv) {
132
+ const aliases = new Set(['conservative', 'balanced', 'aggressive', 'max'])
133
+ let raw = null
134
+ for (let i = 0; i < argv.length; i++) {
135
+ const a = argv[i]
136
+ if (a === '--level') { raw = argv[i + 1]; break }
137
+ if (a.startsWith('--level=')) { raw = a.slice('--level='.length); break }
138
+ }
139
+ if (raw === null || raw === undefined) return null
140
+ if (raw === '') {
141
+ console.error(`[tamp] --level requires a value (1..9 or one of: conservative, balanced, aggressive, max)`)
142
+ process.exit(2)
143
+ }
144
+ if (/^-?\d+$/.test(raw)) {
145
+ const n = parseInt(raw, 10)
146
+ if (n < 1 || n > 9) {
147
+ console.error(`[tamp] --level must be 1..9 (got ${raw})`)
148
+ process.exit(2)
149
+ }
150
+ return n
151
+ }
152
+ if (aliases.has(raw)) return raw
153
+ console.error(`[tamp] invalid --level=${raw} โ€” expected 1..9 or one of: conservative, balanced, aggressive, max`)
154
+ process.exit(2)
155
+ }
156
+
157
+ const argvLevel = parseLevelArgv(process.argv.slice(2))
158
+
85
159
  if (subcommand === 'init') {
86
160
  const dir = dirname(CONFIG_PATH)
87
161
  if (existsSync(CONFIG_PATH)) {
@@ -97,6 +171,55 @@ if (subcommand === 'init') {
97
171
  process.exit(0)
98
172
  }
99
173
 
174
+ if (subcommand === 'settings' || subcommand === 'config') {
175
+ if (process.argv.includes('--help') || process.argv.includes('-h')) {
176
+ console.log(`Usage: tamp settings\n`)
177
+ console.log('Interactive editor for compression level (1..9) and stages.')
178
+ console.log('Writes to: ' + CONFIG_PATH)
179
+ process.exit(0)
180
+ }
181
+
182
+ const current = loadConfig()
183
+ const envLevel = Number.isInteger(current.level) ? current.level : DEFAULT_LEVEL
184
+
185
+ if (!process.stdin.isTTY) {
186
+ console.error('[tamp] settings requires an interactive terminal (TTY). Edit ' + CONFIG_PATH + ' directly.')
187
+ process.exit(1)
188
+ }
189
+
190
+ const { render } = await import('ink')
191
+ const React = await import('react')
192
+ const { LevelPicker } = await import('./ui/LevelPicker.js')
193
+ const h = React.createElement
194
+
195
+ let instance = null
196
+ const onSelect = (payload) => {
197
+ try {
198
+ if (payload.kind === 'level') {
199
+ writeConfigField('level', payload.level)
200
+ if (instance) instance.unmount()
201
+ console.log(`Saved level=${payload.level} to ${CONFIG_PATH}`)
202
+ process.exit(0)
203
+ } else if (payload.kind === 'stages') {
204
+ writeConfigField('TAMP_STAGES', payload.stages.join(','))
205
+ if (instance) instance.unmount()
206
+ console.log(`Saved TAMP_STAGES=${payload.stages.join(',')} to ${CONFIG_PATH}`)
207
+ process.exit(0)
208
+ }
209
+ } catch (err) {
210
+ if (instance) instance.unmount()
211
+ console.error(`[tamp] failed to write config: ${err.message}`)
212
+ process.exit(1)
213
+ }
214
+ }
215
+ const onCancel = () => {
216
+ if (instance) instance.unmount()
217
+ process.exit(0)
218
+ }
219
+
220
+ instance = render(h(LevelPicker, { version: VERSION, envLevel, onSelect, onCancel }))
221
+ }
222
+
100
223
  if (subcommand === 'install-service') {
101
224
  if (process.platform !== 'linux') {
102
225
  console.error('Service installation requires Linux (systemd).')
@@ -245,7 +368,7 @@ if (subcommand === 'stop') {
245
368
  process.exit(0)
246
369
  }
247
370
 
248
- if (subcommand === 'help' || subcommand === '--help' || subcommand === '-h') {
371
+ if (subcommand === 'help' || subcommand === '--help' || subcommand === '-h' || process.argv.includes('--help') || process.argv.includes('-h')) {
249
372
  console.log(`Tamp v${VERSION} โ€” Token compression proxy for coding agents\n`)
250
373
  console.log('Usage: tamp [command] [options]\n')
251
374
  console.log('Commands:')
@@ -255,10 +378,14 @@ if (subcommand === 'help' || subcommand === '--help' || subcommand === '-h') {
255
378
  console.log(' stop Stop a running Tamp on TAMP_PORT (default 7778)')
256
379
  console.log(' compress-config Compress CLAUDE.md or config files (caveman mode)')
257
380
  console.log(' init Create config file (~/.config/tamp/config)')
381
+ console.log(' settings Edit compression level and stages')
258
382
  console.log(' status Check if proxy is running')
259
383
  console.log(' install-service Install systemd user service (Linux)')
260
384
  console.log(' uninstall-service Remove systemd service')
261
385
  console.log(' help Show this help')
386
+ console.log('')
387
+ console.log('Options:')
388
+ console.log(' --level N Compression level 1..9 (or: conservative, balanced, aggressive, max)')
262
389
  console.log(`\nConfig: ${CONFIG_PATH}`)
263
390
  process.exit(0)
264
391
  }
@@ -303,8 +430,23 @@ if (skipPrompt) {
303
430
  // --- Non-interactive mode (plain text, no Ink) ---
304
431
  const { ANSI: c } = await import('./ui/theme.js')
305
432
 
306
- let selectedStages = envStages ? [...envStages] : [...DEFAULT_STAGES]
307
- process.env.TAMP_STAGES = selectedStages.join(',')
433
+ // When --level is given (and TAMP_STAGES is unset), resolve stages via
434
+ // loadConfig so the level ladder drives the selection. Otherwise keep legacy
435
+ // behavior (envStages-derived TAMP_STAGES auto-echo).
436
+ let selectedStages
437
+ if (envStages) {
438
+ selectedStages = [...envStages]
439
+ process.env.TAMP_STAGES = selectedStages.join(',')
440
+ } else if (argvLevel !== null) {
441
+ const { loadConfig } = await import('../config.js')
442
+ const probe = loadConfig(process.env, { levelOverride: argvLevel })
443
+ selectedStages = [...probe.stages]
444
+ // Do NOT set TAMP_STAGES โ€” that would clobber level-flag source tracking
445
+ // when the full createProxy call runs below.
446
+ } else {
447
+ selectedStages = [...DEFAULT_STAGES]
448
+ process.env.TAMP_STAGES = selectedStages.join(',')
449
+ }
308
450
 
309
451
  if (selectedStages.includes('llmlingua')) {
310
452
  const sidecarUrl = await startSidecar()
@@ -320,7 +462,7 @@ if (skipPrompt) {
320
462
  }
321
463
  }
322
464
 
323
- const { config, server } = createProxy()
465
+ const { config, server } = createProxy({}, argvLevel !== null ? { levelOverride: argvLevel } : {})
324
466
 
325
467
  await ensurePortFree(config.port)
326
468
 
@@ -402,6 +544,7 @@ if (skipPrompt) {
402
544
  render(h(App, {
403
545
  version: VERSION,
404
546
  envStages,
547
+ argvLevel,
405
548
  startSidecar,
406
549
  createProxy,
407
550
  getSidecarProc,
package/bin/ui/App.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import React, { useState, useEffect, useCallback, useRef } from 'react'
2
2
  import { Box, Text, useApp } from 'ink'
3
- import { StagePicker } from './StagePicker.js'
3
+ import { LevelPicker } from './LevelPicker.js'
4
4
  import { SidecarLoader } from './SidecarLoader.js'
5
5
  import { Dashboard } from './Dashboard.js'
6
6
  import { installShutdown, writePidFile, diagnoseBindConflict } from '../lifecycle.js'
7
7
 
8
8
  const h = React.createElement
9
9
 
10
- export function App({ version, envStages, startSidecar, createProxy, getSidecarProc, ensurePortFree }) {
10
+ export function App({ version, envStages, argvLevel, startSidecar, createProxy, getSidecarProc, ensurePortFree }) {
11
11
  const { exit } = useApp()
12
12
  const [phase, setPhase] = useState('pick')
13
13
  const [stages, setStages] = useState(null)
@@ -70,6 +70,14 @@ export function App({ version, envStages, startSidecar, createProxy, getSidecarP
70
70
  }
71
71
  }, [startProxy])
72
72
 
73
+ const onPickerSubmit = useCallback((payload) => {
74
+ // payload: { kind: 'level', level, stages } | { kind: 'stages', stages }
75
+ if (payload && payload.kind === 'level' && Number.isInteger(payload.level)) {
76
+ process.env.TAMP_LEVEL = String(payload.level)
77
+ }
78
+ onStagesSelected(payload.stages)
79
+ }, [onStagesSelected])
80
+
73
81
  // Use stagesRef to avoid stale closure โ€” SidecarLoader's useEffect
74
82
  // captures onReady/onFail on first render only
75
83
  const onSidecarReady = useCallback((url) => {
@@ -85,7 +93,7 @@ export function App({ version, envStages, startSidecar, createProxy, getSidecarP
85
93
  }, [startProxy])
86
94
 
87
95
  if (phase === 'pick') {
88
- return h(StagePicker, { version, envStages, onSelect: onStagesSelected })
96
+ return h(LevelPicker, { version, envLevel: argvLevel, envStages, onSelect: onPickerSubmit })
89
97
  }
90
98
 
91
99
  if (phase === 'loading') {
package/bin/ui/Banner.js CHANGED
@@ -5,13 +5,17 @@ import { ALL_STAGES, DEFAULT_STAGES, EXTRA_STAGES, STAGE_HINTS, isLossy } from '
5
5
 
6
6
  const h = React.createElement
7
7
 
8
- export function Banner({ version, port, stages, llmLinguaUrl, outputMode }) {
8
+ export function Banner({ version, port, stages, llmLinguaUrl, outputMode, level }) {
9
9
  const url = `http://localhost:${port}`
10
10
  const active = new Set(stages)
11
11
  const defaultActive = DEFAULT_STAGES.filter(s => active.has(s))
12
12
  const extraActive = EXTRA_STAGES.filter(s => active.has(s))
13
13
  const disabled = ALL_STAGES.filter(s => !active.has(s))
14
14
  const showOutput = outputMode && outputMode !== 'off'
15
+ const hasLevel = level != null
16
+ const stagesHeader = hasLevel
17
+ ? h(Text, { bold: true }, `Stages `, h(Text, { dimColor: true }, `(${stages.length} active \u2192 expand with TAMP_STAGES)`))
18
+ : h(Text, { bold: true }, `Stages `, h(Text, { dimColor: true }, `(${stages.length} of ${ALL_STAGES.length} active)`))
15
19
 
16
20
  return h(Box, { flexDirection: 'column', paddingX: 1 },
17
21
  h(Box, { gap: 2 },
@@ -20,6 +24,12 @@ export function Banner({ version, port, stages, llmLinguaUrl, outputMode }) {
20
24
  h(Badge, { color: 'green' }, 'READY'),
21
25
  h(Text, { color: 'green' }, url),
22
26
  ),
27
+ hasLevel ? h(Text, null, '') : null,
28
+ hasLevel ? h(Text, null,
29
+ h(Text, { bold: true }, 'Level '),
30
+ h(Text, { color: 'yellow' }, String(level)),
31
+ h(Text, { dimColor: true }, ` (${stages.length} stages \u2014 tamp settings to change)`),
32
+ ) : null,
23
33
  h(Text, null, ''),
24
34
  h(Text, { bold: true }, 'Setup'),
25
35
  h(Box, { paddingLeft: 2, flexDirection: 'column' },
@@ -40,8 +50,8 @@ export function Banner({ version, port, stages, llmLinguaUrl, outputMode }) {
40
50
  h(Text, { dimColor: true }, ' (caveman, task-aware)')
41
51
  ) : null,
42
52
  showOutput ? h(Text, null, '') : null,
43
- h(Text, { bold: true }, `Stages `, h(Text, { dimColor: true }, `(${stages.length} of ${ALL_STAGES.length} active)`)),
44
- h(Box, { paddingLeft: 2, flexDirection: 'column' },
53
+ stagesHeader,
54
+ hasLevel ? null : h(Box, { paddingLeft: 2, flexDirection: 'column' },
45
55
  ...defaultActive.map(s =>
46
56
  h(Text, { key: s },
47
57
  h(Text, { color: 'green' }, '\u2713 '),
@@ -57,9 +67,9 @@ export function Banner({ version, port, stages, llmLinguaUrl, outputMode }) {
57
67
  )
58
68
  ),
59
69
  ),
60
- disabled.length ? h(Text, null, '') : null,
61
- disabled.length ? h(Text, { bold: true }, 'Available ', h(Text, { dimColor: true }, '(not active โ€” opt in for more savings)')) : null,
62
- disabled.length ? h(Box, { paddingLeft: 2, flexDirection: 'column' },
70
+ !hasLevel && disabled.length ? h(Text, null, '') : null,
71
+ !hasLevel && disabled.length ? h(Text, { bold: true }, 'Available ', h(Text, { dimColor: true }, '(not active โ€” opt in for more savings)')) : null,
72
+ !hasLevel && disabled.length ? h(Box, { paddingLeft: 2, flexDirection: 'column' },
63
73
  ...disabled.flatMap(s => {
64
74
  const hint = STAGE_HINTS[s]
65
75
  const lines = [
@@ -0,0 +1,107 @@
1
+ import React, { useState } from 'react'
2
+ import { Box, Text, useInput } from 'ink'
3
+ import { StagePicker } from './StagePicker.js'
4
+ import { COMPRESSION_LEVELS, DEFAULT_LEVEL, resolveLevel } from '../../metadata.js'
5
+
6
+ const h = React.createElement
7
+
8
+ // Pure reducer โ€” exported for testability. Handles clamping and NaN-safe jumps.
9
+ export function levelReducer(state, action) {
10
+ switch (action.type) {
11
+ case 'moveLeft':
12
+ return state > 1 ? state - 1 : 1
13
+ case 'moveRight':
14
+ return state < 9 ? state + 1 : 9
15
+ case 'jumpTo': {
16
+ const n = Number(action.value)
17
+ if (!Number.isInteger(n) || n < 1 || n > 9) return state
18
+ return n
19
+ }
20
+ default:
21
+ return state
22
+ }
23
+ }
24
+
25
+ export function initialLevel(envLevel) {
26
+ if (Number.isInteger(envLevel) && envLevel >= 1 && envLevel <= 9) return envLevel
27
+ return DEFAULT_LEVEL
28
+ }
29
+
30
+ // Build the payload emitted by onSelect when a level is confirmed.
31
+ export function buildLevelPayload(level) {
32
+ return { kind: 'level', level, stages: [...resolveLevel(level).stages] }
33
+ }
34
+
35
+ function Slider({ level }) {
36
+ // 9-position slider: oโ”€โ”€โ”€โ—โ”€โ”€โ”€o style
37
+ const cells = []
38
+ for (let i = 1; i <= 9; i++) {
39
+ if (i === level) cells.push(h(Text, { key: i, color: 'cyan', bold: true }, 'โ—'))
40
+ else cells.push(h(Text, { key: i, dimColor: true }, 'โ”€'))
41
+ if (i < 9) cells.push(h(Text, { key: `s${i}`, dimColor: true }, 'โ”€'))
42
+ }
43
+ return h(Box, null, ...cells)
44
+ }
45
+
46
+ function Chips({ stages }) {
47
+ const children = []
48
+ stages.forEach((s, i) => {
49
+ children.push(h(Text, { key: `c${i}`, color: 'cyan' }, ` ${s} `))
50
+ if (i < stages.length - 1) children.push(h(Text, { key: `g${i}` }, ' '))
51
+ })
52
+ return h(Box, { flexWrap: 'wrap' }, ...children)
53
+ }
54
+
55
+ export function LevelPicker({ version, envLevel, envStages, onSelect, onCancel }) {
56
+ const [level, setLevel] = useState(() => initialLevel(envLevel))
57
+ const [advanced, setAdvanced] = useState(false)
58
+
59
+ useInput((input, key) => {
60
+ if (advanced) return
61
+ if (key.leftArrow || input === 'h') setLevel(s => levelReducer(s, { type: 'moveLeft' }))
62
+ else if (key.rightArrow || input === 'l') setLevel(s => levelReducer(s, { type: 'moveRight' }))
63
+ else if (input === 'a' || input === 'A') setAdvanced(true)
64
+ else if (key.return) onSelect(buildLevelPayload(level))
65
+ else if (key.escape) { if (onCancel) onCancel() }
66
+ else if (input && /^[1-9]$/.test(input)) setLevel(s => levelReducer(s, { type: 'jumpTo', value: input }))
67
+ })
68
+
69
+ if (advanced) {
70
+ return h(StagePicker, {
71
+ version,
72
+ envStages: envStages || resolveLevel(level).stages,
73
+ onSelect: (stages) => onSelect({ kind: 'stages', stages }),
74
+ })
75
+ }
76
+
77
+ const meta = resolveLevel(level) || COMPRESSION_LEVELS[DEFAULT_LEVEL]
78
+ const lossy = meta.lossy
79
+
80
+ return h(Box, { flexDirection: 'column', paddingX: 1 },
81
+ h(Box, { gap: 1, marginBottom: 1 },
82
+ h(Text, { bold: true, color: 'cyan' }, 'Tamp'),
83
+ h(Text, { dimColor: true }, `v${version}`),
84
+ ),
85
+ h(Text, { dimColor: true }, 'Compression level โ€” โ† โ†’ to adjust, 1-9 to jump, Enter to confirm'),
86
+ h(Box, { marginTop: 1, gap: 2, alignItems: 'center' },
87
+ h(Text, { bold: true, color: 'cyan' }, String(level)),
88
+ h(Slider, { level }),
89
+ h(Text, { color: lossy ? 'yellow' : 'green', bold: true }, lossy ? ' LOSSY ' : ' LOSSLESS '),
90
+ ),
91
+ h(Box, { marginTop: 1 },
92
+ h(Text, null, 'Expected savings: '),
93
+ h(Text, { bold: true, color: 'green' }, meta.savings),
94
+ ),
95
+ h(Box, { marginTop: 1, flexDirection: 'column' },
96
+ h(Text, { dimColor: true }, `Stages (${meta.stages.length})`),
97
+ h(Chips, { stages: meta.stages }),
98
+ ),
99
+ h(Box, { marginTop: 1 },
100
+ h(Text, { dimColor: true }, 'Press '),
101
+ h(Text, { bold: true }, 'A'),
102
+ h(Text, { dimColor: true }, ' for advanced per-stage picker ยท '),
103
+ h(Text, { bold: true }, 'Esc'),
104
+ h(Text, { dimColor: true }, ' to cancel'),
105
+ ),
106
+ )
107
+ }