cc-viewer 1.4.18 → 1.4.19
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/package.json +2 -1
- package/workspace-registry.js +82 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-viewer",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.19",
|
|
4
4
|
"description": "Claude Code Logger visualization management tool",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "server.js",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"plugin-loader.js",
|
|
56
56
|
"pty-manager.js",
|
|
57
57
|
"locales/",
|
|
58
|
+
"workspace-registry.js",
|
|
58
59
|
"concepts/"
|
|
59
60
|
],
|
|
60
61
|
"devDependencies": {
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Workspace Registry - 工作区持久化管理
|
|
2
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, statSync, readdirSync } from 'node:fs';
|
|
3
|
+
import { join, basename, resolve } from 'node:path';
|
|
4
|
+
import { randomBytes } from 'node:crypto';
|
|
5
|
+
import { LOG_DIR } from './findcc.js';
|
|
6
|
+
|
|
7
|
+
const WORKSPACES_FILE = join(LOG_DIR, 'workspaces.json');
|
|
8
|
+
|
|
9
|
+
export function loadWorkspaces() {
|
|
10
|
+
try {
|
|
11
|
+
if (!existsSync(WORKSPACES_FILE)) return [];
|
|
12
|
+
const data = JSON.parse(readFileSync(WORKSPACES_FILE, 'utf-8'));
|
|
13
|
+
return Array.isArray(data.workspaces) ? data.workspaces : [];
|
|
14
|
+
} catch {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function saveWorkspaces(list) {
|
|
20
|
+
try {
|
|
21
|
+
mkdirSync(LOG_DIR, { recursive: true });
|
|
22
|
+
writeFileSync(WORKSPACES_FILE, JSON.stringify({ workspaces: list }, null, 2));
|
|
23
|
+
} catch (err) {
|
|
24
|
+
console.error('[CC Viewer] Failed to save workspaces:', err.message);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function registerWorkspace(absolutePath) {
|
|
29
|
+
const resolvedPath = resolve(absolutePath);
|
|
30
|
+
const projectName = basename(resolvedPath).replace(/[^a-zA-Z0-9_\-\.]/g, '_');
|
|
31
|
+
const list = loadWorkspaces();
|
|
32
|
+
const existing = list.find(w => w.path === resolvedPath);
|
|
33
|
+
if (existing) {
|
|
34
|
+
existing.lastUsed = new Date().toISOString();
|
|
35
|
+
existing.projectName = projectName;
|
|
36
|
+
saveWorkspaces(list);
|
|
37
|
+
return existing;
|
|
38
|
+
}
|
|
39
|
+
const entry = {
|
|
40
|
+
id: randomBytes(6).toString('hex'),
|
|
41
|
+
path: resolvedPath,
|
|
42
|
+
projectName,
|
|
43
|
+
lastUsed: new Date().toISOString(),
|
|
44
|
+
createdAt: new Date().toISOString(),
|
|
45
|
+
};
|
|
46
|
+
list.push(entry);
|
|
47
|
+
saveWorkspaces(list);
|
|
48
|
+
return entry;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function removeWorkspace(id) {
|
|
52
|
+
const list = loadWorkspaces();
|
|
53
|
+
const filtered = list.filter(w => w.id !== id);
|
|
54
|
+
if (filtered.length !== list.length) {
|
|
55
|
+
saveWorkspaces(filtered);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function getWorkspaces() {
|
|
62
|
+
const list = loadWorkspaces();
|
|
63
|
+
return list
|
|
64
|
+
.map(w => {
|
|
65
|
+
let logCount = 0;
|
|
66
|
+
let totalSize = 0;
|
|
67
|
+
const logDir = join(LOG_DIR, w.projectName);
|
|
68
|
+
try {
|
|
69
|
+
if (existsSync(logDir)) {
|
|
70
|
+
const files = readdirSync(logDir);
|
|
71
|
+
for (const f of files) {
|
|
72
|
+
if (f.endsWith('.jsonl')) {
|
|
73
|
+
logCount++;
|
|
74
|
+
try { totalSize += statSync(join(logDir, f)).size; } catch {}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} catch {}
|
|
79
|
+
return { ...w, logCount, totalSize };
|
|
80
|
+
})
|
|
81
|
+
.sort((a, b) => new Date(b.lastUsed) - new Date(a.lastUsed));
|
|
82
|
+
}
|