@qiaolei81/copilot-session-viewer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,613 @@
1
+ # Copilot Session Viewer
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@qiaolei81/copilot-session-viewer.svg)](https://www.npmjs.com/package/@qiaolei81/copilot-session-viewer)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D22.0.0-brightgreen)](https://nodejs.org/)
6
+
7
+ **AI-Assisted Session Log Analysis Tool for GitHub Copilot CLI**
8
+
9
+ A web-based visualization and analysis interface for GitHub Copilot CLI session logs. This tool provides comprehensive session inspection, time-series analysis, and event stream visualization capabilities.
10
+
11
+ ---
12
+
13
+ ## Quick Start
14
+
15
+ ### Install via npm (recommended)
16
+
17
+ ```bash
18
+ npm install -g @qiaolei81/copilot-session-viewer
19
+ copilot-session-viewer
20
+ ```
21
+
22
+ Then open http://localhost:3838
23
+
24
+ ### Install from source
25
+
26
+ ```bash
27
+ git clone https://github.com/qiaolei81/copilot-session-viewer.git
28
+ cd copilot-session-viewer
29
+ npm install
30
+ npm start
31
+ ```
32
+
33
+ ---
34
+
35
+ ## System Overview
36
+
37
+ ### Core Capabilities
38
+
39
+ - **Session Management**: Complete CRUD operations for session archives (list, view, export, import)
40
+ - **Event Stream Analysis**: Real-time event log parsing with type filtering and search functionality
41
+ - **Time Analysis**: Turn execution timelines, sub-agent lifecycle tracking, tool invocation metrics
42
+ - **Virtual Scrolling**: High-performance rendering of large event streams (1000+ events) using Vue 3 reactive virtual scrolling
43
+ - **AI-Powered Insights**: Integrated LLM-based session analysis via GitHub Copilot CLI
44
+ - **Export/Import**: ZIP-based session sharing with metadata preservation
45
+ - **Multi-Format Support**: Directory-based sessions and legacy JSONL file formats
46
+
47
+ ### Technical Architecture
48
+
49
+ ```
50
+ ┌─────────────────────────────────────────────────┐
51
+ │ Frontend (Vue 3 + EJS Templates) │
52
+ │ - Virtual Scroller (vue-virtual-scroller) │
53
+ │ - Reactive State Management │
54
+ │ - GitHub-Inspired Dark Theme │
55
+ └─────────────────────────────────────────────────┘
56
+
57
+ ┌─────────────────────────────────────────────────┐
58
+ │ Backend (Node.js + Express) │
59
+ │ - Session Repository (FileSystemWatcher) │
60
+ │ - JSONL Parser (line-by-line streaming) │
61
+ │ - Multer (file upload handling) │
62
+ └─────────────────────────────────────────────────┘
63
+
64
+ ┌─────────────────────────────────────────────────┐
65
+ │ Data Layer │
66
+ │ ~/.copilot/session-state/ │
67
+ │ - events.jsonl (event stream) │
68
+ │ - workspace.yaml (metadata) │
69
+ │ - insight-report.md (AI analysis) │
70
+ └─────────────────────────────────────────────────┘
71
+ ```
72
+
73
+ ---
74
+
75
+ ## Installation
76
+
77
+ ### Prerequisites
78
+
79
+ **Required:**
80
+ - Node.js >= 18.0.0 (LTS recommended)
81
+ - npm >= 9.0.0 or yarn >= 1.22.0
82
+ - GitHub Copilot CLI (for session data generation)
83
+
84
+ **Optional:**
85
+ - GitHub Copilot CLI with `--yolo` mode enabled (for AI insights feature)
86
+
87
+ ### Installation Steps
88
+
89
+ **1. Clone Repository**
90
+
91
+ ```bash
92
+ git clone <repository-url>
93
+ cd copilot-session-viewer
94
+ ```
95
+
96
+ **2. Install Dependencies**
97
+
98
+ ```bash
99
+ npm install
100
+ ```
101
+
102
+ **3. Verify Installation**
103
+
104
+ ```bash
105
+ npm run check
106
+ ```
107
+
108
+ This command will verify:
109
+ - Node.js version compatibility
110
+ - Dependency integrity
111
+ - Session directory accessibility
112
+
113
+ **4. Configure Environment (Optional)**
114
+
115
+ ```bash
116
+ cp .env.example .env
117
+ ```
118
+
119
+ Edit `.env` with your configuration:
120
+
121
+ ```env
122
+ # Server Configuration
123
+ PORT=3838
124
+ NODE_ENV=development
125
+
126
+ # Session Data Directory (auto-detected if omitted)
127
+ SESSION_DIR=/custom/path/to/session-state
128
+
129
+ # Feature Flags
130
+ ENABLE_INSIGHTS=true
131
+ ENABLE_EXPORT=true
132
+ ```
133
+
134
+ ---
135
+
136
+ ## Development
137
+
138
+ ### Development Workflow
139
+
140
+ **1. Start Development Server**
141
+
142
+ ```bash
143
+ npm run dev
144
+ ```
145
+
146
+ This command:
147
+ - Starts Express server with `nodemon` auto-reload
148
+ - Watches template files (`.ejs`) for changes
149
+ - Disables template caching for hot-reload
150
+ - Enables verbose logging (`DEBUG=copilot-viewer:*`)
151
+
152
+ **2. Development Server Access**
153
+
154
+ Navigate to: `http://localhost:3838`
155
+
156
+ **3. Directory Structure**
157
+
158
+ ```
159
+ copilot-session-viewer/
160
+ ├── server.js # Express application entry point
161
+ ├── src/
162
+ │ ├── fileUtils.js # File system utilities
163
+ │ ├── session.js # Session data parser
164
+ │ ├── sessionRepository.js # Session management layer
165
+ │ └── teamsShareService.js # (Legacy) Teams integration stub
166
+ ├── views/
167
+ │ ├── index.ejs # Session list page
168
+ │ ├── session.ejs # Legacy session detail view
169
+ │ ├── session-vue.ejs # Vue 3 virtual scrolling view
170
+ │ └── time-analyze.ejs # Time analysis dashboard
171
+ ├── package.json
172
+ └── README.md
173
+ ```
174
+
175
+ **4. Code Style Guidelines**
176
+
177
+ This project follows standard Node.js conventions:
178
+ - **Indentation**: 2 spaces
179
+ - **Quotes**: Single quotes for JavaScript, double quotes for HTML/EJS
180
+ - **Semicolons**: Required
181
+ - **Async/Await**: Preferred over Promise chains
182
+
183
+ **5. Testing**
184
+
185
+ ```bash
186
+ # Run unit tests (if available)
187
+ npm test
188
+
189
+ # Manual integration testing
190
+ npm run dev
191
+ # Navigate to http://localhost:3838 and verify all features
192
+ ```
193
+
194
+ **6. Debugging**
195
+
196
+ Enable verbose logging:
197
+
198
+ ```bash
199
+ DEBUG=copilot-viewer:* npm run dev
200
+ ```
201
+
202
+ Inspect session parsing:
203
+
204
+ ```bash
205
+ node -e "const session = require('./src/session'); session.parseSession('<session-id>').then(console.log)"
206
+ ```
207
+
208
+ ---
209
+
210
+ ## Quick Start
211
+
212
+ ### Basic Usage
213
+
214
+ **Step 1: Generate Session Data**
215
+
216
+ Use GitHub Copilot CLI to create session logs:
217
+
218
+ ```bash
219
+ # Example: Run a task with Copilot CLI
220
+ copilot --model claude-sonnet-4.5 --yolo -p "Analyze this codebase"
221
+ ```
222
+
223
+ Sessions are automatically saved to:
224
+ - **macOS/Linux**: `~/.copilot/session-state/`
225
+ - **Windows**: `C:\Users\<username>\.copilot\session-state\`
226
+
227
+ **Step 2: Start Viewer**
228
+
229
+ ```bash
230
+ npm start
231
+ ```
232
+
233
+ **Step 3: Access Web Interface**
234
+
235
+ Open browser: `http://localhost:3838`
236
+
237
+ **Step 4: Explore Sessions**
238
+
239
+ 1. **Session List**: Browse all sessions with metadata (duration, event count)
240
+ 2. **Session Detail**: Click any session to view event stream
241
+ 3. **Time Analysis**: Click "Time Analysis" to view execution breakdown
242
+ 4. **AI Insights**: Click "Generate Insight" for LLM-powered analysis (requires `copilot --yolo`)
243
+
244
+ ### Advanced Features
245
+
246
+ **Exporting Sessions**
247
+
248
+ 1. Navigate to session detail page
249
+ 2. Click "Share Session" button
250
+ 3. Download ZIP archive containing:
251
+ - `events.jsonl`
252
+ - `workspace.yaml`
253
+ - `insight-report.md` (if generated)
254
+
255
+ **Importing Sessions**
256
+
257
+ 1. On homepage, click "Import session from zip"
258
+ 2. Select ZIP file exported from another viewer instance
259
+ 3. Session automatically extracted to `~/.copilot/session-state/`
260
+
261
+ **AI Insight Generation**
262
+
263
+ Prerequisites:
264
+ - GitHub Copilot CLI installed
265
+ - `copilot --yolo` mode functional
266
+
267
+ Process:
268
+ 1. Navigate to Time Analysis tab
269
+ 2. Click "Copilot Insight" tab
270
+ 3. Click "Generate Insight" button
271
+ 4. System executes: `copilot --yolo -p "<analysis-prompt>"`
272
+ 5. Real-time streaming output displayed
273
+ 6. Report saved to `session-dir/insight-report.md`
274
+
275
+ ---
276
+
277
+ ## Configuration
278
+
279
+ ### Environment Variables
280
+
281
+ | Variable | Type | Default | Description |
282
+ |----------|------|---------|-------------|
283
+ | `PORT` | Integer | `3838` | HTTP server port |
284
+ | `NODE_ENV` | String | `development` | Environment mode (`development` \| `production`) |
285
+ | `SESSION_DIR` | Path | `~/.copilot/session-state` | Session data directory |
286
+ | `ENABLE_INSIGHTS` | Boolean | `true` | Enable AI insights feature |
287
+ | `ENABLE_EXPORT` | Boolean | `true` | Enable session export/import |
288
+
289
+ ### Production Deployment
290
+
291
+ **Option 1: Direct Execution**
292
+
293
+ ```bash
294
+ NODE_ENV=production PORT=8080 npm start
295
+ ```
296
+
297
+ **Option 2: Process Manager (PM2)**
298
+
299
+ ```bash
300
+ npm install -g pm2
301
+ pm2 start server.js --name copilot-viewer
302
+ pm2 save
303
+ ```
304
+
305
+ **Option 3: Docker (Example)**
306
+
307
+ ```dockerfile
308
+ FROM node:18-alpine
309
+ WORKDIR /app
310
+ COPY package*.json ./
311
+ RUN npm ci --only=production
312
+ COPY . .
313
+ EXPOSE 3838
314
+ CMD ["node", "server.js"]
315
+ ```
316
+
317
+ ```bash
318
+ docker build -t copilot-viewer .
319
+ docker run -p 3838:3838 -v ~/.copilot:/root/.copilot copilot-viewer
320
+ ```
321
+
322
+ **Production Optimizations:**
323
+ - Template caching enabled (`NODE_ENV=production`)
324
+ - Static asset compression (gzip)
325
+ - Session directory monitoring disabled for performance
326
+
327
+ ---
328
+
329
+ ## Session Data Format
330
+
331
+ ### Directory-Based Format (Current)
332
+
333
+ ```
334
+ ~/.copilot/session-state/<session-id>/
335
+ ├── events.jsonl # Event stream (JSONL format)
336
+ ├── workspace.yaml # Session metadata
337
+ ├── checkpoints/ # Session checkpoints (optional)
338
+ ├── files/ # Temporary file artifacts
339
+ └── insight-report.md # AI-generated analysis (optional)
340
+ ```
341
+
342
+ ### JSONL Event Structure
343
+
344
+ Each line in `events.jsonl` is a JSON object:
345
+
346
+ ```json
347
+ {
348
+ "type": "user.message",
349
+ "timestamp": "2026-02-15T02:30:00.000Z",
350
+ "message": "Analyze this codebase",
351
+ "parentId": "msg_abc123",
352
+ "turnId": 0,
353
+ "userReqNumber": 1
354
+ }
355
+ ```
356
+
357
+ ### Event Type Taxonomy
358
+
359
+ | Category | Event Types | Description |
360
+ |----------|-------------|-------------|
361
+ | **Session** | `session.start`, `session.model_change` | Session lifecycle |
362
+ | **User** | `user.message`, `user.confirmation` | User interactions |
363
+ | **Assistant** | `assistant.message`, `assistant.turn_start`, `assistant.turn_end` | LLM responses |
364
+ | **Tool** | `tool.execution_start`, `tool.execution_complete` | Tool invocations |
365
+ | **Sub-Agent** | `subagent.started`, `subagent.completed` | Sub-agent lifecycle |
366
+ | **System** | `client.log`, `error` | System diagnostics |
367
+
368
+ ---
369
+
370
+ ## API Reference
371
+
372
+ ### REST Endpoints
373
+
374
+ **Session List**
375
+
376
+ ```http
377
+ GET /api/sessions
378
+ ```
379
+
380
+ Response:
381
+ ```json
382
+ [
383
+ {
384
+ "id": "f9db650c-1f87-491f-8e4f-52d45538d677",
385
+ "startTime": "2026-02-15T02:30:00.000Z",
386
+ "duration": 17936000,
387
+ "eventCount": 1044,
388
+ "type": "directory"
389
+ }
390
+ ]
391
+ ```
392
+
393
+ **Session Events**
394
+
395
+ ```http
396
+ GET /api/session/:id/events
397
+ ```
398
+
399
+ Response: JSONL stream
400
+
401
+ **AI Insight Generation**
402
+
403
+ ```http
404
+ POST /session/:id/insight
405
+ Content-Type: application/json
406
+
407
+ {}
408
+ ```
409
+
410
+ Response (SSE stream):
411
+ ```
412
+ data: {"status":"generating","progress":0.1}
413
+ data: {"status":"generating","progress":0.5}
414
+ data: {"status":"completed","report":"..."}
415
+ ```
416
+
417
+ **Session Export**
418
+
419
+ ```http
420
+ GET /session/:id/download
421
+ ```
422
+
423
+ Response: `application/zip` (session archive)
424
+
425
+ **Session Import**
426
+
427
+ ```http
428
+ POST /session/import
429
+ Content-Type: multipart/form-data
430
+
431
+ file: <session.zip>
432
+ ```
433
+
434
+ Response:
435
+ ```json
436
+ {
437
+ "success": true,
438
+ "sessionId": "imported-session-id"
439
+ }
440
+ ```
441
+
442
+ ---
443
+
444
+ ## Feature Documentation
445
+
446
+ ### Time Analysis Dashboard
447
+
448
+ **Components:**
449
+
450
+ 1. **Summary Cards**
451
+ - Total Duration
452
+ - Tool Call Count
453
+ - Average Tool Duration
454
+ - Sub-Agent Count
455
+
456
+ 2. **Turns Tab**
457
+ - Grouped by UserReq (user request)
458
+ - Timeline visualization (gantt chart in table)
459
+ - Turn-level metrics (duration, tool calls)
460
+
461
+ 3. **Sub-Agents Tab**
462
+ - Agent lifecycle timeline
463
+ - Status indicators (Completed ✓ | Failed ✗ | Incomplete ⏳)
464
+ - Tool call aggregation
465
+
466
+ 4. **Tool Summary Tab**
467
+ - Tool invocation frequency
468
+ - Average duration per tool
469
+ - Category-based aggregation
470
+
471
+ 5. **Copilot Insight Tab**
472
+ - AI-powered session analysis
473
+ - Incremental generation with progress tracking
474
+ - Timeout handling (5-minute threshold)
475
+ - Force regenerate option
476
+
477
+ ### Virtual Scrolling
478
+
479
+ **Performance Characteristics:**
480
+
481
+ - **Rendering**: Only visible items rendered (viewport + buffer)
482
+ - **Capacity**: Tested up to 10,000 events without performance degradation
483
+ - **Memory**: Constant memory footprint regardless of event count
484
+ - **Scroll**: 60 FPS smooth scrolling
485
+
486
+ **Implementation Details:**
487
+
488
+ ```javascript
489
+ // Vue 3 + vue-virtual-scroller
490
+ <virtual-scroller
491
+ :items="events"
492
+ :item-size="80"
493
+ :buffer="200"
494
+ key-field="index"
495
+ >
496
+ <template #default="{ item }">
497
+ <!-- Event rendering -->
498
+ </template>
499
+ </virtual-scroller>
500
+ ```
501
+
502
+ ---
503
+
504
+ ## Troubleshooting
505
+
506
+ ### Common Issues
507
+
508
+ **Issue: Session directory not found**
509
+
510
+ ```
511
+ Error: ENOENT: no such file or directory, scandir '/Users/xxx/.copilot/session-state'
512
+ ```
513
+
514
+ **Solution:**
515
+ 1. Verify GitHub Copilot CLI is installed: `copilot --version`
516
+ 2. Run at least one Copilot CLI command to initialize session directory
517
+ 3. Or manually set `SESSION_DIR` in `.env`
518
+
519
+ **Issue: Port already in use**
520
+
521
+ ```
522
+ Error: listen EADDRINUSE: address already in use :::3838
523
+ ```
524
+
525
+ **Solution:**
526
+ ```bash
527
+ # Option 1: Kill existing process
528
+ lsof -ti:3838 | xargs kill -9
529
+
530
+ # Option 2: Use different port
531
+ PORT=3839 npm start
532
+ ```
533
+
534
+ **Issue: AI Insight generation fails**
535
+
536
+ ```
537
+ Error: copilot command not found
538
+ ```
539
+
540
+ **Solution:**
541
+ 1. Install GitHub Copilot CLI
542
+ 2. Verify `copilot --yolo` works: `echo "test" | copilot --yolo -p "analyze"`
543
+ 3. Check PATH includes Copilot CLI binary location
544
+
545
+ **Issue: Large session crashes browser**
546
+
547
+ **Solution:**
548
+ - Upgrade to `session-vue.ejs` view (automatic for 500+ events)
549
+ - Virtual scrolling handles sessions up to 10,000 events
550
+ - If issues persist, increase browser memory limit
551
+
552
+ ---
553
+
554
+ ## Performance Optimization
555
+
556
+ ### Server-Side
557
+
558
+ - **Template Caching**: Enabled in production (`NODE_ENV=production`)
559
+ - **JSONL Streaming**: Line-by-line parsing (constant memory)
560
+ - **Session Repository**: In-memory cache with file system watching
561
+
562
+ ### Client-Side
563
+
564
+ - **Virtual Scrolling**: Only render visible DOM nodes
565
+ - **Event Batching**: Process events in chunks (100 at a time)
566
+ - **Debounced Search**: 300ms delay to prevent excessive filtering
567
+ - **CSS Containment**: `contain: layout style` for scroller items
568
+
569
+ ---
570
+
571
+ ## Roadmap
572
+
573
+ - [ ] WebSocket support for real-time session updates
574
+ - [ ] Advanced filtering (regex, date ranges, multi-field queries)
575
+ - [ ] Session comparison (diff view for multiple sessions)
576
+ - [ ] Export formats (CSV, JSON, HTML report)
577
+ - [ ] Authentication/authorization for multi-user deployments
578
+ - [ ] Database backend (PostgreSQL/SQLite) for large-scale deployments
579
+
580
+ ---
581
+
582
+ ## Contributing
583
+
584
+ This project is maintained as an internal tool. External contributions are not currently accepted.
585
+
586
+ For bug reports or feature requests, contact the repository maintainer.
587
+
588
+ ---
589
+
590
+ ## License
591
+
592
+ MIT License - See LICENSE file for details
593
+
594
+ ---
595
+
596
+ ## Acknowledgments
597
+
598
+ **AI-Generated Code:**
599
+ This project was developed with assistance from GitHub Copilot and Claude AI. All code generation, documentation, and architectural decisions were guided by AI-assisted development workflows.
600
+
601
+ **Dependencies:**
602
+ - Vue 3 (Frontend reactivity)
603
+ - vue-virtual-scroller (Performance-critical virtual scrolling)
604
+ - Express.js (HTTP server framework)
605
+ - EJS (Server-side templating)
606
+ - Multer (File upload handling)
607
+
608
+ **Inspired By:**
609
+ GitHub Copilot CLI session architecture and event stream design patterns.
610
+
611
+ ---
612
+
613
+ **Status:** Active Development | **Version:** 1.0.0 | **Last Updated:** 2026-02-15