superlocalmemory 4.0.4 → 4.0.5
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 +33 -0
- package/README.md +18 -13
- package/ide/configs/codex-mcp.toml +2 -2
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.mcp.json +1 -0
- package/plugin/CLAUDE.md +3 -3
- package/plugin/agents/slm-governance-advisor.md +1 -1
- package/plugin/agents/slm-loop-runner.md +1 -1
- package/plugin/agents/slm-memory-advisor.md +1 -1
- package/plugin/agents/slm-optimize-advisor.md +1 -1
- package/plugin/requirements.txt +1 -1
- package/plugin/skills/slm-cache/SKILL.md +1 -1
- package/plugin/skills/slm-compress/SKILL.md +1 -1
- package/plugin/skills/slm-governance/SKILL.md +1 -1
- package/plugin/skills/slm-graph/SKILL.md +3 -2
- package/plugin/skills/slm-loop/SKILL.md +1 -1
- package/plugin/skills/slm-mesh/SKILL.md +1 -1
- package/plugin/skills/slm-profile/SKILL.md +2 -1
- package/plugin/skills/slm-recall/SKILL.md +1 -1
- package/plugin/skills/slm-remember/SKILL.md +1 -1
- package/plugin/skills/slm-scope/SKILL.md +1 -1
- package/plugin/skills/slm-session/SKILL.md +1 -1
- package/plugin/skills/slm-status/SKILL.md +1 -1
- package/plugin-src/rules/AGENTS.md +6 -5
- package/plugin-src/skills/slm-graph/SKILL.md +2 -1
- package/plugin-src/skills/slm-profile/SKILL.md +1 -0
- package/pyproject.toml +1 -1
- package/src/superlocalmemory/__init__.py +1 -1
- package/src/superlocalmemory/brain/__init__.py +5 -0
- package/src/superlocalmemory/brain/truth.py +348 -0
- package/src/superlocalmemory/cli/commands.py +82 -25
- package/src/superlocalmemory/cli/main.py +12 -0
- package/src/superlocalmemory/core/context_cache.py +58 -1
- package/src/superlocalmemory/core/mutations.py +155 -25
- package/src/superlocalmemory/core/recall_pipeline.py +6 -10
- package/src/superlocalmemory/core/remember_runtime.py +271 -2
- package/src/superlocalmemory/core/store_pipeline.py +100 -38
- package/src/superlocalmemory/encoding/consolidator.py +17 -47
- package/src/superlocalmemory/encoding/temporal_validator.py +14 -18
- package/src/superlocalmemory/hooks/user_prompt_hook.py +1 -1
- package/src/superlocalmemory/integrations/bounded_loops_mcp.py +4 -3
- package/src/superlocalmemory/mcp/profiles.py +19 -7
- package/src/superlocalmemory/mcp/server.py +4 -2
- package/src/superlocalmemory/mcp/tools_brain.py +54 -10
- package/src/superlocalmemory/mcp/tools_core.py +88 -3
- package/src/superlocalmemory/retrieval/engine.py +7 -10
- package/src/superlocalmemory/retrieval/temporal_validity_filter.py +119 -19
- package/src/superlocalmemory/server/routes/brain.py +15 -0
- package/src/superlocalmemory/server/routes/memories.py +129 -3
- package/src/superlocalmemory/storage/_migration_internals.py +4 -0
- package/src/superlocalmemory/storage/_schema_version.py +2 -2
- package/src/superlocalmemory/storage/correction_cases.py +670 -0
- package/src/superlocalmemory/storage/database.py +194 -24
- package/src/superlocalmemory/storage/migration_runner.py +7 -0
- package/src/superlocalmemory/storage/migrations/M042_correction_case_ledger.py +245 -0
- package/src/superlocalmemory/storage/migrations/__init__.py +2 -0
- package/src/superlocalmemory/storage/write_coordinator.py +4 -0
- package/src/superlocalmemory/ui/js/brain.js +43 -7
- package/src/superlocalmemory/ui/js/od-brain.js +44 -28
|
@@ -14,6 +14,7 @@ from __future__ import annotations
|
|
|
14
14
|
import hashlib
|
|
15
15
|
import json
|
|
16
16
|
import logging
|
|
17
|
+
import sqlite3
|
|
17
18
|
import uuid
|
|
18
19
|
from typing import TYPE_CHECKING, Any
|
|
19
20
|
|
|
@@ -51,6 +52,72 @@ def _ingestion_effect_id(operation_id: str, *parts: object) -> str:
|
|
|
51
52
|
return hashlib.sha256(payload.encode("utf-8")).hexdigest()[:32]
|
|
52
53
|
|
|
53
54
|
|
|
55
|
+
def _record_correction_candidate(
|
|
56
|
+
db: DatabaseManager,
|
|
57
|
+
*,
|
|
58
|
+
operation_id: str,
|
|
59
|
+
profile_id: str,
|
|
60
|
+
scope: str,
|
|
61
|
+
predecessor_fact_id: str,
|
|
62
|
+
successor_fact_id: str,
|
|
63
|
+
reason_code: str,
|
|
64
|
+
trusted_actor_id: str,
|
|
65
|
+
) -> None:
|
|
66
|
+
"""Append a review candidate through the current canonical transaction.
|
|
67
|
+
|
|
68
|
+
This intentionally carries identifiers and a controlled reason code only.
|
|
69
|
+
It must not use detector prose because that can contain user memory text.
|
|
70
|
+
If the current path is bound to the canonical coordinator,
|
|
71
|
+
``raw_connection`` yields its already-open transaction; otherwise the
|
|
72
|
+
database manager owns the short transaction. Either path is atomic.
|
|
73
|
+
"""
|
|
74
|
+
if not trusted_actor_id or not predecessor_fact_id or not successor_fact_id:
|
|
75
|
+
return
|
|
76
|
+
if predecessor_fact_id == successor_fact_id:
|
|
77
|
+
return
|
|
78
|
+
from superlocalmemory.storage.correction_cases import (
|
|
79
|
+
CorrectionActor,
|
|
80
|
+
CorrectionCaseError,
|
|
81
|
+
propose_on_connection,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
case_id = _ingestion_effect_id(
|
|
85
|
+
operation_id, "correction-case", profile_id, predecessor_fact_id,
|
|
86
|
+
successor_fact_id, reason_code,
|
|
87
|
+
)
|
|
88
|
+
idempotency_key = _ingestion_effect_id(
|
|
89
|
+
operation_id, "correction-proposal", profile_id, predecessor_fact_id,
|
|
90
|
+
successor_fact_id, reason_code,
|
|
91
|
+
)
|
|
92
|
+
actor = CorrectionActor(
|
|
93
|
+
actor_id=trusted_actor_id,
|
|
94
|
+
actor_kind="host_attested",
|
|
95
|
+
trust_tier="canonical_writer",
|
|
96
|
+
)
|
|
97
|
+
try:
|
|
98
|
+
with db.raw_connection() as conn:
|
|
99
|
+
propose_on_connection(
|
|
100
|
+
conn,
|
|
101
|
+
case_id=case_id,
|
|
102
|
+
profile_id=profile_id,
|
|
103
|
+
scope=scope,
|
|
104
|
+
predecessor_fact_id=predecessor_fact_id,
|
|
105
|
+
successor_fact_id=successor_fact_id,
|
|
106
|
+
reason_code=reason_code,
|
|
107
|
+
actor=actor,
|
|
108
|
+
idempotency_key=idempotency_key,
|
|
109
|
+
# Candidate detection observes a possible correction. It does
|
|
110
|
+
# not claim an event-time boundary from heuristic evidence.
|
|
111
|
+
is_profile_active=lambda candidate_profile: candidate_profile == profile_id,
|
|
112
|
+
is_actor_trusted=lambda candidate_actor: candidate_actor == actor,
|
|
113
|
+
)
|
|
114
|
+
except (CorrectionCaseError, sqlite3.Error, ValueError) as exc:
|
|
115
|
+
# A missing/hot-upgrading M042 ledger must not make memory ingestion
|
|
116
|
+
# unavailable. The candidate is advisory and has no retrieval effect;
|
|
117
|
+
# the warning is the operational signal that an operator must inspect.
|
|
118
|
+
logger.warning("Correction candidate not recorded for %s: %s", successor_fact_id, exc)
|
|
119
|
+
|
|
120
|
+
|
|
54
121
|
def _record_fact_entity_association(
|
|
55
122
|
db: DatabaseManager,
|
|
56
123
|
*,
|
|
@@ -731,47 +798,30 @@ def run_store(
|
|
|
731
798
|
continue
|
|
732
799
|
fact = existing_fact
|
|
733
800
|
|
|
734
|
-
# Opinion confidence tracking: reinforce or decay
|
|
735
|
-
if fact.fact_type == FactType.OPINION and action.action_type.value == "update":
|
|
736
|
-
try:
|
|
737
|
-
existing = db.get_fact(
|
|
738
|
-
action.existing_fact_id or action.new_fact_id
|
|
739
|
-
)
|
|
740
|
-
if existing and existing.fact_type == FactType.OPINION:
|
|
741
|
-
new_conf = min(1.0, existing.confidence + 0.1)
|
|
742
|
-
db.update_fact(existing.fact_id, {"confidence": new_conf})
|
|
743
|
-
except Exception:
|
|
744
|
-
pass
|
|
745
|
-
elif fact.fact_type == FactType.OPINION and action.action_type.value == "supersede":
|
|
746
|
-
try:
|
|
747
|
-
old_id = getattr(action, "old_fact_id", None)
|
|
748
|
-
if old_id:
|
|
749
|
-
old_fact = db.get_fact(old_id)
|
|
750
|
-
if old_fact:
|
|
751
|
-
new_conf = max(0.0, old_fact.confidence - 0.2)
|
|
752
|
-
db.update_fact(old_id, {"confidence": new_conf})
|
|
753
|
-
except Exception:
|
|
754
|
-
pass
|
|
755
|
-
|
|
756
801
|
if action.action_type.value in ("update", "supersede"):
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
updated_fact = db.get_fact(target_id)
|
|
765
|
-
if updated_fact is None:
|
|
802
|
+
# A consolidator UPDATE/SUPERSEDE is a review-required
|
|
803
|
+
# proposal. It persists the incoming successor and does
|
|
804
|
+
# not mutate, delete, archive, or change trust on the
|
|
805
|
+
# matched predecessor. Continue materializing the
|
|
806
|
+
# incoming fact through the common projection pipeline.
|
|
807
|
+
proposed_fact = db.get_fact(action.new_fact_id)
|
|
808
|
+
if proposed_fact is None:
|
|
766
809
|
raise RuntimeError(
|
|
767
|
-
f"consolidation {action.action_type.value} produced "
|
|
768
|
-
f"missing fact {
|
|
810
|
+
f"consolidation {action.action_type.value} proposal produced "
|
|
811
|
+
f"missing fact {action.new_fact_id}"
|
|
812
|
+
)
|
|
813
|
+
fact = proposed_fact
|
|
814
|
+
if action.existing_fact_id:
|
|
815
|
+
_record_correction_candidate(
|
|
816
|
+
db,
|
|
817
|
+
operation_id=ingestion_operation_id,
|
|
818
|
+
profile_id=profile_id,
|
|
819
|
+
scope=scope,
|
|
820
|
+
predecessor_fact_id=action.existing_fact_id,
|
|
821
|
+
successor_fact_id=action.new_fact_id,
|
|
822
|
+
reason_code=f"consolidation_{action.action_type.value}",
|
|
823
|
+
trusted_actor_id=trusted_actor_id,
|
|
769
824
|
)
|
|
770
|
-
# Continue through the shared index/graph/temporal/
|
|
771
|
-
# provenance stages. The previous early continue made
|
|
772
|
-
# UPDATE/SUPERSEDE facts look stored while skipping half of
|
|
773
|
-
# canonical materialization.
|
|
774
|
-
fact = updated_fact
|
|
775
825
|
# ADD case: consolidator already stored the fact (F8 fix)
|
|
776
826
|
# Fall through to post-processing below
|
|
777
827
|
else:
|
|
@@ -860,6 +910,18 @@ def run_store(
|
|
|
860
910
|
"Temporal: %d facts invalidated by new fact %s",
|
|
861
911
|
len(invalidations), fact.fact_id,
|
|
862
912
|
)
|
|
913
|
+
for candidate in invalidations:
|
|
914
|
+
predecessor_fact_id = str(candidate.get("old_fact_id") or "")
|
|
915
|
+
_record_correction_candidate(
|
|
916
|
+
db,
|
|
917
|
+
operation_id=ingestion_operation_id,
|
|
918
|
+
profile_id=profile_id,
|
|
919
|
+
scope=scope,
|
|
920
|
+
predecessor_fact_id=predecessor_fact_id,
|
|
921
|
+
successor_fact_id=fact.fact_id,
|
|
922
|
+
reason_code="temporal_contradiction",
|
|
923
|
+
trusted_actor_id=trusted_actor_id,
|
|
924
|
+
)
|
|
863
925
|
except Exception as exc:
|
|
864
926
|
temporal_complete = False
|
|
865
927
|
logger.debug(
|
|
@@ -4,10 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
"""SuperLocalMemory V3 — Memory Consolidator.
|
|
6
6
|
|
|
7
|
-
Mem0-style ADD/UPDATE/SUPERSEDE/NOOP
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
Mem0-style ADD/UPDATE/SUPERSEDE/NOOP classification for incoming facts.
|
|
8
|
+
|
|
9
|
+
UPDATE and SUPERSEDE are now *proposal classifications*: they persist the
|
|
10
|
+
incoming fact but never rewrite, archive, lower trust for, or otherwise mutate
|
|
11
|
+
the matched fact. A reviewed correction owner may later apply a case through
|
|
12
|
+
the correction ledger. This keeps ingestion useful while preventing an
|
|
13
|
+
automatic model judgement from changing the historical record.
|
|
11
14
|
|
|
12
15
|
Mode A: keyword-based contradiction detection (zero LLM).
|
|
13
16
|
Mode B/C: LLM-assisted contradiction detection when available.
|
|
@@ -20,7 +23,7 @@ from __future__ import annotations
|
|
|
20
23
|
|
|
21
24
|
import logging
|
|
22
25
|
import math
|
|
23
|
-
from typing import
|
|
26
|
+
from typing import Protocol
|
|
24
27
|
|
|
25
28
|
from superlocalmemory.core.config import EncodingConfig
|
|
26
29
|
from superlocalmemory.storage.database import DatabaseManager
|
|
@@ -30,7 +33,6 @@ from superlocalmemory.storage.models import (
|
|
|
30
33
|
ConsolidationActionType,
|
|
31
34
|
EdgeType,
|
|
32
35
|
GraphEdge,
|
|
33
|
-
MemoryLifecycle,
|
|
34
36
|
)
|
|
35
37
|
|
|
36
38
|
logger = logging.getLogger(__name__)
|
|
@@ -310,29 +312,17 @@ class MemoryConsolidator:
|
|
|
310
312
|
*,
|
|
311
313
|
reason: str,
|
|
312
314
|
) -> ConsolidationAction:
|
|
313
|
-
"""
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
updates: dict[str, Any] = {
|
|
317
|
-
"evidence_count": new_evidence,
|
|
318
|
-
"confidence": new_confidence,
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
# If LLM available, merge content for a richer fact
|
|
322
|
-
if self._llm is not None and self._llm.is_available():
|
|
323
|
-
merged = self._merge_facts(existing.content, new_fact.content)
|
|
324
|
-
if merged:
|
|
325
|
-
updates["content"] = merged
|
|
326
|
-
|
|
327
|
-
self._db.update_fact(existing.fact_id, updates)
|
|
315
|
+
"""Persist a proposed refinement without rewriting the predecessor."""
|
|
316
|
+
self._db.store_fact(new_fact)
|
|
317
|
+
self._create_semantic_edges(new_fact, profile_id)
|
|
328
318
|
action = self._log_action(
|
|
329
319
|
ConsolidationActionType.UPDATE,
|
|
330
320
|
new_fact.fact_id, existing.fact_id,
|
|
331
321
|
profile_id, reason,
|
|
332
322
|
)
|
|
333
323
|
logger.debug(
|
|
334
|
-
"UPDATE
|
|
335
|
-
existing.fact_id,
|
|
324
|
+
"UPDATE proposal %s -> %s: %s",
|
|
325
|
+
existing.fact_id, new_fact.fact_id, reason,
|
|
336
326
|
)
|
|
337
327
|
return action
|
|
338
328
|
|
|
@@ -344,37 +334,17 @@ class MemoryConsolidator:
|
|
|
344
334
|
*,
|
|
345
335
|
reason: str,
|
|
346
336
|
) -> ConsolidationAction:
|
|
347
|
-
"""
|
|
348
|
-
# Archive old fact (keep for history but deprioritize in retrieval)
|
|
349
|
-
self._db.update_fact(
|
|
350
|
-
existing.fact_id,
|
|
351
|
-
{"lifecycle": MemoryLifecycle.ARCHIVED},
|
|
352
|
-
)
|
|
353
|
-
# Store new fact
|
|
337
|
+
"""Persist a proposed successor without changing the predecessor."""
|
|
354
338
|
self._db.store_fact(new_fact)
|
|
355
|
-
|
|
356
|
-
self._db.store_edge(GraphEdge(
|
|
357
|
-
profile_id=profile_id,
|
|
358
|
-
source_id=new_fact.fact_id,
|
|
359
|
-
target_id=existing.fact_id,
|
|
360
|
-
edge_type=EdgeType.CONTRADICTION,
|
|
361
|
-
weight=1.0,
|
|
362
|
-
))
|
|
363
|
-
self._db.store_edge(GraphEdge(
|
|
364
|
-
profile_id=profile_id,
|
|
365
|
-
source_id=new_fact.fact_id,
|
|
366
|
-
target_id=existing.fact_id,
|
|
367
|
-
edge_type=EdgeType.SUPERSEDES,
|
|
368
|
-
weight=1.0,
|
|
369
|
-
))
|
|
339
|
+
self._create_semantic_edges(new_fact, profile_id)
|
|
370
340
|
action = self._log_action(
|
|
371
341
|
ConsolidationActionType.SUPERSEDE,
|
|
372
342
|
new_fact.fact_id, existing.fact_id,
|
|
373
343
|
profile_id, reason,
|
|
374
344
|
)
|
|
375
345
|
logger.debug(
|
|
376
|
-
"SUPERSEDE %s
|
|
377
|
-
|
|
346
|
+
"SUPERSEDE proposal %s -> %s: %s",
|
|
347
|
+
existing.fact_id, new_fact.fact_id, reason,
|
|
378
348
|
)
|
|
379
349
|
return action
|
|
380
350
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# Licensed under AGPL-3.0-or-later - see LICENSE file
|
|
3
3
|
# Part of SuperLocalMemory V3
|
|
4
4
|
|
|
5
|
-
"""Temporal Intelligence -- contradiction detection and
|
|
5
|
+
"""Temporal Intelligence -- contradiction detection and reviewable proposals.
|
|
6
6
|
|
|
7
7
|
Implements full bi-temporal validity tracking with 4 timestamps (L8 fix).
|
|
8
8
|
Contradiction detection via sheaf cohomology (Mode A: pure math) or
|
|
@@ -36,7 +36,7 @@ logger = logging.getLogger(__name__)
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
class TemporalValidator:
|
|
39
|
-
"""Validates temporal consistency and
|
|
39
|
+
"""Validates temporal consistency and proposes fact corrections.
|
|
40
40
|
|
|
41
41
|
Components received via __init__ (NOT the engine -- Rule 06):
|
|
42
42
|
- db: DatabaseManager
|
|
@@ -75,15 +75,20 @@ class TemporalValidator:
|
|
|
75
75
|
new_fact: AtomicFact,
|
|
76
76
|
profile_id: str,
|
|
77
77
|
) -> list[dict]:
|
|
78
|
-
"""Check new fact for contradictions
|
|
78
|
+
"""Check new fact for contradictions without mutating old facts.
|
|
79
79
|
|
|
80
80
|
Algorithm:
|
|
81
81
|
1. Detect contradictions (sheaf or LLM).
|
|
82
|
-
2.
|
|
83
|
-
3.
|
|
84
|
-
4. Return list of invalidation actions.
|
|
82
|
+
2. Exclude valid historical progressions using explicit event anchors.
|
|
83
|
+
3. Return review-required correction candidates.
|
|
85
84
|
|
|
86
|
-
|
|
85
|
+
This legacy method name is intentionally retained for API compatibility.
|
|
86
|
+
It no longer expires facts, changes trust, or changes retrieval state.
|
|
87
|
+
The reviewed-correction owner is the only layer permitted to apply a
|
|
88
|
+
candidate to bi-temporal validity.
|
|
89
|
+
|
|
90
|
+
Returns list of dicts: {old_fact_id, new_fact_id, reason, severity,
|
|
91
|
+
status="proposed"}.
|
|
87
92
|
"""
|
|
88
93
|
contradictions = self.detect_contradiction(new_fact, profile_id)
|
|
89
94
|
|
|
@@ -108,25 +113,16 @@ class TemporalValidator:
|
|
|
108
113
|
)
|
|
109
114
|
continue
|
|
110
115
|
|
|
111
|
-
# Step 1: Invalidate the old fact (bi-temporal)
|
|
112
|
-
self.invalidate_fact(
|
|
113
|
-
fact_id=old_fact_id,
|
|
114
|
-
invalidated_by=new_fact.fact_id,
|
|
115
|
-
reason=reason,
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
# Step 2: Apply trust penalty
|
|
119
|
-
self._apply_trust_penalty(old_fact_id, profile_id)
|
|
120
|
-
|
|
121
116
|
actions.append({
|
|
122
117
|
"old_fact_id": old_fact_id,
|
|
123
118
|
"new_fact_id": new_fact.fact_id,
|
|
124
119
|
"reason": reason,
|
|
125
120
|
"severity": severity,
|
|
121
|
+
"status": "proposed",
|
|
126
122
|
})
|
|
127
123
|
|
|
128
124
|
logger.info(
|
|
129
|
-
"Temporal:
|
|
125
|
+
"Temporal: proposed %d correction(s) due to new fact %s",
|
|
130
126
|
len(actions), new_fact.fact_id,
|
|
131
127
|
)
|
|
132
128
|
return actions
|
|
@@ -98,7 +98,7 @@ def main() -> int:
|
|
|
98
98
|
|
|
99
99
|
try:
|
|
100
100
|
topic_sig = compute_topic_signature(prompt, entity_hits=entity_hits)
|
|
101
|
-
entry = read_entry_fast(session_id, topic_sig)
|
|
101
|
+
entry = read_entry_fast(session_id, topic_sig, require_current_admission=True)
|
|
102
102
|
except Exception:
|
|
103
103
|
sys.stdout.write("{}")
|
|
104
104
|
return 0
|
|
@@ -9,7 +9,6 @@ import shutil
|
|
|
9
9
|
import stat
|
|
10
10
|
from collections.abc import Awaitable, Callable
|
|
11
11
|
from copy import deepcopy
|
|
12
|
-
from datetime import timedelta
|
|
13
12
|
from pathlib import Path
|
|
14
13
|
from typing import Any
|
|
15
14
|
|
|
@@ -134,14 +133,16 @@ async def observe_from_stdio(*, command: str, cwd: str, profile_id: str) -> list
|
|
|
134
133
|
async with ClientSession(
|
|
135
134
|
read,
|
|
136
135
|
write,
|
|
137
|
-
|
|
136
|
+
# MCP 2.x passes this directly to AnyIO's timeout machinery,
|
|
137
|
+
# which accepts a numeric duration rather than timedelta.
|
|
138
|
+
read_timeout_seconds=_OBSERVATION_TIMEOUT_SECONDS,
|
|
138
139
|
) as session:
|
|
139
140
|
async def observe() -> list[dict[str, Any]]:
|
|
140
141
|
await session.initialize()
|
|
141
142
|
|
|
142
143
|
async def call(name: str, arguments: dict[str, Any]) -> dict[str, Any]:
|
|
143
144
|
result = await session.call_tool(name, arguments)
|
|
144
|
-
if result.
|
|
145
|
+
if result.is_error:
|
|
145
146
|
raise BridgeUnavailable(
|
|
146
147
|
"bounded-loops rejected the observation request"
|
|
147
148
|
)
|
|
@@ -17,10 +17,13 @@ from __future__ import annotations
|
|
|
17
17
|
# v3.6.14 WP-01: Named profile definitions
|
|
18
18
|
# ---------------------------------------------------------------------------
|
|
19
19
|
|
|
20
|
-
_PROFILE_CORE: frozenset[str] = frozenset({ #
|
|
20
|
+
_PROFILE_CORE: frozenset[str] = frozenset({ # 16
|
|
21
21
|
"remember", "recall", "search", "fetch", "list_recent", "update_memory", "forget",
|
|
22
22
|
"session_init", "close_session",
|
|
23
23
|
"slm_compress", "slm_retrieve", "slm_cache_set", "slm_cache_get", "slm_optimize_stats",
|
|
24
|
+
# A client that can propose a correction must be able to inspect and
|
|
25
|
+
# authenticate its review; otherwise the core lifecycle is incomplete.
|
|
26
|
+
"review_correction", "list_corrections",
|
|
24
27
|
})
|
|
25
28
|
|
|
26
29
|
# Portable Brain evidence must reach the coding-host profile shipped by the
|
|
@@ -31,7 +34,7 @@ _PROFILE_BRAIN: frozenset[str] = frozenset({
|
|
|
31
34
|
"observe_bounded_loop_evidence",
|
|
32
35
|
})
|
|
33
36
|
|
|
34
|
-
_PROFILE_CODE: frozenset[str] = _PROFILE_CORE | _PROFILE_BRAIN | frozenset({ #
|
|
37
|
+
_PROFILE_CODE: frozenset[str] = _PROFILE_CORE | _PROFILE_BRAIN | frozenset({ # 31
|
|
35
38
|
"build_code_graph", "get_blast_radius", "query_graph",
|
|
36
39
|
"semantic_search_code", "get_review_context", "detect_changes",
|
|
37
40
|
# switch_profile lets a plugin/IDE session change the active workspace over
|
|
@@ -48,22 +51,23 @@ _PROFILE_FULL_MESH: frozenset[str] = frozenset({ # 8
|
|
|
48
51
|
"mesh_state", "mesh_lock", "mesh_events", "mesh_status",
|
|
49
52
|
})
|
|
50
53
|
|
|
51
|
-
|
|
54
|
+
# 41 base — explicit literal, not runtime _ESSENTIAL_TOOLS (OQ-2).
|
|
55
|
+
_PROFILE_FULL: frozenset[str] = frozenset({
|
|
52
56
|
"remember", "recall", "search", "fetch", "list_recent", "delete_memory", "update_memory",
|
|
53
57
|
"get_status", "session_init", "observe", "close_session", "report_feedback", "forget",
|
|
54
58
|
"run_maintenance", "consolidate_cognitive", "get_soft_prompts", "set_mode", "report_outcome",
|
|
55
59
|
"log_tool_event", "get_assertions", "reinforce_assertion", "contradict_assertion",
|
|
56
60
|
"get_brain_evidence_status", "record_agent_experience",
|
|
57
61
|
"record_cognitive_turn", "finalize_cognitive_turn",
|
|
58
|
-
"observe_bounded_loop_evidence",
|
|
62
|
+
"observe_bounded_loop_evidence", "review_correction", "list_corrections",
|
|
59
63
|
"evolve_skill", "skill_health", "skill_lineage", "switch_profile",
|
|
60
64
|
"slm_compress", "slm_retrieve", "slm_cache_set", "slm_cache_get", "slm_optimize_stats",
|
|
61
65
|
# v3.8.0: bounded-loop tools (CLI + /slm-loop command + MCP).
|
|
62
66
|
"slm_loop_run", "slm_loop_history", "slm_loop_show",
|
|
63
67
|
# prestage_context remains registered but deliberately raw-server-only.
|
|
64
|
-
}) | _PROFILE_FULL_MESH #
|
|
68
|
+
}) | _PROFILE_FULL_MESH # 49
|
|
65
69
|
|
|
66
|
-
_PROFILE_POWER: frozenset[str] = _PROFILE_FULL | frozenset({ #
|
|
70
|
+
_PROFILE_POWER: frozenset[str] = _PROFILE_FULL | frozenset({ # 61
|
|
67
71
|
"get_version", "get_mode", "health", "consistency_check", "recall_trace",
|
|
68
72
|
"get_lifecycle_status", "set_retention_policy", "compact_memories",
|
|
69
73
|
"get_behavioral_patterns", "audit_trail", "quantize", "get_retention_stats",
|
|
@@ -86,6 +90,7 @@ _PROFILE_DEFINITIONS: dict[str, frozenset[str]] = {
|
|
|
86
90
|
# at server startup. Any other value is a configuration error (fail closed).
|
|
87
91
|
_PROFILE_ALIASES: dict[str, str] = {
|
|
88
92
|
"core14": "core",
|
|
93
|
+
"core16": "core",
|
|
89
94
|
# 3.8.0 and later additions grew code/full/power; every historical count
|
|
90
95
|
# power. Every historical count-suffixed name is kept so a v3.6/3.7/early-
|
|
91
96
|
# 3.8 config still resolves (back-compat); new 3.8.0 counts added alongside.
|
|
@@ -94,21 +99,25 @@ _PROFILE_ALIASES: dict[str, str] = {
|
|
|
94
99
|
"code24": "code",
|
|
95
100
|
"code28": "code",
|
|
96
101
|
"code29": "code",
|
|
102
|
+
"code31": "code",
|
|
97
103
|
"full38": "full",
|
|
98
104
|
"full39": "full",
|
|
99
105
|
"full42": "full",
|
|
100
106
|
"full46": "full",
|
|
101
107
|
"full47": "full",
|
|
108
|
+
"full49": "full",
|
|
102
109
|
"power50": "power",
|
|
103
110
|
"power51": "power",
|
|
104
111
|
"power54": "power",
|
|
105
112
|
"power58": "power",
|
|
106
113
|
"power59": "power",
|
|
114
|
+
"power61": "power",
|
|
107
115
|
"mesh8": "mesh",
|
|
108
116
|
"whole81": "whole",
|
|
109
117
|
"whole84": "whole",
|
|
110
118
|
"whole91": "whole",
|
|
111
119
|
"whole92": "whole",
|
|
120
|
+
"whole94": "whole",
|
|
112
121
|
}
|
|
113
122
|
|
|
114
123
|
# Plain-English descriptions for UI display.
|
|
@@ -116,7 +125,10 @@ _PROFILE_ALIASES: dict[str, str] = {
|
|
|
116
125
|
# one sentence, user-facing language only.
|
|
117
126
|
PROFILE_DESCRIPTIONS: dict[str, str] = {
|
|
118
127
|
"core": "Essential memory: store, recall, search, sessions",
|
|
119
|
-
"code":
|
|
128
|
+
"code": (
|
|
129
|
+
"Core + code graph, portable Brain evidence, and profile switching "
|
|
130
|
+
"(default for IDE coding agents)"
|
|
131
|
+
),
|
|
120
132
|
"full": "All everyday memory, portable Brain evidence, optimization, and mesh tools",
|
|
121
133
|
"power": "Everything in full plus advanced governance and behavioral tools",
|
|
122
134
|
"mesh": "Cross-device mesh coordination only",
|
|
@@ -77,13 +77,13 @@ def reset_engine():
|
|
|
77
77
|
|
|
78
78
|
# Register tools and resources -------------------------------------------------
|
|
79
79
|
#
|
|
80
|
-
# Essential-only default:
|
|
80
|
+
# Essential-only default: 41 base tools + 8 mesh tools = 49 registered.
|
|
81
81
|
# when mesh is enabled. Set ``SLM_MCP_ALL_TOOLS=1`` to expose the full
|
|
82
82
|
# toolset. Rationale: IDEs cap at 50-100 tools total (Cursor,
|
|
83
83
|
# Antigravity, Windsurf) and a maximal SLM registration crowds out
|
|
84
84
|
# other MCP servers the user may have installed.
|
|
85
85
|
# Admin/diagnostics tools remain available via CLI (`slm <command>`).
|
|
86
|
-
# Set SLM_MCP_ALL_TOOLS=1 to enable all
|
|
86
|
+
# Set SLM_MCP_ALL_TOOLS=1 to enable all 94 tools (power users).
|
|
87
87
|
|
|
88
88
|
import os as _os_reg
|
|
89
89
|
|
|
@@ -103,6 +103,8 @@ _ESSENTIAL_TOOLS: set[str] = {
|
|
|
103
103
|
# v4.0.4: explicit, optional observation from the separately installed
|
|
104
104
|
# Bounded Loops MCP producer. It never participates in recall/ranking.
|
|
105
105
|
"observe_bounded_loop_evidence",
|
|
106
|
+
# Update, review, and list form one core correction lifecycle.
|
|
107
|
+
"review_correction", "list_corrections",
|
|
106
108
|
# Memory management (2)
|
|
107
109
|
"forget", "run_maintenance",
|
|
108
110
|
# NOTE: prestage_context IS registered (see register_prestage_tool below)
|
|
@@ -16,6 +16,7 @@ from typing import Any, Callable
|
|
|
16
16
|
|
|
17
17
|
from mcp.types import ToolAnnotations
|
|
18
18
|
|
|
19
|
+
from superlocalmemory.brain.truth import BrainTruthService
|
|
19
20
|
from superlocalmemory.core.admission import admits
|
|
20
21
|
from superlocalmemory.core.operation_request import OperationKind
|
|
21
22
|
from superlocalmemory.infra.data_root import state_path
|
|
@@ -26,13 +27,11 @@ from superlocalmemory.storage.agent_experience import (
|
|
|
26
27
|
CognitiveTurnTransitionError,
|
|
27
28
|
LearningWriteBusyError,
|
|
28
29
|
ProfileAdmissionError,
|
|
29
|
-
get_profile_receipt_summary,
|
|
30
30
|
)
|
|
31
31
|
from superlocalmemory.storage.external_evidence import (
|
|
32
32
|
ExternalEvidenceConflictError,
|
|
33
33
|
ExternalEvidenceStore,
|
|
34
34
|
ExternalEvidenceValidationError,
|
|
35
|
-
get_profile_external_evidence_summary,
|
|
36
35
|
)
|
|
37
36
|
|
|
38
37
|
|
|
@@ -52,6 +51,48 @@ def _external_store_for(engine: Any) -> ExternalEvidenceStore:
|
|
|
52
51
|
)
|
|
53
52
|
|
|
54
53
|
|
|
54
|
+
def _brain_truth_for(engine: Any) -> dict[str, Any]:
|
|
55
|
+
"""Read the portable truth snapshot without opening an engine or a writer."""
|
|
56
|
+
return BrainTruthService(
|
|
57
|
+
memory_db_path=state_path("memory.db"),
|
|
58
|
+
learning_db_path=state_path("learning.db"),
|
|
59
|
+
).snapshot(engine.profile_id)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _legacy_agent_experience(truth: dict[str, Any]) -> dict[str, Any]:
|
|
63
|
+
"""Keep the v4.0.4 MCP alias during the one-release transition window."""
|
|
64
|
+
evidence = truth["agent_experience"]
|
|
65
|
+
available = evidence["availability"] == "available"
|
|
66
|
+
claimed = evidence["claimed_experiences_total"]
|
|
67
|
+
turns = evidence["cognitive_turns_total"]
|
|
68
|
+
states = evidence["cognitive_turns_by_state"]
|
|
69
|
+
return {
|
|
70
|
+
"is_real": available,
|
|
71
|
+
"availability": evidence["availability"],
|
|
72
|
+
"experiences_total": claimed if available else 0,
|
|
73
|
+
"turns_total": turns if available else 0,
|
|
74
|
+
"turns_by_state": states if available else {},
|
|
75
|
+
# The old name remains an alias only. BrainTruth deliberately calls
|
|
76
|
+
# these declared claims, never independently verified learning.
|
|
77
|
+
"claimed_evidence_experiences": claimed if available else 0,
|
|
78
|
+
"source": evidence["source"],
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _legacy_external_evidence(truth: dict[str, Any]) -> dict[str, Any]:
|
|
83
|
+
"""Keep the v4.0.4 external-graph alias without a second database read."""
|
|
84
|
+
evidence = truth["external_evidence"]
|
|
85
|
+
available = evidence["availability"] == "available"
|
|
86
|
+
return {
|
|
87
|
+
"is_real": available,
|
|
88
|
+
"availability": evidence["availability"],
|
|
89
|
+
"total": evidence["receipts_total"] if available else 0,
|
|
90
|
+
"by_run_state": evidence["receipts_by_run_state"] if available else {},
|
|
91
|
+
"demonstrations": evidence["demonstrations_total"] if available else 0,
|
|
92
|
+
"control_plane": "observation_only",
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
55
96
|
def _require_active_profile(engine: Any, payload: dict[str, Any]) -> str | None:
|
|
56
97
|
supplied = payload.get("profile_id")
|
|
57
98
|
if supplied != engine.profile_id:
|
|
@@ -90,18 +131,21 @@ def register_brain_tools(server: Any, get_engine: Callable[[], Any]) -> None:
|
|
|
90
131
|
|
|
91
132
|
@server.tool(annotations=ToolAnnotations(readOnlyHint=True))
|
|
92
133
|
async def get_brain_evidence_status() -> dict[str, Any]:
|
|
93
|
-
"""Get profile-scoped, observation-only Brain evidence totals.
|
|
134
|
+
"""Get profile-scoped, observation-only Living Brain evidence totals.
|
|
135
|
+
|
|
136
|
+
``brain_truth`` is the canonical v1 payload. The legacy aliases are
|
|
137
|
+
retained for one release so existing hosts can move independently.
|
|
138
|
+
"""
|
|
94
139
|
engine = get_engine()
|
|
140
|
+
truth = _brain_truth_for(engine)
|
|
95
141
|
return {
|
|
96
142
|
"success": True,
|
|
97
143
|
"profile_id": engine.profile_id,
|
|
98
|
-
"
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
"external_graph_evidence":
|
|
102
|
-
|
|
103
|
-
),
|
|
104
|
-
"control_plane": "observation_only",
|
|
144
|
+
"brain_truth": truth,
|
|
145
|
+
"agent_experience": _legacy_agent_experience(truth),
|
|
146
|
+
"external_evidence": truth["external_evidence"],
|
|
147
|
+
"external_graph_evidence": _legacy_external_evidence(truth),
|
|
148
|
+
"control_plane": truth["control_plane"],
|
|
105
149
|
}
|
|
106
150
|
|
|
107
151
|
@server.tool()
|