Skip to main content

Crate cortex_session

Crate cortex_session 

Source
Expand description

cortex-session — session-close pipeline extracted from cortex-cli.

§Why this crate exists

cortex-mcp cannot depend on cortex-cli (that would be circular: cortex-cli will depend on cortex-mcp for the Serve subcommand). This crate exposes close_from_bytes so both cortex-cli and cortex-mcp can run the session-close pipeline.

§Pipeline

  1. Parse — parse raw as session events JSON (envelope {"events":[...]} or bare array [...] or single object).
  2. Ingest — append non-duplicate events to the JSONL ledger at event_log. User-sourced events are refused (no attestor available in the library context; operator must call CLI cortex ingest for those).
  3. Extract trace — extract the first trace_id from the parsed events. If none, returns CloseOutcome { pending_commit: 0, no_candidates: true }.
  4. Reflect — run cortex_reflect::reflect() over the trace via a ReplayAdapter built from fixtures_dir (see close_from_bytes).
  5. Tag as pending — for each reflected candidate, set lifecycle state to pending_mcp_commit (ADR 0047). The caller (MCP server) promotes to active on cortex_session_commit; the CLI wrapper calls MemoryRepo::set_active itself after receiving the CloseOutcome.
  6. Pre-compute embeddings — BLAKE3 stub embeddings via LocalStubEmbedder, written to the store so semantic search is immediately warm after promotion.
  7. Return CloseOutcomepending_commit is the count of memories in pending_mcp_commit state; callers decide whether to promote them.

Structs§

CloseOutcome
Outcome returned from close_from_bytes.

Enums§

SessionError
Errors raised by the session-close pipeline.

Functions§

close_from_bytes
Run the full session-close pipeline.