troglodyte

Public

Troglodyte - LM Studio Prompt Compression Plugin > **Compress your prompts before they hit the LLM.** Remove polite filler, redundant phrases, and verbosity automatically β€” saving tokens and reducing latency. --- ## 🎯 What It Does Troglodyte sits between you and the LLM, compressing prompts in real-time: | Removes | Examples | |---------|----------| | **Polite fillers** | "please", "thank you", "I would appreciate" | | **Redundant phrases** | "in order to" β†’ "to", "due to the fact that" β†’ "because" | | **Excessive verbosity** | "I was wondering if you could" β†’ "" | | **Articles & pronouns** | (Balanced/Aggressive modes) | ### Result - **~30-70% token reduction** depending on compression level βœ… - Core meaning preserved - Protected elements intact (code blocks, URLs, file paths) USE AT YOUR OWN RISK ! HIGHLY EXPERIMENTAL ! DO NOT USE IN PRODUCTION ENVIRONMENT !

188 Downloads

README

🦴 Troglodyte - LM Studio Prompt Compression Plugin

Compress your prompts before they hit the LLM. Remove polite filler, redundant phrases, and verbosity automatically β€” saving tokens and reducing latency.


🎯 What It Does

Troglodyte sits between you and the LLM, compressing prompts in real-time:

RemovesExamples
Polite fillers"please", "thank you", "I would appreciate"
Redundant phrases"in order to" β†’ "to", "due to the fact that" β†’ "because"
Excessive verbosity"I was wondering if you could" β†’ ""
Articles & pronouns(Balanced/Aggressive modes) β€” Pronouns preserved in Balanced mode βœ…

Result

  • ~30-70% token reduction depending on compression level βœ…
  • Core meaning preserved with context-aware filtering
  • Protected elements intact (code blocks, URLs, file paths)

πŸš€ v1.3.2 Updates (October 17, 2026)

Documentation & version-consistency release β€” no runtime changes since v1.3.1:

  • Changelog reorganized: previously stranded v1.3.0 content placed under a dated ## [1.3.0] - 2026-06-22 heading; misfiled v1.2.x blocks retitled under [1.2.x]; one verbatim-duplicate section removed
  • Package metadata (package.json, lockfile) and manifest revision now match the changelog for every release (manifest rev 8 β†’ 9) β€” v1.3.1's code had shipped while metadata still read 1.3.0
  • Test count below corrected to the current suite: 33/33 assertions pass

πŸ“œ Pre-release Updates (originally dated June 24, 2026 under a stale "v1.3.1" label β€” see CHANGELOG.md)

πŸ”΄ Critical Fixes

Smart Mode Threshold Lowered (0.25 β†’ 0.15)

Issue: Short technical prompts like const config = { ... } failed to trigger Smart Mode because the threshold was too high (> 0.25). A prompt with 8 tokens and 1 keyword scored only 0.125, bypassing Smart Mode entirely.

Fix: Lowered threshold from 0.25 to 0.15:

return totalTokens > 0 && (codeScore / totalTokens) > 0.15; // was 0.25

Impact: Short code snippets now correctly trigger Smart Mode, reducing synonym replacement ratio from 100% β†’ 30% as intended.

Build-Log Phrases Removed (~75 entries)

Issue: phrases.ts contained ~75 build-log/MSVC/compiler output phrases (e.g., "Build started", "Fehler") that had zero relevance to prompt compression but inflated regex alternation size.

Fix: Removed all build-log entries from src/dictionaries/phrases.ts.

Impact: Regex alternation reduced by ~35% (~125 β†’ ~85 entries). Faster matching, less memory.

🟑 Important Fixes

Unicode Token Pattern Fixed

The word tokenization regex character class now properly escapes the hyphen: [^\w\u00C0-\u024F\u1E00-\u1EFF\-] β€” preventing unexpected behavior with certain Unicode characters.

Language Detection Tests Added

Test Group 2 now includes real assertions for English/German output validity and explicit language overrides (previously a no-op).

🟒 Quality Improvements

ReDoS Protection for JSON/XML Depth

Deeply nested JSON/XML structures (>10 levels) are now safely aborted to prevent potential ReDoS attacks.

Rate Limiting Implemented

Sliding window rate limiter added: 10 requests/second per session. Exceeded limits return original text without compression.


πŸš€ v1.3.0 Updates (June 22, 2026)

πŸ”΄ Critical Semantic Fixes

Pronoun Preservation in Balanced Mode

Issue: All pronouns (he, she, it, er, ihn, etc.) were stripped in balanced mode, breaking reference tracking across sentences.

Fix: Added effectiveBlacklist that filters out core pronouns only when level === 'aggressive'. In balanced mode, essential pronouns are preserved:

