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
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.
| Name | Type | Description |
|---|---|---|
row | Object | The plain database row. |
The session Info object.
- Type:
- Object
(static) isDefaultTitle(title) → {boolean}
Tests whether a title is an auto-generated default (prefix + ISO timestamp).
| Name | Type | Description |
|---|---|---|
title | string | The session title to test. |
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.
| Name | Type | Description |
|---|---|---|
input | Object | Optional filters |
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.
| Name | Type | Description |
|---|---|---|
input | Object | Session info providing |
instance | Object | Instance context with |
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.
| Name | Type | Description |
|---|---|---|
info | Object | The session Info object. |
The database row representation.
- Type:
- Object
(inner) createDefaultTitle(isChild) → {string}
Builds a default session title from a timestamped prefix.
| Name | Type | Default | Description |
|---|---|---|---|
isChild | boolean | false | Whether the session is a child session (uses the child prefix). |
The generated default title.
- Type:
- string
(inner) db(fn) → {*}
Runs an async database callback inside an Effect, providing the sequelize handle.
| Name | Type | Description |
|---|---|---|
fn | function | Async callback receiving the handle |
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.
| Name | Type | Description |
|---|---|---|
title | string | The original session title. |
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.
| Name | Type | Description |
|---|---|---|
input | Object | Filters including |
A promise of matching session Info objects.
- Type:
- Promise.<Array>
(inner) plain(row) → {Object}
Extracts a plain JS object from a sequelize row instance.
| Name | Type | Description |
|---|---|---|
row | * | The sequelize row (or null/undefined). |
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.
| Name | Type | Description |
|---|---|---|
worktree | string | Absolute worktree root. |
cwd | string | The session's working directory. |
The worktree-relative, slash-normalized path.
- Type:
- string