-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewer.html
More file actions
193 lines (181 loc) · 13.7 KB
/
viewer.html
File metadata and controls
193 lines (181 loc) · 13.7 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Agent Log Viewer</title>
<style>
*{margin:0;padding:0;box-sizing:border-box}
/* Dark theme (default) */
:root{--bg:#0d0d0d;--sidebar:#171717;--card:#1e1e1e;--border:#2a2a2a;--hover:#2a2a2a;--text:#e3e3e3;--text2:#999;--text3:#666;--blue:#3b82f6;--green:#10a37f;--code-bg:#161616;--user-bg:#1e3a5f;--sep:#3a3a3a;--sb-track:#1a1a1a;--sb-thumb:#555;--inline-code-bg:#333;--strong:#fff;--th-bg:#2a2a2a}
/* Light theme */
.light{--bg:#f5f5f5;--sidebar:#ffffff;--card:#ffffff;--border:#e0e0e0;--hover:#f0f0f0;--text:#1a1a1a;--text2:#666;--text3:#999;--blue:#2563eb;--green:#059669;--code-bg:#f8f8f8;--user-bg:#dbeafe;--sep:#d0d0d0;--sb-track:#e8e8e8;--sb-thumb:#bbb;--inline-code-bg:#e8e8e8;--strong:#000;--th-bg:#f0f0f0}
body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:var(--bg);color:var(--text);height:100vh;overflow:hidden;transition:background .2s,color .2s}
code,pre{font-family:'Cascadia Code','Fira Code',Consolas,Monaco,monospace}
.app{display:flex;height:100vh}
.sidebar{width:260px;min-width:260px;background:var(--sidebar);display:flex;flex-direction:column;border-right:1px solid var(--border);transition:background .2s}
.sidebar.collapsed{width:0;min-width:0;overflow:hidden;border:none}
.sidebar.collapsed *{display:none}
.sb-header{padding:16px 18px;border-bottom:1px solid var(--border)}
.sb-header h1{font-size:13px;font-weight:600}
.sb-header .sub{font-size:11px;color:var(--text3);margin-top:3px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.sb-search{padding:10px 14px;border-bottom:1px solid var(--border)}
.sb-search input{width:100%;background:var(--hover);border:1px solid var(--border);border-radius:6px;padding:6px 10px;color:var(--text);font-size:12px;outline:none}
.sb-search input:focus{border-color:var(--blue)}
.sb-search input::placeholder{color:var(--text3)}
.session-list{flex:1;overflow-y:auto}
.si{padding:10px 18px;cursor:pointer;border-bottom:1px solid var(--border);transition:background .15s}
.si:hover{background:var(--hover)}
.si.active{background:var(--hover)}
.si-time{font-size:11px;color:var(--text2)}
.si-preview{font-size:11px;color:var(--text3);margin-top:2px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.main{flex:1;display:flex;flex-direction:column;overflow:hidden}
.top-bar{padding:8px 20px;border-bottom:1px solid var(--border);display:flex;align-items:center;gap:10px;flex-shrink:0}
.top-bar button{background:none;border:1px solid var(--border);border-radius:6px;color:var(--text2);padding:4px 8px;cursor:pointer;font-size:13px;transition:background .15s}
.top-bar button:hover{background:var(--hover);color:var(--text)}
.top-bar .title{font-size:14px;font-weight:500}
.top-bar .meta{font-size:11px;color:var(--text3)}
.top-bar .spacer{flex:1}
/* Export dropdown */
.export-wrap{position:relative;display:inline-block}
.export-menu{display:none;position:absolute;right:0;top:100%;margin-top:4px;background:var(--sidebar);border:1px solid var(--border);border-radius:8px;overflow:hidden;z-index:100;box-shadow:0 4px 12px rgba(0,0,0,.2);min-width:120px}
.export-menu.open{display:block}
.export-menu button{display:block;width:100%;text-align:left;padding:8px 16px;border:none;background:none;color:var(--text);font-size:12px;cursor:pointer}
.export-menu button:hover{background:var(--hover)}
.msg-wrap{flex:1;overflow-y:auto}
.msg-inner{max-width:800px;margin:0 auto;padding:20px 24px 80px}
.divider{display:flex;align-items:center;gap:14px;margin:28px 0 18px}
.divider::before,.divider::after{content:'';flex:1;height:1px;background:var(--border)}
.divider span{font-size:11px;color:var(--text3);white-space:nowrap}
.msg{display:flex;gap:10px;margin-bottom:18px;align-items:flex-start}
.msg.user{flex-direction:row-reverse}
.ava{width:28px;height:28px;border-radius:6px;flex-shrink:0;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:700}
.msg.user .ava{background:var(--blue);color:#fff}
.msg.assistant .ava{background:var(--green);color:#fff}
.body{max-width:85%;min-width:0}
.msg.user .body{background:var(--user-bg);border-radius:14px 14px 4px 14px;padding:10px 16px}
.msg.assistant .body{background:var(--card);border-radius:14px 14px 14px 4px;padding:10px 16px}
.ts{font-size:10px;color:var(--text3);margin-top:4px}
.msg.user .ts{text-align:right}
.md p{margin-bottom:8px;line-height:1.65}
.md p:last-child{margin-bottom:0}
.md pre{background:var(--code-bg);border-radius:6px;padding:14px;overflow-x:auto;margin:8px 0;position:relative}
.md pre code{font-size:12.5px;line-height:1.5}
.md :not(pre)>code{background:var(--inline-code-bg);padding:1px 5px;border-radius:3px;font-size:12px}
.md ul,.md ol{padding-left:22px;margin:6px 0}
.md li{margin:3px 0;line-height:1.55}
.md blockquote{border-left:3px solid var(--blue);padding-left:12px;color:var(--text2);margin:8px 0}
.md a{color:var(--blue);text-decoration:none}
.md a:hover{text-decoration:underline}
.md table{border-collapse:collapse;margin:8px 0;font-size:12px}
.md th,.md td{border:1px solid var(--border);padding:6px 10px}
.md th{background:var(--th-bg)}
.md h1,.md h2,.md h3,.md h4{margin:14px 0 6px;line-height:1.35}
.md h1{font-size:18px}.md h2{font-size:16px}.md h3{font-size:14px}
.md hr{border:none;border-top:1px solid var(--border);margin:14px 0}
.md strong{color:var(--strong);font-weight:600}
.md img{max-width:100%;border-radius:6px}
.cp{position:absolute;top:6px;right:6px;background:var(--hover);border:1px solid var(--border);border-radius:4px;color:var(--text3);padding:3px 7px;font-size:10px;cursor:pointer;opacity:0;transition:opacity .2s}
pre:hover .cp{opacity:1}
.cp:hover{background:var(--border);color:var(--text)}
::-webkit-scrollbar{width:8px}
::-webkit-scrollbar-track{background:var(--sb-track)}
::-webkit-scrollbar-thumb{background:var(--sb-thumb);border-radius:4px}
::-webkit-scrollbar-thumb:hover{background:var(--text3)}
.msg-sep{border-top:1px dashed var(--sep);margin:8px 0}
/* not-found page */
.nf{display:flex;align-items:center;justify-content:center;height:100vh}
.nf-card{background:var(--card);border-radius:16px;padding:40px;max-width:540px;text-align:center}
.nf-card h2{font-size:18px;margin-bottom:12px}
.nf-card p{color:var(--text2);line-height:1.6;font-size:13px;margin-bottom:8px}
.nf-card code{background:var(--hover);padding:6px 10px;border-radius:4px;font-size:12px;word-break:break-all}
.nf-card ul{text-align:left;padding-left:20px;margin:8px 0}
.nf-card ul li{margin:4px 0}
.nf-card ul code{font-size:11px}
</style>
</head>
<body>
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
(function(){
var MODE='__MODE__';
var DATA=__DATA__;
var PATH='__PATH__';
var NAME='__NAME__';
if(typeof marked!=='undefined'){marked.setOptions({breaks:true,gfm:true});}
function esc(s){var d=document.createElement('div');d.textContent=s;return d.innerHTML;}
function md(t){if(typeof marked!=='undefined'){try{return marked.parse(t);}catch(e){}}return t.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/\n/g,'<br>');}
function fmt(ts){if(!ts)return'';try{var d=new Date(ts);return d.toLocaleString('zh-CN',{month:'2-digit',day:'2-digit',hour:'2-digit',minute:'2-digit'});}catch(e){return ts;}}
// Theme
var isDark=localStorage.getItem('cc-theme')!=='light';
function applyTheme(){document.body.className=isDark?'':'light';var b=document.getElementById('themeBtn');if(b)b.textContent=isDark?'☀':'☾';}
applyTheme();
if(MODE==='notfound'){
var projs='';
if(DATA&&DATA.length){projs='<p style="margin-top:20px;text-align:left">Known Claude Code projects:</p><ul>';DATA.forEach(function(p){projs+='<li><code>'+esc(p)+'</code></li>';});projs+='</ul>';}
document.getElementById('app').innerHTML='<div class="nf"><div class="nf-card"><h2>No Conversations Found</h2><p>This directory has no Claude Code session history:</p><p><code>'+esc(PATH)+'</code></p><p style="margin-top:12px;color:var(--text3);font-size:12px">Only directories where Claude Code has been used will have conversation logs.</p>'+projs+'</div></div>';
return;
}
// Normal mode
var S=DATA;
var totalMsgs=0;S.forEach(function(s){totalMsgs+=s.messages.length;});
document.getElementById('app').innerHTML='<div class="app"><div class="sidebar" id="sidebar"><div class="sb-header"><h1>Agent Log Viewer</h1><div class="sub" title="'+esc(PATH)+'">'+esc(NAME)+'</div></div><div class="sb-search"><input type="text" id="searchInput" placeholder="Search messages..."></div><div class="session-list" id="sessionList"></div></div><div class="main"><div class="top-bar"><button onclick="document.getElementById(\'sidebar\').classList.toggle(\'collapsed\')">☰</button><span class="title">'+esc(NAME)+'</span><span class="meta">'+totalMsgs+' messages</span><span class="spacer"></span><button id="themeBtn" onclick="toggleTheme()"></button><div class="export-wrap"><button onclick="toggleExport()">Export</button><div class="export-menu" id="exportMenu"><button onclick="doExport(\'md\')">Markdown (.md)</button><button onclick="doExport(\'txt\')">Text (.txt)</button><button onclick="doExport(\'doc\')">Word (.doc)</button></div></div></div><div class="msg-wrap" id="msgWrap"><div class="msg-inner" id="msgInner"></div></div></div></div>';
applyTheme();
var sl=document.getElementById('sessionList');
var mi=document.getElementById('msgInner');
function cpBtns(c){c.querySelectorAll('pre').forEach(function(p){var b=document.createElement('button');b.className='cp';b.textContent='Copy';b.onclick=function(){navigator.clipboard.writeText(p.textContent.trim()).then(function(){b.textContent='Done';setTimeout(function(){b.textContent='Copy';},1200);});};p.appendChild(b);});}
function render(){
var sh='',mh='';
S.forEach(function(s,i){
sh+='<div class="si" onclick="go('+i+')" id="si'+i+'"><div class="si-time">'+esc(fmt(s.startTime))+'</div><div class="si-preview">'+esc((s.messages.filter(function(m){return m.role==='user';})[0]||{}).content||'').substring(0,80)+' </div></div>';
mh+='<div class="divider" id="dv'+i+'"><span>'+esc(fmt(s.startTime))+'</span></div>';
var prevRole='';
s.messages.forEach(function(m,j){
var role=m.role,ts=m.ts?fmt(m.ts):'',ct=md(m.content);
if(role!==prevRole){
if(prevRole) mh+='</div></div>';
var av=role==='user'?'U':'C';
mh+='<div class="msg '+role+'"><div class="ava">'+av+'</div><div class="body"><div class="md">'+ct+'</div>'+(ts?'<div class="ts">'+esc(ts)+'</div>':'');
} else {
mh+='<div class="msg-sep"></div><div class="md">'+ct+'</div>'+(ts?'<div class="ts">'+esc(ts)+'</div>':'');
}
prevRole=role;
});
if(prevRole) mh+='</div></div>';
});
sl.innerHTML=sh;mi.innerHTML=mh;cpBtns(mi);
}
window.go=function(i){var el=document.getElementById('dv'+i);if(el)el.scrollIntoView({behavior:'smooth',block:'start'});document.querySelectorAll('.si').forEach(function(x){x.classList.remove('active');});var si=document.getElementById('si'+i);if(si)si.classList.add('active');};
// Theme toggle
window.toggleTheme=function(){isDark=!isDark;localStorage.setItem('cc-theme',isDark?'dark':'light');applyTheme();};
// Export
window.toggleExport=function(){var m=document.getElementById('exportMenu');m.classList.toggle('open');};
document.addEventListener('click',function(e){if(!e.target.closest('.export-wrap')){var m=document.getElementById('exportMenu');if(m)m.classList.remove('open');}});
window.doExport=function(type){
document.getElementById('exportMenu').classList.remove('open');
var text='',ext='';
if(type==='md'){
ext='md';
S.forEach(function(s){text+='## Session - '+fmt(s.startTime)+'\n\n';s.messages.forEach(function(m){text+=(m.role==='user'?'**User**':'**Assistant**')+'\n\n'+m.content+'\n\n---\n\n';});});
} else if(type==='txt'){
ext='txt';
S.forEach(function(s){text+='=== Session: '+fmt(s.startTime)+' ===\n\n';s.messages.forEach(function(m){text+='['+(m.role==='user'?'User':'Assistant')+'] '+((m.ts||'').substring(0,16))+'\n'+m.content+'\n\n';});});
} else if(type==='doc'){
ext='doc';
var html='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"><head><meta charset="utf-8"><style>body{font-family:sans-serif;margin:40px}h2{border-bottom:1px solid #ccc;padding-bottom:4px}.u{color:#2563eb;font-weight:bold}.a{color:#059669;font-weight:bold}blockquote{border-left:3px solid #ccc;padding-left:8px;color:#666}pre{background:#f5f5f5;padding:10px;border-radius:4px;font-family:monospace;font-size:12px}</style></head><body>';
S.forEach(function(s){html+='<h2>Session - '+esc(fmt(s.startTime))+'</h2>';s.messages.forEach(function(m){html+='<p class="'+(m.role==='user'?'u':'a')+'">'+(m.role==='user'?'User':'Assistant')+'</p><div>'+md(m.content)+'</div><hr>';});});
html+='</body></html>';
downloadBlob(new Blob([html],{type:'application/msword'}),NAME+'.'+ext);
return;
}
downloadBlob(new Blob([text],{type:'text/plain;charset=utf-8'}),NAME+'.'+ext);
};
function downloadBlob(blob,name){var a=document.createElement('a');a.href=URL.createObjectURL(blob);a.download=name;document.body.appendChild(a);a.click();document.body.removeChild(a);URL.revokeObjectURL(a.href);}
var st;document.getElementById('searchInput').addEventListener('input',function(){clearTimeout(st);var q=this.value.trim().toLowerCase();st=setTimeout(function(){document.querySelectorAll('.si').forEach(function(e){e.style.display=(!q||e.textContent.toLowerCase().includes(q))?'':'none';});},200);});
document.getElementById('msgWrap').addEventListener('scroll',function(){var ds=document.querySelectorAll('.divider'),ai=0;ds.forEach(function(d,i){if(d.getBoundingClientRect().top<200)ai=i;});document.querySelectorAll('.si').forEach(function(x){x.classList.remove('active');});var a=document.getElementById('si'+ai);if(a)a.classList.add('active');});
render();
})();
</script>
</body>
</html>