Frozen dataclass. Canonical definition re-exported by memory/__init__.py.
@dataclass(frozen=True)
class MemoryEntry:
memory_id: str # UUID hex (32 chars)
content: str # Non-empty stripped text
tags: tuple[str, ...] # Lowercase, stripped, sorted, deduplicated
created_at: str # UTC ISO timestamp
branch_name: str | None # Optional git branch isolation scope
run_id: str | None # Optional run ID isolation scopeMethods:
to_dict() -> dict[str, Any]— serializes to JSON-compatible dict withtagsas list
Mutable dataclass (not frozen).
@dataclass
class FailureCard:
id: str # 8-char UUID prefix
run_id: str
timestamp: float # Unix timestamp of failure
error_type: str # e.g. 'TypeError', 'ImportError'
file_path: str # File where error occurred
line_number: Optional[int]
error_message: str
task_description: str
context_files: list[str]
confidence: str # 'low' | 'medium' | 'high'
expires_at: Optional[float] # Unix timestamp; None = no expiry
invalidated: bool # True = permanently inactive
invalidation_reason: Optional[str]
warning_behavior: str # 'info' | 'warning' | 'block'
reviewer_type: str # 'auto' | 'human'
evidence_command: Optional[str]
evidence_exit_code: Optional[int]
DEFAULT_TTL_SECONDS: ClassVar[int] = 2592000 # 30 daysMutable dataclass.
@dataclass
class PinnedFile:
file_path: str # Relative path from workspace root
pinned_at: float # Unix timestamp when pinned
last_modified: float # Unix timestamp of last known modification@dataclass
class AutoInvalidationRule:
trigger: str # 'file_signature_change' | 'test_refactor' | 'dependency_version_change'
confidence: str # 'high' | 'medium' | 'low'
action: str # 'invalidate' | 'warn' | 'block'
paths: Optional[list[str]] # Optional path prefix filters
enabled: boolNot a memory module class, but used in ContextBus.archive_to_rag().
Constructor:
MemoryCatalog(root: str | Path = '.', *, readonly: bool = False)- Pre:
rootmust be a valid directory path (created if writable). - Post:
self.path = <root>/.teaagent/memory.jsonl; directory created ifnot readonly.
- Pre:
readonly=False;content.strip()must be non-empty. - Post: Entry appended to
memory.jsonl; returnedMemoryEntryhas normalized tags. - Raises:
RuntimeErrorif readonly;ValueError('memory content cannot be empty')if blank.
- Pre:
readonly=False;content.strip()non-empty;provenanceis a dict. - Post: Entry appended to
memory-quarantine.jsonlwithquarantine=Trueandprovenancekeys. - Raises:
RuntimeErrorif readonly;ValueErrorif blank content.
- Post: Returns up to
limitmost-recent entries (reversed insertion order). Returns[]if file absent.
- Pre:
queryis any string. - Post: Returns entries where ALL query tokens appear in
content.lower()or anytag. Ranked by relevance score descending thencreated_atdescending. Returns[]for empty query.
Relevance scoring (memory/catalog.py):
- +3 per token found in content
- +2 per token found in any tag
- +4 if
'auto-curated'is in tags - +2 if
'run-summary'is in tags
- Raises:
FileNotFoundErrorifmemory_idnot found.
- Pre:
readonly=False. - Post: Atomically rewrites
memory.jsonlexcluding entries wherebranch_namematches; returns count deleted. - Raises:
RuntimeErrorif readonly.
Same contract as delete_by_branch but filters on run_id.
- Pre:
readonly=False. - Post: Removes matched entries from
memory.jsonl(atomic rewrite), appends each tomemory-quarantine.jsonlwith provenance dict containingreason,original_branch,quarantined_at. Returns count quarantined.
FailureCard.create(run_id, error_type, file_path, error_message, task_description, context_files, line_number=None, *, confidence='low', ttl_seconds=DEFAULT_TTL_SECONDS, ...) -> FailureCard
- Post: Returns new card with
id = str(uuid4())[:8];timestamp = datetime.now().timestamp();expires_at = now + ttl_seconds(orNoneifttl_seconds <= 0);confidenceclamped to valid set.
- Post:
Falseifinvalidated=TrueOR ifexpires_atis set and(now or time.time()) >= expires_at.Trueotherwise.
Returns: 'ignore' (inactive), 'block' (human-reviewed, high confidence, block behavior), otherwise warning_behavior value.
Constructor:
FailureCardStorage(root: Path)Creates <root>/.teaagent/memory/failures.json storage directory.
Reads full list, appends, writes full list.
Returns all cards regardless of active status.
Filters list_all() by card.is_active().
Sets invalidated=True and invalidation_reason in storage. Returns True if found and updated.
Removes all inactive cards from storage; returns count removed.
Truncates failures.json to an empty list.
Removes exactly one card by ID. Returns True if found.
- Post: Returns up to
limitactive cards scored by: +10 for matching file path, +5 for matching error type, +N for keyword overlap in task descriptions. Sorted by score descending then timestamp descending.
- Post: Applies
AutoInvalidationRules. Returns dict mapping trigger name to count of invalidated/warned cards. Reads workspace.teaagent/config.jsonifconfigisNone.
Returns the card if found, None otherwise.
Constructor:
PinnedFileStorage(root: Path)- Pre:
file_pathmust exist atroot / file_path; must not match secret filename patterns. - Post: Adds new
PinnedFileentry if not already pinned. ReturnsTrueon success,Falseif already pinned, missing, or secret.
Returns True if the file was pinned and is now removed, False if not found.
Returns all pinned files.
Removes all pinned file entries.
Updates last_modified timestamp to datetime.now().timestamp(). Returns True if found.
Returns True if the given path is in the pinned list.
Constructor:
FileWatcher(root: Path, callback: Callable[[str, str], None], debounce_ms: int = 500)- Raises:
ImportErrorifwatchdogis not installed.
Starts background Observer thread watching root recursively. No-op if already running.
Stops Observer thread with 5-second join timeout.
Replaces the set of watched absolute paths. Thread-safe.
Thread-safe check of running state.
Constructor:
TeamMemory(root: str | Path = '.')Appends - <ISO timestamp> — <entry>\n to team-memory.md. Returns the written line (without trailing newline).
Returns all non-empty lines from team-memory.md. Returns [] if file absent.
Returns a prompt-ready string with most recent entries first, capped at ~limit_tokens * 4 characters.
Lowercases, strips, deduplicates, and sorts tags.
All query tokens (split on whitespace) must appear in entry.content.lower() or any tag.
Returns integer score; higher = more relevant.
Validates and reconstructs MemoryEntry from a dict. Returns None on any validation failure.
Converts a list of entries to a list of serialized dicts.