-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewer.html
More file actions
324 lines (287 loc) · 13.2 KB
/
viewer.html
File metadata and controls
324 lines (287 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Claude Timecodes</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
--bg: #0d1117; --surface: #161b22; --border: #30363d;
--text: #e6edf3; --dim: #7d8590; --accent: #f0c14b;
--user: #3fb950; --claude: #58a6ff; --hover: #1c2128;
}
body { font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; background: var(--bg); color: var(--text); display: flex; height: 100vh; font-size: 13px; }
/* Sidebar */
#sidebar { width: 340px; min-width: 340px; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--surface); }
#sidebar-header { padding: 16px; border-bottom: 1px solid var(--border); }
#sidebar-header h1 { font-size: 16px; color: var(--accent); margin-bottom: 10px; letter-spacing: 1px; }
#search-box { width: 100%; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-family: inherit; font-size: 13px; outline: none; }
#search-box:focus { border-color: var(--accent); }
#search-box::placeholder { color: var(--dim); }
#session-list { flex: 1; overflow-y: auto; }
.session-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
.session-item:hover { background: var(--hover); }
.session-item.active { background: var(--hover); border-left: 3px solid var(--accent); }
.session-date { color: var(--accent); font-size: 12px; font-weight: 600; }
.session-duration { color: var(--dim); font-size: 11px; margin-left: 8px; }
.session-preview { color: var(--dim); font-size: 12px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-meta { color: var(--dim); font-size: 11px; margin-top: 2px; }
#stats { padding: 10px 16px; border-top: 1px solid var(--border); color: var(--dim); font-size: 11px; }
/* Main content */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#main-header { padding: 16px; border-bottom: 1px solid var(--border); background: var(--surface); display: flex; align-items: center; gap: 12px; }
#main-header .session-id { color: var(--dim); font-size: 12px; }
#main-header .session-title { color: var(--text); font-size: 14px; font-weight: 600; }
#conversation { flex: 1; overflow-y: auto; padding: 16px; }
.message { margin-bottom: 16px; max-width: 900px; }
.message-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.timecode { color: var(--accent); font-size: 11px; font-weight: 600; cursor: pointer; }
.timecode:hover { text-decoration: underline; }
.role { font-weight: 700; font-size: 13px; }
.role-user { color: var(--user); }
.role-claude { color: var(--claude); }
.message-body { padding: 8px 12px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; }
.message-body.user-body { border-left: 3px solid var(--user); }
.message-body.claude-body { border-left: 3px solid var(--claude); }
.highlight { background: rgba(240, 193, 75, 0.25); padding: 1px 2px; border-radius: 2px; }
.no-session { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--dim); font-size: 15px; }
/* Search results in main */
.search-result { margin-bottom: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; transition: border-color 0.1s; }
.search-result:hover { border-color: var(--accent); }
.search-result .sr-session { color: var(--dim); font-size: 11px; }
.search-result .sr-timecode { color: var(--accent); font-size: 12px; margin-right: 8px; }
.search-result .sr-content { margin-top: 4px; color: var(--text); font-size: 13px; }
/* Timeline bar */
#timeline { height: 40px; background: var(--surface); border-top: 1px solid var(--border); padding: 8px 16px; display: flex; align-items: center; gap: 4px; }
.timeline-block { height: 20px; border-radius: 3px; min-width: 2px; cursor: pointer; transition: opacity 0.1s; }
.timeline-block:hover { opacity: 0.8; }
.timeline-block.user-block { background: var(--user); }
.timeline-block.claude-block { background: var(--claude); }
/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--dim); }
</style>
</head>
<body>
<div id="sidebar">
<div id="sidebar-header">
<h1>CLAUDE TIMECODES</h1>
<input type="text" id="search-box" placeholder="Search conversations..." />
</div>
<div id="session-list"></div>
<div id="stats"></div>
</div>
<div id="main">
<div id="main-header" style="display:none;">
<div>
<div class="session-title" id="session-title"></div>
<div class="session-id" id="session-id-display"></div>
</div>
</div>
<div id="conversation">
<div class="no-session">Select a session to view timestamped conversation</div>
</div>
<div id="timeline" style="display:none;"></div>
</div>
<script>
let allSessions = [];
let allMessages = {};
let currentSession = null;
let searchTimeout = null;
let userName = 'You';
async function fetchJSON(url) {
const res = await fetch(url);
return res.json();
}
function formatTimecode(isoStr) {
try {
const d = new Date(isoStr);
return d.toLocaleString('en-US', {
year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', second: '2-digit',
hour12: false
});
} catch { return ''; }
}
function formatDuration(ms) {
const mins = Math.floor(ms / 60000);
if (mins < 60) return `${mins}m`;
const hours = Math.floor(mins / 60);
const rem = mins % 60;
return `${hours}h${rem}m`;
}
function extractText(content) {
if (typeof content === 'string') return content;
if (Array.isArray(content)) {
return content.map(b => {
if (b.type === 'text') return b.text || '';
if (b.type === 'tool_use') return `[tool: ${b.name || '?'}]`;
if (b.type === 'tool_result') return '[tool result]';
return '';
}).join(' ');
}
return String(content || '');
}
function truncate(text, len) {
text = text.replace(/\n/g, ' ').trim();
return text.length > len ? text.slice(0, len) + '...' : text;
}
function escapeHtml(text) {
const el = document.createElement('div');
el.textContent = text;
return el.innerHTML;
}
function highlightText(text, query) {
if (!query) return escapeHtml(text);
const escaped = escapeHtml(text);
const re = new RegExp(`(${query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`, 'gi');
return escaped.replace(re, '<span class="highlight">$1</span>');
}
async function loadSessions() {
const config = await fetchJSON('/api/config');
userName = config.displayName || 'You';
allSessions = await fetchJSON('/api/sessions');
allSessions.sort((a, b) => new Date(b.first_ts) - new Date(a.first_ts));
renderSessionList(allSessions);
document.getElementById('stats').textContent =
`${allSessions.length} sessions | ${allSessions.reduce((s, x) => s + x.message_count, 0)} messages`;
}
function renderSessionList(sessions) {
const list = document.getElementById('session-list');
list.innerHTML = sessions.map(s => {
const start = formatTimecode(s.first_ts);
const dur = s.first_ts && s.last_ts
? formatDuration(new Date(s.last_ts) - new Date(s.first_ts))
: '';
const active = currentSession === s.session_id ? ' active' : '';
return `<div class="session-item${active}" data-id="${s.session_id}">
<span class="session-date">${start}</span>
<span class="session-duration">${dur} · ${s.message_count} msgs</span>
<div class="session-preview">${escapeHtml(s.preview || '')}</div>
</div>`;
}).join('');
list.querySelectorAll('.session-item').forEach(el => {
el.addEventListener('click', () => loadConversation(el.dataset.id));
});
}
async function loadConversation(sessionId) {
currentSession = sessionId;
renderSessionList(allSessions);
if (!allMessages[sessionId]) {
allMessages[sessionId] = await fetchJSON(`/api/session/${sessionId}`);
}
const messages = allMessages[sessionId];
const conv = document.getElementById('conversation');
const header = document.getElementById('main-header');
const timeline = document.getElementById('timeline');
// Find first user message for title
const firstUser = messages.find(m => m.type === 'user');
const title = firstUser ? truncate(extractText(firstUser.message?.content || ''), 80) : 'Session';
header.style.display = 'flex';
document.getElementById('session-title').textContent = title;
document.getElementById('session-id-display').textContent = sessionId;
conv.innerHTML = messages.map((msg, i) => {
const tc = formatTimecode(msg.timestamp);
const role = msg.type === 'user' ? userName : 'Claude';
const roleClass = msg.type === 'user' ? 'role-user' : 'role-claude';
const bodyClass = msg.type === 'user' ? 'user-body' : 'claude-body';
const content = extractText(msg.message?.content || '');
// Truncate very long Claude messages
const display = content.length > 2000 ? content.slice(0, 2000) + '\n\n[...truncated]' : content;
return `<div class="message" id="msg-${i}">
<div class="message-header">
<span class="timecode" title="Click to copy">${tc}</span>
<span class="role ${roleClass}">${role}</span>
</div>
<div class="message-body ${bodyClass}">${escapeHtml(display)}</div>
</div>`;
}).join('');
// Timeline
if (messages.length > 1) {
const start = new Date(messages[0].timestamp).getTime();
const end = new Date(messages[messages.length - 1].timestamp).getTime();
const span = end - start || 1;
timeline.style.display = 'flex';
timeline.innerHTML = messages.map((msg, i) => {
const pos = ((new Date(msg.timestamp).getTime() - start) / span) * 100;
const cls = msg.type === 'user' ? 'user-block' : 'claude-block';
return `<div class="timeline-block ${cls}" style="flex: 0 0 ${Math.max(100 / messages.length, 2)}px" data-idx="${i}" title="${formatTimecode(msg.timestamp)}"></div>`;
}).join('');
timeline.querySelectorAll('.timeline-block').forEach(el => {
el.addEventListener('click', () => {
document.getElementById(`msg-${el.dataset.idx}`)?.scrollIntoView({ behavior: 'smooth', block: 'center' });
});
});
}
// Timecode click-to-copy
conv.querySelectorAll('.timecode').forEach(el => {
el.addEventListener('click', () => {
navigator.clipboard.writeText(el.textContent);
el.style.color = '#3fb950';
setTimeout(() => el.style.color = '', 600);
});
});
}
function doSearch(query) {
if (!query.trim()) {
renderSessionList(allSessions);
document.getElementById('conversation').innerHTML =
'<div class="no-session">Select a session to view timestamped conversation</div>';
document.getElementById('main-header').style.display = 'none';
document.getElementById('timeline').style.display = 'none';
return;
}
// Filter sessions by preview text
const filtered = allSessions.filter(s =>
(s.preview || '').toLowerCase().includes(query.toLowerCase())
);
renderSessionList(filtered.length ? filtered : allSessions);
// Search via API
fetch(`/api/search?q=${encodeURIComponent(query)}`)
.then(r => r.json())
.then(results => {
const conv = document.getElementById('conversation');
document.getElementById('main-header').style.display = 'flex';
document.getElementById('session-title').textContent = `Search: "${query}"`;
document.getElementById('session-id-display').textContent = `${results.length} results`;
document.getElementById('timeline').style.display = 'none';
if (!results.length) {
conv.innerHTML = '<div class="no-session">No results found</div>';
return;
}
conv.innerHTML = results.map(r => {
const tc = formatTimecode(r.timestamp);
const role = r.type === 'user' ? userName : 'Claude';
const roleClass = r.type === 'user' ? 'role-user' : 'role-claude';
const content = truncate(extractText(r.content), 300);
return `<div class="search-result" data-session="${r.session_id}">
<span class="sr-timecode">${tc}</span>
<span class="role ${roleClass}">${role}</span>
<span class="sr-session">${r.session_id.slice(0, 8)}</span>
<div class="sr-content">${highlightText(content, query)}</div>
</div>`;
}).join('');
conv.querySelectorAll('.search-result').forEach(el => {
el.addEventListener('click', () => loadConversation(el.dataset.session));
});
});
}
// Search with debounce
document.getElementById('search-box').addEventListener('input', e => {
clearTimeout(searchTimeout);
searchTimeout = setTimeout(() => doSearch(e.target.value), 300);
});
// Keyboard shortcut: Ctrl/Cmd+K to focus search
document.addEventListener('keydown', e => {
if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
e.preventDefault();
document.getElementById('search-box').focus();
}
});
loadSessions();
</script>
</body>
</html>