H.Session (H v0.3.0)

Copy Markdown View Source

Pure session history: a working directory, conversations, and immutable entries.

Conversation 1 is the root. Forks reference visible entry cutoffs rather than copying transcripts. Conversation and entry IDs come from one strictly monotonic session-local sequence (next_id), which fork prefix traversal relies on (entry.id <= cutoff). All functions return new values; this module performs no persistence, process management, model requests, or tool execution.

This is the trusted in-memory core. External data validation and durable command admission belong to the daemon boundary, not these constructors.

Summary

Functions

Appends a raw entry to a conversation's own segment.

Creates another independent conversation in the session.

Returns visible entries oldest first, respecting every ancestor's fork cutoff.

Forks through a concrete entry visible in the source conversation, inclusively.

Creates an empty root conversation. The working directory must be absolute.

Types

error()

@type error() :: :conversation_not_found | :entry_not_visible

t()

@opaque t()

Functions

append(session, conversation_id, kind, data)

@spec append(t(), pos_integer(), String.t(), map()) ::
  {:ok, t(), H.Entry.t()} | {:error, error()}

Appends a raw entry to a conversation's own segment.

create_conversation(session)

@spec create_conversation(t()) :: {:ok, t(), H.Conversation.t()}

Creates another independent conversation in the session.

entries(session, conversation_id)

@spec entries(t(), pos_integer()) :: {:ok, [H.Entry.t()]} | {:error, error()}

Returns visible entries oldest first, respecting every ancestor's fork cutoff.

fork(session, conversation_id, at)

@spec fork(t(), pos_integer(), pos_integer()) ::
  {:ok, t(), H.Conversation.t()} | {:error, error()}

Forks through a concrete entry visible in the source conversation, inclusively.

new(id, cwd)

@spec new(String.t(), String.t()) :: t()

Creates an empty root conversation. The working directory must be absolute.