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
- Parse — parse
rawas session events JSON (envelope{"events":[...]}or bare array[...]or single object). - 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 CLIcortex ingestfor those). - Extract trace — extract the first
trace_idfrom the parsed events. If none, returnsCloseOutcome { pending_commit: 0, no_candidates: true }. - Reflect — run
cortex_reflect::reflect()over the trace via aReplayAdapterbuilt fromfixtures_dir(seeclose_from_bytes). - Tag as pending — for each reflected candidate, set lifecycle state
to
pending_mcp_commit(ADR 0047). The caller (MCP server) promotes toactiveoncortex_session_commit; the CLI wrapper callsMemoryRepo::set_activeitself after receiving theCloseOutcome. - Pre-compute embeddings — BLAKE3 stub embeddings via
LocalStubEmbedder, written to the store so semantic search is immediately warm after promotion. - Return
CloseOutcome—pending_commitis the count of memories inpending_mcp_commitstate; callers decide whether to promote them.
Structs§
- Close
Outcome - Outcome returned from
close_from_bytes.
Enums§
- Session
Error - Errors raised by the session-close pipeline.
Functions§
- close_
from_ bytes - Run the full session-close pipeline.