ihmt-memory 1.2.0__tar.gz → 1.2.1__tar.gz
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.
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/PKG-INFO +1 -1
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/config.py +3 -1
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/storage.py +20 -2
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/mcp_server.py +30 -2
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/pyproject.toml +1 -1
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/server.json +2 -2
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/.gitignore +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/LICENSE +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/README.md +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/__init__.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/api.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/chunkers/__init__.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/chunkers/base.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/chunkers/code.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/chunkers/generic.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/chunkers/narrative.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/chunkers/process.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/chunkers/temporal.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/conflict_resolver.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/detectors.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/models.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/project_index.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/recursive_summarizer.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/semantic_navigator.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/summarizers.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/textutils.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt/universal_ingestor.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/ihmt_launcher.py +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/requirements-mcp.txt +0 -0
- {ihmt_memory-1.2.0 → ihmt_memory-1.2.1}/templates/memory-instructions.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: ihmt-memory
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: Long-term memory for AI coding agents as a tree of plain local files, served over MCP.
|
|
5
5
|
Project-URL: Homepage, https://github.com/gonzaroman/IHMT-MEMORY
|
|
6
6
|
Project-URL: Issues, https://github.com/gonzaroman/IHMT-MEMORY/issues
|
|
@@ -8,6 +8,8 @@ can be relocated as a single directory.
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
10
|
import json
|
|
11
|
+
import os
|
|
12
|
+
import threading
|
|
11
13
|
from dataclasses import asdict, dataclass, field, fields
|
|
12
14
|
from pathlib import Path
|
|
13
15
|
from typing import Any, Dict
|
|
@@ -125,7 +127,7 @@ class IHMTConfig:
|
|
|
125
127
|
def save(self) -> None:
|
|
126
128
|
"""Persist the configuration next to the store."""
|
|
127
129
|
self.config_path.parent.mkdir(parents=True, exist_ok=True)
|
|
128
|
-
tmp = self.config_path.with_suffix(".json.tmp")
|
|
130
|
+
tmp = self.config_path.with_suffix(f".json.{os.getpid()}.{threading.get_ident()}.tmp")
|
|
129
131
|
tmp.write_text(
|
|
130
132
|
json.dumps(self.to_dict(), indent=2, ensure_ascii=False) + "\n",
|
|
131
133
|
encoding="utf-8",
|
|
@@ -12,6 +12,7 @@ from __future__ import annotations
|
|
|
12
12
|
import errno
|
|
13
13
|
import json
|
|
14
14
|
import os
|
|
15
|
+
import threading
|
|
15
16
|
import time
|
|
16
17
|
from contextlib import contextmanager
|
|
17
18
|
from dataclasses import dataclass, field
|
|
@@ -75,6 +76,22 @@ class _FileLock:
|
|
|
75
76
|
self.path.unlink(missing_ok=True)
|
|
76
77
|
|
|
77
78
|
|
|
79
|
+
def _replace(src: Path, dst: Path, attempts: int = 50) -> None:
|
|
80
|
+
"""``os.replace``, retried on Windows while another handle has ``dst`` open.
|
|
81
|
+
|
|
82
|
+
Windows refuses to replace a file that a reader or another writer holds
|
|
83
|
+
open at that instant; the handle goes away within milliseconds.
|
|
84
|
+
"""
|
|
85
|
+
for attempt in range(attempts):
|
|
86
|
+
try:
|
|
87
|
+
os.replace(src, dst)
|
|
88
|
+
return
|
|
89
|
+
except PermissionError:
|
|
90
|
+
if os.name != "nt" or attempt == attempts - 1:
|
|
91
|
+
raise
|
|
92
|
+
time.sleep(0.02)
|
|
93
|
+
|
|
94
|
+
|
|
78
95
|
@dataclass
|
|
79
96
|
class CatalogEntry:
|
|
80
97
|
"""Lightweight index record for one node of the tree."""
|
|
@@ -249,13 +266,14 @@ class MemoryStore:
|
|
|
249
266
|
def write_atomic(self, path: Path, text: str) -> None:
|
|
250
267
|
"""Durably write ``text`` to ``path``, replacing it in one step."""
|
|
251
268
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
252
|
-
|
|
269
|
+
# Unique per process and thread, so concurrent writers never share a temporary file.
|
|
270
|
+
tmp = path.with_name(f".{path.name}.{os.getpid()}.{threading.get_ident()}.tmp")
|
|
253
271
|
try:
|
|
254
272
|
with open(tmp, "w", encoding="utf-8", newline="\n") as handle:
|
|
255
273
|
handle.write(text)
|
|
256
274
|
handle.flush()
|
|
257
275
|
os.fsync(handle.fileno())
|
|
258
|
-
|
|
276
|
+
_replace(tmp, path)
|
|
259
277
|
finally:
|
|
260
278
|
if tmp.exists(): # pragma: no cover - only on a failed write
|
|
261
279
|
tmp.unlink(missing_ok=True)
|
|
@@ -35,14 +35,16 @@ from __future__ import annotations
|
|
|
35
35
|
|
|
36
36
|
import atexit
|
|
37
37
|
import difflib
|
|
38
|
+
import functools
|
|
38
39
|
import hashlib
|
|
39
40
|
import logging
|
|
40
41
|
import os
|
|
41
42
|
import re
|
|
42
43
|
import sys
|
|
43
44
|
import tempfile
|
|
45
|
+
import threading
|
|
44
46
|
from pathlib import Path
|
|
45
|
-
from typing import Dict, List, Optional, Tuple
|
|
47
|
+
from typing import Callable, Dict, List, Optional, Tuple, TypeVar
|
|
46
48
|
|
|
47
49
|
# --------------------------------------------------------------------- SDK
|
|
48
50
|
# MCP 2.x renamed FastMCP to MCPServer. Both spellings, plus the standalone
|
|
@@ -105,7 +107,7 @@ pass long logs through `digest_output`.
|
|
|
105
107
|
server = _Server(
|
|
106
108
|
name="ihmt-memory",
|
|
107
109
|
instructions=SERVER_INSTRUCTIONS,
|
|
108
|
-
version="1.2.
|
|
110
|
+
version="1.2.1",
|
|
109
111
|
)
|
|
110
112
|
|
|
111
113
|
_memory: Optional[IHMT] = None
|
|
@@ -115,6 +117,23 @@ _session: Optional[IHMT] = None
|
|
|
115
117
|
_session_dir: Optional[tempfile.TemporaryDirectory] = None
|
|
116
118
|
_session_counter = 0
|
|
117
119
|
|
|
120
|
+
#: The SDK runs each tool call in a worker thread, and agents often call several
|
|
121
|
+
#: tools at once. The stores and caches above are not thread-safe, so tool calls
|
|
122
|
+
#: take turns.
|
|
123
|
+
_tool_lock = threading.RLock()
|
|
124
|
+
_Tool = TypeVar("_Tool", bound=Callable[..., str])
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _one_at_a_time(tool: _Tool) -> _Tool:
|
|
128
|
+
"""Run ``tool`` under the server-wide lock (signature and docstring kept for the SDK)."""
|
|
129
|
+
|
|
130
|
+
@functools.wraps(tool)
|
|
131
|
+
def locked(*args, **kwargs): # type: ignore[no-untyped-def]
|
|
132
|
+
with _tool_lock:
|
|
133
|
+
return tool(*args, **kwargs)
|
|
134
|
+
|
|
135
|
+
return locked # type: ignore[return-value]
|
|
136
|
+
|
|
118
137
|
|
|
119
138
|
def get_memory() -> IHMT:
|
|
120
139
|
"""Return the shared long-term facade, creating the store on first use.
|
|
@@ -277,6 +296,7 @@ def _search(memory: IHMT, query: str, clue: Optional[str], detail: str, empty_hi
|
|
|
277
296
|
|
|
278
297
|
# ------------------------------------------------------ long-term memory tools
|
|
279
298
|
@server.tool()
|
|
299
|
+
@_one_at_a_time
|
|
280
300
|
def search_memory(query: str, clue: Optional[str] = None, detail: str = "compact") -> str:
|
|
281
301
|
"""Search the user's long-term memory (IHMT): decisions, setup, preferences, people, earlier sessions.
|
|
282
302
|
|
|
@@ -303,6 +323,7 @@ def search_memory(query: str, clue: Optional[str] = None, detail: str = "compact
|
|
|
303
323
|
|
|
304
324
|
|
|
305
325
|
@server.tool()
|
|
326
|
+
@_one_at_a_time
|
|
306
327
|
def save_memory(content: str, domain: str = "general", content_type: str = "auto", replaces: str = "") -> str:
|
|
307
328
|
"""Store durable knowledge in the user's long-term memory (IHMT).
|
|
308
329
|
|
|
@@ -467,6 +488,7 @@ def _apply_correction(memory: IHMT, content: str, new_ids: List[str], replaces:
|
|
|
467
488
|
|
|
468
489
|
|
|
469
490
|
@server.tool()
|
|
491
|
+
@_one_at_a_time
|
|
470
492
|
def mark_outdated(old_id: str, new_id: str) -> str:
|
|
471
493
|
"""Flag one memory as corrected by another, after save_memory listed candidates.
|
|
472
494
|
|
|
@@ -486,6 +508,7 @@ def mark_outdated(old_id: str, new_id: str) -> str:
|
|
|
486
508
|
|
|
487
509
|
# ------------------------------------------------------------ project tools
|
|
488
510
|
@server.tool()
|
|
511
|
+
@_one_at_a_time
|
|
489
512
|
def project_map(path: str, detail: str = "files", subpath: str = "") -> str:
|
|
490
513
|
"""Compact map of a codebase: files with their size in tokens, optionally their symbols and line ranges.
|
|
491
514
|
|
|
@@ -506,6 +529,7 @@ def project_map(path: str, detail: str = "files", subpath: str = "") -> str:
|
|
|
506
529
|
|
|
507
530
|
|
|
508
531
|
@server.tool()
|
|
532
|
+
@_one_at_a_time
|
|
509
533
|
def find_code(
|
|
510
534
|
query: str,
|
|
511
535
|
path: str,
|
|
@@ -547,6 +571,7 @@ def find_code(
|
|
|
547
571
|
|
|
548
572
|
|
|
549
573
|
@server.tool()
|
|
574
|
+
@_one_at_a_time
|
|
550
575
|
def read_file(path: str, force: bool = False, start_line: int = 0, end_line: int = 0) -> str:
|
|
551
576
|
"""Read a text file, remembering what you were given this session.
|
|
552
577
|
|
|
@@ -605,6 +630,7 @@ def read_file(path: str, force: bool = False, start_line: int = 0, end_line: int
|
|
|
605
630
|
|
|
606
631
|
# ------------------------------------------------------------ session tools
|
|
607
632
|
@server.tool()
|
|
633
|
+
@_one_at_a_time
|
|
608
634
|
def note(text: str) -> str:
|
|
609
635
|
"""Keep something you learned in this session (where a thing lives, what a method does, a result).
|
|
610
636
|
|
|
@@ -621,6 +647,7 @@ def note(text: str) -> str:
|
|
|
621
647
|
|
|
622
648
|
|
|
623
649
|
@server.tool()
|
|
650
|
+
@_one_at_a_time
|
|
624
651
|
def recall(query: str, clue: Optional[str] = None) -> str:
|
|
625
652
|
"""Search what you kept earlier in this session with note or digest_output (not long-term memory).
|
|
626
653
|
|
|
@@ -643,6 +670,7 @@ _DIGEST_RE = re.compile(
|
|
|
643
670
|
|
|
644
671
|
|
|
645
672
|
@server.tool()
|
|
673
|
+
@_one_at_a_time
|
|
646
674
|
def digest_output(text: str, label: str = "output") -> str:
|
|
647
675
|
"""Condense a long command output (build log, test report) and keep the full text for recall.
|
|
648
676
|
|
|
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "ihmt-memory"
|
|
10
10
|
# Keep equal to the version in mcp_server.py and server.json (tests/test_packaging.py checks it).
|
|
11
|
-
version = "1.2.
|
|
11
|
+
version = "1.2.1"
|
|
12
12
|
description = "Long-term memory for AI coding agents as a tree of plain local files, served over MCP."
|
|
13
13
|
readme = "README.md"
|
|
14
14
|
requires-python = ">=3.10"
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
"url": "https://github.com/gonzaroman/IHMT-MEMORY",
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
|
-
"version": "1.2.
|
|
10
|
+
"version": "1.2.1",
|
|
11
11
|
"packages": [
|
|
12
12
|
{
|
|
13
13
|
"registryType": "pypi",
|
|
14
14
|
"registryBaseUrl": "https://pypi.org",
|
|
15
15
|
"identifier": "ihmt-memory",
|
|
16
|
-
"version": "1.2.
|
|
16
|
+
"version": "1.2.1",
|
|
17
17
|
"runtimeHint": "uvx",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|