Skip to main content

Module import_opencode_session

Module import_opencode_session 

Source
Expand description

ImportOpencodeSession — bulk import of an opencode transcript (Slice-8).

Parses already-flattened assistant turns (the adapter layer’s AssistantTurn is produced by smos::opencode::transcript) and re-runs the SAME extraction pipeline the live proxy runs after each chat completion. Concretely: every turn is fed to ExtractFactsFromResponse, so dedup, embedding, cross-session confirmation, and the MIN_INPUT_CHARS floor are reused verbatim — the import path is DRY with the live path.

§Filtering

The use case applies two pre-extraction filters that mirror the POC iter_assistant_turns:

  1. Agent filter — optional &[String] allow-list. Turns whose agent is not in the list are skipped (turns_skipped).
  2. Min-chars floor — turns with fewer than min_chars content chars AND no tool calls are skipped. Tool-call-only turns survive because the extraction pipeline renders tool calls into the input, so a turn with zero prose still carries extractable signal.

min_chars is wired from the SAME const as the live extraction pipeline ([extract_facts_from_response::MIN_INPUT_CHARS]) by the CLI binary, so the import path and the live response path cannot drift apart. The use case keeps the field as a runtime knob (not a const) so future callers can override it explicitly when they have a stronger reason than “match the live path”.

§Stats

ImportStats is the wire shape surfaced by the smos-import binary. The facts_extracted counter is the sum of ExtractFactsFromResponse::execute return values — i.e. ONLY newly-created pending facts. Cross-session confirmations on pre-existing facts do NOT increment the counter (they update an existing fact’s provenance instead), so re-importing the same session is idempotent on the new-fact axis.

Structs§

AssistantTurn
One assistant turn parsed from an opencode transcript.
ImportOpencodeSession
Import an opencode transcript by re-running the live extraction pipeline.
ImportStats
Aggregate outcome counters for one import run.