superlocalmemory 3.7.0 → 3.7.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/CHANGELOG.md +19 -0
- package/README.md +2 -2
- package/package.json +2 -2
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/requirements.txt +1 -1
- package/plugin/scripts/slm-launch +11 -3
- package/plugin/scripts/slm-launch.bat +8 -2
- package/plugin-src/.mcp.json +12 -0
- package/plugin-src/agents/slm-memory-advisor.md +44 -0
- package/plugin-src/agents/slm-optimize-advisor.md +38 -0
- package/plugin-src/hooks/.gitkeep +0 -0
- package/plugin-src/hooks/hooks.json +23 -0
- package/plugin-src/manifest.json +25 -0
- package/plugin-src/requirements.txt +1 -0
- package/plugin-src/rules/CLAUDE.md.fragment +44 -0
- package/plugin-src/scripts/ensure-venv.bat +122 -0
- package/plugin-src/scripts/ensure-venv.sh +105 -0
- package/plugin-src/scripts/slm-launch +23 -0
- package/plugin-src/scripts/slm-launch.bat +23 -0
- package/plugin-src/settings.json +16 -0
- package/plugin-src/skills/slm-cache/SKILL.md +140 -0
- package/plugin-src/skills/slm-compress/SKILL.md +143 -0
- package/plugin-src/skills/slm-graph/SKILL.md +300 -0
- package/plugin-src/skills/slm-recall/SKILL.md +204 -0
- package/plugin-src/skills/slm-remember/SKILL.md +194 -0
- package/plugin-src/skills/slm-session/SKILL.md +207 -0
- package/plugin-src/skills/slm-status/SKILL.md +149 -0
- package/pyproject.toml +1 -1
- package/src/superlocalmemory/__init__.py +1 -1
- package/src/superlocalmemory/cli/_lazy_init.py +4 -2
- package/src/superlocalmemory/core/embedding_worker.py +7 -1
- package/src/superlocalmemory/core/embeddings.py +8 -0
- package/src/superlocalmemory/core/engine.py +1 -3
- package/src/superlocalmemory/core/engine_wiring.py +30 -28
- package/src/superlocalmemory/core/ram_lock.py +42 -4
- package/src/superlocalmemory/evolution/budget.py +43 -8
- package/src/superlocalmemory/hooks/claude_code_hooks.py +1 -1
- package/src/superlocalmemory/hooks/context_payload.py +1 -1
- package/src/superlocalmemory/mcp/http_transport.py +1 -1
- package/src/superlocalmemory/mcp/tools_core.py +48 -31
- package/src/superlocalmemory/mesh/broker.py +111 -61
- package/src/superlocalmemory/optimize/proxy/server.py +1 -1
- package/src/superlocalmemory/retrieval/spreading_activation.py +53 -3
- package/src/superlocalmemory/server/routes/brain.py +1 -1
- package/src/superlocalmemory/server/unified_daemon.py +24 -7
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: slm-cache
|
|
3
|
+
description: KV cache for repeated reads — call slm_cache_get(key) first; on a miss do the expensive operation then slm_cache_set(key, value, ttl_seconds) to store it; on a hit use the returned value directly; always fail-open (hit:false on any error, never raises); saves tokens when the same file, query result, or tool output is read more than once in a session.
|
|
4
|
+
when_to_use: "cache file, avoid re-reading, repeated read, cache result, cache tool output, save re-read, reuse across session, cache check, cache hit, cache miss"
|
|
5
|
+
allowed-tools: slm_cache_set, slm_cache_get, Bash
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# slm-cache — KV Cache for Repeated Reads (Surface B)
|
|
9
|
+
|
|
10
|
+
## Purpose
|
|
11
|
+
|
|
12
|
+
When the same file, query result, or expensive tool output is needed more than once in a session, fetching it again wastes tokens and time. `slm_cache_set` stores a result under a stable key; `slm_cache_get` retrieves it on subsequent calls. The cache is agent-scoped (automatically namespaced by tenant/agent ID), TTL-bounded, and fail-open.
|
|
13
|
+
|
|
14
|
+
This is an agent-routed cache — it caches results the agent explicitly routes through SLM. It cannot cache Claude conversation turns.
|
|
15
|
+
|
|
16
|
+
## Tool: slm_cache_set
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
slm_cache_set(
|
|
20
|
+
key: str, # required — cache key (max 512 chars)
|
|
21
|
+
value: str, # required — value to store (max 1 MB)
|
|
22
|
+
ttl_seconds: int = 86400, # time-to-live in seconds (default 24 h)
|
|
23
|
+
) -> dict
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Return dict
|
|
27
|
+
|
|
28
|
+
| Key | Type | Meaning |
|
|
29
|
+
|-----|------|---------|
|
|
30
|
+
| `ok` | bool | `True` on success; `False` on validation error or internal error |
|
|
31
|
+
| `stored` | bool | `True` when the value was written to the cache |
|
|
32
|
+
| `note` | str \| None | Error detail or `None` on success |
|
|
33
|
+
|
|
34
|
+
Keys are SHA-256-hashed internally per agent so they do not collide across agents. The raw key string you supply is the only handle you need.
|
|
35
|
+
|
|
36
|
+
## Tool: slm_cache_get
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
slm_cache_get(
|
|
40
|
+
key: str, # required — same key used in slm_cache_set
|
|
41
|
+
) -> dict
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Return dict
|
|
45
|
+
|
|
46
|
+
| Key | Type | Meaning |
|
|
47
|
+
|-----|------|---------|
|
|
48
|
+
| `ok` | bool | `True` on clean execution (including miss); `False` on internal error |
|
|
49
|
+
| `hit` | bool | `True` when the key exists and has not expired |
|
|
50
|
+
| `value` | str \| None | The stored value on a hit; `None` on miss |
|
|
51
|
+
| `note` | str \| None | Error detail or `None` |
|
|
52
|
+
|
|
53
|
+
A miss returns `{"ok": true, "hit": false, "value": null, "note": null}`. `ok: false` means something went wrong internally but the miss behaviour is the same — treat both as a cache miss and proceed with the real fetch.
|
|
54
|
+
|
|
55
|
+
## Standard Pattern: Cache-Aside
|
|
56
|
+
|
|
57
|
+
Always check the cache first, then fill on miss:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
# 1. Check cache
|
|
61
|
+
cached = await slm_cache_get(key="file:/absolute/path/to/config.json")
|
|
62
|
+
|
|
63
|
+
if cached["hit"]:
|
|
64
|
+
content = cached["value"]
|
|
65
|
+
else:
|
|
66
|
+
# 2. Expensive operation (file read, search, API call)
|
|
67
|
+
content = read_file("/absolute/path/to/config.json")
|
|
68
|
+
|
|
69
|
+
# 3. Store for the rest of the session
|
|
70
|
+
await slm_cache_set(
|
|
71
|
+
key="file:/absolute/path/to/config.json",
|
|
72
|
+
value=content,
|
|
73
|
+
ttl_seconds=3600, # 1 h — adjust to data volatility
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# 4. Use content
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Key Naming Convention
|
|
80
|
+
|
|
81
|
+
Use a stable, human-readable prefix so keys are recognisable in stats and won't collide accidentally:
|
|
82
|
+
|
|
83
|
+
| Content type | Suggested prefix | Example |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| File read | `file:` | `file:/repo/src/config.py` |
|
|
86
|
+
| Search result | `search:` | `search:recall:session_init_context` |
|
|
87
|
+
| Tool output | `tool:` | `tool:build_code_graph:/repo` |
|
|
88
|
+
| External fetch | `url:` | `url:https://api.example.com/v1/data` |
|
|
89
|
+
|
|
90
|
+
Key length cap: 512 characters. Keys longer than that are rejected (`ok: false`).
|
|
91
|
+
|
|
92
|
+
## When Caching Pays Off
|
|
93
|
+
|
|
94
|
+
**Cache when:**
|
|
95
|
+
- You will read the same file more than once in a session.
|
|
96
|
+
- A search or recall result is reused across multiple reasoning steps.
|
|
97
|
+
- An expensive MCP tool call (graph build, semantic search) produces output that is stable for the session duration.
|
|
98
|
+
|
|
99
|
+
**Do NOT cache:**
|
|
100
|
+
- Volatile data (live API responses that change minute-to-minute, current timestamps, streaming output).
|
|
101
|
+
- Secrets, credentials, tokens, or `ccr_id` values (CCR already handles its own storage).
|
|
102
|
+
- Data that must be fresh for correctness — a stale cache is worse than a cache miss.
|
|
103
|
+
- Intermediate scratchpad text you will discard.
|
|
104
|
+
|
|
105
|
+
## Fail-Open Guarantee
|
|
106
|
+
|
|
107
|
+
Neither tool raises an exception. On any internal error:
|
|
108
|
+
|
|
109
|
+
- `slm_cache_get` returns `{"ok": false, "hit": false, "value": null, ...}` — treat as a miss and proceed with the real fetch.
|
|
110
|
+
- `slm_cache_set` returns `{"ok": false, "stored": false, ...}` — log the note if useful, but continue; the value is still available in memory this step.
|
|
111
|
+
|
|
112
|
+
Never block a task on a cache failure.
|
|
113
|
+
|
|
114
|
+
## TTL Guidance
|
|
115
|
+
|
|
116
|
+
| Data type | Suggested TTL |
|
|
117
|
+
|---|---|
|
|
118
|
+
| Static config / generated file | 86400 s (24 h — the default) |
|
|
119
|
+
| Session-specific tool output | 3600 s (1 h) |
|
|
120
|
+
| Rapidly changing API data | Do not cache, or 60–300 s |
|
|
121
|
+
|
|
122
|
+
Set `ttl_seconds` to match how long the data remains valid. After expiry `slm_cache_get` returns a miss automatically.
|
|
123
|
+
|
|
124
|
+
## Secondary CLI (fallback when MCP is unavailable)
|
|
125
|
+
|
|
126
|
+
The `slm cache` subcommand exists but has known pre-existing parse-test failures. Prefer the MCP tools above. If you must use CLI:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
slm cache status [--json] [--tenant default]
|
|
130
|
+
slm cache clear [--json] [--tenant default]
|
|
131
|
+
slm cache invalidate --tag <tag> [--json] [--tenant default]
|
|
132
|
+
slm cache ttl --set <seconds> [--semantic <seconds>] [--json] [--tenant default]
|
|
133
|
+
slm cache semantic on|off [--json] [--tenant default]
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
These subcommands control daemon-level cache settings. They do not read or write individual cache entries — use the MCP tools for that.
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
SuperLocalMemory v3.6.18 · Qualixar · AGPL-3.0-or-later
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: slm-compress
|
|
3
|
+
description: Compress large text, tool output, or transcripts to reduce context-window usage while keeping the full 1M window intact — call slm_compress(content, mode, reversible, ttl_seconds) to shrink content; if the result is lossy a ccr_id is returned so you can call slm_retrieve(ccr_id) later to recover the exact original; always fail-open (ok:false → continue with the original).
|
|
4
|
+
when_to_use: "compress context, shrink output, save tokens, context window full, long transcript, compress tool result, reduce tokens, large output, compress text"
|
|
5
|
+
allowed-tools: slm_compress, slm_retrieve, Bash
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# slm-compress — Reversible Context Compression (Surface B)
|
|
9
|
+
|
|
10
|
+
## Purpose
|
|
11
|
+
|
|
12
|
+
When a tool output, transcript, or accumulated context grows large enough to crowd out working space, `slm_compress` reduces it in-place. The compressed form is used for the remainder of the session; the exact original is recoverable on demand via `slm_retrieve`. This works without a proxy and without touching `ANTHROPIC_BASE_URL`, so the full 1M context window is never sacrificed.
|
|
13
|
+
|
|
14
|
+
## Primary MCP Tool: slm_compress
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
slm_compress(
|
|
18
|
+
content: str, # required — text to compress (max 1 MB)
|
|
19
|
+
mode: str = "auto", # "normalize" | "auto" | "aggressive"
|
|
20
|
+
reversible: bool = True, # store original in CCR for later retrieval
|
|
21
|
+
ttl_seconds: int = 86400, # CCR lifetime in seconds (default 24 h)
|
|
22
|
+
) -> dict
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Return dict (all keys always present)
|
|
26
|
+
|
|
27
|
+
| Key | Type | Meaning |
|
|
28
|
+
|-----|------|---------|
|
|
29
|
+
| `ok` | bool | `True` on success; `False` on internal error or empty input |
|
|
30
|
+
| `compressed` | str | Compressed text (or original on failure) |
|
|
31
|
+
| `strategy` | str | Which strategy was applied (e.g. `"normalize"`, `"none"`) |
|
|
32
|
+
| `tokens_before` | int | Word-count estimate of the input |
|
|
33
|
+
| `tokens_after` | int | Word-count estimate of the output |
|
|
34
|
+
| `ratio` | float | `tokens_after / tokens_before` (lower = more compact) |
|
|
35
|
+
| `lossy` | bool | Whether information was removed |
|
|
36
|
+
| `ccr_id` | str \| None | UUID4 session token; present only when `lossy=True` and `reversible=True` |
|
|
37
|
+
| `note` | str \| None | Human-readable note (e.g. warnings, recovery hint) |
|
|
38
|
+
|
|
39
|
+
### Mode semantics (verified from source)
|
|
40
|
+
|
|
41
|
+
- **`"normalize"`** — lossless whitespace collapse; no daemon dependency; `lossy: false`, `ccr_id: null`.
|
|
42
|
+
- **`"auto"`** — delegates to `CompressRouter`; may be lossy depending on daemon config; default.
|
|
43
|
+
- **`"aggressive"`** — requests aggressive compression from the daemon; daemon must have `compress_mode=aggressive` set in config; note field will warn if daemon config does not match.
|
|
44
|
+
|
|
45
|
+
## Recovery Tool: slm_retrieve
|
|
46
|
+
|
|
47
|
+
When `slm_compress` returns `lossy: true`, the original is stored under the `ccr_id`. Use `slm_retrieve` to get it back:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
slm_retrieve(ccr_id: str) -> dict
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Key | Type | Meaning |
|
|
54
|
+
|-----|------|---------|
|
|
55
|
+
| `ok` | bool | `True` when content was found |
|
|
56
|
+
| `content` | str \| None | Original text, decoded from UTF-8 (or Latin-1 fallback) |
|
|
57
|
+
| `size_bytes` | int | Byte length of the stored original |
|
|
58
|
+
| `error` | str \| None | Error message on failure; `None` on success |
|
|
59
|
+
|
|
60
|
+
`ccr_id` must be a valid UUID4. Non-UUID4 strings return `ok: false` immediately.
|
|
61
|
+
|
|
62
|
+
### CCR security rule
|
|
63
|
+
|
|
64
|
+
`ccr_id` values are **unguessable session tokens**. Treat them like short-lived credentials:
|
|
65
|
+
- Never log them.
|
|
66
|
+
- Never share them across agents.
|
|
67
|
+
- Never pass them as tool arguments to any tool other than `slm_retrieve`.
|
|
68
|
+
- Never compress a `ccr_id` string itself.
|
|
69
|
+
- They expire after `ttl_seconds` (default 24 h); `slm_retrieve` returns `ok: false` after expiry.
|
|
70
|
+
|
|
71
|
+
## Decision: When to Compress
|
|
72
|
+
|
|
73
|
+
**Compress when:**
|
|
74
|
+
- A single tool output or transcript exceeds approximately 2 000 characters.
|
|
75
|
+
- You are accumulating repeated context (e.g. full file reads across multiple steps).
|
|
76
|
+
- Context is nearing the point where recall quality or response quality degrades.
|
|
77
|
+
|
|
78
|
+
**Do NOT compress:**
|
|
79
|
+
- Code you are about to read, edit, or diff — you need every character.
|
|
80
|
+
- JSON you will parse programmatically — compression may alter structure.
|
|
81
|
+
- Secrets, credentials, or `ccr_id` strings.
|
|
82
|
+
- Anything under ~500 characters — overhead exceeds benefit.
|
|
83
|
+
- The compressed form of content already compressed this session.
|
|
84
|
+
|
|
85
|
+
## Fail-Open Guarantee
|
|
86
|
+
|
|
87
|
+
`slm_compress` never raises an exception. On any internal error it returns:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{ "ok": false, "compressed": "<original input>", "ratio": 1.0, ... }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**When `ok` is `false`, continue with the original content.** Never block a task waiting for compression to succeed.
|
|
94
|
+
|
|
95
|
+
## Worked Example
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
# Step 1: compress a large tool output
|
|
99
|
+
result = await slm_compress(
|
|
100
|
+
content=long_log_text,
|
|
101
|
+
mode="auto",
|
|
102
|
+
reversible=True,
|
|
103
|
+
ttl_seconds=3600,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
if result["ok"]:
|
|
107
|
+
working_text = result["compressed"]
|
|
108
|
+
ccr_id = result["ccr_id"] # None if lossless
|
|
109
|
+
else:
|
|
110
|
+
working_text = long_log_text # fail-open
|
|
111
|
+
ccr_id = None
|
|
112
|
+
|
|
113
|
+
# ... work with working_text ...
|
|
114
|
+
|
|
115
|
+
# Step 2: restore original when needed (e.g. before final summary)
|
|
116
|
+
if ccr_id:
|
|
117
|
+
restore = await slm_retrieve(ccr_id=ccr_id)
|
|
118
|
+
if restore["ok"]:
|
|
119
|
+
original_text = restore["content"]
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Secondary CLI (fallback when MCP is unavailable)
|
|
123
|
+
|
|
124
|
+
The `slm compress` subcommand exists but has known pre-existing parse-test failures. Prefer the MCP tools above. If you must use CLI:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
slm compress status [--json]
|
|
128
|
+
slm compress mode safe|aggressive [--json]
|
|
129
|
+
slm compress code on|off [--json]
|
|
130
|
+
slm compress prose on|off [--json]
|
|
131
|
+
slm compress ccr on|off [--json]
|
|
132
|
+
slm compress align on|off [--json]
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
These subcommands control daemon-level compression settings — they do not compress content inline. For inline compression, use `slm_compress` via MCP.
|
|
136
|
+
|
|
137
|
+
## Size Cap
|
|
138
|
+
|
|
139
|
+
Content over 1 MB (1 000 000 bytes UTF-8) is processed but `reversible` is forced to `False` and `ccr_id` will be `None`. The `note` field will state `"content over 1MB: ccr skipped"`.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
SuperLocalMemory v3.6.18 · Qualixar · AGPL-3.0-or-later
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: slm-graph
|
|
3
|
+
description: >
|
|
4
|
+
Index and query a codebase as a structural graph — build the code graph, trace blast radius of a
|
|
5
|
+
change, find callers/callees/inheritors, semantic code search by meaning, assemble PR review
|
|
6
|
+
context, and detect what changed since last index. Use when the user asks how code connects, what
|
|
7
|
+
breaks if X changes, what calls a function, what a class inherits from, how to navigate an
|
|
8
|
+
unfamiliar codebase, or to understand risk before editing.
|
|
9
|
+
when_to_use: |
|
|
10
|
+
- what calls X
|
|
11
|
+
- what breaks if I change Y
|
|
12
|
+
- what does Z inherit from
|
|
13
|
+
- find code that handles authentication
|
|
14
|
+
- impact analysis before editing
|
|
15
|
+
- code navigation in unfamiliar repos
|
|
16
|
+
- blast radius before a PR
|
|
17
|
+
- pre-commit change detection
|
|
18
|
+
allowed-tools: build_code_graph, query_graph, get_blast_radius, semantic_search_code, get_review_context, detect_changes, Bash
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
# slm-graph — Code Intelligence Skill
|
|
22
|
+
|
|
23
|
+
Index any repo as a code knowledge graph and answer structural questions about it: callers, callees, impact radius, semantic search, and review context. Requires the `code` MCP profile (set `SLM_MCP_PROFILE=code` in your plugin `.mcp.json`).
|
|
24
|
+
|
|
25
|
+
**Prerequisite rule:** every tool except `build_code_graph` self-guards — if the graph is not built it returns `{"success": false, "error": "Code graph not built. Run build_code_graph first."}`. Always index first.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Tool Reference
|
|
30
|
+
|
|
31
|
+
### 1. `build_code_graph` — index a repository
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
build_code_graph(
|
|
35
|
+
repo_path: str,
|
|
36
|
+
languages: str = "",
|
|
37
|
+
exclude_patterns: str = "",
|
|
38
|
+
) -> {success, files_parsed, nodes, edges, flows, communities, duration_ms}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Parses all supported source files, extracts functions/classes/imports, builds the call graph, detects execution flows, and identifies code communities. Replaces any previous index for the same repo.
|
|
42
|
+
|
|
43
|
+
- `repo_path` — absolute path to the repository root. Must exist.
|
|
44
|
+
- `languages` — comma-separated language filter, e.g. `"python,typescript"`. Empty string = index all supported languages.
|
|
45
|
+
- `exclude_patterns` — comma-separated glob patterns to exclude, e.g. `"**/node_modules/**,**/.venv/**"`. Empty = no exclusions.
|
|
46
|
+
|
|
47
|
+
When to (re)build:
|
|
48
|
+
- Before using any other graph tool for the first time on a repo.
|
|
49
|
+
- After significant changes to the codebase (pull, merge, large refactor).
|
|
50
|
+
- When `detect_changes` or `query_graph` returns stale/unexpected results.
|
|
51
|
+
- Rebuild is safe and idempotent — it replaces the previous index atomically per file.
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
# Index the full repo
|
|
55
|
+
build_code_graph(repo_path="/abs/path/to/myrepo")
|
|
56
|
+
|
|
57
|
+
# Index only Python, skip tests and generated code
|
|
58
|
+
build_code_graph(
|
|
59
|
+
repo_path="/abs/path/to/myrepo",
|
|
60
|
+
languages="python",
|
|
61
|
+
exclude_patterns="**/tests/**,**/generated/**"
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
### 2. `query_graph` — traverse relationships
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
query_graph(
|
|
71
|
+
pattern: str,
|
|
72
|
+
target: str = "",
|
|
73
|
+
limit: int = 20,
|
|
74
|
+
) -> {success, pattern, target, results: [{qualified_name, kind, file_path, name}]}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Query the graph for structural relationships. `pattern` is required and must be one of the eight valid values below. `target` is a qualified name, partial name, or node ID — matched with exact-then-LIKE fallback.
|
|
78
|
+
|
|
79
|
+
Valid patterns:
|
|
80
|
+
|
|
81
|
+
| pattern | returns |
|
|
82
|
+
|---|---|
|
|
83
|
+
| `callers_of` | functions/methods that call `target` |
|
|
84
|
+
| `callees_of` | functions/methods that `target` calls |
|
|
85
|
+
| `imports_of` | modules/symbols that `target` imports |
|
|
86
|
+
| `imported_by` | who imports `target` |
|
|
87
|
+
| `tests_for` | test nodes associated with `target` |
|
|
88
|
+
| `inherits_from` | base classes of `target` |
|
|
89
|
+
| `inherited_by` | subclasses of `target` |
|
|
90
|
+
| `contains` | symbols defined inside `target` (e.g. methods in a class) |
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
# Who calls the auth handler?
|
|
94
|
+
query_graph(pattern="callers_of", target="authenticate_user")
|
|
95
|
+
|
|
96
|
+
# What does the payment processor import?
|
|
97
|
+
query_graph(pattern="imports_of", target="PaymentProcessor", limit=30)
|
|
98
|
+
|
|
99
|
+
# What classes inherit from BaseModel?
|
|
100
|
+
query_graph(pattern="inherited_by", target="BaseModel")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### 3. `get_blast_radius` — impact analysis
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
get_blast_radius(
|
|
109
|
+
changed_files: str,
|
|
110
|
+
max_depth: int = 2,
|
|
111
|
+
max_nodes: int = 500,
|
|
112
|
+
) -> {success, changed_nodes, impacted_nodes, impacted_files, edges, depth_reached, truncated}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Computes the full impact radius for one or more changed files using bidirectional BFS (callers and callees). Returns every node and file reachable within `max_depth` hops. Use this before editing to understand risk surface.
|
|
116
|
+
|
|
117
|
+
- `changed_files` — comma-separated file paths relative to the repo root, e.g. `"src/auth/handler.py,src/auth/models.py"`.
|
|
118
|
+
- `max_depth` — BFS depth. Default 2. Increase to 3–4 for deep call chains; lower to 1 for a quick first-degree check.
|
|
119
|
+
- `max_nodes` — caps the result set. If `truncated=true` in the response, the real blast radius is larger.
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
# What breaks if I change the auth handler?
|
|
123
|
+
get_blast_radius(changed_files="src/auth/handler.py")
|
|
124
|
+
|
|
125
|
+
# Deeper analysis across two files
|
|
126
|
+
get_blast_radius(
|
|
127
|
+
changed_files="src/payments/gateway.py,src/payments/models.py",
|
|
128
|
+
max_depth=3,
|
|
129
|
+
max_nodes=200
|
|
130
|
+
)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
If `truncated` is `true`, narrow the scope with `max_nodes` or reduce `max_depth` to get a reliable result.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### 4. `semantic_search_code` — find code by meaning
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
semantic_search_code(
|
|
141
|
+
query: str,
|
|
142
|
+
kind: str = "",
|
|
143
|
+
limit: int = 20,
|
|
144
|
+
) -> {success, results: [{qualified_name, kind, file_path, score, line_start, name}]}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Hybrid FTS5 + vector search over all indexed code entities. Use when you know what the code *does* but not what it's *called*.
|
|
148
|
+
|
|
149
|
+
- `query` — natural language description, e.g. `"retry logic for HTTP requests"` or `"parse JWT token from header"`.
|
|
150
|
+
- `kind` — optional filter: `"Function"`, `"Class"`, `"File"`, or `"Test"`. Empty = all kinds. Case-insensitive match in the engine.
|
|
151
|
+
- `limit` — max results. Default 20.
|
|
152
|
+
|
|
153
|
+
Results include a `score` field (higher = more relevant).
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
# Find where authentication is handled
|
|
157
|
+
semantic_search_code(query="authenticate user from request token")
|
|
158
|
+
|
|
159
|
+
# Find only test functions that cover database writes
|
|
160
|
+
semantic_search_code(query="database write transaction rollback", kind="Test")
|
|
161
|
+
|
|
162
|
+
# Find the rate limiter class
|
|
163
|
+
semantic_search_code(query="rate limiting middleware", kind="Class", limit=5)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
### 5. `get_review_context` — assemble PR review context
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
get_review_context(
|
|
172
|
+
changed_files: str,
|
|
173
|
+
include_source: bool = True,
|
|
174
|
+
) -> {success, summary, review_items, test_gaps, risk_score}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Produces a token-optimized review package for a set of changed files: a plain-language summary, a ranked list of review items with per-node risk scores, and a list of changed symbols that have no associated test coverage.
|
|
178
|
+
|
|
179
|
+
- `changed_files` — comma-separated file paths relative to the repo root.
|
|
180
|
+
- `include_source` — whether to include source code snippets in the context (default `True`). Set `False` to reduce token usage when you only need the risk analysis.
|
|
181
|
+
|
|
182
|
+
`risk_score` is a float 0–1 on the overall changeset. `review_items[].risk_score` is per-node.
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
# Get review context for a PR touching two files
|
|
186
|
+
get_review_context(changed_files="src/auth/handler.py,src/auth/utils.py")
|
|
187
|
+
|
|
188
|
+
# Risk summary only, no source snippets
|
|
189
|
+
get_review_context(
|
|
190
|
+
changed_files="src/payments/gateway.py",
|
|
191
|
+
include_source=False
|
|
192
|
+
)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
### 6. `detect_changes` — what changed since last index
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
detect_changes(
|
|
201
|
+
base: str = "HEAD~1",
|
|
202
|
+
) -> {success, summary, risk_score, changed_functions, test_gaps, review_priorities}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Runs `git diff` against `base`, maps the changed hunks to graph nodes, and returns a risk-scored list of changed functions, test gaps, and review priorities. Requires the repo to be a git repository.
|
|
206
|
+
|
|
207
|
+
- `base` — git ref to diff against. Default `"HEAD~1"` (one commit back). Any valid git ref works: `"main"`, `"v3.6.13"`, a commit SHA, etc.
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
# What changed in the last commit?
|
|
211
|
+
detect_changes()
|
|
212
|
+
|
|
213
|
+
# What changed since the release branch?
|
|
214
|
+
detect_changes(base="release/v3.6.13")
|
|
215
|
+
|
|
216
|
+
# What changed relative to main?
|
|
217
|
+
detect_changes(base="main")
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Returns `error` if the repo root is not a git repository or if git is not available.
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## Realistic Workflow
|
|
225
|
+
|
|
226
|
+
### Explore an unfamiliar codebase
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
# 1. Index it
|
|
230
|
+
build_code_graph(repo_path="/abs/path/to/repo")
|
|
231
|
+
|
|
232
|
+
# 2. Find the entry point by meaning
|
|
233
|
+
semantic_search_code(query="request router entry point", kind="Function")
|
|
234
|
+
|
|
235
|
+
# 3. Trace what it calls
|
|
236
|
+
query_graph(pattern="callees_of", target="handle_request")
|
|
237
|
+
|
|
238
|
+
# 4. See who else calls the same core function
|
|
239
|
+
query_graph(pattern="callers_of", target="authenticate_user")
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Before editing a function
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
# 1. Know what you are touching
|
|
246
|
+
semantic_search_code(query="retry HTTP requests with backoff")
|
|
247
|
+
|
|
248
|
+
# 2. Understand blast radius before making the change
|
|
249
|
+
get_blast_radius(changed_files="src/http/client.py")
|
|
250
|
+
|
|
251
|
+
# 3. Check test gaps
|
|
252
|
+
get_review_context(changed_files="src/http/client.py")
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Pre-commit / PR review
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
# 1. What changed in this branch vs main?
|
|
259
|
+
detect_changes(base="main")
|
|
260
|
+
|
|
261
|
+
# 2. Full impact analysis for the changed files
|
|
262
|
+
get_blast_radius(changed_files="src/auth/handler.py,src/auth/models.py")
|
|
263
|
+
|
|
264
|
+
# 3. Assemble review context
|
|
265
|
+
get_review_context(changed_files="src/auth/handler.py,src/auth/models.py")
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Error Handling
|
|
271
|
+
|
|
272
|
+
All tools return `{"success": false, "error": "<message>"}` on failure — they never raise.
|
|
273
|
+
|
|
274
|
+
| Error message | Cause | Fix |
|
|
275
|
+
|---|---|---|
|
|
276
|
+
| `Code graph not built. Run build_code_graph first.` | No index exists | Call `build_code_graph(repo_path=...)` first |
|
|
277
|
+
| `Repository path does not exist: <path>` | Bad `repo_path` in build | Pass an absolute path that exists |
|
|
278
|
+
| `Git not available or not a git repository: ...` | `detect_changes` needs git | Only works in git repos with git installed |
|
|
279
|
+
| `Invalid pattern '...'` | Wrong `pattern` in `query_graph` | Use one of the 8 valid pattern strings |
|
|
280
|
+
| `No node found matching '<target>'` | Target not in index | Rebuild or check the qualified name via `semantic_search_code` |
|
|
281
|
+
|
|
282
|
+
If `build_code_graph` returns `files_parsed: 0`, no supported source files were found — check `repo_path` and `exclude_patterns`.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Profile Requirement
|
|
287
|
+
|
|
288
|
+
This skill uses graph tools that are only active under the `code` MCP profile. Your plugin `.mcp.json` must include:
|
|
289
|
+
|
|
290
|
+
```json
|
|
291
|
+
"env": {
|
|
292
|
+
"SLM_MCP_PROFILE": "code"
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Without this, the six graph tools are not registered and will appear as unknown tools. Run `slm status` to confirm the active profile.
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
SuperLocalMemory v3.6.18 · Qualixar · AGPL-3.0-or-later
|