SessionManager
Category: Session
Source: session_manager.dart
Enums
SessionReplayKind
| Value | Description |
|---|---|
user | |
assistant | |
toolCall | |
toolResult | |
subagentSpawned | |
subagentEvent | |
subagentCompleted |
SessionResumeStatus
| Value | Description |
|---|---|
resumed | |
empty | |
locked |
Classes
SessionReplayEntry
Constructor
factory SessionReplayEntry.user(String text)factory SessionReplayEntry.assistant(String text)factory SessionReplayEntry.toolCall(
String name,
Map<String, dynamic> arguments,
)factory SessionReplayEntry.toolResult(String text)factory SessionReplayEntry.subagentSpawned({
required String subagentId,
required String task,
int? index,
int? total,
})factory SessionReplayEntry.subagentEvent({
required String subagentId,
required SessionReplayEntry inner,
})factory SessionReplayEntry.subagentCompleted({
required String subagentId,
String? error,
})Properties
| Property | Type | Description |
|---|---|---|
kind | SessionReplayKind | |
text | String | |
toolName | String? | |
toolArguments | Map<String, dynamic>? | |
subagentId | String? | |
subagentIndex | int? | |
subagentTotal | int? | |
subagentInner | SessionReplayEntry? | |
subagentError | String? |
SessionReplay
Constructor
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
| Property | Type | Description |
|---|---|---|
entries | List<SessionReplayEntry> | |
userCount | int | |
assistantCount | int | |
firstUserMessage | String? | |
latestUserMessage | String? | |
firstAssistantMessage | String? | |
latestAssistantMessage | String? | |
toolNames | List<String> | |
totalUsage | UsageReport | Per-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
const SessionResumeResult({
required this.message,
required this.status,
required this.replay,
})Properties
| Property | Type | Description |
|---|---|---|
message | String | |
status | SessionResumeStatus | |
replay | SessionReplay | |
hasConversation | bool get | |
hasConversation | bool get |
SessionForkResult
Constructor
const SessionForkResult({
required this.message,
required this.draftText,
required this.replay,
})Properties
| Property | Type | Description |
|---|---|---|
message | String | |
draftText | String | |
replay | SessionReplay |
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
const TitleContext({
this.firstUserMessage,
this.latestUserMessage,
this.firstAssistantMessage,
this.latestAssistantMessage,
this.toolNames = const [],
this.filesTouched = const [],
this.cwdBasename,
})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
| Property | Type | Description |
|---|---|---|
firstUserMessage | String? | |
latestUserMessage | String? | |
firstAssistantMessage | String? | |
latestAssistantMessage | String? | |
toolNames | List<String> | |
filesTouched | List<String> | |
cwdBasename | String? |
SessionManager
Constructor
SessionManager({
required this.environment,
SessionStore? sessionStore,
Observability? observability,
})Properties
| Property | Type | Description |
|---|---|---|
environment | Environment | |
titleInitialRequested | bool | |
titleReevaluationRequested | bool | |
titleManuallyOverridden | bool | |
currentStore | SessionStore? get | |
currentSessionId | SessionId? get | |
currentStore | SessionStore? get | |
currentSessionId | SessionId? 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<SessionMeta> 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<String, dynamic> 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<void> closeCurrent({SessionTerminationStatus? status})
`Future<void> generateTitle({
required String userMessage,
required Future<String?> Function(String userMessage) generate,
})`
Future<void> renameTitle(String title)
`Future<void> reevaluateTitle({
required TitleContext context,
required Future<String?> Function(TitleContext context) generate,
})`
`SessionResumeResult resumeSession({
required SessionMeta session,
required AgentCore agent,
})`
`SessionForkResult? forkSession({
required int userMessageIndex,
required String messageText,
required AgentCore agent,
})`