@sliday/tamp 0.3.1 → 0.3.2
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 +3 -2
- package/compress.js +14 -0
- package/package.json +1 -1
package/bin/tamp.js
CHANGED
|
@@ -34,6 +34,7 @@ const STAGE_INFO = {
|
|
|
34
34
|
dedup: 'Replace duplicate tool_results with references',
|
|
35
35
|
diff: 'Replace similar re-reads with unified diffs',
|
|
36
36
|
prune: 'Strip lockfile hashes, registry URLs, npm metadata',
|
|
37
|
+
'strip-comments': 'Remove code comments (lossy, opt-in)',
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
// --- Determine stages ---
|
|
@@ -43,7 +44,7 @@ let selectedStages
|
|
|
43
44
|
if (process.env.TAMP_STAGES) {
|
|
44
45
|
selectedStages = process.env.TAMP_STAGES.split(',').map(s => s.trim()).filter(Boolean)
|
|
45
46
|
} else if (skipPrompt) {
|
|
46
|
-
selectedStages = Object.keys(STAGE_INFO)
|
|
47
|
+
selectedStages = Object.keys(STAGE_INFO).filter(s => s !== 'strip-comments')
|
|
47
48
|
} else {
|
|
48
49
|
log('')
|
|
49
50
|
log(` ${c.bold}${c.cyan}Tamp${c.reset} ${c.dim}v${pkg.version}${c.reset} — Token compression proxy`)
|
|
@@ -53,7 +54,7 @@ if (process.env.TAMP_STAGES) {
|
|
|
53
54
|
choices: Object.entries(STAGE_INFO).map(([value, desc]) => ({
|
|
54
55
|
name: `${value.padEnd(12)} ${c.dim}— ${desc}${c.reset}`,
|
|
55
56
|
value,
|
|
56
|
-
checked:
|
|
57
|
+
checked: value !== 'strip-comments',
|
|
57
58
|
})),
|
|
58
59
|
})
|
|
59
60
|
if (selectedStages.length === 0) {
|
package/compress.js
CHANGED
|
@@ -102,6 +102,17 @@ function pruneJSON(text) {
|
|
|
102
102
|
return result
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
// --- Stage: strip-comments (opt-in, not in defaults) ---
|
|
106
|
+
function stripComments(text) {
|
|
107
|
+
return text
|
|
108
|
+
.replace(/\/\*\*[\s\S]*?\*\//g, '') // JSDoc /** ... */
|
|
109
|
+
.replace(/\/\*[\s\S]*?\*\//g, '') // block /* ... */
|
|
110
|
+
.replace(/\/\/.*$/gm, '') // line // ...
|
|
111
|
+
.replace(/^\s*#(?!!).*$/gm, '') // Python/shell # (not #!)
|
|
112
|
+
.replace(/<!--[\s\S]*?-->/g, '') // HTML <!-- ... -->
|
|
113
|
+
.replace(/\n\s*\n\s*\n/g, '\n\n') // collapse resulting blank lines
|
|
114
|
+
}
|
|
115
|
+
|
|
105
116
|
// --- Core compression ---
|
|
106
117
|
export function compressText(text, config) {
|
|
107
118
|
if (text.length < config.minSize) return null
|
|
@@ -117,6 +128,9 @@ export function compressText(text, config) {
|
|
|
117
128
|
if (config.stages.includes('whitespace')) {
|
|
118
129
|
processed = normalizeWhitespace(processed)
|
|
119
130
|
}
|
|
131
|
+
if (config.stages.includes('strip-comments')) {
|
|
132
|
+
processed = stripComments(processed)
|
|
133
|
+
}
|
|
120
134
|
if (processed.length < text.length * 0.9) {
|
|
121
135
|
return { text: processed, method: 'normalize', originalLen: text.length, compressedLen: processed.length, originalTokens: countTokens(text), compressedTokens: countTokens(processed) }
|
|
122
136
|
}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"providers.js",
|
|
10
10
|
"stats.js"
|
|
11
11
|
],
|
|
12
|
-
"version": "0.3.
|
|
12
|
+
"version": "0.3.2",
|
|
13
13
|
"description": "Token compression proxy for coding agents. Works with Claude Code, Aider, Cursor, Cline, Windsurf. 50.5% fewer input tokens.",
|
|
14
14
|
"type": "module",
|
|
15
15
|
"main": "index.js",
|