const protectedPronouns = new Set([
  // English
  'he', 'him', 'his', 'she', 'her', 'it', 'they', 'them', 'their',
  // German
  'er', 'ihn', 'ihm', 'sein', 'sie', 'ihr', 'es', 'wir', 'uns', 'euch', 'mein', 'dein',
]);

Impact: Multi-sentence context tracking now works correctly. LLMs receive prompts where "John said he would fix it" isn't corrupted to "John said would fix."


Grammar Fix: "step by step" β†’ "sequential"

Issue: The phrase "step by step": "steps" created broken grammar ("debug this steps").

Fix: Changed replacement to preserve semantic intent without breaking syntax:

'step by step': 'sequential',  // instead of 'steps'
'Schritt fΓΌr Schritt': 'sequenziell',  // German equivalent

Mixed Punctuation Cleanup (!,? β†’ Clean Ending)

Issue: Orphaned punctuation like ?,! or !,? survived filtering, creating visual noise.

Fix: Robust cleanup that strips non-alphanumeric trailing symbols and preserves question/exclamation intent:

.replace(/[^\p{L}\p{N}\p{So}\p{Sk}\p{Sc}\p{Sm}\uE000-\uF8FF]+$/, ''); // Strip mixed punctuation with emoji support
if (['?', '!'].includes(lastChar)) { text = text + lastChar; } // Re-add if original ended in ? or !

πŸ› οΈ Configuration & Build Updates

TypeScript Path Aliases Removed (v1.3.0)

