runtime-memory 3.0.0__py3-none-any.whl
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.
- runtime_memory/__init__.py +28 -0
- runtime_memory/claude_code/__init__.py +48 -0
- runtime_memory/claude_code/commands.py +698 -0
- runtime_memory/claude_code/daemon.py +852 -0
- runtime_memory/claude_code/hooks.py +722 -0
- runtime_memory/cli/__init__.py +8 -0
- runtime_memory/cli/main.py +1936 -0
- runtime_memory/core/__init__.py +216 -0
- runtime_memory/core/config.py +473 -0
- runtime_memory/core/embeddings.py +908 -0
- runtime_memory/core/engine.py +1007 -0
- runtime_memory/core/exceptions.py +547 -0
- runtime_memory/core/legacy_env.py +39 -0
- runtime_memory/core/logging.py +160 -0
- runtime_memory/core/models.py +1051 -0
- runtime_memory/core/observability.py +725 -0
- runtime_memory/core/paths.py +30 -0
- runtime_memory/core/resilience.py +511 -0
- runtime_memory/core/retrieval.py +819 -0
- runtime_memory/core/storage.py +1105 -0
- runtime_memory/extraction/__init__.py +36 -0
- runtime_memory/extraction/extractor.py +1143 -0
- runtime_memory/hermes/__init__.py +39 -0
- runtime_memory/hermes/_base.py +154 -0
- runtime_memory/hermes/bridge.py +119 -0
- runtime_memory/hermes/plugin.yaml +13 -0
- runtime_memory/hermes/provider.py +536 -0
- runtime_memory/hermes/tools.py +230 -0
- runtime_memory/hermes/trace.py +177 -0
- runtime_memory/plugin/__init__.py +646 -0
- runtime_memory/sdk/__init__.py +97 -0
- runtime_memory/sdk/client.py +1577 -0
- runtime_memory/server/__init__.py +75 -0
- runtime_memory/server/api.py +1665 -0
- runtime_memory/server/mcp.py +1574 -0
- runtime_memory/server/static/css/styles.css +1110 -0
- runtime_memory/server/static/index.html +264 -0
- runtime_memory/server/static/js/api.js +294 -0
- runtime_memory/server/static/js/app.js +771 -0
- runtime_memory/tasks/__init__.py +114 -0
- runtime_memory/tasks/adapter.py +501 -0
- runtime_memory/tasks/claude_code_adapter.py +495 -0
- runtime_memory/tasks/claude_code_parser.py +339 -0
- runtime_memory/tasks/cli_bridge.py +415 -0
- runtime_memory/tasks/linking.py +397 -0
- runtime_memory/tasks/models.py +520 -0
- runtime_memory/tasks/outcomes.py +320 -0
- runtime_memory/tasks/parser.py +305 -0
- runtime_memory/tasks/unified_adapter.py +661 -0
- runtime_memory-3.0.0.dist-info/METADATA +497 -0
- runtime_memory-3.0.0.dist-info/RECORD +54 -0
- runtime_memory-3.0.0.dist-info/WHEEL +4 -0
- runtime_memory-3.0.0.dist-info/entry_points.txt +6 -0
- runtime_memory-3.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""Logging infrastructure for Runtime Memory.
|
|
2
|
+
|
|
3
|
+
Provides structured logging with support for both console and JSON output formats.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import logging
|
|
10
|
+
import sys
|
|
11
|
+
from datetime import UTC, datetime
|
|
12
|
+
from typing import Any, ClassVar
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class JSONFormatter(logging.Formatter):
|
|
16
|
+
"""JSON formatter for structured logging output."""
|
|
17
|
+
|
|
18
|
+
def format(self, record: logging.LogRecord) -> str:
|
|
19
|
+
"""Format log record as JSON."""
|
|
20
|
+
log_data: dict[str, Any] = {
|
|
21
|
+
"timestamp": datetime.now(UTC).isoformat(),
|
|
22
|
+
"level": record.levelname,
|
|
23
|
+
"logger": record.name,
|
|
24
|
+
"message": record.getMessage(),
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if record.exc_info:
|
|
28
|
+
log_data["exception"] = self.formatException(record.exc_info)
|
|
29
|
+
|
|
30
|
+
if hasattr(record, "extra"):
|
|
31
|
+
log_data["extra"] = record.extra
|
|
32
|
+
|
|
33
|
+
return json.dumps(log_data)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ConsoleFormatter(logging.Formatter):
|
|
37
|
+
"""Console formatter with color support."""
|
|
38
|
+
|
|
39
|
+
COLORS: ClassVar[dict[str, str]] = {
|
|
40
|
+
"DEBUG": "\033[36m", # Cyan
|
|
41
|
+
"INFO": "\033[32m", # Green
|
|
42
|
+
"WARNING": "\033[33m", # Yellow
|
|
43
|
+
"ERROR": "\033[31m", # Red
|
|
44
|
+
"CRITICAL": "\033[35m", # Magenta
|
|
45
|
+
}
|
|
46
|
+
RESET: ClassVar[str] = "\033[0m"
|
|
47
|
+
|
|
48
|
+
def __init__(self, use_colors: bool = True) -> None:
|
|
49
|
+
"""Initialize formatter.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
use_colors: Whether to use ANSI color codes in output.
|
|
53
|
+
"""
|
|
54
|
+
super().__init__()
|
|
55
|
+
self.use_colors = use_colors and sys.stderr.isatty()
|
|
56
|
+
|
|
57
|
+
def format(self, record: logging.LogRecord) -> str:
|
|
58
|
+
"""Format log record for console output."""
|
|
59
|
+
timestamp = datetime.now(UTC).strftime("%Y-%m-%d %H:%M:%S")
|
|
60
|
+
level = record.levelname
|
|
61
|
+
|
|
62
|
+
if self.use_colors:
|
|
63
|
+
color = self.COLORS.get(level, "")
|
|
64
|
+
level_str = f"{color}{level:8}{self.RESET}"
|
|
65
|
+
else:
|
|
66
|
+
level_str = f"{level:8}"
|
|
67
|
+
|
|
68
|
+
message = record.getMessage()
|
|
69
|
+
formatted = f"{timestamp} | {level_str} | {record.name} | {message}"
|
|
70
|
+
|
|
71
|
+
if record.exc_info:
|
|
72
|
+
formatted += "\n" + self.formatException(record.exc_info)
|
|
73
|
+
|
|
74
|
+
return formatted
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def setup_logging(
|
|
78
|
+
level: int | str = logging.INFO,
|
|
79
|
+
json_output: bool = False,
|
|
80
|
+
log_file: str | None = None,
|
|
81
|
+
) -> logging.Logger:
|
|
82
|
+
"""Configure logging for Runtime Memory.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
level: Logging level (e.g., logging.INFO, "DEBUG").
|
|
86
|
+
json_output: If True, use JSON format for output.
|
|
87
|
+
log_file: Optional path to log file.
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
Configured root logger for runtime_memory.
|
|
91
|
+
"""
|
|
92
|
+
logger = logging.getLogger("runtime_memory")
|
|
93
|
+
|
|
94
|
+
if isinstance(level, str):
|
|
95
|
+
level = getattr(logging, level.upper(), logging.INFO)
|
|
96
|
+
|
|
97
|
+
logger.setLevel(level)
|
|
98
|
+
|
|
99
|
+
# Remove existing handlers
|
|
100
|
+
logger.handlers.clear()
|
|
101
|
+
|
|
102
|
+
# Console handler
|
|
103
|
+
console_handler = logging.StreamHandler(sys.stderr)
|
|
104
|
+
console_handler.setLevel(level)
|
|
105
|
+
|
|
106
|
+
if json_output:
|
|
107
|
+
console_handler.setFormatter(JSONFormatter())
|
|
108
|
+
else:
|
|
109
|
+
console_handler.setFormatter(ConsoleFormatter())
|
|
110
|
+
|
|
111
|
+
logger.addHandler(console_handler)
|
|
112
|
+
|
|
113
|
+
# File handler (optional)
|
|
114
|
+
if log_file:
|
|
115
|
+
file_handler = logging.FileHandler(log_file)
|
|
116
|
+
file_handler.setLevel(level)
|
|
117
|
+
file_handler.setFormatter(JSONFormatter())
|
|
118
|
+
logger.addHandler(file_handler)
|
|
119
|
+
|
|
120
|
+
# Prevent propagation to root logger
|
|
121
|
+
logger.propagate = False
|
|
122
|
+
|
|
123
|
+
return logger
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def get_logger(name: str) -> logging.Logger:
|
|
127
|
+
"""Get a logger instance for a specific module.
|
|
128
|
+
|
|
129
|
+
Callers pass ``__name__``, which inside this package already starts with
|
|
130
|
+
``runtime_memory``. Prefixing unconditionally produced names like
|
|
131
|
+
``runtime_memory.runtime_memory.core.embeddings``, which is what users saw in
|
|
132
|
+
every log line. Names from outside the package still get the prefix, so
|
|
133
|
+
``setup_logging`` keeps one place to attach handlers.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
name: Module name (typically __name__).
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
Logger instance.
|
|
140
|
+
"""
|
|
141
|
+
if name == "runtime_memory" or name.startswith("runtime_memory."):
|
|
142
|
+
return logging.getLogger(name)
|
|
143
|
+
return logging.getLogger(f"runtime_memory.{name}")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class _DefaultLoggerHolder:
|
|
147
|
+
"""Holder for the default logger to avoid global statement."""
|
|
148
|
+
|
|
149
|
+
logger: logging.Logger | None = None
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def get_default_logger() -> logging.Logger:
|
|
153
|
+
"""Get or create the default Runtime Memory logger.
|
|
154
|
+
|
|
155
|
+
Returns:
|
|
156
|
+
Default logger instance.
|
|
157
|
+
"""
|
|
158
|
+
if _DefaultLoggerHolder.logger is None:
|
|
159
|
+
_DefaultLoggerHolder.logger = setup_logging()
|
|
160
|
+
return _DefaultLoggerHolder.logger
|