createSessionAnalyzer
Analyzes complete coding session history to understand user intent, decision-making patterns, problem-solving strategies, and learning patterns.Function Signature
src/core/session-analyzer.ts:105
Return Value
Returns an object with session analysis methods.Methods
analyzeSession
Analyzes a complete session with full context extraction.Session identifier.
Ordered list of tool events from the session.
Optional full conversation transcript for deeper intent analysis.
SessionContext - Rich analysis including intent, domains, workflow type, and success metrics.
Analysis pipeline:
- Parse conversation turns (grouped by 60-second gaps)
- Detect primary user intent via keyword scoring
- Extract problem domains from file paths
- Detect workflow type from tool sequences
- Calculate success indicators (tool success rate, duration)
src/core/session-analyzer.ts:302
detectProblemSolvingPatterns
Detects high-level problem-solving patterns across multiple sessions.Array of session data with events.
ProblemSolvingPattern[] - List of detected patterns sorted by success rate descending.
Detection logic:
- Analyze each session individually
- Group sessions by workflow type
- Calculate success rates per workflow
- Extract common domains and intents
- Create patterns for groups with 2+ occurrences
src/core/session-analyzer.ts:340
SessionContext Type
Session identifier.
ISO-8601 timestamp of first event.
ISO-8601 timestamp of last event.
Absolute path to the project workspace.
Array of conversation turns (user messages + agent responses + tools used).
Detected user intent:
"debug", "implement", "refactor", "test", "explore", or "document".List of problem domains extracted from file paths (e.g.
["src", "tests", "api"]).Detected workflow pattern:
"TDD", "Debug-Systematic", "Refactor-Safe", or "Explore-Then-Implement".Success metrics:
tool_success_rate: Ratio of successful tool invocations (0.0 to 1.0)total_tools_used: Count of tools invokedsession_duration_minutes: Session duration in minutes
Important decisions made during the session (future enhancement).
src/types/index.ts:81-92
ConversationTurn Type
Session identifier.
ISO-8601 timestamp of the turn.
User’s message (null if not available).
Agent’s response (null if not available).
List of tools invoked during this turn.
Categorized intent for this turn.
Problem domain for this turn.
Outcome of this turn (success/failure).
src/types/index.ts:69-78
ProblemSolvingPattern Type
Unique pattern identifier (e.g.
"ps-TDD").Workflow type (e.g.
"TDD", "Debug-Systematic").Plain language description of the pattern.
Generic workflow steps (e.g.
["Analyze problem", "Plan approach", "Implement", "Verify"]).Success rate across sessions using this pattern (0.0 to 1.0).
Number of sessions matching this pattern.
Sample session IDs (up to 3).
Context metadata:
primary_intents: List of primary intents across sessionscommon_domains: Top 3 problem domains
src/types/index.ts:95-104
Intent Detection
Intent is detected via keyword scoring across conversation turns:Intent Keywords
debug: bug, error, fix, issue, problem, not working, broken implement: create, add, implement, build, make, new feature refactor: refactor, clean up, reorganize, improve, optimize test: test, TDD, unit test, testing, coverage explore: understand, explain, how does, what is, show me document: document, comment, README, docs, documentation Scoring algorithm:- Scan all user messages for keywords
- Increment intent score for each keyword match
- Return intent with highest score, or
nullif no matches
src/core/session-analyzer.ts:21-28, 174
Workflow Detection
Workflow types are detected by matching tool sequences against known patterns:Workflow Patterns
TDD:["Write", "Bash", "Edit", "Bash"]
- Keywords: test, TDD, red-green-refactor
["Read", "Grep", "Bash", "Edit"]
- Keywords: error, bug, debug, fix
["Read", "Edit", "Bash"]
- Keywords: refactor, improve, clean
["Grep", "Read", "Write"]
- Keywords: understand, then, create
src/core/session-analyzer.ts:31-51, 237
Usage Example
Problem Domain Extraction
Domains are extracted from file paths in tool inputs:- Extract
pathorfile_pathfrom tool inputs - Split path by
/or\\ - Take parent directory name (second-to-last component)
- Return up to 5 unique domains
src/core/session-analyzer.ts:210
Conversation Turn Grouping
Events are grouped into turns based on 60-second time gaps:src/core/session-analyzer.ts:119
Success Rate Calculation
Success indicators are calculated from event metadata: Tool Success Rate:src/core/session-analyzer.ts:255
See Also
- createPatternDetector - Uses session context for v2 pattern enrichment
- createEventStore - Provides event data for analysis
- SessionContext Type - Full context schema