Session domain model. Creates and persists chat sessions, tracks parent / child relationships and usage, maps between storage rows and runtime objects, and publishes session lifecycle events on the bus.

Classes

BusyError
Service

Members

(static, constant) Event

Session-related events. Created/Updated/Deleted are sync events persisted via projectors; Diff and Error are bus-only events.

(static, constant) getUsage

Computes token usage and cost for a model step. Normalizes provider usage fields (subtracting cached tokens from input, separating reasoning tokens) and applies the model's per-million pricing, including the optional over-200K tier.

(static, constant) layer

Layer that builds the Session service: CRUD over sessions, messages, and parts.

Methods

(static) fromRow(row) → {Object}

Converts a sqlite session row into a runtime session Info object, decoding nested summary/share/model/time fields and normalizing nulls to undefined.

Parameters:
NameTypeDescription
rowObject

The plain database row.

Returns:

The session Info object.

Type: 
Object

(static) isDefaultTitle(title) → {boolean}

Tests whether a title is an auto-generated default (prefix + ISO timestamp).

Parameters:
NameTypeDescription
titlestring

The session title to test.

Returns:

True if the title matches the default-title pattern.

Type: 
boolean

(static) listGlobal(input) → {AsyncGenerator.<Object>}

Async-iterates sessions across all projects (not scoped to the current instance), applying optional directory/roots/time-range/search/archived filters and joining each session with its project summary.

Parameters:
NameTypeDescription
inputObject

Optional filters { directory, roots, start, cursor, search, archived, limit }.

Returns:

Yields GlobalInfo-shaped session objects with an attached project.

Type: 
AsyncGenerator.<Object>

(static) plan(input, instance) → {string}

Computes the absolute path of a session's plan markdown file. Stored under the worktree's .closedcode/plans when the project is under version control, otherwise under the global data directory.

Parameters:
NameTypeDescription
inputObject

Session info providing time.created and slug.

instanceObject

Instance context with project.vcs and worktree.

Returns:

The absolute path to the plan file.

Type: 
string

(static) toRow(info) → {Object}

Converts a runtime session Info object into a sqlite row, flattening nested summary/share/time fields to their column names.

Parameters:
NameTypeDescription
infoObject

The session Info object.

Returns:

The database row representation.

Type: 
Object

(inner) createDefaultTitle(isChild) → {string}

Builds a default session title from a timestamped prefix.

Parameters:
NameTypeDefaultDescription
isChildbooleanfalse

Whether the session is a child session (uses the child prefix).

Returns:

The generated default title.

Type: 
string

(inner) db(fn) → {*}

Runs an async database callback inside an Effect, providing the sequelize handle.

Parameters:
NameTypeDescription
fnfunction

Async callback receiving the handle { models, sequelize, tx }.

Returns:

An Effect yielding the callback's result.

Type: 
*

(inner) getForkedTitle(title) → {string}

Derives a forked-session title, incrementing an existing (fork #N) suffix or appending (fork #1) when none is present.

Parameters:
NameTypeDescription
titlestring

The original session title.

Returns:

The title for the new fork.

Type: 
string

(async, inner) listByProject(input) → {Promise.<Array>}

Queries sessions for a project, applying optional workspace/path/directory, roots-only, start time, and title-search filters, ordered by most recently updated.

Parameters:
NameTypeDescription
inputObject

Filters including projectID plus optional workspaceID, path, directory, scope, roots, start, search, limit.

Returns:

A promise of matching session Info objects.

Type: 
Promise.<Array>

(inner) plain(row) → {Object}

Extracts a plain JS object from a sequelize row instance.

Parameters:
NameTypeDescription
row*

The sequelize row (or null/undefined).

Returns:

The plain row object, or undefined when the row is null.

Type: 
Object

(inner) sessionPath(worktree, cwd) → {string}

Computes a session's directory path relative to the worktree, normalized to forward slashes.

Parameters:
NameTypeDescription
worktreestring

Absolute worktree root.

cwdstring

The session's working directory.

Returns:

The worktree-relative, slash-normalized path.

Type: 
string