@sliday/tamp 0.5.8 → 0.5.9

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
@@ -152,19 +152,24 @@ TAMP_COMPRESSION_PRESET=balanced
152
152
  TAMP_STAGES=minify,toon # Override preset
153
153
  ```
154
154
 
155
- ### Output Compression (New!)
155
+ ### Output Compression — Caveman Mode
156
156
 
157
- Task-type-aware output compression via CLAUDE.md injection:
157
+ Task-type-aware output compression. Tamp classifies each request as `safe` (typo fixes, env var changes, doc updates) or `dangerous` (security, debug, refactor) and injects matching rules into the last user message before forwarding. Cache-safe — the prefix stays untouched so prompt caching keeps working.
158
+
159
+ **Opt in** (default is `off` — zero behavior change unless you flip the switch):
158
160
 
159
161
  ```bash
160
- export TAMP_OUTPUT_MODE=balanced # conservative | balanced | aggressive
161
- export TAMP_AUTO_DETECT_TASK_TYPE=true # Auto-detect safe vs dangerous tasks
162
+ export TAMP_OUTPUT_MODE=balanced # off | conservative | balanced | aggressive
163
+ export TAMP_AUTO_DETECT_TASK_TYPE=true # default; set to false to force 'complex'
162
164
  ```
163
165
 
164
166
  **Mode behavior:**
165
- - **Conservative**: Professional but concise (40-50% output savings)
166
- - **Balanced**: Terse on safe tasks, full output on dangerous (65-75% on safe)
167
- - **Aggressive**: Minimal caveman-style (75-85% on safe, partial on dangerous)
167
+ - **off** *(default)*: No injection. Pass-through.
168
+ - **conservative**: Professional but concise for all tasks (40-50% output savings).
169
+ - **balanced**: Terse on safe tasks, full output on dangerous (65-75% on safe).
170
+ - **aggressive**: Minimal caveman-style (75-85% on safe, partial on dangerous).
171
+
172
+ Supported on all providers: Anthropic, OpenAI Chat, OpenAI Responses (Codex), Gemini.
168
173
 
169
174
  ### Other Settings
170
175
 
package/bin/tamp.js CHANGED
@@ -162,6 +162,47 @@ if (subcommand === 'status') {
162
162
  process.exit(healthy ? 0 : 1)
163
163
  }
164
164
 
165
+ if (subcommand === 'compress-config') {
166
+ const { compressFiles, formatResult } = await import('../lib/compress-file.js')
167
+ const args = process.argv.slice(3)
168
+ const flags = new Set(args.filter(a => a.startsWith('--')))
169
+ const files = args.filter(a => !a.startsWith('--'))
170
+
171
+ if (!files.length) {
172
+ console.error('Usage: tamp compress-config [--dry-run] [--no-backup] <file> [file...]')
173
+ console.error('')
174
+ console.error('Compress CLAUDE.md, config, or markdown files using lossy strategies')
175
+ console.error('inspired by JuliusBrussee/caveman-compress.')
176
+ console.error('')
177
+ console.error('Examples:')
178
+ console.error(' tamp compress-config --dry-run ~/.claude/CLAUDE.md')
179
+ console.error(' tamp compress-config ~/.claude/CLAUDE.md ~/.config/tamp/config')
180
+ process.exit(1)
181
+ }
182
+
183
+ const opts = {
184
+ dryRun: flags.has('--dry-run'),
185
+ noBackup: flags.has('--no-backup'),
186
+ }
187
+
188
+ const results = await compressFiles(files, opts)
189
+ let failures = 0
190
+ for (const result of results) {
191
+ console.log(formatResult(result))
192
+ console.log('')
193
+ if (!result.success && !result.skipped && !result.dryRun) failures++
194
+ }
195
+
196
+ const totalOrig = results.reduce((a, r) => a + (r.originalLen || 0), 0)
197
+ const totalComp = results.reduce((a, r) => a + (r.compressedLen || r.originalLen || 0), 0)
198
+ if (totalOrig > 0) {
199
+ const pct = ((totalOrig - totalComp) / totalOrig * 100).toFixed(1)
200
+ console.log(`Total: ${totalOrig} → ${totalComp} chars (${pct}% saved across ${results.length} file${results.length !== 1 ? 's' : ''})`)
201
+ }
202
+
203
+ process.exit(failures > 0 ? 1 : 0)
204
+ }
205
+
165
206
  if (subcommand === 'stop') {
166
207
  const port = Number(process.env.TAMP_PORT) || 7778
167
208
  await reconcileStalePidFile(port)
@@ -212,6 +253,7 @@ if (subcommand === 'help' || subcommand === '--help' || subcommand === '-h') {
212
253
  console.log(' -y Start proxy (non-interactive, use defaults)')
213
254
  console.log(' -y --force Replace any existing Tamp on the same port')
214
255
  console.log(' stop Stop a running Tamp on TAMP_PORT (default 7778)')
256
+ console.log(' compress-config Compress CLAUDE.md or config files (caveman mode)')
215
257
  console.log(' init Create config file (~/.config/tamp/config)')
216
258
  console.log(' status Check if proxy is running')
217
259
  console.log(' install-service Install systemd user service (Linux)')
@@ -296,6 +338,10 @@ if (skipPrompt) {
296
338
  console.error(` ${c.dim}Aider/Cursor:${c.reset} OPENAI_API_BASE=${c.yellow}${url}${c.reset}`)
297
339
  console.error('')
298
340
  const total = DEFAULT_STAGES.length + EXTRA_STAGES.length
341
+ if (config.outputMode && config.outputMode !== 'off') {
342
+ console.error(` ${c.bold}Output mode${c.reset} ${c.yellow}${config.outputMode}${c.reset} ${c.dim}(caveman, task-aware)${c.reset}`)
343
+ console.error('')
344
+ }
299
345
  console.error(` ${c.bold}Stages${c.reset} ${c.dim}(${active.length} of ${total} active)${c.reset}`)
300
346
  for (const s of defaultActive) {
301
347
  const extra = s === 'llmlingua' && config.llmLinguaUrl ? ` ${c.dim}(${config.llmLinguaUrl})${c.reset}` : ''
package/bin/ui/Banner.js CHANGED
@@ -5,12 +5,13 @@ 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 }) {
8
+ export function Banner({ version, port, stages, llmLinguaUrl, outputMode }) {
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
+ const showOutput = outputMode && outputMode !== 'off'
14
15
 
15
16
  return h(Box, { flexDirection: 'column', paddingX: 1 },
16
17
  h(Box, { gap: 2 },
@@ -34,6 +35,11 @@ export function Banner({ version, port, stages, llmLinguaUrl }) {
34
35
  ),
35
36
  ),
36
37
  h(Text, null, ''),
38
+ showOutput ? h(Text, { bold: true }, 'Output mode ',
39
+ h(Text, { color: 'yellow' }, outputMode),
40
+ h(Text, { dimColor: true }, ' (caveman, task-aware)')
41
+ ) : null,
42
+ showOutput ? h(Text, null, '') : null,
37
43
  h(Text, { bold: true }, `Stages `, h(Text, { dimColor: true }, `(${stages.length} of ${ALL_STAGES.length} active)`)),
38
44
  h(Box, { paddingLeft: 2, flexDirection: 'column' },
39
45
  ...defaultActive.map(s =>
@@ -92,6 +92,7 @@ export function Dashboard({ version, config, events, totals }) {
92
92
  port: config.port,
93
93
  stages: config.stages,
94
94
  llmLinguaUrl: config.llmLinguaUrl,
95
+ outputMode: config.outputMode,
95
96
  }),
96
97
  h(StatsBar, { totals, tokenCost: config.tokenCost }),
97
98
  events.length > 0
package/compress.js CHANGED
@@ -6,6 +6,7 @@ import { createPatch } from 'diff'
6
6
  import { tryParseJSON, classifyContent, stripLineNumbers } from './detect.js'
7
7
  import { anthropic } from './providers.js'
8
8
  import { graphDeduplicateTargets } from './session-graph.js'
9
+ import { detectTaskType, generateOutputRules } from './lib/rules-generator.js'
9
10
 
10
11
  const cache = new Map()
11
12
  const MAX_CACHE = 500
@@ -426,7 +427,32 @@ async function compressBlock(text, config) {
426
427
  return result
427
428
  }
428
429
 
430
+ // Caveman-style output compression: append task-type-aware rules to the
431
+ // LATEST user message. Cache-safe — only the freshest message is touched,
432
+ // so the prefix (system prompt + earlier turns) stays cacheable.
433
+ function maybeInjectOutputHint(body, config, provider) {
434
+ const mode = config.outputMode
435
+ if (!mode || mode === 'off') return null
436
+ if (typeof provider.injectOutputHint !== 'function') return null
437
+ if (typeof provider.getLastUserText !== 'function') return null
438
+
439
+ const userText = provider.getLastUserText(body)
440
+ if (!userText) return null
441
+
442
+ const taskType = config.autoDetectTaskType === false ? 'complex' : detectTaskType(userText)
443
+ const rules = generateOutputRules(mode, taskType)
444
+ if (!rules) return null
445
+
446
+ // Keep the injected hint compact and clearly marked so the model knows
447
+ // it's a system-style instruction and not part of the user's prose.
448
+ const wrapped = `[tamp output rules — ${mode} mode, ${taskType} task]\n${rules.trim()}`
449
+ const ok = provider.injectOutputHint(body, wrapped)
450
+ return ok ? { mode, taskType, bytes: wrapped.length } : null
451
+ }
452
+
429
453
  export async function compressRequest(body, config, provider) {
454
+ const outputHint = maybeInjectOutputHint(body, config, provider)
455
+
430
456
  const targets = provider.extract(body, { ...config, cacheSafe: config.cacheSafe !== false })
431
457
 
432
458
  // Dedup: replace identical blocks with reference markers
@@ -467,7 +493,7 @@ export async function compressRequest(body, config, provider) {
467
493
  }
468
494
  }
469
495
  provider.apply(body, targets)
470
- return { body, stats, targetCount: targets.length }
496
+ return { body, stats, targetCount: targets.length, outputHint }
471
497
  }
472
498
 
473
499
  export async function compressMessages(body, config) {
package/config.js CHANGED
@@ -76,7 +76,7 @@ export function loadConfig(env = process.env) {
76
76
  minSize: parseInt(get('TAMP_MIN_SIZE'), 10) || 200,
77
77
  stages,
78
78
  preset: presetName,
79
- outputMode: get('TAMP_OUTPUT_MODE') || 'balanced',
79
+ outputMode: get('TAMP_OUTPUT_MODE') || 'off',
80
80
  autoDetectTaskType: parseBoolean(get('TAMP_AUTO_DETECT_TASK_TYPE'), true),
81
81
  log: get('TAMP_LOG') !== 'false',
82
82
  logFile: get('TAMP_LOG_FILE') || null,
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "stats.js",
13
13
  "lib/"
14
14
  ],
15
- "version": "0.5.8",
15
+ "version": "0.5.9",
16
16
  "description": "Token compression proxy for coding agents. Works with Claude Code, Aider, Cursor, Cline, Windsurf. 60-70% combined input+output savings with Caveman-integrated presets.",
17
17
  "type": "module",
18
18
  "main": "index.js",
package/providers.js CHANGED
@@ -52,6 +52,9 @@ function extractAnthropicMessageTargets(msg, mi) {
52
52
 
53
53
  function getLastUserTextFromAnthropicMessages(messages) {
54
54
  if (!Array.isArray(messages)) return null
55
+ // Walk back across user messages until we find one with actual text
56
+ // content. Latest user messages in a Claude Code session are often
57
+ // pure tool_result blocks; the human's intent text is in an earlier turn.
55
58
  for (let i = messages.length - 1; i >= 0; i--) {
56
59
  const msg = messages[i]
57
60
  if (msg?.role !== 'user') continue
@@ -61,7 +64,7 @@ function getLastUserTextFromAnthropicMessages(messages) {
61
64
  if (b?.type === 'text' && typeof b.text === 'string') return b.text
62
65
  }
63
66
  }
64
- return null
67
+ // No text in this user message — keep walking back
65
68
  }
66
69
  return null
67
70
  }
@@ -291,6 +294,7 @@ const openaiResponses = {
291
294
  },
292
295
  getLastUserText(body) {
293
296
  if (!Array.isArray(body?.input) || !body.input.length) return null
297
+ // Walk back across user items until we find one with actual text content
294
298
  for (let i = body.input.length - 1; i >= 0; i--) {
295
299
  const item = body.input[i]
296
300
  if (item?.role !== 'user' || !Array.isArray(item.content)) continue
@@ -302,6 +306,8 @@ const openaiResponses = {
302
306
  },
303
307
  injectOutputHint(body, text) {
304
308
  if (!Array.isArray(body?.input) || !body.input.length || !text) return false
309
+ // Target the LATEST user item (cache-safe). If it has no input_text
310
+ // block we push one, so injection always succeeds for any user item.
305
311
  for (let i = body.input.length - 1; i >= 0; i--) {
306
312
  const item = body.input[i]
307
313
  if (item?.role !== 'user' || !Array.isArray(item.content)) continue