kodelyth-ecc 1.2.2 → 1.3.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.
@@ -1,201 +0,0 @@
1
- // Kodelyth Lens — OpenCode Reader
2
- // Reads OpenCode session logs from ~/.opencode/ and project .opencode/
3
- // OpenCode stores conversations in JSONL and JSON formats
4
- // Part of Kodelyth ECC — github.com/sifxprime/kodelyth-ecc
5
-
6
- import fs from 'node:fs';
7
- import path from 'node:path';
8
- import os from 'node:os';
9
- import { detectAgentsInMessages } from '../agent-tracker.js';
10
-
11
- const HOME = os.homedir();
12
-
13
- export async function readOpenCodeData(dataDir) {
14
- // OpenCode may store data in multiple locations
15
- const searchDirs = [
16
- dataDir,
17
- path.join(HOME, '.opencode'),
18
- path.join(HOME, '.config', 'opencode'),
19
- path.join(HOME, 'Library', 'Application Support', 'opencode'), // macOS
20
- path.join(HOME, 'AppData', 'Roaming', 'opencode'), // Windows
21
- path.join(process.cwd(), '.opencode'), // project-local
22
- ].filter(Boolean);
23
-
24
- const sessions = [];
25
-
26
- for (const dir of searchDirs) {
27
- if (!dir || !fs.existsSync(dir)) continue;
28
-
29
- try {
30
- await collectSessionsFromDir(dir, sessions);
31
- } catch { /* skip inaccessible directories */ }
32
- }
33
-
34
- // Deduplicate by id
35
- const seen = new Set();
36
- const unique = sessions.filter(s => {
37
- if (seen.has(s.id)) return false;
38
- seen.add(s.id);
39
- return true;
40
- });
41
-
42
- unique.sort((a, b) => (b.timestamp || '').localeCompare(a.timestamp || ''));
43
-
44
- return { sessions: unique, available: unique.length > 0 };
45
- }
46
-
47
- async function collectSessionsFromDir(dir, sessions) {
48
- const entries = fs.readdirSync(dir, { withFileTypes: true });
49
-
50
- for (const entry of entries) {
51
- const fullPath = path.join(dir, entry.name);
52
-
53
- if (entry.isDirectory()) {
54
- // Recurse one level into sessions/, conversations/, history/ subdirs
55
- const name = entry.name.toLowerCase();
56
- if (['sessions', 'conversations', 'history', 'chats', 'logs'].includes(name)) {
57
- try {
58
- await collectSessionsFromDir(fullPath, sessions);
59
- } catch { /* skip */ }
60
- }
61
- continue;
62
- }
63
-
64
- if (!entry.isFile()) continue;
65
-
66
- const isJsonl = entry.name.endsWith('.jsonl');
67
- const isJson = entry.name.endsWith('.json');
68
- if (!isJsonl && !isJson) continue;
69
-
70
- try {
71
- const session = parseOpenCodeFile(fullPath);
72
- if (session) sessions.push(session);
73
- } catch { /* skip malformed files */ }
74
- }
75
- }
76
-
77
- function parseOpenCodeFile(filePath) {
78
- const raw = fs.readFileSync(filePath, 'utf-8').trim();
79
- if (!raw) return null;
80
-
81
- const messages = [];
82
- let firstTs = null;
83
- let tokens = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 };
84
-
85
- // ── Try JSONL (line-by-line events) ─────────────────────────────────────────
86
- const lines = raw.split('\n').filter(Boolean);
87
- let jsonlOk = false;
88
-
89
- for (const line of lines) {
90
- try {
91
- const entry = JSON.parse(line);
92
- if (typeof entry !== 'object' || !entry) continue;
93
-
94
- // Extract timestamp
95
- const ts = entry.timestamp || entry.created_at || entry.time || null;
96
- if (ts && !firstTs) firstTs = ts;
97
-
98
- // Extract role + content — OpenCode may use different field names
99
- const role = entry.role
100
- || (entry.type === 'user' ? 'user' : null)
101
- || (entry.type === 'assistant' ? 'assistant' : null)
102
- || (entry.sender === 'human' ? 'user' : null)
103
- || (entry.sender === 'ai' ? 'assistant' : null)
104
- || 'user';
105
-
106
- const content = entry.content
107
- || entry.message
108
- || entry.text
109
- || entry.body
110
- || (typeof entry.parts === 'string' ? entry.parts : null)
111
- || (Array.isArray(entry.parts)
112
- ? entry.parts.map(p => (typeof p === 'string' ? p : p?.text || '')).join(' ')
113
- : null)
114
- || '';
115
-
116
- if (content) {
117
- messages.push({ role, content, timestamp: ts });
118
- jsonlOk = true;
119
- }
120
-
121
- // Accumulate token usage if present
122
- if (entry.usage) {
123
- tokens.input += entry.usage.input_tokens || entry.usage.prompt_tokens || 0;
124
- tokens.output += entry.usage.output_tokens || entry.usage.completion_tokens || 0;
125
- tokens.cacheRead += entry.usage.cache_read_input_tokens || 0;
126
- tokens.cacheWrite+= entry.usage.cache_creation_input_tokens || 0;
127
- }
128
- } catch { /* not valid JSON line */ }
129
- }
130
-
131
- // ── Try single JSON object ───────────────────────────────────────────────────
132
- if (!jsonlOk || messages.length === 0) {
133
- try {
134
- const data = JSON.parse(raw);
135
- const items = data.messages
136
- || data.history
137
- || data.conversation
138
- || data.turns
139
- || [];
140
-
141
- for (const item of items) {
142
- if (!item) continue;
143
- const ts = item.timestamp || item.created_at || null;
144
- if (ts && !firstTs) firstTs = ts;
145
-
146
- const role = item.role || item.sender || 'user';
147
- const content = item.content || item.text || item.message || '';
148
-
149
- if (content) messages.push({ role, content, timestamp: ts });
150
- }
151
-
152
- // Top-level usage
153
- if (data.usage) {
154
- tokens.input = data.usage.input_tokens || data.usage.prompt_tokens || 0;
155
- tokens.output = data.usage.output_tokens || data.usage.completion_tokens || 0;
156
- }
157
-
158
- // Top-level timestamp
159
- if (!firstTs) firstTs = data.timestamp || data.created_at || data.startedAt || null;
160
- } catch { /* skip */ }
161
- }
162
-
163
- if (messages.length === 0) return null;
164
-
165
- tokens.total = tokens.input + tokens.output;
166
-
167
- const ts = firstTs || new Date().toISOString();
168
- const agents = detectAgentsInMessages(messages);
169
-
170
- return {
171
- id: path.basename(filePath),
172
- platform: 'opencode',
173
- project: path.dirname(filePath).split(path.sep).pop() || 'opencode',
174
- date: ts.slice(0, 10),
175
- lastDate: ts.slice(0, 10),
176
- timestamp: ts,
177
- lastActivity: ts,
178
- tokens,
179
- cost: estimateCost(tokens),
180
- cacheSaved: estimateCacheSavings(tokens),
181
- messageCount: messages.length,
182
- agents,
183
- agentCalls: agents.length,
184
- };
185
- }
186
-
187
- // OpenCode uses Claude/OpenAI models — approximate pricing
188
- function estimateCost(tokens) {
189
- // Sonnet 4 pricing: $3/M input, $15/M output
190
- const inputCost = (tokens.input / 1_000_000) * 3;
191
- const outputCost = (tokens.output / 1_000_000) * 15;
192
- const cacheRead = (tokens.cacheRead / 1_000_000) * 0.3;
193
- return Math.round((inputCost + outputCost + cacheRead) * 10000) / 10000;
194
- }
195
-
196
- function estimateCacheSavings(tokens) {
197
- // Cache reads are ~10x cheaper than fresh input
198
- const fullPrice = (tokens.cacheRead / 1_000_000) * 3;
199
- const cachePrice = (tokens.cacheRead / 1_000_000) * 0.3;
200
- return Math.round((fullPrice - cachePrice) * 10000) / 10000;
201
- }
@@ -1,146 +0,0 @@
1
- // Kodelyth Lens — Windsurf Reader
2
- // Reads Windsurf (Codeium) real quota data from state.vscdb SQLite databases
3
- // Part of Kodelyth ECC — github.com/sifxprime/kodelyth-ecc
4
-
5
- import fs from 'node:fs';
6
- import path from 'node:path';
7
- import os from 'node:os';
8
- import { execSync } from 'node:child_process';
9
- import { detectAgentsInMessages } from '../agent-tracker.js';
10
-
11
- const HOME = os.homedir();
12
-
13
- // ── SQLite helpers (same pattern as codex-reader) ──────────────────────────────
14
-
15
- function sqlite3Available() {
16
- try { execSync('sqlite3 --version', { stdio: 'pipe', timeout: 3000 }); return true; }
17
- catch { return false; }
18
- }
19
-
20
- function querySqliteJson(dbPath, sql) {
21
- try {
22
- const raw = execSync(
23
- `sqlite3 -json "${dbPath}" "${sql.replace(/"/g, '\\"')}"`,
24
- { stdio: 'pipe', timeout: 5000, encoding: 'utf-8' }
25
- ).trim();
26
- return raw ? JSON.parse(raw) : [];
27
- } catch { return []; }
28
- }
29
-
30
- function readDbKey(dbPath, key) {
31
- const rows = querySqliteJson(dbPath, `SELECT value FROM ItemTable WHERE key='${key}'`);
32
- if (!rows.length || !rows[0].value) return null;
33
- try { return JSON.parse(rows[0].value); } catch { return rows[0].value; }
34
- }
35
-
36
- // ── Find Windsurf data directory ───────────────────────────────────────────────
37
-
38
- function findWindsurfDir(override) {
39
- return [
40
- override,
41
- process.env.WINDSURF_DIR,
42
- path.join(HOME, 'Library', 'Application Support', 'Windsurf'),
43
- path.join(HOME, 'AppData', 'Roaming', 'Windsurf'),
44
- path.join(HOME, '.codeium', 'windsurf'),
45
- ].filter(Boolean).find(d => fs.existsSync(d)) || null;
46
- }
47
-
48
- // ── Main reader ────────────────────────────────────────────────────────────────
49
-
50
- export async function readWindsurfData(dataDir) {
51
- const windsurfDir = findWindsurfDir(dataDir);
52
- if (!windsurfDir) return { sessions: [], available: false, quotaData: null };
53
-
54
- const hasSqlite = sqlite3Available();
55
- let quotaData = null;
56
-
57
- // ── 1. Read real quota / plan info from global state.vscdb ─────────────────
58
- const globalDb = path.join(windsurfDir, 'User', 'globalStorage', 'state.vscdb');
59
- if (hasSqlite && fs.existsSync(globalDb)) {
60
- const plan = readDbKey(globalDb, 'windsurf.settings.cachedPlanInfo');
61
- if (plan?.usage) {
62
- const daily = plan.quotaUsage?.dailyRemainingPercent ?? 100;
63
- const weekly = plan.quotaUsage?.weeklyRemainingPercent ?? 100;
64
- quotaData = {
65
- planName: plan.planName || 'Unknown',
66
- usedMessages: plan.usage.usedMessages || 0,
67
- totalMessages: plan.usage.messages || 0,
68
- usedFlowActions: plan.usage.usedFlowActions || 0,
69
- totalFlowActions: plan.usage.flowActions || 0,
70
- dailyUsedPercent: Math.round(100 - daily),
71
- weeklyUsedPercent: Math.round(100 - weekly),
72
- dailyRemainingPercent: Math.round(daily),
73
- weeklyRemainingPercent:Math.round(weekly),
74
- startDate: plan.startTimestamp ? new Date(plan.startTimestamp).toISOString().slice(0, 10) : null,
75
- endDate: plan.endTimestamp ? new Date(plan.endTimestamp).toISOString().slice(0, 10) : null,
76
- };
77
- }
78
- }
79
-
80
- // ── 2. Read workspace sessions from workspaceStorage SQLite DBs ─────────────
81
- const sessions = [];
82
- const wsStorageDir = path.join(windsurfDir, 'User', 'workspaceStorage');
83
-
84
- if (hasSqlite && fs.existsSync(wsStorageDir)) {
85
- const wsDirs = fs.readdirSync(wsStorageDir, { withFileTypes: true })
86
- .filter(d => d.isDirectory())
87
- .map(d => path.join(wsStorageDir, d.name));
88
-
89
- for (const wsDir of wsDirs) {
90
- const db = path.join(wsDir, 'state.vscdb');
91
- if (!fs.existsSync(db)) continue;
92
-
93
- // Determine timestamp: readDateBaseline2 → epoch dirname → skip
94
- const baseline = readDbKey(db, 'agentSessions.readDateBaseline2');
95
- const dirName = path.basename(wsDir);
96
- let ts = null;
97
- if (baseline && !isNaN(parseInt(baseline, 10))) {
98
- ts = new Date(parseInt(baseline, 10)).toISOString();
99
- } else if (/^\d{13}$/.test(dirName)) {
100
- ts = new Date(parseInt(dirName, 10)).toISOString();
101
- }
102
- if (!ts) continue;
103
-
104
- // Resolve project name from workspace.json
105
- let projectName = dirName;
106
- const wsJson = path.join(wsDir, 'workspace.json');
107
- if (fs.existsSync(wsJson)) {
108
- try {
109
- const wd = JSON.parse(fs.readFileSync(wsJson, 'utf-8'));
110
- const uri = wd.folder || wd.workspace?.folders?.[0]?.uri || '';
111
- if (uri) projectName = path.basename(decodeURIComponent(uri).replace(/\/$/, ''));
112
- } catch { /* skip */ }
113
- }
114
-
115
- // Check for any agent usage in this workspace
116
- const agentCache = readDbKey(db, 'agentSessions.state.cache') || [];
117
- const messages = Array.isArray(agentCache)
118
- ? agentCache.flatMap(s => (s.messages || []).map(m => ({
119
- role: m.role || 'user',
120
- content: m.content || m.text || '',
121
- })))
122
- : [];
123
- const agents = detectAgentsInMessages(messages);
124
-
125
- sessions.push({
126
- id: dirName,
127
- platform: 'windsurf',
128
- project: projectName,
129
- date: ts.slice(0, 10),
130
- lastDate: ts.slice(0, 10),
131
- timestamp: ts,
132
- lastActivity: ts,
133
- tokens: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
134
- cost: null, // Windsurf is quota-based, not per-token
135
- cacheSaved: 0,
136
- messageCount: messages.length,
137
- agents,
138
- agentCalls: agents.length,
139
- cloudAI: true,
140
- });
141
- }
142
- }
143
-
144
- sessions.sort((a, b) => (b.timestamp || '').localeCompare(a.timestamp || ''));
145
- return { sessions, available: true, quotaData };
146
- }
@@ -1,24 +0,0 @@
1
- {
2
- "name": "kodelyth-lens",
3
- "version": "1.2.0",
4
- "description": "Kodelyth Lens — AI coding agent usage dashboard for Claude Code, Cursor, Windsurf, Codex, OpenCode, and Antigravity",
5
- "type": "module",
6
- "main": "server.js",
7
- "bin": {
8
- "kodelyth-lens": "./server.js"
9
- },
10
- "scripts": {
11
- "start": "node server.js",
12
- "dev": "node --watch server.js"
13
- },
14
- "engines": {
15
- "node": ">=18.0.0"
16
- },
17
- "keywords": ["claude-code", "ai-agents", "developer-tools", "kodelyth", "dashboard"],
18
- "author": "Kodelyth <github.com/sifxprime>",
19
- "license": "MIT",
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/sifxprime/kodelyth-ecc.git"
23
- }
24
- }