superlocalmemory 3.6.13 → 3.6.14

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.
Files changed (124) hide show
  1. package/.claude-plugin/marketplace.json +17 -0
  2. package/README.md +187 -741
  3. package/package.json +12 -5
  4. package/plugin/.claude-plugin/plugin.json +20 -0
  5. package/plugin/.mcp.json +12 -0
  6. package/plugin/CLAUDE.md +43 -0
  7. package/plugin/_GENERATED.md +6 -0
  8. package/plugin/agents/slm-memory-advisor.md +43 -0
  9. package/plugin/agents/slm-optimize-advisor.md +38 -0
  10. package/plugin/hooks/hooks.json +14 -0
  11. package/plugin/requirements.txt +1 -0
  12. package/plugin/scripts/ensure-venv.bat +122 -0
  13. package/plugin/scripts/ensure-venv.sh +105 -0
  14. package/plugin/scripts/slm-launch +15 -0
  15. package/plugin/scripts/slm-launch.bat +17 -0
  16. package/plugin/settings.json +16 -0
  17. package/plugin/skills/slm-cache/SKILL.md +140 -0
  18. package/plugin/skills/slm-compress/SKILL.md +143 -0
  19. package/plugin/skills/slm-graph/SKILL.md +300 -0
  20. package/plugin/skills/slm-recall/SKILL.md +196 -0
  21. package/plugin/skills/slm-remember/SKILL.md +182 -0
  22. package/plugin/skills/slm-session/SKILL.md +207 -0
  23. package/plugin/skills/slm-status/SKILL.md +149 -0
  24. package/plugin-src/.mcp.json +12 -0
  25. package/plugin-src/agents/slm-memory-advisor.md +43 -0
  26. package/plugin-src/agents/slm-optimize-advisor.md +38 -0
  27. package/plugin-src/commands/slm-optimize.md +22 -0
  28. package/plugin-src/commands/slm-recall.md +16 -0
  29. package/plugin-src/commands/slm-remember.md +16 -0
  30. package/plugin-src/commands/slm-status.md +15 -0
  31. package/plugin-src/hooks/.gitkeep +0 -0
  32. package/plugin-src/hooks/hooks.json +14 -0
  33. package/plugin-src/manifest.json +25 -0
  34. package/plugin-src/requirements.txt +1 -0
  35. package/plugin-src/rules/AGENTS.md +90 -0
  36. package/plugin-src/rules/CLAUDE.md.fragment +43 -0
  37. package/plugin-src/scripts/ensure-venv.bat +122 -0
  38. package/plugin-src/scripts/ensure-venv.sh +105 -0
  39. package/plugin-src/scripts/slm-launch +15 -0
  40. package/plugin-src/scripts/slm-launch.bat +17 -0
  41. package/plugin-src/settings.json +16 -0
  42. package/plugin-src/skills/slm-cache/SKILL.md +140 -0
  43. package/plugin-src/skills/slm-compress/SKILL.md +143 -0
  44. package/plugin-src/skills/slm-graph/SKILL.md +300 -0
  45. package/plugin-src/skills/slm-recall/SKILL.md +196 -0
  46. package/plugin-src/skills/slm-remember/SKILL.md +182 -0
  47. package/plugin-src/skills/slm-session/SKILL.md +207 -0
  48. package/plugin-src/skills/slm-status/SKILL.md +149 -0
  49. package/pyproject.toml +6 -2
  50. package/scripts/__tests__/build-plugin.test.mjs +613 -0
  51. package/scripts/_savings_math.py +270 -0
  52. package/scripts/build-plugin.js +742 -0
  53. package/scripts/dogfood_savings.py +490 -0
  54. package/scripts/install-skills.ps1 +4 -334
  55. package/scripts/install-skills.sh +4 -435
  56. package/scripts/postinstall-interactive.js +0 -27
  57. package/scripts/postinstall.js +21 -2
  58. package/src/superlocalmemory/__init__.py +1 -1
  59. package/src/superlocalmemory/cli/_lazy_init.py +115 -0
  60. package/src/superlocalmemory/cli/commands.py +348 -39
  61. package/src/superlocalmemory/cli/main.py +47 -4
  62. package/src/superlocalmemory/cli/setup_wizard.py +20 -6
  63. package/src/superlocalmemory/core/config.py +79 -9
  64. package/src/superlocalmemory/core/embeddings.py +10 -5
  65. package/src/superlocalmemory/core/engine.py +2 -2
  66. package/src/superlocalmemory/hooks/claude_code_hooks.py +27 -3
  67. package/src/superlocalmemory/hooks/portable_kit.py +506 -0
  68. package/src/superlocalmemory/infra/cloud_backup.py +99 -23
  69. package/src/superlocalmemory/mcp/cli_fallback.py +602 -0
  70. package/src/superlocalmemory/mcp/server.py +75 -4
  71. package/src/superlocalmemory/mcp/tools_code_graph.py +3 -3
  72. package/src/superlocalmemory/mcp/tools_core.py +12 -4
  73. package/src/superlocalmemory/optimize/cache/boundary_store.py +25 -6
  74. package/src/superlocalmemory/optimize/cache/centroid_store.py +27 -4
  75. package/src/superlocalmemory/optimize/cache/manager.py +92 -6
  76. package/src/superlocalmemory/optimize/cache/semantic.py +20 -1
  77. package/src/superlocalmemory/optimize/compress/ccr.py +12 -0
  78. package/src/superlocalmemory/optimize/compress/router.py +46 -13
  79. package/src/superlocalmemory/optimize/config/schema.py +6 -0
  80. package/src/superlocalmemory/optimize/proxy/_helpers.py +111 -8
  81. package/src/superlocalmemory/optimize/proxy/anthropic_surface.py +14 -4
  82. package/src/superlocalmemory/optimize/proxy/gemini_surface.py +23 -6
  83. package/src/superlocalmemory/optimize/proxy/openai_surface.py +10 -4
  84. package/src/superlocalmemory/optimize/proxy/server.py +11 -0
  85. package/src/superlocalmemory/optimize/proxy/vertex_surface.py +246 -0
  86. package/src/superlocalmemory/optimize/storage/db.py +30 -0
  87. package/src/superlocalmemory/server/recall_serializer.py +3 -1
  88. package/src/superlocalmemory/server/unified_daemon.py +24 -6
  89. package/src/superlocalmemory/ui/css/legacy-dashboard.css +18 -0
  90. package/src/superlocalmemory/ui/css/neural-glass.css +5 -0
  91. package/src/superlocalmemory/ui/index.html +2 -2
  92. package/src/superlocalmemory/ui/js/core.js +98 -0
  93. package/src/superlocalmemory/ui/js/dashboard.js +8 -1
  94. package/src/superlocalmemory/ui/js/ide-status.js +16 -3
  95. package/src/superlocalmemory/ui/js/math-health.js +15 -3
  96. package/src/superlocalmemory/ui/js/optimize.js +18 -2
  97. package/src/superlocalmemory/ui/js/trust-dashboard.js +10 -1
  98. package/src/superlocalmemory.egg-info/PKG-INFO +189 -742
  99. package/src/superlocalmemory.egg-info/SOURCES.txt +6 -9
  100. package/src/superlocalmemory.egg-info/requires.txt +1 -0
  101. package/ide/skills/slm-build-graph/SKILL.md +0 -423
  102. package/ide/skills/slm-list-recent/SKILL.md +0 -348
  103. package/ide/skills/slm-recall/SKILL.md +0 -326
  104. package/ide/skills/slm-remember/SKILL.md +0 -194
  105. package/ide/skills/slm-show-patterns/SKILL.md +0 -224
  106. package/ide/skills/slm-status/SKILL.md +0 -363
  107. package/ide/skills/slm-switch-profile/SKILL.md +0 -442
  108. package/skills/slm-build-graph/SKILL.md +0 -423
  109. package/skills/slm-list-recent/SKILL.md +0 -348
  110. package/skills/slm-optimize/README.md +0 -55
  111. package/skills/slm-optimize/SKILL.md +0 -139
  112. package/skills/slm-recall/SKILL.md +0 -343
  113. package/skills/slm-remember/SKILL.md +0 -194
  114. package/skills/slm-show-patterns/SKILL.md +0 -224
  115. package/skills/slm-status/SKILL.md +0 -363
  116. package/skills/slm-switch-profile/SKILL.md +0 -442
  117. package/src/superlocalmemory/cli/doctor_cmd.py +0 -152
  118. package/src/superlocalmemory/skills/slm-build-graph/SKILL.md +0 -423
  119. package/src/superlocalmemory/skills/slm-list-recent/SKILL.md +0 -348
  120. package/src/superlocalmemory/skills/slm-recall/SKILL.md +0 -343
  121. package/src/superlocalmemory/skills/slm-remember/SKILL.md +0 -194
  122. package/src/superlocalmemory/skills/slm-show-patterns/SKILL.md +0 -224
  123. package/src/superlocalmemory/skills/slm-status/SKILL.md +0 -363
  124. package/src/superlocalmemory/skills/slm-switch-profile/SKILL.md +0 -442
