superlocalmemory 3.6.10 → 3.6.12
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/CHANGELOG.md +65 -0
- package/README.md +62 -6
- package/package.json +1 -1
- package/pyproject.toml +1 -1
- package/skills/slm-optimize/README.md +55 -0
- package/skills/slm-optimize/SKILL.md +139 -0
- package/src/superlocalmemory/cli/commands.py +1 -0
- package/src/superlocalmemory/cli/daemon.py +0 -407
- package/src/superlocalmemory/cli/main.py +3 -1
- package/src/superlocalmemory/core/context_cache.py +4 -1
- package/src/superlocalmemory/core/fact_consolidator.py +4 -1
- package/src/superlocalmemory/core/remote_mode.py +197 -0
- package/src/superlocalmemory/core/summarizer.py +4 -1
- package/src/superlocalmemory/llm/backbone.py +7 -1
- package/src/superlocalmemory/mcp/agent_context.py +7 -3
- package/src/superlocalmemory/mcp/server.py +4 -0
- package/src/superlocalmemory/mcp/tools_core.py +13 -1
- package/src/superlocalmemory/mcp/tools_mesh.py +14 -6
- package/src/superlocalmemory/mcp/tools_optimize.py +304 -0
- package/src/superlocalmemory/mesh/broker.py +15 -4
- package/src/superlocalmemory/optimize/compress/router.py +9 -4
- package/src/superlocalmemory/optimize/storage/db.py +40 -2
- package/src/superlocalmemory/server/api.py +11 -3
- package/src/superlocalmemory/server/routes/mesh.py +13 -0
- package/src/superlocalmemory/server/routes/token.py +14 -2
- package/src/superlocalmemory/server/routes/v3_api.py +83 -17
- package/src/superlocalmemory/server/ui.py +15 -4
- package/src/superlocalmemory/server/unified_daemon.py +96 -160
- package/src/superlocalmemory/storage/database.py +10 -1
- package/src/superlocalmemory/ui/js/auto-settings.js +24 -0
- package/src/superlocalmemory.egg-info/PKG-INFO +63 -7
- package/src/superlocalmemory.egg-info/SOURCES.txt +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,71 @@ All notable changes to SuperLocalMemory V3 will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.6.12] - 2026-06-14 — Distributed-ready + stability fixes
|
|
9
|
+
|
|
10
|
+
Makes SuperLocalMemory work correctly across a LAN / distributed deployment (issues #39, #40) and fixes a set of stability and security defects. Default single-machine behavior is unchanged.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`SLM_REMOTE=1` — one-switch LAN mode** (default OFF). When enabled, SLM serves the dashboard install token to allowlisted LAN clients, runs the MCP transport statelessly so a gateway/hub can forward tool calls, allows trusted LAN dashboard origins, and exempts the trusted LAN dashboard from rate limiting. LAN access stays gated by `SLM_MCP_ALLOWED_HOSTS`. Granular flags: `SLM_MCP_STATELESS=1`, and tunable rate limits `SLM_RATE_LIMIT_WRITE` / `SLM_RATE_LIMIT_READ` / `SLM_RATE_LIMIT_WINDOW`. See `docs/distributed-deployment.md`.
|
|
15
|
+
- **`slm search`** CLI command (parity with the MCP `search` tool).
|
|
16
|
+
|
|
17
|
+
### Fixed — Distributed / LAN (#39, #40)
|
|
18
|
+
|
|
19
|
+
- **The Brain page now loads from a remote browser** on the LAN (the install-token endpoint serves allowlisted LAN clients in remote mode instead of being loopback-only).
|
|
20
|
+
- **Mesh tools no longer fail with `-32600 Session not found`** when called through an MCP gateway/hub (the transport can now run stateless so the session id need not be replayed).
|
|
21
|
+
- **Custom LLM endpoints (llama.cpp / LM Studio / Azure) can now be configured from the dashboard** — the Settings page shows, sends, and saves the endpoint, and switching mode actually persists.
|
|
22
|
+
- **The dashboard rate limit (`429 Too Many Requests`) is now configurable** and trusted LAN clients are exempt in remote mode.
|
|
23
|
+
|
|
24
|
+
### Fixed — Stability & security
|
|
25
|
+
|
|
26
|
+
- **Authentication now fails closed.** A failure to install the auth gate could previously leave write endpoints unauthenticated; it now logs and denies non-loopback writes instead.
|
|
27
|
+
- **Mesh peer registration fixed** — sessions now register with the correct peer id, so heartbeat, direct messages, and inbox work reliably (previously they could silently target a non-existent peer).
|
|
28
|
+
- **`SLM_MESH_SHARED_SECRET` is now enforced** on inbound mesh requests from non-loopback callers.
|
|
29
|
+
- **The cache no longer raises on a corrupted or wrong-key entry** — it degrades to a cache miss.
|
|
30
|
+
- **SSRF protection** added to the provider connection test (cloud-metadata and internal addresses are blocked for remote callers; the local dashboard can still test local/LAN endpoints).
|
|
31
|
+
- **Mode B no longer silently falls back to Mode A** when using a keyless local LLM endpoint.
|
|
32
|
+
- **Memory search no longer errors on punctuation** (`?`, `-`, quotes, etc.).
|
|
33
|
+
- **Mode B honors the configured LLM endpoint and timeout** in summarization and consolidation (previously hardcoded to localhost).
|
|
34
|
+
- **Math-health dashboard reports real status** instead of always showing green.
|
|
35
|
+
- Mesh lock release and inbox now behave correctly (no false success, no re-listing of already-read messages); switching profile takes effect immediately for recall.
|
|
36
|
+
|
|
37
|
+
### Removed
|
|
38
|
+
|
|
39
|
+
- Removed legacy dead code (an unused in-process daemon handler and superseded duplicate API routes) for a cleaner, more maintainable codebase. No functional change. — Optimize Everywhere: three surfaces (proxy · MCP tools · skill)
|
|
40
|
+
|
|
41
|
+
Cache + compress across **every setup** — proxy, MCP tools, or skill. Five new MCP tools land directly inside `slm mcp` (no proxy, full 1M context window preserved). A new `slm-optimize` skill makes compression and routed-result caching zero-config for Claude Code users. Overclaim in prior docs fixed; three-surfaces table added.
|
|
42
|
+
|
|
43
|
+
### Added — Surface B: MCP Optimize Tools (proxy-free)
|
|
44
|
+
|
|
45
|
+
Five new tools registered in `slm mcp` from v3.6.11+:
|
|
46
|
+
|
|
47
|
+
- **`slm_compress`** — compress text or tool output. `mode=normalize` is lossless whitespace normalization; `mode=auto`/`aggressive` delegates to the existing CompressRouter engine. Lossy + reversible stores the original in CCR and returns a `ccr_id`. Content >1 MB is stored unreversed. All fail-open.
|
|
48
|
+
- **`slm_retrieve`** — recover the exact original bytes from a `ccr_id` UUID4 returned by `slm_compress`. Validates UUID format before lookup.
|
|
49
|
+
- **`slm_cache_set`** — cache any string result the agent routes through SLM (file reads, bash output, search results, sub-model calls). Key is SHA-256 namespaced `mcpkv:{agent_id}:{key}` — no cross-agent collisions. TTL default 24 h.
|
|
50
|
+
- **`slm_cache_get`** — retrieve a cached result by key. Returns `hit:True/False`. Increments in-module `_kv_hits`/`_kv_misses` counters for stats.
|
|
51
|
+
- **`slm_optimize_stats`** — session compression + cache statistics. Proxy counters read from `CacheDB.metrics_load()` (daemon-persisted, accurate across restarts); KV counters are in-module for this MCP process session.
|
|
52
|
+
|
|
53
|
+
All five are **fail-open**: any internal error returns `{ok: False, note: <error>}` with the original content unchanged — never raises to the agent.
|
|
54
|
+
|
|
55
|
+
### Added — Surface C: slm-optimize Skill (zero-config)
|
|
56
|
+
|
|
57
|
+
- **`skills/slm-optimize/SKILL.md`** and **`ide/skills/slm-optimize/SKILL.md`** — agent-behavior instruction file. Eight behavioral rules: compress CLAUDE.md at session start, compress large tool outputs via `slm_compress`, KV-cache repeated file reads and bash/search results, recover originals with `slm_retrieve`, never-compress list (secrets, JSON, code/Edit/Write outputs), emit stats on request, fail-open on `ok:False`. Compatible with Claude Code, Cursor, Antigravity, Codex, and any IDE that supports MCP tool calls.
|
|
58
|
+
- **`skills/slm-optimize/README.md`** — human install guide: prerequisites, install steps, activation options, feature table, and explicit "what it does NOT do" section.
|
|
59
|
+
|
|
60
|
+
### Changed — `CacheDB` (new public method)
|
|
61
|
+
|
|
62
|
+
- **`CacheDB.get_value(cache_key, tenant_id)`** added to `optimize/storage/db.py` — pure `SELECT` lookup with no `hit_count` side-effect (unlike `get()`). Used by `slm_cache_get` to avoid inflating proxy cache counters when agents read KV entries. Fail-open: returns `None` on any SQLite/decryption/zlib error.
|
|
63
|
+
|
|
64
|
+
### Changed — MCP server registration
|
|
65
|
+
|
|
66
|
+
- Five optimize tool names added to `_ESSENTIAL_TOOLS` frozenset in `mcp/server.py` (v3.6.11 Surface B). Without this the `_FilteredServer` wrapper silently drops tools whose names are not in the set.
|
|
67
|
+
- `register_optimize_tools(_target)` call added after other `register_*` calls.
|
|
68
|
+
|
|
69
|
+
### Fixed — Overclaim in README / docs
|
|
70
|
+
|
|
71
|
+
- Replaced "Save up to 90% on every LLM API call" headline with accurate three-surfaces framing: proxy (full-turn caching on metered API), MCP tools (routed-result caching + compression), skill (auto-applied compression). Hard constraint documented: primary Claude conversation turn cannot be cached without a proxy — never implied otherwise.
|
|
72
|
+
|
|
8
73
|
## [3.6.10] - 2026-06-14 — Optimize correctness (cache + lossless compression) · MCP per-agent identity · runtime toggles · benchmark + shadow-capture · Issue #38
|
|
9
74
|
|
|
10
75
|
This release makes the **Optimize** subsystem (the HTTP proxy that caches and compresses LLM API calls) correct, observable, and **independently controllable at runtime**, adds **per-agent identity** to the HTTP MCP transport, ships a **benchmark + shadow-capture** harness that proves the cache and compression behaviour, and fixes GitHub issue #38. Cache and compression remain **default-OFF** and are now separately toggleable from the dashboard.
|
package/README.md
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
<img src="https://superlocalmemory.com/assets/logo-mark.png" alt="SuperLocalMemory" width="200"/>
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
<h1 align="center">SuperLocalMemory V3.6</h1>
|
|
6
|
-
<p align="center"><strong>
|
|
7
|
-
<p align="center"><code>v3.6.
|
|
5
|
+
<h1 align="center">SuperLocalMemory V3.6.11</h1>
|
|
6
|
+
<p align="center"><strong>Cache. Compress. Remember. Three surfaces — proxy, MCP tools, or skill. Every setup covered.</strong><br/><em>The only local-first layer that pairs persistent memory with compression + caching across every Claude plan. Full 1M window preserved in MCP and skill mode.</em></p>
|
|
7
|
+
<p align="center"><code>v3.6.11 "Optimize Everywhere"</code> — <strong>Compress + cache on any plan, three ways in.</strong><br/>Proxy (full-turn cache): <code>slm wrap claude</code> · MCP (proxy-free): add <code>slm_compress</code> to your MCP config · Skill (zero-config): <code>~/.claude/skills/slm-optimize/</code></p>
|
|
8
8
|
<p align="center"><strong>Backed by 3 published research papers</strong> (arXiv preprints + Zenodo-archived) · <a href="https://arxiv.org/abs/2603.02240">arXiv:2603.02240</a> · <a href="https://arxiv.org/abs/2603.14588">arXiv:2603.14588</a> · <a href="https://arxiv.org/abs/2604.04514">arXiv:2604.04514</a></p>
|
|
9
9
|
|
|
10
10
|
<p align="center">
|
|
11
|
-
<code>
|
|
11
|
+
<code>Proxy · MCP tools · Skill — three surfaces</code> · <code>+10.6pp vs Mem0 zero-LLM</code> · <code>85% Open-Domain (best zero-LLM score)</code> · <code>EU AI Act Ready</code>
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
14
|
<p align="center">
|
|
15
15
|
<a href="https://arxiv.org/abs/2603.14588"><img src="https://img.shields.io/badge/arXiv-2603.14588-b31b1b?style=for-the-badge&logo=arxiv&logoColor=white" alt="arXiv Paper"/></a>
|
|
16
|
-
<a href="
|
|
16
|
+
<a href="#three-surfaces-proxy--mcp-tools--skill"><img src="https://img.shields.io/badge/Proxy_|_MCP_|_Skill-22c55e?style=for-the-badge" alt="Three Surfaces: Proxy, MCP Tools, Skill"/></a>
|
|
17
17
|
<a href="https://pypi.org/project/superlocalmemory/"><img src="https://img.shields.io/pypi/v/superlocalmemory?style=for-the-badge&logo=pypi&logoColor=white" alt="PyPI"/></a>
|
|
18
18
|
<a href="https://www.npmjs.com/package/superlocalmemory"><img src="https://img.shields.io/npm/v/superlocalmemory?style=for-the-badge&logo=npm&logoColor=white" alt="npm"/></a>
|
|
19
19
|
<a href="https://www.gnu.org/licenses/agpl-3.0"><img src="https://img.shields.io/badge/License-AGPL_v3-blue.svg?style=for-the-badge" alt="AGPL v3"/></a>
|
|
@@ -33,7 +33,11 @@
|
|
|
33
33
|
<details>
|
|
34
34
|
<summary><strong>What's New in V3.6 — Optimize: SKIP, SHRINK, DISCOUNT, REMEMBER</strong> (click to expand)</summary>
|
|
35
35
|
|
|
36
|
-
> V3.6 is the only local-first layer that SKIPS repeat LLM calls (cache: 100%
|
|
36
|
+
> V3.6 is the only local-first layer that SKIPS repeat LLM calls (cache: 100% on a hit), SHRINKS tool outputs and injected context (compress: lossless-by-default, opt-in LLMLingua-2), and DISCOUNTS prefix costs (align: native KV-cache) — and remembers everything — in one install.
|
|
37
|
+
>
|
|
38
|
+
> **v3.6.12 "Distributed-ready":** Run SLM on a server and reach it across your LAN. `SLM_REMOTE=1` (default off) lets the dashboard load from a remote browser, lets MCP gateways/hubs forward tool calls, and makes custom local LLM endpoints (llama.cpp / LM Studio / Azure) configurable right from the dashboard — plus a batch of stability and security fixes. See [`docs/distributed-deployment.md`](docs/distributed-deployment.md).
|
|
39
|
+
>
|
|
40
|
+
> **v3.6.11 "Optimize Everywhere":** Three surfaces. **Proxy** (Surface A) — full-turn cache + compress on transport; needs `ANTHROPIC_BASE_URL`, shrinks the context window. **MCP tools** (Surface B) — `slm_compress`, `slm_retrieve`, `slm_cache_set`, `slm_cache_get`, `slm_optimize_stats`; no proxy, no window shrink, works on any Claude subscription. **Skill** (Surface C) — `slm-optimize` installs in `~/.claude/skills/`; zero-config auto-compress for large tool outputs and CLAUDE.md. No proxy, full 1M window. [See Three Surfaces →](#three-surfaces-proxy--mcp-tools--skill)
|
|
37
41
|
>
|
|
38
42
|
> **v3.6.10:** cache and compression are now **independent runtime switches** (cache-only, compress-only, both, or neither — toggle live from the dashboard, no restart). Compression was rebuilt to be **lossless by default** (the old string/array/code truncation is gone); aggressive mode adds LLMLingua-2 for **prose only** — never code, numbers, structured data, or the current turn.
|
|
39
43
|
|
|
@@ -120,6 +124,57 @@ Full docs:
|
|
|
120
124
|
|
|
121
125
|
---
|
|
122
126
|
|
|
127
|
+
## Three Surfaces: Proxy · MCP Tools · Skill
|
|
128
|
+
|
|
129
|
+
v3.6.11 delivers one engine across **three ways in** — choose the surface that fits your setup:
|
|
130
|
+
|
|
131
|
+
| Surface | How you use it | Requires proxy? | Window effect | Cache scope |
|
|
132
|
+
|---------|---------------|:---------------:|:-------------:|-------------|
|
|
133
|
+
| **A — Proxy** | `slm wrap claude` or `ANTHROPIC_BASE_URL=http://127.0.0.1:8765` | **Yes** | Shrinks (proxy intercepts full context) | Full-turn cache — every Claude call |
|
|
134
|
+
| **B — MCP tools** | Add 5 tools to MCP config; call `slm_compress`, `slm_cache_set/get` | **No** | **Preserved** (full 1M) | Results you explicitly route through SLM |
|
|
135
|
+
| **C — Skill** | Copy `skills/slm-optimize/SKILL.md` → `~/.claude/skills/` | **No** | **Preserved** (full 1M) | Auto-applied by the agent per skill rules |
|
|
136
|
+
|
|
137
|
+
**How to choose:**
|
|
138
|
+
- On a **metered API** (pay-per-token) and want to cache every call → **Proxy (A)**
|
|
139
|
+
- On a **Pro/Max/Team subscription** or any plan where you can't or won't run a proxy → **MCP tools (B)** or **Skill (C)**
|
|
140
|
+
- Want zero configuration → **Skill (C)**: install once, auto-compresses CLAUDE.md and large outputs
|
|
141
|
+
- Want agent-controlled caching of repeated file reads and tool outputs → **MCP tools (B)**
|
|
142
|
+
|
|
143
|
+
**The hard constraint:** The primary Claude conversation turn cannot be cached without a proxy — the MCP/skill path caches results you explicitly route through SLM (tool outputs, file reads, sub-model calls).
|
|
144
|
+
|
|
145
|
+
### MCP Tools Setup (Surface B)
|
|
146
|
+
|
|
147
|
+
Add to your `claude_desktop_config.json` or IDE MCP config alongside your existing SLM entry:
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"mcpServers": {
|
|
152
|
+
"superlocalmemory": {
|
|
153
|
+
"command": "slm",
|
|
154
|
+
"args": ["mcp"]
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The 5 optimize tools (`slm_compress`, `slm_retrieve`, `slm_cache_set`, `slm_cache_get`, `slm_optimize_stats`) are included automatically from v3.6.11+. Verify with `slm_optimize_stats()`.
|
|
161
|
+
|
|
162
|
+
### Skill Setup (Surface C)
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
mkdir -p ~/.claude/skills/slm-optimize
|
|
166
|
+
cp $(pip show superlocalmemory | grep Location | awk '{print $2}')/superlocalmemory/skills/slm-optimize/SKILL.md \
|
|
167
|
+
~/.claude/skills/slm-optimize/SKILL.md
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Then reference in your `CLAUDE.md`:
|
|
171
|
+
```markdown
|
|
172
|
+
## Context Management
|
|
173
|
+
Use the `slm-optimize` skill to compress large outputs and cache repeated reads.
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
123
178
|
<details>
|
|
124
179
|
<summary><strong>What's New in V3.3 — The Living Brain Evolves</strong> (click to expand)</summary>
|
|
125
180
|
|
|
@@ -296,6 +351,7 @@ No manual commands. No data loss. Zero downtime.
|
|
|
296
351
|
|
|
297
352
|
| Version | Codename | Key Features |
|
|
298
353
|
|---|---|---|
|
|
354
|
+
| **v3.6.11** | Optimize Everywhere | **Three surfaces** — Proxy (A: full-turn cache), MCP tools (B: `slm_compress`/`slm_retrieve`/`slm_cache_set`/`slm_cache_get`/`slm_optimize_stats` — proxy-free, 1M window), Skill (C: `slm-optimize` zero-config). `CacheDB.get_value()` (pure KV lookup). 23 new tests. Links: [Three Surfaces →](#three-surfaces-proxy--mcp-tools--skill) · [docs/optimize-overview.md](docs/optimize-overview.md) |
|
|
299
355
|
| **v3.6.0** | Optimize | **Cache** (skip repeat calls, 100% on hit) · **Compress** (shrink prompts 60-95%) · **Align** (KV-cache stabilization) · `slm optimize\|cache\|compress\|proxy\|wrap` CLI · Live savings dashboard (USD/INR/tokens) · Hot-reload config · Safe defaults · Links: [docs/optimize-overview.md](docs/optimize-overview.md) · [V3.6 Wiki](https://github.com/qualixar/superlocalmemory/wiki/V3.6-Overview) |
|
|
300
356
|
| **v3.5.0** | Scale-Ready + Context Injection v2 | CozoDB/LanceDB migration, 6-channel recall <1s, Core Memory Block, BM25→FTS5, context injection v2, score normalization |
|
|
301
357
|
| **v3.4.5** | Scale-Ready (foundation) | Tiered storage (active/warm/cold), graph pruning, BackendOrchestrator scaffolding, CozoDB + LanceDB init + migration code (read path wired in v3.5.0) |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "superlocalmemory",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.12",
|
|
4
4
|
"description": "Information-geometric agent memory with mathematical guarantees. 4-channel retrieval, Fisher-Rao similarity, zero-LLM mode, EU AI Act compliant. Works with Claude, Cursor, Windsurf, and 17+ AI tools.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-memory",
|
package/pyproject.toml
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# slm-optimize — Context Optimizer Skill
|
|
2
|
+
|
|
3
|
+
Automatically compresses large tool outputs and caches repeated reads, reducing
|
|
4
|
+
context window usage without a proxy and without losing the full 1M window.
|
|
5
|
+
|
|
6
|
+
## Prerequisites
|
|
7
|
+
|
|
8
|
+
- SuperLocalMemory v3.6.11+
|
|
9
|
+
- `slm mcp` daemon running
|
|
10
|
+
- `slm_compress` visible in `tools/list` (verify with your IDE's MCP tool inspector)
|
|
11
|
+
|
|
12
|
+
## Install (Claude Code)
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
cp skills/slm-optimize/SKILL.md ~/.claude/skills/slm-optimize/SKILL.md
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Activate
|
|
19
|
+
|
|
20
|
+
**Option A — On demand:**
|
|
21
|
+
Invoke via the `Skill` tool: `Skill("slm-optimize")`
|
|
22
|
+
|
|
23
|
+
**Option B — Auto-activate:**
|
|
24
|
+
Add to your project or global `CLAUDE.md`:
|
|
25
|
+
```markdown
|
|
26
|
+
## Context Management
|
|
27
|
+
Use the `slm-optimize` skill to compress large outputs and cache repeated reads.
|
|
28
|
+
Invoke at session start if context > 50k tokens.
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Verify
|
|
32
|
+
|
|
33
|
+
After activation, run `slm_optimize_stats()` from Claude Code. If it returns `ok:True`,
|
|
34
|
+
all 5 optimize tools are reachable and the skill is working.
|
|
35
|
+
|
|
36
|
+
## What it does
|
|
37
|
+
|
|
38
|
+
| Feature | How |
|
|
39
|
+
|---|---|
|
|
40
|
+
| Compresses large tool outputs | `slm_compress` → compressed text + optional `ccr_id` |
|
|
41
|
+
| Caches repeated file reads | `slm_cache_set` / `slm_cache_get` keyed by file path |
|
|
42
|
+
| Caches repeated bash/search | Same KV tools, keyed by command |
|
|
43
|
+
| Recovers exact originals | `slm_retrieve(ccr_id)` when byte-identical content needed |
|
|
44
|
+
| Session stats | `slm_optimize_stats()` |
|
|
45
|
+
|
|
46
|
+
## What it does NOT do
|
|
47
|
+
|
|
48
|
+
- **Full-turn caching**: impossible without a proxy (`ANTHROPIC_BASE_URL`).
|
|
49
|
+
Use Surface A (proxy mode) for that.
|
|
50
|
+
- **Guarantee savings**: results depend on content type and daemon compress config.
|
|
51
|
+
|
|
52
|
+
## For Cursor, Antigravity, Codex
|
|
53
|
+
|
|
54
|
+
Same SKILL.md works — all IDEs that support MCP tool calls can use the 5 tools.
|
|
55
|
+
The skill itself is pure Markdown with no IDE-specific code.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: slm-optimize
|
|
3
|
+
description: >
|
|
4
|
+
Context optimizer for Claude Code + SLM. Compresses large outputs via
|
|
5
|
+
slm_compress (reversible CCR), caches repeated reads via slm_cache_set/get,
|
|
6
|
+
recovers originals via slm_retrieve. Works on any Claude plan, no proxy,
|
|
7
|
+
full context window preserved.
|
|
8
|
+
Requires SuperLocalMemory v3.6.11+ with optimize MCP tools enabled.
|
|
9
|
+
version: "3.6.11"
|
|
10
|
+
license: AGPL-3.0-or-later
|
|
11
|
+
triggers:
|
|
12
|
+
- "slm-optimize"
|
|
13
|
+
- "compress context"
|
|
14
|
+
- "optimize context"
|
|
15
|
+
- "reduce tokens"
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
# slm-optimize: Context Optimizer for Claude Code
|
|
19
|
+
|
|
20
|
+
Reduces context window usage through compression and caching.
|
|
21
|
+
No proxy required. Full 1M window preserved.
|
|
22
|
+
|
|
23
|
+
**What this skill does NOT do:**
|
|
24
|
+
- Cache the primary Claude conversation turn (impossible without a proxy).
|
|
25
|
+
- Guarantee any specific savings percentage — results depend on content type and daemon config.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## When This Skill Is Active
|
|
30
|
+
|
|
31
|
+
Apply these rules automatically throughout the session once this skill is loaded.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Decision Rules
|
|
36
|
+
|
|
37
|
+
### RULE 1 — Session start: compress CLAUDE.md if large
|
|
38
|
+
|
|
39
|
+
At the start of any session where this skill is loaded:
|
|
40
|
+
1. Read `CLAUDE.md` (or project CLAUDE.md).
|
|
41
|
+
2. If `len(content) > 3000` characters: call `slm_compress(content=<text>, mode="normalize", reversible=False)`.
|
|
42
|
+
3. Replace the in-context CLAUDE.md block with the compressed version.
|
|
43
|
+
4. **Do not modify the actual file** — compress only the in-context representation.
|
|
44
|
+
|
|
45
|
+
### RULE 2 — Large tool output: compress before processing
|
|
46
|
+
|
|
47
|
+
After any tool call that returns > 2000 characters:
|
|
48
|
+
1. Call `slm_compress(content=<output>, mode="auto", reversible=True)`.
|
|
49
|
+
2. Work from `compressed` in the response.
|
|
50
|
+
3. If `lossy=True`, store the returned `ccr_id` — call `slm_retrieve` only if you need the exact original for verification, diffing, or code parsing.
|
|
51
|
+
|
|
52
|
+
**Never compress** (see RULE 6 for the complete exclusion list).
|
|
53
|
+
|
|
54
|
+
### RULE 3 — Repeated file reads: KV cache
|
|
55
|
+
|
|
56
|
+
Before calling `Read(file_path)` for a file you have already read this session:
|
|
57
|
+
1. `slm_cache_get(key=f"file:{file_path}")`.
|
|
58
|
+
2. If `hit=True` → use `value` directly. Skip the `Read` call.
|
|
59
|
+
3. If `hit=False` → call `Read`, then `slm_cache_set(key=f"file:{file_path}", value=<content>, ttl_seconds=1800)`.
|
|
60
|
+
|
|
61
|
+
If you edit a file via Edit/Write, immediately update or invalidate the cache entry.
|
|
62
|
+
|
|
63
|
+
### RULE 4 — Repeated bash/search results: KV cache
|
|
64
|
+
|
|
65
|
+
For any Bash or WebSearch call whose result you expect to reuse:
|
|
66
|
+
1. `slm_cache_set(key=f"bash:{command[:64]}", value=<output>, ttl_seconds=600)`.
|
|
67
|
+
2. On the next identical call: `slm_cache_get` first.
|
|
68
|
+
|
|
69
|
+
Use `ttl_seconds=3600` for web search results (more expensive to re-run).
|
|
70
|
+
|
|
71
|
+
### RULE 5 — Retrieve original via slm_retrieve
|
|
72
|
+
|
|
73
|
+
If you compressed content with `lossy=True` and need the exact original:
|
|
74
|
+
1. Call `slm_retrieve(ccr_id=<ccr_id from prior compress response>)`.
|
|
75
|
+
2. Check `size_bytes` before retrieving if context is nearly full.
|
|
76
|
+
3. Do not retrieve unless you actually need byte-identical content.
|
|
77
|
+
|
|
78
|
+
### RULE 6 — What NOT to compress or cache
|
|
79
|
+
|
|
80
|
+
- **Code being sent to Edit/Write**: never compress — the editor needs exact bytes.
|
|
81
|
+
- **JSON or structured data you will parse**: compression can alter whitespace and break parsers.
|
|
82
|
+
- **Secrets, API keys, credentials, tokens**: never store via `slm_cache_set`.
|
|
83
|
+
- **CCR IDs**: never cache via `slm_cache_set` — treat as ephemeral session values.
|
|
84
|
+
- **Very short outputs (< 500 chars)**: compression overhead exceeds the gain.
|
|
85
|
+
|
|
86
|
+
### RULE 7 — Stats and awareness
|
|
87
|
+
|
|
88
|
+
If the user asks "how much context have you saved?" or "what is the optimization status?":
|
|
89
|
+
1. Call `slm_optimize_stats()`.
|
|
90
|
+
2. Report `cache_kv_hits`, `compress_runs`, and `tokens_saved_compress` clearly.
|
|
91
|
+
3. Note that proxy stats are daemon-persisted; KV stats are this session only.
|
|
92
|
+
|
|
93
|
+
### RULE 8 — Fail-open behavior
|
|
94
|
+
|
|
95
|
+
If any `slm_compress`, `slm_retrieve`, `slm_cache_set`, `slm_cache_get`, or
|
|
96
|
+
`slm_optimize_stats` call returns `ok:False`:
|
|
97
|
+
- Continue with the original (uncompressed/uncached) content.
|
|
98
|
+
- Do not retry. Do not surface the error unless the user asks about optimization.
|
|
99
|
+
- Optimization is always advisory — it must never block any primary task.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Examples
|
|
104
|
+
|
|
105
|
+
### Compress a large file read
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
# Instead of working with 8000-char file output directly:
|
|
109
|
+
result = slm_compress(content=<file_content>, mode="auto", reversible=True)
|
|
110
|
+
# Work from result["compressed"]; keep result["ccr_id"] if lossy=True
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Cache a repeated grep result
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
cached = slm_cache_get(key="bash:grep -rn MyClass src/")
|
|
117
|
+
if not cached["hit"]:
|
|
118
|
+
output = Bash("grep -rn MyClass src/")
|
|
119
|
+
slm_cache_set(key="bash:grep -rn MyClass src/", value=output, ttl_seconds=600)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Recover original when needed
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
original = slm_retrieve(ccr_id=<ccr_id>)
|
|
126
|
+
# original["content"] is byte-identical to what was compressed
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Stats and Troubleshooting
|
|
132
|
+
|
|
133
|
+
Run `slm_optimize_stats()` to see current session counters.
|
|
134
|
+
|
|
135
|
+
If tools return `ok:False`, the daemon may be down or the optimize module may not be
|
|
136
|
+
configured. Continue with normal tool calls — this skill degrades gracefully.
|
|
137
|
+
|
|
138
|
+
Verify tools are available: check that `slm_compress` appears in your MCP `tools/list`.
|
|
139
|
+
Requires SuperLocalMemory v3.6.11+ with `slm mcp` running.
|
|
@@ -114,6 +114,7 @@ def dispatch(args: Namespace) -> None:
|
|
|
114
114
|
"list": cmd_list,
|
|
115
115
|
"remember": cmd_remember,
|
|
116
116
|
"recall": cmd_recall,
|
|
117
|
+
"search": cmd_recall, # v3.6.12 (parity-3): MCP exposes a `search` verb; give the CLI parity (recall is multi-channel incl. BM25/keyword).
|
|
117
118
|
"forget": cmd_forget,
|
|
118
119
|
"delete": cmd_delete,
|
|
119
120
|
"update": cmd_update,
|