mempalace.sources.opencode
Source: mempalace/sources/opencode.py
OpenCode source adapter (RFC 002).
Ingests OpenCode AI-coding-CLI session transcripts out of OpenCode's local SQLite store (default ~/.local/share/opencode/opencode.db) into the palace as :class:DrawerRecord instances.
Each OpenCode session becomes one source_file of the shape opencode://<absolute-db-path>#session=<sid>. The drawers under that source_file are exchange-pair chunks of the session transcript, formatted to match the existing convo_miner shape so downstream ranking, search, and closet-building behave identically.
Reverse-engineering credit: the SQLite schema, json_extract paths, tool-echo / file-injection skip filters, and same-role merge originated in @JakobSachs's PR #23 (feat: add OpenCode SQLite session database support). This adapter rebuilds those same primitives on the RFC 002 contract so it can ship as a registered adapter rather than a normalize.py branch.
Classes
class OpenCodeSourceAdapter(BaseSourceAdapter)
Mine OpenCode AI-coding-CLI sessions into the palace (RFC 002 §1).
__init__
def __init__(self) -> Nonedescribe_schema
def describe_schema(self) -> AdapterSchemaingest
def ingest(self, *, source: SourceRef, palace: PalaceContext) -> Iterator[object]is_current
def is_current(self, *, item: SourceItemMetadata, existing_metadata: Optional[dict]) -> boolsource_summary
def source_summary(self, *, source: SourceRef) -> SourceSummaryclose
def close(self) -> NoneFunctions
session_source_file
def session_source_file(db_path: str, session_id: str) -> strConstruct the stable per-session source_file identifier.
Shape: opencode://<absolute-db-path>#session=<sid>. Stable across re-ingests, used as the ChromaDB where={"source_file": ...} key and by is_current to look up existing drawers.