@@ -1,348 +0,0 @@
1
- ---
2
- name: slm-list-recent
3
- description: List most recent memories in chronological order. Use when the user wants to see what was recently saved, review recent conversations, check what they worked on today, or browse memory history. Shows memories sorted by creation time (newest first).
4
- version: "3.4.23"
5
- license: AGPL-3.0-or-later
6
- compatibility: "Requires SuperLocalMemory V2 installed at ~/.claude-memory/"
7
- attribution:
8
- creator: Varun Pratap Bhardwaj
9
- role: Solution Architect & Original Creator
10
- project: SuperLocalMemory V2
11
- ---
12
-
13
- # SuperLocalMemory: List Recent
14
-
15
- List most recent memories in chronological order (newest first).
16
-
17
- ## Usage
18
-
19
- ```bash
20
- slm list [--limit N] [--project name] [--tags tag1,tag2] [--today|--week|--month]
21
- ```
22
-
23
- ## Examples
24
-
25
- ### Example 1: Last 10 Memories (Default)
26
- ```bash
27
- $ slm list
28
- ```
29
-
30
- **Output:**
31
- ```
32
- 📝 Recent Memories (10 most recent)
33
-
34
- [ID: 1247] 5 minutes ago
35
- Fixed JWT token refresh bug - tokens were expiring too fast
36
- Tags: bug-fix, jwt, auth
37
- Project: myapp
38
- Importance: 8
39
-
40
- [ID: 1246] 2 hours ago
41
- React hooks best practices: useCallback for memoization
42
- Tags: react, performance, hooks
43
- Project: frontend-app
44
- Importance: 6
45
-
46
- [ID: 1245] 4 hours ago
47
- Database migration strategy: use Alembic for versioning
48
- Tags: database, postgresql, migration
49
- Project: myapp
50
- Importance: 7
51
-
52
- [ID: 1244] Yesterday 18:42
53
- Decided to use FastAPI over Flask for new microservice
54
- Tags: python, backend, api, decision
55
- Project: myapp
56
- Importance: 9
57
-
58
- [ID: 1243] Yesterday 15:30
59
- Code review feedback: add more error handling to API endpoints
60
- Tags: code-review, api, error-handling
61
- Project: myapp
62
- Importance: 6
63
-
64
- ...
65
- ```
66
-
67
- ### Example 2: Last 5 Memories
68
- ```bash
69
- $ slm list --limit 5
70
- ```
71
-
72
- ### Example 3: Today's Memories
73
- ```bash
74
- $ slm list --today
75
- ```
76
-
77
- **Shows only memories created today**
78
-
79
- ### Example 4: This Week
80
- ```bash
81
- $ slm list --week
82
- ```
83
-
84
- **Shows memories from last 7 days**
85
-
86
- ### Example 5: Filter by Project
87
- ```bash
88
- $ slm list --project myapp --limit 20
89
- ```
90
-
91
- **Shows 20 most recent memories from "myapp" project**
92
-
93
- ### Example 6: Filter by Tags
94
- ```bash
95
- $ slm list --tags security,auth --limit 15
96
- ```
97
-
98
- **Shows 15 most recent memories tagged with security AND auth**
99
-
100
- ## Arguments
101
-
102
- | Argument | Type | Required | Default | Description |
103
- |----------|------|----------|---------|-------------|
104
- | `--limit` | integer | No | 10 | Number of memories to show |
105
- | `--project` | string | No | All | Filter by project |
106
- | `--tags` | string | No | All | Filter by tags (comma-separated) |
107
- | `--today` | flag | No | - | Show only today's memories |
108
- | `--week` | flag | No | - | Show last 7 days |
109
- | `--month` | flag | No | - | Show last 30 days |
110
-
111
- ## Sorting & Display
112
-
113
- ### Chronological Order
114
- Memories are always shown **newest first** (reverse chronological).
115
-
116
- **Rationale:** Recent context is usually most relevant.
117
-
118
- ### Timestamps
119
- - **"5 minutes ago"** - Within last hour
120
- - **"2 hours ago"** - Within last 24 hours
121
- - **"Yesterday 18:42"** - Yesterday with time
122
- - **"Feb 05 14:23"** - Older than yesterday
123
-
124
- ### Content Preview
125
- - First 200 characters shown
126
- - Ellipsis (...) if truncated
127
- - Use `slm recall --id <ID>` for full content
128
-
129
- ## Use Cases
130
-
131
- ### 1. Daily Standup Prep
132
- ```bash
133
- # What did I work on yesterday?
134
- slm list --yesterday
135
- ```
136
-
137
- ### 2. Resume Context
138
- ```bash
139
- # What was I working on before lunch?
140
- slm list --today --limit 5
141
- ```
142
-
143
- ### 3. Weekly Review
144
- ```bash
145
- # What decisions did I make this week?
146
- slm list --week --tags decision
147
- ```
148
-
149
- ### 4. Project Check-In
150
- ```bash
151
- # Recent memories for current project
152
- slm list --project myapp --limit 20
153
- ```
154
-
155
- ### 5. Security Audit
156
- ```bash
157
- # All security-related memories
158
- slm list --tags security --limit 100
159
- ```
160
-
161
- ## Advanced Usage
162
-
163
- ### Pagination
164
- ```bash
165
- # First page
166
- slm list --limit 10
167
-
168
- # Next page (note IDs, then use recall)
169
- slm recall --before-id 1237 --limit 10
170
- ```
171
-
172
- ### Export to File
173
- ```bash
174
- # Save recent work to file
175
- slm list --week > this-week.txt
176
-
177
- # JSON export (for processing)
178
- slm list --format json --limit 100 > memories.json
179
- ```
180
-
181
- ### Pipe to Other Commands
182
- ```bash
183
- # Count memories per project
184
- slm list --limit 1000 | grep "Project:" | sort | uniq -c
185
-
186
- # Find common tags
187
- slm list --limit 500 | grep "Tags:" | tr ',' '\n' | sort | uniq -c | sort -rn
188
- ```
189
-
190
- ### Combined with Other Skills
191
- ```bash
192
- # 1. List recent memories
193
- slm list --today
194
-
195
- # 2. Notice interesting pattern
196
-
197
- # 3. Search for related memories
198
- slm recall "FastAPI performance"
199
-
200
- # 4. Add new related memory
201
- slm remember "FastAPI async endpoints improve throughput by 3x" --tags performance,fastapi
202
- ```
203
-
204
- ## Output Formats
205
-
206
- ### Standard Format (Default)
207
- ```
208
- [ID: 42] Timestamp
209
- Content preview...
210
- Tags: tag1, tag2
211
- Project: name
212
- Importance: 7
213
- ```
214
-
215
- ### Compact Format
216
- ```bash
217
- slm list --format compact
218
- ```
219
- ```
220
- 42 | 5m ago | Content preview... | myapp
221
- 43 | 2h ago | Another memory... | default
222
- ```
223
-
224
- ### JSON Format
225
- ```bash
226
- slm list --format json
227
- ```
228
- ```json
229
- {
230
- "memories": [
231
- {
232
- "id": 42,
233
- "content": "Full content here",
234
- "tags": ["tag1", "tag2"],
235
- "project": "myapp",
236
- "importance": 7,
237
- "created_at": "2026-02-07T14:23:00Z"
238
- }
239
- ],
240
- "count": 10,
241
- "total": 1247
242
- }
243
- ```
244
-
245
- ### CSV Format
246
- ```bash
247
- slm list --format csv
248
- ```
249
- ```csv
250
- id,content,tags,project,importance,created_at
251
- 42,"Content here","tag1,tag2",myapp,7,2026-02-07T14:23:00Z
252
- 43,"Another memory","tag3",default,5,2026-02-07T12:15:00Z
253
- ```
254
-
255
- ## Performance
256
-
257
- | Memory Count | List Time | Notes |
258
- |--------------|-----------|-------|
259
- | 10 | ~50ms | Instant |
260
- | 100 | ~200ms | Fast |
261
- | 1,000 | ~500ms | Acceptable |
262
- | 10,000+ | ~1s | Use filters |
263
-
264
- **Optimization tips:**
265
- - Use `--limit` to reduce results
266
- - Use `--project` or `--tags` filters
267
- - Use time filters (`--today`, `--week`)
268
-
269
- ## Troubleshooting
270
-
271
- ### "No memories found"
272
- **Cause:** Empty database or filters too restrictive
273
-
274
- **Solution:**
275
- ```bash
276
- # Check total memory count
277
- slm status | grep "Total Memories"
278
-
279
- # Remove filters
280
- slm list # No filters
281
-
282
- # Try different project
283
- slm list --project default
284
- ```
285
-
286
- ### "List takes too long"
287
- **Cause:** Large database, no filters
288
-
289
- **Solution:**
290
- ```bash
291
- # Use smaller limit
292
- slm list --limit 5
293
-
294
- # Add filters
295
- slm list --today --project myapp
296
-
297
- # Rebuild indexes
298
- slm build-graph
299
- ```
300
-
301
- ### "Timestamps wrong"
302
- **Cause:** System timezone changed
303
-
304
- **Solution:**
305
- ```bash
306
- # Check system timezone
307
- date
308
-
309
- # Timestamps are stored in UTC, displayed in local time
310
- # No action needed usually
311
- ```
312
-
313
- ## Comparison with Search
314
-
315
- | Feature | `slm list` | `slm recall` |
316
- |---------|------------|--------------|
317
- | **Sorting** | Chronological | Relevance |
318
- | **Use case** | Browse recent | Find specific |
319
- | **Speed** | Fast | Slower |
320
- | **Filters** | Basic | Advanced |
321
- | **Scoring** | No | Yes (relevance) |
322
-
323
- **Rule of thumb:**
324
- - Use `list` when you want to see **what you worked on recently**
325
- - Use `recall` when you want to **find specific information**
326
-
327
- ## Notes
328
-
329
- - **Read-only:** Never modifies data
330
- - **Real-time:** Shows latest state
331
- - **Cross-tool:** Same list from Cursor, ChatGPT, Claude, etc.
332
- - **Privacy:** All local, no external calls
333
-
334
- ## Related Commands
335
-
336
- - `slm remember` - Save a new memory
337
- - `slm recall` - Search memories by relevance
338
- - `slm status` - Check memory count and stats
339
- - `slm switch-profile` - View different profile's memories
340
-
341
- ---
342
-
343
- **Created by:** [Varun Pratap Bhardwaj](https://github.com/varun369) (Solution Architect)
344
- **Project:** SuperLocalMemory V2
345
- **License:** MIT (see [LICENSE](../../LICENSE))
346
- **Repository:** https://github.com/varun369/SuperLocalMemoryV2
347
-
348
- *Open source doesn't mean removing credit. Attribution must be preserved per MIT License terms.*
@@ -1,55 +0,0 @@
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.
@@ -1,139 +0,0 @@
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.