@sliday/tamp 0.5.7 → 0.5.8

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 CHANGED
@@ -5,7 +5,7 @@ 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, VERSION, isLossy } from '../metadata.js'
8
+ import { DEFAULT_STAGES, EXTRA_STAGES, STAGE_DESCRIPTIONS, STAGE_HINTS, VERSION, isLossy } from '../metadata.js'
9
9
  import { CONFIG_PATH, CONFIG_TEMPLATE } from '../config.js'
10
10
  import {
11
11
  checkPort,
@@ -295,7 +295,8 @@ if (skipPrompt) {
295
295
  console.error(` ${c.dim}Claude Code:${c.reset} ANTHROPIC_BASE_URL=${c.yellow}${url}${c.reset}`)
296
296
  console.error(` ${c.dim}Aider/Cursor:${c.reset} OPENAI_API_BASE=${c.yellow}${url}${c.reset}`)
297
297
  console.error('')
298
- console.error(` ${c.bold}Stages${c.reset} ${c.dim}(${active.length} active)${c.reset}`)
298
+ const total = DEFAULT_STAGES.length + EXTRA_STAGES.length
299
+ console.error(` ${c.bold}Stages${c.reset} ${c.dim}(${active.length} of ${total} active)${c.reset}`)
299
300
  for (const s of defaultActive) {
300
301
  const extra = s === 'llmlingua' && config.llmLinguaUrl ? ` ${c.dim}(${config.llmLinguaUrl})${c.reset}` : ''
301
302
  console.error(` ${c.green}\u2713${c.reset} ${c.cyan}${s}${c.reset}${extra}`)
@@ -304,9 +305,22 @@ if (skipPrompt) {
304
305
  const tag = isLossy(s) ? '(lossy)' : '(opt-in)'
305
306
  console.error(` ${c.yellow}\u2713${c.reset} ${c.yellow}${s}${c.reset} ${c.dim}${tag}${c.reset}`)
306
307
  }
308
+
307
309
  const disabled = [...DEFAULT_STAGES, ...EXTRA_STAGES].filter(s => !active.includes(s))
308
- if (disabled.length && disabled.length <= 4) {
309
- console.error(` ${c.dim}\u2717 ${disabled.join(', ')}${c.reset}`)
310
+ if (disabled.length) {
311
+ console.error('')
312
+ console.error(` ${c.bold}Available${c.reset} ${c.dim}(not active — opt in for more savings)${c.reset}`)
313
+ for (const s of disabled) {
314
+ const hint = STAGE_HINTS[s]
315
+ if (hint) {
316
+ console.error(` ${c.dim}\u25EF${c.reset} ${c.cyan}${s}${c.reset} ${c.dim}— ${hint.summary}${c.reset}`)
317
+ if (hint.setup) {
318
+ console.error(` ${c.dim}\u2192 ${hint.setup}${c.reset}`)
319
+ }
320
+ } else {
321
+ console.error(` ${c.dim}\u25EF ${s}${c.reset}`)
322
+ }
323
+ }
310
324
  }
311
325
  console.error('')
312
326
  }
package/bin/ui/Banner.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from 'react'
2
2
  import { Box, Text } from 'ink'
3
3
  import { Badge } from '@inkjs/ui'
4
- import { ALL_STAGES, DEFAULT_STAGES, EXTRA_STAGES, isLossy } from '../../metadata.js'
4
+ import { ALL_STAGES, DEFAULT_STAGES, EXTRA_STAGES, STAGE_HINTS, isLossy } from '../../metadata.js'
5
5
 
6
6
  const h = React.createElement
7
7
 
@@ -34,7 +34,7 @@ export function Banner({ version, port, stages, llmLinguaUrl }) {
34
34
  ),
35
35
  ),
36
36
  h(Text, null, ''),
37
- h(Text, { bold: true }, `Stages `, h(Text, { dimColor: true }, `(${stages.length} active)`)),
37
+ h(Text, { bold: true }, `Stages `, h(Text, { dimColor: true }, `(${stages.length} of ${ALL_STAGES.length} active)`)),
38
38
  h(Box, { paddingLeft: 2, flexDirection: 'column' },
39
39
  ...defaultActive.map(s =>
40
40
  h(Text, { key: s },
@@ -50,10 +50,24 @@ export function Banner({ version, port, stages, llmLinguaUrl }) {
50
50
  h(Text, { dimColor: true }, isLossy(s) ? ' (lossy)' : ' (opt-in)'),
51
51
  )
52
52
  ),
53
- ...(disabled.length && disabled.length <= 4
54
- ? [h(Text, { key: 'disabled', dimColor: true }, `\u2717 ${disabled.join(', ')}`)]
55
- : []
56
- ),
57
53
  ),
54
+ disabled.length ? h(Text, null, '') : null,
55
+ disabled.length ? h(Text, { bold: true }, 'Available ', h(Text, { dimColor: true }, '(not active — opt in for more savings)')) : null,
56
+ disabled.length ? h(Box, { paddingLeft: 2, flexDirection: 'column' },
57
+ ...disabled.flatMap(s => {
58
+ const hint = STAGE_HINTS[s]
59
+ const lines = [
60
+ h(Text, { key: s },
61
+ h(Text, { dimColor: true }, '\u25EF '),
62
+ h(Text, { color: 'cyan' }, s),
63
+ hint ? h(Text, { dimColor: true }, ` \u2014 ${hint.summary}`) : null,
64
+ )
65
+ ]
66
+ if (hint?.setup) {
67
+ lines.push(h(Text, { key: s + '-setup', dimColor: true }, ` \u2192 ${hint.setup}`))
68
+ }
69
+ return lines
70
+ })
71
+ ) : null,
58
72
  )
59
73
  }
package/metadata.js CHANGED
@@ -41,6 +41,32 @@ export function isLossy(stage) {
41
41
  return LOSSY_STAGES.has(stage)
42
42
  }
43
43
 
44
+ // Hints shown in the banner when a stage is NOT active. summary describes
45
+ // the value the user is missing; setup is a copy-pasteable enable command
46
+ // (or null if the stage just needs TAMP_STAGES=...,<name>).
47
+ export const STAGE_HINTS = Object.freeze({
48
+ llmlingua: {
49
+ summary: 'neural text compression, +7-12% savings',
50
+ setup: 'install uv: curl -LsSf https://astral.sh/uv/install.sh | sh',
51
+ },
52
+ graph: {
53
+ summary: 'cross-request dedup, lossless, -99% on re-reads',
54
+ setup: 'TAMP_STAGES=...,graph',
55
+ },
56
+ 'strip-comments': {
57
+ summary: 'remove code comments (lossy)',
58
+ setup: null,
59
+ },
60
+ textpress: {
61
+ summary: 'LLM semantic compression via Ollama/OpenRouter (lossy)',
62
+ setup: null,
63
+ },
64
+ 'foundation-models': {
65
+ summary: 'Apple Intelligence neural (macOS 15+, lossy)',
66
+ setup: null,
67
+ },
68
+ })
69
+
44
70
  export const STAGE_DESCRIPTIONS = Object.freeze({
45
71
  minify: 'Strip JSON whitespace (lossless)',
46
72
  toon: 'Columnar array encoding (lossless)',
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "stats.js",
13
13
  "lib/"
14
14
  ],
15
- "version": "0.5.7",
15
+ "version": "0.5.8",
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
@@ -50,6 +50,47 @@ function extractAnthropicMessageTargets(msg, mi) {
50
50
  return targets
51
51
  }
52
52
 
53
+ function getLastUserTextFromAnthropicMessages(messages) {
54
+ if (!Array.isArray(messages)) return null
55
+ for (let i = messages.length - 1; i >= 0; i--) {
56
+ const msg = messages[i]
57
+ if (msg?.role !== 'user') continue
58
+ if (typeof msg.content === 'string') return msg.content
59
+ if (Array.isArray(msg.content)) {
60
+ for (const b of msg.content) {
61
+ if (b?.type === 'text' && typeof b.text === 'string') return b.text
62
+ }
63
+ }
64
+ return null
65
+ }
66
+ return null
67
+ }
68
+
69
+ function appendToLastUserMessageAnthropic(messages, text) {
70
+ if (!Array.isArray(messages) || !text) return false
71
+ for (let i = messages.length - 1; i >= 0; i--) {
72
+ const msg = messages[i]
73
+ if (msg?.role !== 'user') continue
74
+ if (typeof msg.content === 'string') {
75
+ msg.content = msg.content + '\n\n' + text
76
+ return true
77
+ }
78
+ if (Array.isArray(msg.content)) {
79
+ for (let j = msg.content.length - 1; j >= 0; j--) {
80
+ const b = msg.content[j]
81
+ if (b?.type === 'text' && typeof b.text === 'string') {
82
+ b.text = b.text + '\n\n' + text
83
+ return true
84
+ }
85
+ }
86
+ msg.content.push({ type: 'text', text })
87
+ return true
88
+ }
89
+ return false
90
+ }
91
+ return false
92
+ }
93
+
53
94
  const anthropic = {
54
95
  name: 'anthropic',
55
96
  match(method, url) {
@@ -66,6 +107,12 @@ const anthropic = {
66
107
  apply(body, targets) {
67
108
  applyTargets(body, targets)
68
109
  },
110
+ getLastUserText(body) {
111
+ return getLastUserTextFromAnthropicMessages(body?.messages)
112
+ },
113
+ injectOutputHint(body, text) {
114
+ return appendToLastUserMessageAnthropic(body?.messages, text)
115
+ },
69
116
  }
70
117
 
71
118
  function extractOpenAIChatTargets(msg, i) {
@@ -103,6 +150,27 @@ const openai = {
103
150
  apply(body, targets) {
104
151
  applyTargets(body, targets)
105
152
  },
153
+ getLastUserText(body) {
154
+ if (!body?.messages?.length) return null
155
+ for (let i = body.messages.length - 1; i >= 0; i--) {
156
+ const msg = body.messages[i]
157
+ if (msg?.role === 'user' && typeof msg.content === 'string') return msg.content
158
+ }
159
+ return null
160
+ },
161
+ injectOutputHint(body, text) {
162
+ if (!body?.messages?.length || !text) return false
163
+ for (let i = body.messages.length - 1; i >= 0; i--) {
164
+ const msg = body.messages[i]
165
+ if (msg?.role !== 'user') continue
166
+ if (typeof msg.content === 'string') {
167
+ msg.content = msg.content + '\n\n' + text
168
+ return true
169
+ }
170
+ return false
171
+ }
172
+ return false
173
+ },
106
174
  }
107
175
 
108
176
  function extractGeminiContentTargets(content, ci) {
@@ -138,6 +206,36 @@ const gemini = {
138
206
 
139
207
  return body.contents.flatMap(extractGeminiContentTargets)
140
208
  },
209
+ getLastUserText(body) {
210
+ if (!body?.contents?.length) return null
211
+ for (let i = body.contents.length - 1; i >= 0; i--) {
212
+ const c = body.contents[i]
213
+ if (c?.role && c.role !== 'user') continue
214
+ if (!Array.isArray(c?.parts)) continue
215
+ for (const p of c.parts) {
216
+ if (typeof p?.text === 'string') return p.text
217
+ }
218
+ }
219
+ return null
220
+ },
221
+ injectOutputHint(body, text) {
222
+ if (!body?.contents?.length || !text) return false
223
+ for (let i = body.contents.length - 1; i >= 0; i--) {
224
+ const c = body.contents[i]
225
+ if (c?.role && c.role !== 'user') continue
226
+ if (!Array.isArray(c?.parts)) continue
227
+ for (let j = c.parts.length - 1; j >= 0; j--) {
228
+ const p = c.parts[j]
229
+ if (typeof p?.text === 'string') {
230
+ p.text = p.text + '\n\n' + text
231
+ return true
232
+ }
233
+ }
234
+ c.parts.push({ text })
235
+ return true
236
+ }
237
+ return false
238
+ },
141
239
  apply(body, targets) {
142
240
  for (const t of targets) {
143
241
  if (t.skip || !t.compressed) continue
@@ -191,6 +289,34 @@ const openaiResponses = {
191
289
  apply(body, targets) {
192
290
  applyTargets(body, targets)
193
291
  },
292
+ getLastUserText(body) {
293
+ if (!Array.isArray(body?.input) || !body.input.length) return null
294
+ for (let i = body.input.length - 1; i >= 0; i--) {
295
+ const item = body.input[i]
296
+ if (item?.role !== 'user' || !Array.isArray(item.content)) continue
297
+ for (const block of item.content) {
298
+ if (block?.type === 'input_text' && typeof block.text === 'string') return block.text
299
+ }
300
+ }
301
+ return null
302
+ },
303
+ injectOutputHint(body, text) {
304
+ if (!Array.isArray(body?.input) || !body.input.length || !text) return false
305
+ for (let i = body.input.length - 1; i >= 0; i--) {
306
+ const item = body.input[i]
307
+ if (item?.role !== 'user' || !Array.isArray(item.content)) continue
308
+ for (let j = item.content.length - 1; j >= 0; j--) {
309
+ const block = item.content[j]
310
+ if (block?.type === 'input_text' && typeof block.text === 'string') {
311
+ block.text = block.text + '\n\n' + text
312
+ return true
313
+ }
314
+ }
315
+ item.content.push({ type: 'input_text', text })
316
+ return true
317
+ }
318
+ return false
319
+ },
194
320
  }
195
321
 
196
322
  const providers = [anthropic, openai, openaiResponses, gemini]