alma-memory 0.5.0__py3-none-any.whl → 0.7.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.
- alma/__init__.py +296 -194
- alma/compression/__init__.py +33 -0
- alma/compression/pipeline.py +980 -0
- alma/confidence/__init__.py +47 -47
- alma/confidence/engine.py +540 -540
- alma/confidence/types.py +351 -351
- alma/config/loader.py +157 -157
- alma/consolidation/__init__.py +23 -23
- alma/consolidation/engine.py +678 -678
- alma/consolidation/prompts.py +84 -84
- alma/core.py +1189 -322
- alma/domains/__init__.py +30 -30
- alma/domains/factory.py +359 -359
- alma/domains/schemas.py +448 -448
- alma/domains/types.py +272 -272
- alma/events/__init__.py +75 -75
- alma/events/emitter.py +285 -284
- alma/events/storage_mixin.py +246 -246
- alma/events/types.py +126 -126
- alma/events/webhook.py +425 -425
- alma/exceptions.py +49 -49
- alma/extraction/__init__.py +31 -31
- alma/extraction/auto_learner.py +265 -264
- alma/extraction/extractor.py +420 -420
- alma/graph/__init__.py +106 -81
- alma/graph/backends/__init__.py +32 -18
- alma/graph/backends/kuzu.py +624 -0
- alma/graph/backends/memgraph.py +432 -0
- alma/graph/backends/memory.py +236 -236
- alma/graph/backends/neo4j.py +417 -417
- alma/graph/base.py +159 -159
- alma/graph/extraction.py +198 -198
- alma/graph/store.py +860 -860
- alma/harness/__init__.py +35 -35
- alma/harness/base.py +386 -386
- alma/harness/domains.py +705 -705
- alma/initializer/__init__.py +37 -37
- alma/initializer/initializer.py +418 -418
- alma/initializer/types.py +250 -250
- alma/integration/__init__.py +62 -62
- alma/integration/claude_agents.py +444 -432
- alma/integration/helena.py +423 -423
- alma/integration/victor.py +471 -471
- alma/learning/__init__.py +101 -86
- alma/learning/decay.py +878 -0
- alma/learning/forgetting.py +1446 -1446
- alma/learning/heuristic_extractor.py +390 -390
- alma/learning/protocols.py +374 -374
- alma/learning/validation.py +346 -346
- alma/mcp/__init__.py +123 -45
- alma/mcp/__main__.py +156 -156
- alma/mcp/resources.py +122 -122
- alma/mcp/server.py +955 -591
- alma/mcp/tools.py +3254 -511
- alma/observability/__init__.py +91 -0
- alma/observability/config.py +302 -0
- alma/observability/guidelines.py +170 -0
- alma/observability/logging.py +424 -0
- alma/observability/metrics.py +583 -0
- alma/observability/tracing.py +440 -0
- alma/progress/__init__.py +21 -21
- alma/progress/tracker.py +607 -607
- alma/progress/types.py +250 -250
- alma/retrieval/__init__.py +134 -53
- alma/retrieval/budget.py +525 -0
- alma/retrieval/cache.py +1304 -1061
- alma/retrieval/embeddings.py +202 -202
- alma/retrieval/engine.py +850 -366
- alma/retrieval/modes.py +365 -0
- alma/retrieval/progressive.py +560 -0
- alma/retrieval/scoring.py +344 -344
- alma/retrieval/trust_scoring.py +637 -0
- alma/retrieval/verification.py +797 -0
- alma/session/__init__.py +19 -19
- alma/session/manager.py +442 -399
- alma/session/types.py +288 -288
- alma/storage/__init__.py +101 -61
- alma/storage/archive.py +233 -0
- alma/storage/azure_cosmos.py +1259 -1048
- alma/storage/base.py +1083 -525
- alma/storage/chroma.py +1443 -1443
- alma/storage/constants.py +103 -0
- alma/storage/file_based.py +614 -619
- alma/storage/migrations/__init__.py +21 -0
- alma/storage/migrations/base.py +321 -0
- alma/storage/migrations/runner.py +323 -0
- alma/storage/migrations/version_stores.py +337 -0
- alma/storage/migrations/versions/__init__.py +11 -0
- alma/storage/migrations/versions/v1_0_0.py +373 -0
- alma/storage/migrations/versions/v1_1_0_workflow_context.py +551 -0
- alma/storage/pinecone.py +1080 -1080
- alma/storage/postgresql.py +1948 -1452
- alma/storage/qdrant.py +1306 -1306
- alma/storage/sqlite_local.py +3041 -1358
- alma/testing/__init__.py +46 -0
- alma/testing/factories.py +301 -0
- alma/testing/mocks.py +389 -0
- alma/types.py +292 -264
- alma/utils/__init__.py +19 -0
- alma/utils/tokenizer.py +521 -0
- alma/workflow/__init__.py +83 -0
- alma/workflow/artifacts.py +170 -0
- alma/workflow/checkpoint.py +311 -0
- alma/workflow/context.py +228 -0
- alma/workflow/outcomes.py +189 -0
- alma/workflow/reducers.py +393 -0
- {alma_memory-0.5.0.dist-info → alma_memory-0.7.0.dist-info}/METADATA +244 -72
- alma_memory-0.7.0.dist-info/RECORD +112 -0
- alma_memory-0.5.0.dist-info/RECORD +0 -76
- {alma_memory-0.5.0.dist-info → alma_memory-0.7.0.dist-info}/WHEEL +0 -0
- {alma_memory-0.5.0.dist-info → alma_memory-0.7.0.dist-info}/top_level.txt +0 -0
alma/progress/types.py
CHANGED
|
@@ -1,250 +1,250 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Progress Tracking Types.
|
|
3
|
-
|
|
4
|
-
Data models for tracking work items and progress.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import uuid
|
|
8
|
-
from dataclasses import dataclass, field
|
|
9
|
-
from datetime import datetime, timezone
|
|
10
|
-
from typing import Any, Dict, List, Literal, Optional
|
|
11
|
-
|
|
12
|
-
WorkItemStatus = Literal[
|
|
13
|
-
"pending", # Not started
|
|
14
|
-
"in_progress", # Currently being worked on
|
|
15
|
-
"blocked", # Waiting on something
|
|
16
|
-
"review", # Completed, awaiting review
|
|
17
|
-
"done", # Completed and verified
|
|
18
|
-
"failed", # Could not complete
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@dataclass
|
|
23
|
-
class WorkItem:
|
|
24
|
-
"""
|
|
25
|
-
A trackable unit of work.
|
|
26
|
-
|
|
27
|
-
Can represent features, bugs, tasks, research questions,
|
|
28
|
-
or any domain-specific work unit.
|
|
29
|
-
"""
|
|
30
|
-
|
|
31
|
-
id: str
|
|
32
|
-
project_id: str
|
|
33
|
-
agent: Optional[str]
|
|
34
|
-
|
|
35
|
-
# Work item details
|
|
36
|
-
title: str
|
|
37
|
-
description: str
|
|
38
|
-
item_type: str # "feature", "bug", "task", "research_question", etc.
|
|
39
|
-
status: WorkItemStatus = "pending"
|
|
40
|
-
priority: int = 50 # 0-100, higher = more important
|
|
41
|
-
|
|
42
|
-
# Progress tracking
|
|
43
|
-
started_at: Optional[datetime] = None
|
|
44
|
-
completed_at: Optional[datetime] = None
|
|
45
|
-
time_spent_ms: int = 0
|
|
46
|
-
attempt_count: int = 0
|
|
47
|
-
|
|
48
|
-
# Relationships
|
|
49
|
-
parent_id: Optional[str] = None
|
|
50
|
-
blocks: List[str] = field(default_factory=list)
|
|
51
|
-
blocked_by: List[str] = field(default_factory=list)
|
|
52
|
-
|
|
53
|
-
# Validation
|
|
54
|
-
tests: List[str] = field(default_factory=list)
|
|
55
|
-
tests_passing: bool = False
|
|
56
|
-
acceptance_criteria: List[str] = field(default_factory=list)
|
|
57
|
-
|
|
58
|
-
# Timestamps
|
|
59
|
-
created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
|
60
|
-
updated_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
|
61
|
-
|
|
62
|
-
# Extensible metadata
|
|
63
|
-
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
64
|
-
|
|
65
|
-
@classmethod
|
|
66
|
-
def create(
|
|
67
|
-
cls,
|
|
68
|
-
project_id: str,
|
|
69
|
-
title: str,
|
|
70
|
-
description: str,
|
|
71
|
-
item_type: str = "task",
|
|
72
|
-
agent: Optional[str] = None,
|
|
73
|
-
priority: int = 50,
|
|
74
|
-
parent_id: Optional[str] = None,
|
|
75
|
-
**kwargs,
|
|
76
|
-
) -> "WorkItem":
|
|
77
|
-
"""Factory method to create a new work item."""
|
|
78
|
-
return cls(
|
|
79
|
-
id=str(uuid.uuid4()),
|
|
80
|
-
project_id=project_id,
|
|
81
|
-
agent=agent,
|
|
82
|
-
title=title,
|
|
83
|
-
description=description,
|
|
84
|
-
item_type=item_type,
|
|
85
|
-
priority=priority,
|
|
86
|
-
parent_id=parent_id,
|
|
87
|
-
**kwargs,
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
def start(self) -> None:
|
|
91
|
-
"""Mark work item as started."""
|
|
92
|
-
self.status = "in_progress"
|
|
93
|
-
self.started_at = datetime.now(timezone.utc)
|
|
94
|
-
self.attempt_count += 1
|
|
95
|
-
self.updated_at = datetime.now(timezone.utc)
|
|
96
|
-
|
|
97
|
-
def complete(self, tests_passing: bool = True) -> None:
|
|
98
|
-
"""Mark work item as completed."""
|
|
99
|
-
self.status = "done"
|
|
100
|
-
self.completed_at = datetime.now(timezone.utc)
|
|
101
|
-
self.tests_passing = tests_passing
|
|
102
|
-
if self.started_at:
|
|
103
|
-
self.time_spent_ms += int(
|
|
104
|
-
(self.completed_at - self.started_at).total_seconds() * 1000
|
|
105
|
-
)
|
|
106
|
-
self.updated_at = datetime.now(timezone.utc)
|
|
107
|
-
|
|
108
|
-
def block(self, blocked_by: Optional[str] = None, reason: str = "") -> None:
|
|
109
|
-
"""Mark work item as blocked."""
|
|
110
|
-
self.status = "blocked"
|
|
111
|
-
if blocked_by:
|
|
112
|
-
self.blocked_by.append(blocked_by)
|
|
113
|
-
if reason:
|
|
114
|
-
self.metadata["block_reason"] = reason
|
|
115
|
-
self.updated_at = datetime.now(timezone.utc)
|
|
116
|
-
|
|
117
|
-
def fail(self, reason: str = "") -> None:
|
|
118
|
-
"""Mark work item as failed."""
|
|
119
|
-
self.status = "failed"
|
|
120
|
-
if reason:
|
|
121
|
-
self.metadata["failure_reason"] = reason
|
|
122
|
-
self.updated_at = datetime.now(timezone.utc)
|
|
123
|
-
|
|
124
|
-
def is_actionable(self) -> bool:
|
|
125
|
-
"""Check if work item can be worked on."""
|
|
126
|
-
return self.status in ("pending", "in_progress") and len(self.blocked_by) == 0
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
@dataclass
|
|
130
|
-
class ProgressLog:
|
|
131
|
-
"""
|
|
132
|
-
Session-level progress snapshot.
|
|
133
|
-
|
|
134
|
-
Records the state of progress at a point in time.
|
|
135
|
-
"""
|
|
136
|
-
|
|
137
|
-
id: str
|
|
138
|
-
project_id: str
|
|
139
|
-
agent: str
|
|
140
|
-
session_id: str
|
|
141
|
-
|
|
142
|
-
# Progress counts
|
|
143
|
-
items_total: int
|
|
144
|
-
items_done: int
|
|
145
|
-
items_in_progress: int
|
|
146
|
-
items_blocked: int
|
|
147
|
-
items_pending: int
|
|
148
|
-
|
|
149
|
-
# Current focus
|
|
150
|
-
current_item_id: Optional[str]
|
|
151
|
-
current_action: str
|
|
152
|
-
|
|
153
|
-
# Session metrics
|
|
154
|
-
session_start: datetime
|
|
155
|
-
actions_taken: int = 0
|
|
156
|
-
outcomes_recorded: int = 0
|
|
157
|
-
|
|
158
|
-
# Timestamp
|
|
159
|
-
created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
|
160
|
-
|
|
161
|
-
@classmethod
|
|
162
|
-
def create(
|
|
163
|
-
cls,
|
|
164
|
-
project_id: str,
|
|
165
|
-
agent: str,
|
|
166
|
-
session_id: str,
|
|
167
|
-
items_total: int,
|
|
168
|
-
items_done: int,
|
|
169
|
-
items_in_progress: int,
|
|
170
|
-
items_blocked: int,
|
|
171
|
-
items_pending: int,
|
|
172
|
-
current_item_id: Optional[str] = None,
|
|
173
|
-
current_action: str = "",
|
|
174
|
-
session_start: Optional[datetime] = None,
|
|
175
|
-
) -> "ProgressLog":
|
|
176
|
-
"""Factory method to create progress log."""
|
|
177
|
-
return cls(
|
|
178
|
-
id=str(uuid.uuid4()),
|
|
179
|
-
project_id=project_id,
|
|
180
|
-
agent=agent,
|
|
181
|
-
session_id=session_id,
|
|
182
|
-
items_total=items_total,
|
|
183
|
-
items_done=items_done,
|
|
184
|
-
items_in_progress=items_in_progress,
|
|
185
|
-
items_blocked=items_blocked,
|
|
186
|
-
items_pending=items_pending,
|
|
187
|
-
current_item_id=current_item_id,
|
|
188
|
-
current_action=current_action,
|
|
189
|
-
session_start=session_start or datetime.now(timezone.utc),
|
|
190
|
-
)
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
@dataclass
|
|
194
|
-
class ProgressSummary:
|
|
195
|
-
"""
|
|
196
|
-
Summary of progress for display/reporting.
|
|
197
|
-
|
|
198
|
-
A simplified view of progress state.
|
|
199
|
-
"""
|
|
200
|
-
|
|
201
|
-
project_id: str
|
|
202
|
-
agent: Optional[str]
|
|
203
|
-
|
|
204
|
-
# Counts
|
|
205
|
-
total: int
|
|
206
|
-
done: int
|
|
207
|
-
in_progress: int
|
|
208
|
-
blocked: int
|
|
209
|
-
pending: int
|
|
210
|
-
failed: int
|
|
211
|
-
|
|
212
|
-
# Percentages
|
|
213
|
-
completion_rate: float # 0-1
|
|
214
|
-
success_rate: float # done / (done + failed)
|
|
215
|
-
|
|
216
|
-
# Current focus
|
|
217
|
-
current_item: Optional[WorkItem]
|
|
218
|
-
next_suggested: Optional[WorkItem]
|
|
219
|
-
|
|
220
|
-
# Blockers
|
|
221
|
-
blockers: List[WorkItem]
|
|
222
|
-
|
|
223
|
-
# Time tracking
|
|
224
|
-
total_time_ms: int
|
|
225
|
-
avg_time_per_item_ms: float
|
|
226
|
-
|
|
227
|
-
# Timestamps
|
|
228
|
-
last_activity: Optional[datetime]
|
|
229
|
-
generated_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
|
230
|
-
|
|
231
|
-
@property
|
|
232
|
-
def completion_percentage(self) -> int:
|
|
233
|
-
"""Get completion as percentage."""
|
|
234
|
-
return int(self.completion_rate * 100)
|
|
235
|
-
|
|
236
|
-
def format_summary(self) -> str:
|
|
237
|
-
"""Format as human-readable string."""
|
|
238
|
-
lines = [
|
|
239
|
-
f"Progress: {self.done}/{self.total} ({self.completion_percentage}%)",
|
|
240
|
-
f" In Progress: {self.in_progress}",
|
|
241
|
-
f" Blocked: {self.blocked}",
|
|
242
|
-
f" Pending: {self.pending}",
|
|
243
|
-
]
|
|
244
|
-
if self.current_item:
|
|
245
|
-
lines.append(f" Current: {self.current_item.title}")
|
|
246
|
-
if self.next_suggested:
|
|
247
|
-
lines.append(f" Next: {self.next_suggested.title}")
|
|
248
|
-
if self.blockers:
|
|
249
|
-
lines.append(f" Blockers: {len(self.blockers)} items")
|
|
250
|
-
return "\n".join(lines)
|
|
1
|
+
"""
|
|
2
|
+
Progress Tracking Types.
|
|
3
|
+
|
|
4
|
+
Data models for tracking work items and progress.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import uuid
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
from datetime import datetime, timezone
|
|
10
|
+
from typing import Any, Dict, List, Literal, Optional
|
|
11
|
+
|
|
12
|
+
WorkItemStatus = Literal[
|
|
13
|
+
"pending", # Not started
|
|
14
|
+
"in_progress", # Currently being worked on
|
|
15
|
+
"blocked", # Waiting on something
|
|
16
|
+
"review", # Completed, awaiting review
|
|
17
|
+
"done", # Completed and verified
|
|
18
|
+
"failed", # Could not complete
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class WorkItem:
|
|
24
|
+
"""
|
|
25
|
+
A trackable unit of work.
|
|
26
|
+
|
|
27
|
+
Can represent features, bugs, tasks, research questions,
|
|
28
|
+
or any domain-specific work unit.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
id: str
|
|
32
|
+
project_id: str
|
|
33
|
+
agent: Optional[str]
|
|
34
|
+
|
|
35
|
+
# Work item details
|
|
36
|
+
title: str
|
|
37
|
+
description: str
|
|
38
|
+
item_type: str # "feature", "bug", "task", "research_question", etc.
|
|
39
|
+
status: WorkItemStatus = "pending"
|
|
40
|
+
priority: int = 50 # 0-100, higher = more important
|
|
41
|
+
|
|
42
|
+
# Progress tracking
|
|
43
|
+
started_at: Optional[datetime] = None
|
|
44
|
+
completed_at: Optional[datetime] = None
|
|
45
|
+
time_spent_ms: int = 0
|
|
46
|
+
attempt_count: int = 0
|
|
47
|
+
|
|
48
|
+
# Relationships
|
|
49
|
+
parent_id: Optional[str] = None
|
|
50
|
+
blocks: List[str] = field(default_factory=list)
|
|
51
|
+
blocked_by: List[str] = field(default_factory=list)
|
|
52
|
+
|
|
53
|
+
# Validation
|
|
54
|
+
tests: List[str] = field(default_factory=list)
|
|
55
|
+
tests_passing: bool = False
|
|
56
|
+
acceptance_criteria: List[str] = field(default_factory=list)
|
|
57
|
+
|
|
58
|
+
# Timestamps
|
|
59
|
+
created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
|
60
|
+
updated_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
|
61
|
+
|
|
62
|
+
# Extensible metadata
|
|
63
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def create(
|
|
67
|
+
cls,
|
|
68
|
+
project_id: str,
|
|
69
|
+
title: str,
|
|
70
|
+
description: str,
|
|
71
|
+
item_type: str = "task",
|
|
72
|
+
agent: Optional[str] = None,
|
|
73
|
+
priority: int = 50,
|
|
74
|
+
parent_id: Optional[str] = None,
|
|
75
|
+
**kwargs,
|
|
76
|
+
) -> "WorkItem":
|
|
77
|
+
"""Factory method to create a new work item."""
|
|
78
|
+
return cls(
|
|
79
|
+
id=str(uuid.uuid4()),
|
|
80
|
+
project_id=project_id,
|
|
81
|
+
agent=agent,
|
|
82
|
+
title=title,
|
|
83
|
+
description=description,
|
|
84
|
+
item_type=item_type,
|
|
85
|
+
priority=priority,
|
|
86
|
+
parent_id=parent_id,
|
|
87
|
+
**kwargs,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
def start(self) -> None:
|
|
91
|
+
"""Mark work item as started."""
|
|
92
|
+
self.status = "in_progress"
|
|
93
|
+
self.started_at = datetime.now(timezone.utc)
|
|
94
|
+
self.attempt_count += 1
|
|
95
|
+
self.updated_at = datetime.now(timezone.utc)
|
|
96
|
+
|
|
97
|
+
def complete(self, tests_passing: bool = True) -> None:
|
|
98
|
+
"""Mark work item as completed."""
|
|
99
|
+
self.status = "done"
|
|
100
|
+
self.completed_at = datetime.now(timezone.utc)
|
|
101
|
+
self.tests_passing = tests_passing
|
|
102
|
+
if self.started_at:
|
|
103
|
+
self.time_spent_ms += int(
|
|
104
|
+
(self.completed_at - self.started_at).total_seconds() * 1000
|
|
105
|
+
)
|
|
106
|
+
self.updated_at = datetime.now(timezone.utc)
|
|
107
|
+
|
|
108
|
+
def block(self, blocked_by: Optional[str] = None, reason: str = "") -> None:
|
|
109
|
+
"""Mark work item as blocked."""
|
|
110
|
+
self.status = "blocked"
|
|
111
|
+
if blocked_by:
|
|
112
|
+
self.blocked_by.append(blocked_by)
|
|
113
|
+
if reason:
|
|
114
|
+
self.metadata["block_reason"] = reason
|
|
115
|
+
self.updated_at = datetime.now(timezone.utc)
|
|
116
|
+
|
|
117
|
+
def fail(self, reason: str = "") -> None:
|
|
118
|
+
"""Mark work item as failed."""
|
|
119
|
+
self.status = "failed"
|
|
120
|
+
if reason:
|
|
121
|
+
self.metadata["failure_reason"] = reason
|
|
122
|
+
self.updated_at = datetime.now(timezone.utc)
|
|
123
|
+
|
|
124
|
+
def is_actionable(self) -> bool:
|
|
125
|
+
"""Check if work item can be worked on."""
|
|
126
|
+
return self.status in ("pending", "in_progress") and len(self.blocked_by) == 0
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@dataclass
|
|
130
|
+
class ProgressLog:
|
|
131
|
+
"""
|
|
132
|
+
Session-level progress snapshot.
|
|
133
|
+
|
|
134
|
+
Records the state of progress at a point in time.
|
|
135
|
+
"""
|
|
136
|
+
|
|
137
|
+
id: str
|
|
138
|
+
project_id: str
|
|
139
|
+
agent: str
|
|
140
|
+
session_id: str
|
|
141
|
+
|
|
142
|
+
# Progress counts
|
|
143
|
+
items_total: int
|
|
144
|
+
items_done: int
|
|
145
|
+
items_in_progress: int
|
|
146
|
+
items_blocked: int
|
|
147
|
+
items_pending: int
|
|
148
|
+
|
|
149
|
+
# Current focus
|
|
150
|
+
current_item_id: Optional[str]
|
|
151
|
+
current_action: str
|
|
152
|
+
|
|
153
|
+
# Session metrics
|
|
154
|
+
session_start: datetime
|
|
155
|
+
actions_taken: int = 0
|
|
156
|
+
outcomes_recorded: int = 0
|
|
157
|
+
|
|
158
|
+
# Timestamp
|
|
159
|
+
created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
|
160
|
+
|
|
161
|
+
@classmethod
|
|
162
|
+
def create(
|
|
163
|
+
cls,
|
|
164
|
+
project_id: str,
|
|
165
|
+
agent: str,
|
|
166
|
+
session_id: str,
|
|
167
|
+
items_total: int,
|
|
168
|
+
items_done: int,
|
|
169
|
+
items_in_progress: int,
|
|
170
|
+
items_blocked: int,
|
|
171
|
+
items_pending: int,
|
|
172
|
+
current_item_id: Optional[str] = None,
|
|
173
|
+
current_action: str = "",
|
|
174
|
+
session_start: Optional[datetime] = None,
|
|
175
|
+
) -> "ProgressLog":
|
|
176
|
+
"""Factory method to create progress log."""
|
|
177
|
+
return cls(
|
|
178
|
+
id=str(uuid.uuid4()),
|
|
179
|
+
project_id=project_id,
|
|
180
|
+
agent=agent,
|
|
181
|
+
session_id=session_id,
|
|
182
|
+
items_total=items_total,
|
|
183
|
+
items_done=items_done,
|
|
184
|
+
items_in_progress=items_in_progress,
|
|
185
|
+
items_blocked=items_blocked,
|
|
186
|
+
items_pending=items_pending,
|
|
187
|
+
current_item_id=current_item_id,
|
|
188
|
+
current_action=current_action,
|
|
189
|
+
session_start=session_start or datetime.now(timezone.utc),
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
@dataclass
|
|
194
|
+
class ProgressSummary:
|
|
195
|
+
"""
|
|
196
|
+
Summary of progress for display/reporting.
|
|
197
|
+
|
|
198
|
+
A simplified view of progress state.
|
|
199
|
+
"""
|
|
200
|
+
|
|
201
|
+
project_id: str
|
|
202
|
+
agent: Optional[str]
|
|
203
|
+
|
|
204
|
+
# Counts
|
|
205
|
+
total: int
|
|
206
|
+
done: int
|
|
207
|
+
in_progress: int
|
|
208
|
+
blocked: int
|
|
209
|
+
pending: int
|
|
210
|
+
failed: int
|
|
211
|
+
|
|
212
|
+
# Percentages
|
|
213
|
+
completion_rate: float # 0-1
|
|
214
|
+
success_rate: float # done / (done + failed)
|
|
215
|
+
|
|
216
|
+
# Current focus
|
|
217
|
+
current_item: Optional[WorkItem]
|
|
218
|
+
next_suggested: Optional[WorkItem]
|
|
219
|
+
|
|
220
|
+
# Blockers
|
|
221
|
+
blockers: List[WorkItem]
|
|
222
|
+
|
|
223
|
+
# Time tracking
|
|
224
|
+
total_time_ms: int
|
|
225
|
+
avg_time_per_item_ms: float
|
|
226
|
+
|
|
227
|
+
# Timestamps
|
|
228
|
+
last_activity: Optional[datetime]
|
|
229
|
+
generated_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
|
230
|
+
|
|
231
|
+
@property
|
|
232
|
+
def completion_percentage(self) -> int:
|
|
233
|
+
"""Get completion as percentage."""
|
|
234
|
+
return int(self.completion_rate * 100)
|
|
235
|
+
|
|
236
|
+
def format_summary(self) -> str:
|
|
237
|
+
"""Format as human-readable string."""
|
|
238
|
+
lines = [
|
|
239
|
+
f"Progress: {self.done}/{self.total} ({self.completion_percentage}%)",
|
|
240
|
+
f" In Progress: {self.in_progress}",
|
|
241
|
+
f" Blocked: {self.blocked}",
|
|
242
|
+
f" Pending: {self.pending}",
|
|
243
|
+
]
|
|
244
|
+
if self.current_item:
|
|
245
|
+
lines.append(f" Current: {self.current_item.title}")
|
|
246
|
+
if self.next_suggested:
|
|
247
|
+
lines.append(f" Next: {self.next_suggested.title}")
|
|
248
|
+
if self.blockers:
|
|
249
|
+
lines.append(f" Blockers: {len(self.blockers)} items")
|
|
250
|
+
return "\n".join(lines)
|
alma/retrieval/__init__.py
CHANGED
|
@@ -1,53 +1,134 @@
|
|
|
1
|
-
"""
|
|
2
|
-
ALMA Retrieval Engine.
|
|
3
|
-
|
|
4
|
-
Provides semantic search, scoring, and caching for memory retrieval.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
"""
|
|
2
|
+
ALMA Retrieval Engine.
|
|
3
|
+
|
|
4
|
+
Provides semantic search, scoring, and caching for memory retrieval.
|
|
5
|
+
Supports mode-aware retrieval for different cognitive tasks.
|
|
6
|
+
Includes token budget management, trust-integrated scoring, and progressive disclosure.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from alma.retrieval.budget import (
|
|
10
|
+
BudgetedItem,
|
|
11
|
+
BudgetReport,
|
|
12
|
+
PriorityTier,
|
|
13
|
+
RetrievalBudget,
|
|
14
|
+
TokenEstimator,
|
|
15
|
+
)
|
|
16
|
+
from alma.retrieval.cache import (
|
|
17
|
+
CacheBackend,
|
|
18
|
+
CacheEntry,
|
|
19
|
+
CacheKeyGenerator,
|
|
20
|
+
CacheStats,
|
|
21
|
+
NullCache,
|
|
22
|
+
PerformanceMetrics,
|
|
23
|
+
RedisCache,
|
|
24
|
+
RetrievalCache,
|
|
25
|
+
create_cache,
|
|
26
|
+
)
|
|
27
|
+
from alma.retrieval.embeddings import (
|
|
28
|
+
AzureEmbedder,
|
|
29
|
+
EmbeddingProvider,
|
|
30
|
+
LocalEmbedder,
|
|
31
|
+
MockEmbedder,
|
|
32
|
+
)
|
|
33
|
+
from alma.retrieval.engine import RetrievalEngine
|
|
34
|
+
from alma.retrieval.modes import (
|
|
35
|
+
ModeConfig,
|
|
36
|
+
RetrievalMode,
|
|
37
|
+
create_custom_mode,
|
|
38
|
+
get_mode_config,
|
|
39
|
+
get_mode_reason,
|
|
40
|
+
infer_mode_from_query,
|
|
41
|
+
validate_mode_config,
|
|
42
|
+
)
|
|
43
|
+
from alma.retrieval.progressive import (
|
|
44
|
+
DisclosureLevel,
|
|
45
|
+
MemorySummary,
|
|
46
|
+
ProgressiveRetrieval,
|
|
47
|
+
ProgressiveSlice,
|
|
48
|
+
)
|
|
49
|
+
from alma.retrieval.scoring import (
|
|
50
|
+
MemoryScorer,
|
|
51
|
+
ScoredItem,
|
|
52
|
+
ScoringWeights,
|
|
53
|
+
compute_composite_score,
|
|
54
|
+
)
|
|
55
|
+
from alma.retrieval.trust_scoring import (
|
|
56
|
+
AgentTrustContext,
|
|
57
|
+
AgentTrustProfile,
|
|
58
|
+
TrustAwareScorer,
|
|
59
|
+
TrustLevel,
|
|
60
|
+
TrustPatternStore,
|
|
61
|
+
TrustScoredItem,
|
|
62
|
+
TrustWeights,
|
|
63
|
+
)
|
|
64
|
+
from alma.retrieval.verification import (
|
|
65
|
+
Verification,
|
|
66
|
+
VerificationConfig,
|
|
67
|
+
VerificationMethod,
|
|
68
|
+
VerificationStatus,
|
|
69
|
+
VerifiedMemory,
|
|
70
|
+
VerifiedResults,
|
|
71
|
+
VerifiedRetriever,
|
|
72
|
+
create_verified_retriever,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
__all__ = [
|
|
76
|
+
# Engine
|
|
77
|
+
"RetrievalEngine",
|
|
78
|
+
# Modes
|
|
79
|
+
"RetrievalMode",
|
|
80
|
+
"ModeConfig",
|
|
81
|
+
"infer_mode_from_query",
|
|
82
|
+
"get_mode_config",
|
|
83
|
+
"get_mode_reason",
|
|
84
|
+
"create_custom_mode",
|
|
85
|
+
"validate_mode_config",
|
|
86
|
+
# Scoring
|
|
87
|
+
"MemoryScorer",
|
|
88
|
+
"ScoringWeights",
|
|
89
|
+
"ScoredItem",
|
|
90
|
+
"compute_composite_score",
|
|
91
|
+
# Trust-Integrated Scoring (v0.8.0+)
|
|
92
|
+
"TrustAwareScorer",
|
|
93
|
+
"TrustWeights",
|
|
94
|
+
"TrustScoredItem",
|
|
95
|
+
"TrustLevel",
|
|
96
|
+
"AgentTrustProfile",
|
|
97
|
+
"AgentTrustContext",
|
|
98
|
+
"TrustPatternStore",
|
|
99
|
+
# Token Budget (v0.8.0+)
|
|
100
|
+
"PriorityTier",
|
|
101
|
+
"TokenEstimator",
|
|
102
|
+
"BudgetedItem",
|
|
103
|
+
"BudgetReport",
|
|
104
|
+
"RetrievalBudget",
|
|
105
|
+
# Progressive Disclosure (v0.8.0+)
|
|
106
|
+
"DisclosureLevel",
|
|
107
|
+
"MemorySummary",
|
|
108
|
+
"ProgressiveSlice",
|
|
109
|
+
"ProgressiveRetrieval",
|
|
110
|
+
# Cache
|
|
111
|
+
"CacheBackend",
|
|
112
|
+
"CacheKeyGenerator",
|
|
113
|
+
"RetrievalCache",
|
|
114
|
+
"RedisCache",
|
|
115
|
+
"NullCache",
|
|
116
|
+
"CacheEntry",
|
|
117
|
+
"CacheStats",
|
|
118
|
+
"PerformanceMetrics",
|
|
119
|
+
"create_cache",
|
|
120
|
+
# Embeddings
|
|
121
|
+
"EmbeddingProvider",
|
|
122
|
+
"LocalEmbedder",
|
|
123
|
+
"AzureEmbedder",
|
|
124
|
+
"MockEmbedder",
|
|
125
|
+
# Verification (v0.7.0+)
|
|
126
|
+
"VerificationStatus",
|
|
127
|
+
"VerificationMethod",
|
|
128
|
+
"Verification",
|
|
129
|
+
"VerifiedMemory",
|
|
130
|
+
"VerifiedResults",
|
|
131
|
+
"VerificationConfig",
|
|
132
|
+
"VerifiedRetriever",
|
|
133
|
+
"create_verified_retriever",
|
|
134
|
+
]
|