@sliday/tamp 0.5.0 → 0.5.3

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
@@ -48,7 +48,7 @@ Auto-detects API format, compresses tool output, forwards upstream. Error result
48
48
  | `diff` | Replace similar re-reads with diffs |
49
49
  | `prune` | Remove low-value metadata |
50
50
 
51
- Opt-in lossy stages: `strip-comments`, `textpress` (LLM semantic compression)
51
+ 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)
52
52
 
53
53
  ## Quick Start
54
54
 
@@ -59,11 +59,27 @@ curl -fsSL https://tamp.dev/setup.sh | bash
59
59
  # Option B: Manual
60
60
  npx @sliday/tamp
61
61
  export ANTHROPIC_BASE_URL=http://localhost:7778 # Claude Code
62
- export OPENAI_API_BASE=http://localhost:7778/v1 # Codex CLI, Aider, Cursor
62
+ export OPENAI_API_BASE=http://localhost:7778/v1 # Aider, Cursor, Cline
63
63
  ```
64
64
 
65
65
  Use your agent as normal — Tamp compresses silently.
66
66
 
67
+ ### Codex CLI
68
+
69
+ Codex CLI reads its upstream from `~/.codex/config.toml`, not `OPENAI_API_BASE`. Add a custom provider:
70
+
71
+ ```toml
72
+ model_provider = "tamp"
73
+
74
+ [model_providers.tamp]
75
+ name = "Tamp Proxy"
76
+ base_url = "http://localhost:7778/v1"
77
+ env_key = "OPENAI_API_KEY"
78
+ wire_api = "responses"
79
+ ```
80
+
81
+ 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.
82
+
67
83
  ## Configuration
68
84
 
69
85
  Run `tamp init` to create `~/.config/tamp/config`. All variables work via env or config file.
package/package.json CHANGED
@@ -8,10 +8,11 @@
8
8
  "detect.js",
9
9
  "metadata.js",
10
10
  "providers.js",
11
+ "session-graph.js",
11
12
  "stats.js",
12
13
  "lib/"
13
14
  ],
14
- "version": "0.5.0",
15
+ "version": "0.5.3",
15
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.",
16
17
  "type": "module",
17
18
  "main": "index.js",
@@ -0,0 +1,60 @@
1
+ import { createHash } from 'node:crypto'
2
+
3
+ const SESSION_TTL_MS = 2 * 60 * 60 * 1000
4
+ const MAX_SESSIONS = 50
5
+ const MIN_BYTES = 512
6
+
7
+ export function createSessionStore({ ttlMs = SESSION_TTL_MS, maxSessions = MAX_SESSIONS } = {}) {
8
+ const store = new Map()
9
+
10
+ function prune() {
11
+ const cutoff = Date.now() - ttlMs
12
+ for (const [k, bucket] of store) {
13
+ if (bucket.lastSeen < cutoff) store.delete(k)
14
+ }
15
+ }
16
+
17
+ function getBucket(key) {
18
+ if (!key) return null
19
+ prune()
20
+ let bucket = store.get(key)
21
+ if (bucket) {
22
+ bucket.lastSeen = Date.now()
23
+ return bucket
24
+ }
25
+ if (store.size >= maxSessions) {
26
+ const oldest = store.keys().next().value
27
+ store.delete(oldest)
28
+ }
29
+ bucket = { refs: new Map(), nextId: 0, lastSeen: Date.now() }
30
+ store.set(key, bucket)
31
+ return bucket
32
+ }
33
+
34
+ return { getBucket, prune, _store: store }
35
+ }
36
+
37
+ export function deriveSessionKey(headers) {
38
+ if (!headers) return null
39
+ const auth = headers.authorization || headers['x-api-key'] || ''
40
+ if (!auth) return null
41
+ return createHash('sha256').update(auth).digest('hex').slice(0, 16)
42
+ }
43
+
44
+ export function graphDeduplicateTargets(targets, bucket, { minBytes = MIN_BYTES } = {}) {
45
+ if (!bucket) return
46
+ for (const target of targets) {
47
+ if (target.skip || target.dedup || target.diffed || target.compressed) continue
48
+ if (typeof target.text !== 'string' || target.text.length < minBytes) continue
49
+
50
+ const hash = createHash('sha256').update(target.text).digest('hex').slice(0, 12)
51
+ const existing = bucket.refs.get(hash)
52
+ if (existing) {
53
+ target.compressed = `<tamp-file-ref id="${existing.id}" sha="${hash}" bytes="${target.text.length}"/>`
54
+ target.graphed = true
55
+ continue
56
+ }
57
+ bucket.nextId += 1
58
+ bucket.refs.set(hash, { id: bucket.nextId, bytes: target.text.length })
59
+ }
60
+ }