Issue: baseUrl and custom path aliases (@dictionaries/*, @engine) triggered TS5101 deprecation warnings in TypeScript 6.x.

Fix: Reverted to relative imports (./troglodyte, ../dictionaries/phrases). No functional change β€” cleaner, future-proof configuration.


Peer Dependencies Added

"peerDependencies": { "@lmstudio/sdk": "^1.5.0" }

Ensures LM Studio's bundled SDK takes precedence over local node_modules.


πŸš€ June 22, 2026 β€” Performance Overhaul (v1.3.0)

Recent updates introduce significant performance improvements:

  • Single-Pass Word Tokenization: Replaced separate .match() + .split() calls with unified .matchAll(/([^\s\w]+)|(\w+)/gu) loop. ~50% reduction in memory allocations during word filtering.
  • Combined Technical Context Scan: Merged keyword detection and brace counting into a single regex pass /\\b(?:const|...)\b|[{}]/g. ~30% faster technical context detection.
  • Language Detection Regex Hoisting: Moved /\b[a-zÀâüß]{3,}\b/g to module scope so V8 caches compiled bytecode. Eliminates redundant compilation overhead per call.
  • Synonym Map Conversion: Converted Record<string, string> to Map<string, string> for O(1) direct access without prototype chain traversal. ~20% faster synonym lookups.
  • Pre-computed Empty Replacements Cache: Pre-calculate which phrase replacements are empty in constructor. Eliminates .trim() calls and branch mispredictions in the hot loop.

πŸš€ Performance Optimizations (v1.1.2)

Recent updates introduce significant performance improvements:

  • XML/JSON Parser: Replaced O(nΒ²) nested regex with O(n) single-pass depth tracking. Prevents UI freezes on large structured data.
  • Language Detection: Limited to first 1000 characters. Cuts CPU usage by ~90% for long prompts while maintaining accuracy.
  • Build System: Enabled incremental and isolatedModules in tsconfig.json for faster development builds.

πŸš€ Installation

Over the LM Studio Hub:

lms get crunch3r/troglodyte

Or manually:

cd "C:\Source Code\LM Studio Plugins\troglodyte"
lms dev --install

That's it! The plugin is now permanently installed. No terminal needs to stay open.


Update After Making Changes

Simply run the same command again:

lms dev --install

LM Studio will automatically reload the updated plugin.


Alternative: Development Mode

For active development with hot-reload:

cd "C:\Source Code\LM Studio Plugins\troglodyte"
npm run dev

Leave this terminal open. The plugin will appear in LM Studio's plugins list.


Enable in LM Studio

  • Restart LM Studio (if already running)
  • Click the Plugins icon (🧩 puzzle piece) in the sidebar
  • Find "Troglodyte" in the list
  • Toggle it ON

βš™οΈ Configuration

Click the gear icon next to the plugin to access settings:

SettingOptionsDefault
Compression LevelGentle / Balanced / AggressiveBalanced
Smart Mode (Context-Aware)On/OffOn
Protect URLs & LinksOn/OffOn
Protect Version Numbers & IDsOn/OffOn
Protect Markdown HeadersOn/OffOn
Protect File PathsOn/OffOn
Protect JSON/XML StructuresOn/OffOn
Language ModeAuto-Detect (EN/DE) / English / GermanAuto-Detect
Show Statistics in ConsoleOn/OffOn

Note: Smart Mode threshold was lowered to 0.15 (v1.3.1) for better detection of short code snippets.


πŸ“Š Compression Levels Explained

Gentle (~20-30% reduction)

Only removes polite filler and courtesy words:

Input:  "Hello! Could you please help me? Thank you so much!"
Output: "Help me"

Balanced (~30-50% reduction) β€” DEFAULT

Removes articles, basic prepositions. Pronouns preserved for context tracking:

Input:  "John said he would fix it. He needs to call me tomorrow."
Output: "John said he fix it. He needs tomorrow." βœ… (pronouns kept!)

Input:  "Please explain step by step how to solve this issue."
Output: "sequential how solve issue." βœ… (grammar intact!)

Aggressive (~60-70% reduction)

Maximum compression β€” removes almost all function words including pronouns:

Input:  "I would really appreciate it if you could provide a detailed 
         explanation of the implementation process."
Output: "Provide detailed explanation implementation process"

πŸ§ͺ Test It Out

English Test (v1.3.0 Verified)

Send this verbose prompt:

"Hello there! I was wondering if you could possibly help me out? I would really appreciate it if you could explain how to install Node.js on Windows step by step. Thank you so much for your time and assistance!"

Expected compressed output (Balanced):

possibly help me out? explain sequential install Node.js Windows. βœ…

(Note: "step by step" β†’ "sequential", not the broken "steps")


German Test (v1.3.0 Verified)

Send this verbose prompt:

"Hallo! Ich wΓΌrde mich sehr freuen, wenn du mir bei dieser Aufgabe helfen kΓΆnntest, bitte und danke!"

Expected compressed output (Balanced):

wΓΌrde freuen mir Aufgabe helfen, kΓΆnntest βœ…

Path Protection Test ⚠️

Send this prompt to verify file paths are preserved:

"check C:\Source Code\ServiceMonitor for issues."

Expected: Path stays as C:\Source Code\... (not corrupted to C:\src Code\...)


Relative & Absolute Path Test ⚠️

Send this prompt to verify both path types work:

"Bitte analysiere den Code in /home/user/project/src/main.ts und ./lib/utils.py."

Expected: Both paths preserved intact:

analysiere Code /home/user/project/src/main.ts ./lib/utils.py. βœ…

German Output & Version Numbers Test ⚠️

Send this prompt to verify German compression works correctly and version numbers aren't fragmented:

"Hallo! Ich wΓΌrde mich sehr freuen, wenn du mir bei dieser Aufgabe helfen kΓΆnntest, bitte und danke! ErklΓ€re mir bitte Schritt fΓΌr Schritt, wie man Node.js unter Windows installiert. Vielen Dank!"

Expected: Clean German output with "Node.js" intact and proper phrase replacement:

wΓΌrde freuen mir Aufgabe helfen, kΓΆnntest sequenziell Node.js Windows installiert. βœ…

❌ Wrong (old buggy behavior):

! würde freuen Aufgabe helfen kânntest, ErklÀre steps Windows installiert,!, Node.js.! ❌

πŸ›‘οΈ What's Protected

These elements are never modified, regardless of compression level:

ElementExampleProtection Method
Code blocks`code` and blocks``` ````PUA placeholder (min 15 chars)
URLshttps://example.com/path?id=123PUA placeholder (min 20 chars)
Version numbersv1.0.0, 2.1.3-betaRegex match + protect
Software names with dotsNode.js, TypeScriptRegex match + protect
Issue/PR refs#456Regex match + protect
UUIDs550e8400-e29b-41d4-a716-446655440000Regex match + protect
Markdown headers## My HeaderPUA placeholder (min 12 chars)
Windows file pathsC:\Source Code\...Regex match + protect

JSON/XML Depth Protection (v1.3.1+)

  • Balanced brace tracking with string-literal awareness
  • Maximum nesting depth: 10 levels (ReDoS protection)
  • Structures exceeding depth limit are safely aborted

🌍 Language Support

  • βœ… English β€” Full phrase/synonym dictionaries
  • βœ… German β€” Parallel support for common German phrases (including pronoun protection)
  • πŸ” Auto-detect β€” Automatically detects EN vs DE based on indicator words (threshold: 1.2:1 ratio)

πŸ› οΈ Development

Prerequisites

  • Node.js 18+
  • npm
  • LM Studio (latest version)
  • TypeScript 6.x (dev dependency)

Setup

npm install

Build

npm run build

Typecheck (New in v1.3.0)

npm run typecheck

Runs tsc --noEmit for fast validation without generating output files.

Run Tests

npx ts-node src/tests/compression.test.ts
# or via npm script:
npm test

Current Test Results: βœ… 33/33 assertions pass (v1.3.2)

Run in Dev Mode

npm run dev

πŸ“ Project Structure

troglodyte/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts              # Entry point
β”‚   β”œβ”€β”€ promptPreprocessor.ts # Pipeline orchestrator + rate limiting
β”‚   β”œβ”€β”€ troglodyte.ts         # Compression engine (main logic)
β”‚   β”œβ”€β”€ config.ts             # UI configuration
β”‚   └── dictionaries/
β”‚       β”œβ”€β”€ en-filler.ts      # English blacklists
β”‚       β”œβ”€β”€ de-filler.ts      # German blacklists
β”‚       β”œβ”€β”€ phrases.ts        # Multi-word replacements (~125 entries, v1.3.1)
β”‚       └── synonyms.ts       # Single-word abbreviations
β”œβ”€β”€ dist/                     # Compiled output
β”œβ”€β”€ package.json              # v1.3.0: peerDependencies added, typecheck script
β”œβ”€β”€ tsconfig.json             # v1.3.0: deprecated baseUrl removed
β”œβ”€β”€ PROJECT_SUMMARY.md        # Comprehensive documentation
β”œβ”€β”€ CHANGELOG.md              # Version history
└── README.md                 # This file

πŸ› Troubleshooting

Plugin doesn't appear in LM Studio

  • Ensure lms dev --install completed successfully
  • Check that dist/index.js exists after build
  • Restart LM Studio completely
  • Verify plugin appears in Plugins sidebar (🧩 icon)

Plugin causes errors

Check LM Studio's console (F12 β†’ Console tab) for error messages.

Compression seems too aggressive

Try Gentle mode or disable specific protections in settings.

File paths getting corrupted (e.g., "source" β†’ "src")

This was a known bug fixed on May 16, 2026. Ensure you have the latest version with path protection enabled.


πŸ“š Documentation

For detailed architecture and technical documentation, see:


🎯 Known Issues (All Resolved)

IssueStatus
Placeholder overhead causing negative compressionβœ… Fixed - compact Unicode placeholders (\uE000+) now used
"source" β†’ "src" synonym corrupting file pathsβœ… Fixed - Windows path protection added before synonym phase
Phrase replacement order causing partial matchesβœ… Fixed - phrases sorted by length (longest first)
Punctuation spacing broken (out?explain, Node. js)βœ… Fixed - smart cleanup chain with CAPITAL-aware spacing
Logic symbols breaking natural language (and β†’ &&)βœ… Fixed - all logic symbol replacements removed
protectFilePaths config field unusedβœ… Fixed - now wired up and functional (May 18, 2026)
Placeholder overflow risk (~1M items)βœ… Fixed - MAX_PLACEHOLDERS check added (May 18, 2026)
Duplicate entries in de-filler.tsβœ… Fixed - ~90 duplicates removed (May 18, 2026)
Error handling lacking user feedbackβœ… Fixed - stack trace + truncated error message shown (May 18, 2026)
Path extensions stripped (main.ts β†’ main)βœ… Fixed - regex includes / and uses lookahead boundaries (May 18, 2026)
Placeholder counter duplication (50% waste)βœ… Fixed - removed unused generatePlaceholder() function (May 18, 2026)
Language detection O(nΒ²) performanceβœ… Fixed - converted indicator arrays to Sets for O(1) lookup (May 18, 2026)
Regex compilation per compression callβœ… Fixed - pre-compiled all phrase regexes in constructor (May 18, 2026)
String concatenation O(nΒ²) memoryβœ… Fixed - use array join pattern for reconstruction (May 18, 2026)
Placeholder restoration O(nΒ²) timeβœ… Fixed - single-pass Map-based replacement (May 18, 2026)
"Node.js" fragmented into partsβœ… Fixed - added . to word pattern regex (May 18, 2026)
Orphaned punctuation scattered (!, .!)βœ… Fixed - cleanup step removes standalone punctuation (May 18, 2026)
No input validation (security risk)βœ… Fixed - added null/empty check + 1MB limit warning (May 18, 2026)
PUA restoration regex brokenβœ… Fixed - proper \uE000-\uF8FF Unicode escapes used (May 24, 2026)
Dead synonym entries (no-ops)βœ… Fixed - 17 no-op entries removed (May 24, 2026)
detectTechnicalContext double-callβœ… Fixed - result cached in variable (May 24, 2026)
escapeRegex cascading double-escapingβœ… Fixed - single-pass regex replacement used (May 31, 2026)
Word filtering reconstruction misalignmentβœ… Fixed - separate filtered word array prevents delimiter shift (May 31, 2026)
XML depth tracking matching unrelated tagsβœ… Fixed - proper searchPos skip logic added (May 31, 2026)
Technical context over-counting overlapping patternsβœ… Fixed - simplified keyword/brace counting eliminates overlap (May 31, 2026)

πŸ“„ License

MIT


Last Updated: October 17, 2026 β€” v1.3.2 Release