jasper-context-compactor 0.3.5 → 0.3.6
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 +14 -3
- package/cli.js +65 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,9 +25,20 @@ npx jasper-context-compactor setup
|
|
|
25
25
|
|
|
26
26
|
1. ✅ **Back up your config** — Saves `openclaw.json` to `~/.openclaw/backups/` with restore instructions
|
|
27
27
|
2. ✅ **Ask permission** — Won't read your config without consent
|
|
28
|
-
3. ✅ **Detect
|
|
29
|
-
4. ✅ **
|
|
30
|
-
5. ✅ **
|
|
28
|
+
3. ✅ **Detect local models** — Automatically identifies Ollama, llama.cpp, MLX, LM Studio providers
|
|
29
|
+
4. ✅ **Suggest token limits** — Based on your model's contextWindow from config
|
|
30
|
+
5. ✅ **Let you customize** — Enter your own values if auto-detection doesn't match
|
|
31
|
+
6. ✅ **Update config safely** — Adds the plugin with your chosen settings
|
|
32
|
+
|
|
33
|
+
### Supported Local Providers
|
|
34
|
+
|
|
35
|
+
The setup automatically detects these providers (primary or fallback):
|
|
36
|
+
- **Ollama** — `/ollama` endpoint
|
|
37
|
+
- **llama.cpp** — llamacpp provider
|
|
38
|
+
- **MLX** — mlx provider
|
|
39
|
+
- **LM Studio** — lmstudio provider
|
|
40
|
+
- **friend-gpu** — Custom GPU servers
|
|
41
|
+
- **OpenRouter** — When routing to local models
|
|
31
42
|
|
|
32
43
|
Then restart OpenClaw:
|
|
33
44
|
```bash
|
package/cli.js
CHANGED
|
@@ -47,6 +47,15 @@ function backupConfig() {
|
|
|
47
47
|
return backupPath;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
// Local model providers that benefit from context compaction
|
|
51
|
+
const LOCAL_PROVIDERS = ['ollama', 'lmstudio', 'llamacpp', 'mlx', 'friend-gpu', 'openrouter'];
|
|
52
|
+
|
|
53
|
+
function isLocalProvider(providerId) {
|
|
54
|
+
if (!providerId) return false;
|
|
55
|
+
const lower = providerId.toLowerCase();
|
|
56
|
+
return LOCAL_PROVIDERS.some(p => lower.includes(p));
|
|
57
|
+
}
|
|
58
|
+
|
|
50
59
|
async function detectModelContextWindow(config) {
|
|
51
60
|
const modelConfig = config?.agents?.defaults?.model;
|
|
52
61
|
if (!modelConfig) return null;
|
|
@@ -58,6 +67,10 @@ async function detectModelContextWindow(config) {
|
|
|
58
67
|
if (modelConfig.primary) candidates.push(modelConfig.primary);
|
|
59
68
|
if (modelConfig.fallbacks) candidates.push(...modelConfig.fallbacks);
|
|
60
69
|
|
|
70
|
+
// Track if any local models are in the chain
|
|
71
|
+
let hasLocalModel = false;
|
|
72
|
+
let localModelInfo = null;
|
|
73
|
+
|
|
61
74
|
// Find the first candidate that has a contextWindow defined in its provider
|
|
62
75
|
for (const modelId of candidates) {
|
|
63
76
|
if (!modelId.includes('/')) continue; // Skip if no provider prefix
|
|
@@ -65,6 +78,24 @@ async function detectModelContextWindow(config) {
|
|
|
65
78
|
const [providerName, ...modelParts] = modelId.split('/');
|
|
66
79
|
const modelName = modelParts.join('/'); // e.g., "qwen2.5"
|
|
67
80
|
|
|
81
|
+
// Check if this is a local provider
|
|
82
|
+
if (isLocalProvider(providerName)) {
|
|
83
|
+
hasLocalModel = true;
|
|
84
|
+
|
|
85
|
+
const provider = providers[providerName];
|
|
86
|
+
const found = provider?.models?.find(m => m.id === modelName);
|
|
87
|
+
|
|
88
|
+
if (!localModelInfo || found?.contextWindow) {
|
|
89
|
+
localModelInfo = {
|
|
90
|
+
model: modelId,
|
|
91
|
+
tokens: found?.contextWindow || null,
|
|
92
|
+
source: found?.contextWindow ? 'config' : 'unknown',
|
|
93
|
+
maxTokens: found?.maxTokens,
|
|
94
|
+
isLocal: true
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
68
99
|
const provider = providers[providerName];
|
|
69
100
|
if (!provider?.models) continue;
|
|
70
101
|
|
|
@@ -76,11 +107,21 @@ async function detectModelContextWindow(config) {
|
|
|
76
107
|
model: modelId,
|
|
77
108
|
tokens: found.contextWindow,
|
|
78
109
|
source: 'config',
|
|
79
|
-
maxTokens: found.maxTokens
|
|
110
|
+
maxTokens: found.maxTokens,
|
|
111
|
+
hasLocalModel,
|
|
112
|
+
localModelInfo
|
|
80
113
|
};
|
|
81
114
|
}
|
|
82
115
|
}
|
|
83
116
|
|
|
117
|
+
// If we have local model info but no contextWindow from config, return that
|
|
118
|
+
if (localModelInfo) {
|
|
119
|
+
return {
|
|
120
|
+
...localModelInfo,
|
|
121
|
+
hasLocalModel: true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
84
125
|
// No contextWindow found in config - try known defaults
|
|
85
126
|
const primaryId = modelConfig.primary || '';
|
|
86
127
|
const knownContexts = {
|
|
@@ -91,11 +132,11 @@ async function detectModelContextWindow(config) {
|
|
|
91
132
|
|
|
92
133
|
for (const [pattern, tokens] of Object.entries(knownContexts)) {
|
|
93
134
|
if (primaryId.toLowerCase().includes(pattern.toLowerCase())) {
|
|
94
|
-
return { model: primaryId, tokens, source: 'fallback' };
|
|
135
|
+
return { model: primaryId, tokens, source: 'fallback', hasLocalModel };
|
|
95
136
|
}
|
|
96
137
|
}
|
|
97
138
|
|
|
98
|
-
return { model: primaryId, tokens: null, source: 'unknown' };
|
|
139
|
+
return { model: primaryId, tokens: null, source: 'unknown', hasLocalModel };
|
|
99
140
|
}
|
|
100
141
|
|
|
101
142
|
async function setup() {
|
|
@@ -200,6 +241,27 @@ async function setup() {
|
|
|
200
241
|
console.log(' [DEBUG] detectedInfo:', JSON.stringify(detectedInfo, null, 2));
|
|
201
242
|
}
|
|
202
243
|
|
|
244
|
+
// Show local model recommendation
|
|
245
|
+
if (detectedInfo?.hasLocalModel || detectedInfo?.isLocal) {
|
|
246
|
+
console.log('');
|
|
247
|
+
console.log(' 🎯 Local model detected in your config!');
|
|
248
|
+
const localModel = detectedInfo.localModelInfo?.model || detectedInfo.model;
|
|
249
|
+
console.log(` → ${localModel}`);
|
|
250
|
+
console.log('');
|
|
251
|
+
console.log(' Local models (Ollama, llama.cpp, MLX, LM Studio) don\'t report');
|
|
252
|
+
console.log(' context overflow errors — they silently truncate or produce garbage.');
|
|
253
|
+
console.log(' This plugin is HIGHLY recommended for your setup.');
|
|
254
|
+
} else if (detectedInfo?.model) {
|
|
255
|
+
// Cloud-only config
|
|
256
|
+
const providerName = detectedInfo.model.split('/')[0] || '';
|
|
257
|
+
if (['anthropic', 'openai', 'google'].includes(providerName.toLowerCase())) {
|
|
258
|
+
console.log('');
|
|
259
|
+
console.log(' ℹ️ Cloud-only config detected (no local models).');
|
|
260
|
+
console.log(' Cloud APIs report context limits properly, so this plugin');
|
|
261
|
+
console.log(' is less critical — but can still help with token costs.');
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
203
265
|
if (detectedInfo && detectedInfo.tokens) {
|
|
204
266
|
console.log('');
|
|
205
267
|
console.log(` ✓ Detected model: ${detectedInfo.model}`);
|
package/package.json
CHANGED