-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewer.html
More file actions
371 lines (319 loc) · 13.2 KB
/
Copy pathviewer.html
File metadata and controls
371 lines (319 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Memory Plugin - 记忆查看器</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1000px;
margin: 0 auto;
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
text-align: center;
}
.header h1 {
font-size: 2em;
margin-bottom: 10px;
}
.content {
padding: 30px;
}
.loading {
text-align: center;
padding: 50px;
color: #666;
}
.error {
background: #ffe6e6;
border: 2px solid #ff6b6b;
color: #c92a2a;
padding: 20px;
border-radius: 10px;
margin: 20px;
}
.section {
margin-bottom: 30px;
}
.section-title {
font-size: 1.5em;
color: #333;
margin-bottom: 15px;
padding-bottom: 8px;
border-bottom: 2px solid #667eea;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-bottom: 20px;
}
.stat-card {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
border-radius: 12px;
text-align: center;
}
.stat-card .label {
font-size: 0.85em;
opacity: 0.9;
margin-bottom: 8px;
}
.stat-card .value {
font-size: 2em;
font-weight: bold;
}
.data-display {
background: #f8f9fa;
padding: 20px;
border-radius: 12px;
font-family: 'Courier New', monospace;
white-space: pre-wrap;
word-wrap: break-word;
max-height: 400px;
overflow-y: auto;
}
.btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 12px 24px;
border-radius: 8px;
cursor: pointer;
font-size: 1em;
margin: 5px;
transition: transform 0.2s;
}
.btn:hover {
transform: translateY(-2px);
}
.btn-danger {
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
}
.actions {
text-align: center;
margin: 20px 0;
}
.tag {
display: inline-block;
background: #667eea;
color: white;
padding: 3px 10px;
border-radius: 15px;
font-size: 0.8em;
margin: 2px;
}
.info-box {
background: #e7f5ff;
border-left: 4px solid #339af0;
padding: 15px;
margin: 15px 0;
border-radius: 8px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🧠 Memory Plugin 查看器</h1>
<p>查看和管理你的记忆数据</p>
</div>
<div class="content">
<div id="loading" class="loading">
<p>⏳ 正在加载记忆数据...</p>
</div>
<div id="error" class="error" style="display: none;">
<h3>❌ 加载失败</h3>
<p id="errorMessage"></p>
</div>
<div id="content" style="display: none;">
<div class="info-box">
<strong>💡 提示:</strong>这是 Memory Plugin 的数据查看器。你可以在这里查看所有的记忆数据,包括偏好设置、工具使用统计、项目信息等。
</div>
<div class="actions">
<button class="btn" onclick="refreshData()">🔄 刷新数据</button>
<button class="btn" onclick="exportData()">💾 导出数据</button>
<button class="btn btn-danger" onclick="clearViewerCache()">🧹 清除查看器缓存</button>
</div>
<div id="dataContent"></div>
</div>
</div>
</div>
<script>
let currentData = null;
// 页面加载时获取数据
window.onload = function() {
loadData();
};
// 加载数据
async function loadData() {
const loadingEl = document.getElementById('loading');
const errorEl = document.getElementById('error');
const contentEl = document.getElementById('content');
const errorMessageEl = document.getElementById('errorMessage');
try {
loadingEl.style.display = 'block';
errorEl.style.display = 'none';
contentEl.style.display = 'none';
// 尝试从 localStorage 或文件加载数据
const data = await fetchMemoryData();
if (!data) {
throw new Error('未找到记忆数据文件。请先使用 Memory Plugin 记录一些数据。');
}
currentData = data;
displayData(data);
loadingEl.style.display = 'none';
contentEl.style.display = 'block';
} catch (error) {
loadingEl.style.display = 'none';
errorEl.style.display = 'block';
errorMessageEl.textContent = error.message;
console.error('加载数据失败:', error);
}
}
// 获取记忆数据
async function fetchMemoryData() {
// 首先尝试从 localStorage 读取(用于演示模式)
const stored = localStorage.getItem('memory-plugin-data');
if (stored) {
return JSON.parse(stored);
}
// 尝试从文件加载(需要服务器环境)
try {
const response = await fetch('.dsh-memory.json');
if (response.ok) {
const data = await response.json();
// 保存到 localStorage 以便下次使用
localStorage.setItem('memory-plugin-data', JSON.stringify(data));
return data;
}
} catch (e) {
console.log('无法从文件加载,使用 localStorage');
}
return null;
}
function escapeHtml(value) {
return String(value ?? '').replace(/[&<>"']/g, character => ({
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
}[character]));
}
// 显示数据
function displayData(data) {
const contentEl = document.getElementById('dataContent');
let html = '';
// 统计概览
html += '<div class="section">';
html += '<h2 class="section-title">📊 数据概览</h2>';
html += '<div class="stats-grid">';
html += `<div class="stat-card"><div class="label">版本</div><div class="value">${escapeHtml(data.version || 'N/A')}</div></div>`;
html += `<div class="stat-card"><div class="label">会话数</div><div class="value">${escapeHtml(data.metadata?.totalSessions || 0)}</div></div>`;
html += `<div class="stat-card"><div class="label">项目数</div><div class="value">${escapeHtml((data.projectContext?.activeProjects || []).length)}</div></div>`;
html += `<div class="stat-card"><div class="label">主题数</div><div class="value">${escapeHtml((data.sessionHistory?.recentTopics || []).length)}</div></div>`;
html += '</div></div>';
// 用户偏好
if (data.userPreferences && Object.keys(data.userPreferences).length > 0) {
html += '<div class="section">';
html += '<h2 class="section-title">👤 用户偏好</h2>';
html += '<div class="data-display">';
html += escapeHtml(JSON.stringify(data.userPreferences, null, 2));
html += '</div></div>';
}
// 工具使用统计
if (data.sessionHistory?.toolUsageStats && Object.keys(data.sessionHistory.toolUsageStats).length > 0) {
html += '<div class="section">';
html += '<h2 class="section-title">🛠️ 工具使用统计</h2>';
html += '<div class="data-display">';
const stats = data.sessionHistory.toolUsageStats;
const sorted = Object.entries(stats).sort((a, b) => b[1] - a[1]);
sorted.forEach(([tool, count]) => {
html += `${escapeHtml(tool)}: ${escapeHtml(count)} 次\n`;
});
html += '</div></div>';
}
// 项目列表
if (data.projectContext?.activeProjects && data.projectContext.activeProjects.length > 0) {
html += '<div class="section">';
html += '<h2 class="section-title">📁 项目列表</h2>';
html += '<div class="data-display">';
data.projectContext.activeProjects.forEach(project => {
html += `• ${escapeHtml(project.name)}\n`;
html += ` 路径: ${escapeHtml(project.path)}\n`;
html += ` 标签: ${escapeHtml((project.tags || []).join(', '))}\n`;
html += ` 最后访问: ${escapeHtml(new Date(project.lastAccessed).toLocaleString('zh-CN'))}\n\n`;
});
html += '</div></div>';
}
// 最近主题
if (data.sessionHistory?.recentTopics && data.sessionHistory.recentTopics.length > 0) {
html += '<div class="section">';
html += '<h2 class="section-title">💬 最近主题</h2>';
html += '<div class="data-display">';
data.sessionHistory.recentTopics.slice(0, 10).forEach((topic, i) => {
html += `${i + 1}. ${escapeHtml(topic.content)} (${escapeHtml(new Date(topic.timestamp).toLocaleString('zh-CN'))})\n`;
});
html += '</div></div>';
}
// 完整数据
html += '<div class="section">';
html += '<h2 class="section-title">📦 完整数据(JSON)</h2>';
html += '<div class="data-display">';
html += escapeHtml(JSON.stringify(data, null, 2));
html += '</div></div>';
contentEl.innerHTML = html;
}
// 刷新数据
function refreshData() {
loadData();
}
// 导出数据
function exportData() {
if (!currentData) {
alert('没有数据可导出');
return;
}
const dataStr = JSON.stringify(currentData, null, 2);
const dataBlob = new Blob([dataStr], { type: 'application/json' });
const url = URL.createObjectURL(dataBlob);
const link = document.createElement('a');
link.href = url;
link.download = `memory-backup-${new Date().toISOString().split('T')[0]}.json`;
link.click();
URL.revokeObjectURL(url);
alert('✅ 数据已导出!');
}
// 清除查看器缓存;不会修改插件的 .dsh-memory.json 文件
function clearViewerCache() {
if (confirm('⚠️ 确定要清除查看器缓存吗?原始记忆文件不会被修改。')) {
localStorage.removeItem('memory-plugin-data');
currentData = null;
document.getElementById('dataContent').textContent = '';
document.getElementById('content').style.display = 'none';
alert('✅ 查看器缓存已清除;原始记忆文件未修改。');
}
}
</script>
</body>
</html>