Skip to content

SessionManager ​

Category: Session

Source: session_manager.dart

Enums ​

SessionReplayKind ​

ValueDescription
user
assistant
toolCall
toolResult
subagentSpawned
subagentEvent
subagentCompleted

SessionResumeStatus ​

ValueDescription
resumed
empty
locked

Classes ​

SessionReplayEntry ​

Constructor ​

dart
factory SessionReplayEntry.user(String text)
dart
factory SessionReplayEntry.assistant(String text)
dart
factory SessionReplayEntry.toolCall(
    String name,
    Map<String, dynamic> arguments,
  )
dart
factory SessionReplayEntry.toolResult(String text)
dart
factory SessionReplayEntry.subagentSpawned({
    required String subagentId,
    required String task,
    int? index,
    int? total,
  })
dart
factory SessionReplayEntry.subagentEvent({
    required String subagentId,
    required SessionReplayEntry inner,
  })
dart
factory SessionReplayEntry.subagentCompleted({
    required String subagentId,
    String? error,
  })

Properties ​

PropertyTypeDescription
kindSessionReplayKind
textString
toolNameString?
toolArgumentsMap&lt;String, dynamic&gt;?
subagentIdString?
subagentIndexint?
subagentTotalint?
subagentInnerSessionReplayEntry?
subagentErrorString?

SessionReplay ​

Constructor ​

dart
const SessionReplay({
    required this.entries,
    required this.userCount,
    required this.assistantCount,
    required this.totalUsage,
    this.firstUserMessage,
    this.latestUserMessage,
    this.firstAssistantMessage,
    this.latestAssistantMessage,
    this.toolNames = const [],
  })

Properties ​

PropertyTypeDescription
entriesList&lt;SessionReplayEntry&gt;
userCountint
assistantCountint
firstUserMessageString?
latestUserMessageString?
firstAssistantMessageString?
latestAssistantMessageString?
toolNamesList&lt;String&gt;
totalUsageUsageReportPer-role token totals aggregated from persisted usage JSONL rows. Always non-null but may have an empty rows list when no usage was ever recorded (Ollama session, very old session predating recordUsage).

SessionResumeResult ​

Constructor ​

dart
const SessionResumeResult({
    required this.message,
    required this.status,
    required this.replay,
  })

Properties ​

PropertyTypeDescription
messageString
statusSessionResumeStatus
replaySessionReplay
hasConversationbool get
hasConversationbool get

SessionForkResult ​

Constructor ​

dart
const SessionForkResult({
    required this.message,
    required this.draftText,
    required this.replay,
  })

Properties ​

PropertyTypeDescription
messageString
draftTextString
replaySessionReplay

TitleContext ​

The compact view of a conversation handed to the title/recap generators.

Deliberately small: a handful of short fields, never the transcript and never tool output. [filesTouched] is the only grounding the generators get — without it a recap has to invent the outcomes it reports.

Constructor ​

dart
const TitleContext({
    this.firstUserMessage,
    this.latestUserMessage,
    this.firstAssistantMessage,
    this.latestAssistantMessage,
    this.toolNames = const [],
    this.filesTouched = const [],
    this.cwdBasename,
  })
dart
factory TitleContext.fromConversation(
    List<Message> conversation, {
    String? cwdBasename,
  })

Collect the context from a live conversation.

Tool results are never read — only call names and the file paths they name — so the blob stays a few hundred tokens regardless of session size.

Properties ​

PropertyTypeDescription
firstUserMessageString?
latestUserMessageString?
firstAssistantMessageString?
latestAssistantMessageString?
toolNamesList&lt;String&gt;
filesTouchedList&lt;String&gt;
cwdBasenameString?

SessionManager ​

Constructor ​

dart
SessionManager({
    required this.environment,
    SessionStore? sessionStore,
    Observability? observability,
  })

Properties ​

PropertyTypeDescription
environmentEnvironment
titleInitialRequestedbool
titleReevaluationRequestedbool
titleManuallyOverriddenbool
currentStoreSessionStore? get
currentSessionIdSessionId? get
currentStoreSessionStore? get
currentSessionIdSessionId? get

Methods ​

void markManuallyRenamed() ​

Marks the session as manually renamed (e.g., from /rename). Sets all three flags so background title generation does not overwrite the user-chosen title.

List&lt;SessionMeta&gt; listSessions() ​
`SessionStore ensureSessionStore({ ​
required String cwd,
required String modelRef,

})`

void switchToSessionStore(SessionMeta meta, {bool lock = false}) ​

Switches the active store to [meta]. When [lock] is set, acquires the advisory session lock before touching any state (M11); if another live process holds it, throws [SessionInUseException] and leaves the current store untouched.

void updateSessionModel({required String modelRef}) ​
`void updateSessionReasoning({ ​
required ReasoningEffort effort,
required bool showThoughts,

})`

void logEvent(String type, Map&lt;String, dynamic&gt; data) ​
`void recordUsage( ​
UsageStats stats, {
required String role,
String? modelRef,
String? subagentId,

})`

Records [stats] against the current session under [role] (e.g. 'main', 'subagent', 'title'). Updates the persisted token counters on SessionMeta and writes a usage JSONL row so a surface or replay can attribute costs to where they came from.

No-op when no session store is active.

Future&lt;void&gt; closeCurrent({SessionTerminationStatus? status}) ​
`Future<void> generateTitle({ ​
required String userMessage,
required Future&lt;String?&gt; Function(String userMessage) generate,

})`

Future&lt;void&gt; renameTitle(String title) ​
`Future<void> reevaluateTitle({ ​
required TitleContext context,
required Future&lt;String?&gt; Function(TitleContext context) generate,

})`

`SessionResumeResult resumeSession({ ​
required SessionMeta session,
required AgentCore agent,

})`

`SessionForkResult? forkSession({ ​
required int userMessageIndex,
required String messageText,
required AgentCore agent,

})`

Released under the MIT License.