Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion mempalace/format_miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ def _file_chunks_locked(
room,
agent,
source_mtime: Optional[float] = None,
content: Optional[str] = None,
):
"""Lock the source file, purge stale drawers, and upsert fresh chunks.
Comment on lines 587 to 592

Expand All @@ -604,7 +605,13 @@ def _file_chunks_locked(
"""
# Lazy imports to avoid a module-load cycle (miner.py imports from this
# module's package, so we defer these helpers until call time).
from .miner import _extract_entities_for_metadata, detect_hall
from .miner import _extract_content_date, _extract_entities_for_metadata, detect_hall

# Tier 6a content-date: extract once per file (not per chunk). Format-mined
# files often have date-rich content (RTF/PDF dates in body text, mtimes on
# the binary source). Caller may pass ``content`` (full extracted text) for
# the body-scan branch; if absent, the helper still uses filename + mtime.
file_content_date = _extract_content_date(source_file, content or "")

drawers_added = 0
with mine_lock(source_file):
Expand Down Expand Up @@ -649,6 +656,17 @@ def _file_chunks_locked(
}
if source_mtime is not None:
meta["source_mtime"] = source_mtime
# Tier 6a — propagate line range from chunk dict into drawer
# metadata so closet pointers can carry "where in source"
# info. Chunks emitted by older code paths without these
# keys produce drawers without the keys (graceful fallback).
if chunk.get("line_start") is not None:
meta["line_start"] = chunk["line_start"]
if chunk.get("line_end") is not None:
meta["line_end"] = chunk["line_end"]
# Tier 6a content-date: shared across all chunks of the file.
if file_content_date:
meta["content_date"] = file_content_date
entities = _extract_entities_for_metadata(content)
if entities:
meta["entities"] = entities
Expand Down Expand Up @@ -864,6 +882,7 @@ def mine_formats(
room,
agent,
source_mtime=source_mtime,
content=text,
)
if skipped:
files_skipped += 1
Expand Down
Loading
Loading