skilltally 1.0.3 → 1.2.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +22 -0
- package/README.md +15 -7
- package/bin/cli.mjs +163 -1
- package/bin/track.mjs +168 -4
- package/gemini-extension.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/skills/skilltally/SKILL.md +23 -8
- package/src/backfill/antigravity.mjs +85 -31
- package/src/backfill/claude.mjs +58 -5
- package/src/backfill/codex.mjs +56 -2
- package/src/backfill/gemini.mjs +66 -3
- package/src/backfill/index.mjs +7 -5
- package/src/core/config.mjs +2 -0
- package/src/core/detect.mjs +2 -0
- package/src/install/prune.mjs +355 -0
- package/src/inventory/scan.mjs +3 -1
- package/src/mcp/server.mjs +345 -0
- package/src/report/aggregate.mjs +421 -18
- package/src/report/chains.mjs +187 -0
- package/src/report/dashboard.mjs +1303 -0
- package/src/report/format.mjs +276 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { basename, join } from 'node:path';
|
|
4
|
-
import { detectSkillCalls, unwrapArg } from '../core/detect.mjs';
|
|
4
|
+
import { detectSkillCalls, extractUsageMetrics, sanitizePromptPreview, unwrapArg } from '../core/detect.mjs';
|
|
5
5
|
|
|
6
6
|
const TARGET_TOOLS = new Set(['read_file', 'view_file', 'run_command']);
|
|
7
7
|
const PRODUCT_DIRS = ['antigravity', 'antigravity-cli', 'antigravity-ide'];
|
|
@@ -65,7 +65,7 @@ function loadFullRecord(fullLinesCache, fullPath, lineIdx, stepIndex) {
|
|
|
65
65
|
return null;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export function backfillAntigravity({ homeDir = homedir(), since = null } = {}) {
|
|
68
|
+
export function backfillAntigravity({ homeDir = homedir(), since = null, storePrompts = false } = {}) {
|
|
69
69
|
const transcripts = findTranscripts(homeDir);
|
|
70
70
|
const sinceMs = since instanceof Date ? since.getTime() : since ? Date.parse(since) : null;
|
|
71
71
|
const events = [];
|
|
@@ -77,16 +77,30 @@ export function backfillAntigravity({ homeDir = homedir(), since = null } = {})
|
|
|
77
77
|
} catch {
|
|
78
78
|
continue;
|
|
79
79
|
}
|
|
80
|
+
if (!raw || (!raw.includes('SKILL.md') && !raw.includes('truncated_fields') && !raw.includes('<SKILL>'))) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
80
83
|
|
|
81
84
|
const lines = raw.split('\n');
|
|
82
85
|
const fullCache = { lines: undefined };
|
|
83
86
|
const convEvents = [];
|
|
84
87
|
const pendingUserSkills = [];
|
|
88
|
+
let turnId = 0;
|
|
89
|
+
let lastUserPrompt = '';
|
|
90
|
+
const turnEndMsMap = new Map();
|
|
91
|
+
const turnUsageMap = new Map();
|
|
92
|
+
|
|
93
|
+
const recordTurnTs = (id, tsStr) => {
|
|
94
|
+
if (!tsStr) return;
|
|
95
|
+
const ms = Date.parse(tsStr);
|
|
96
|
+
if (!Number.isFinite(ms)) return;
|
|
97
|
+
const prev = turnEndMsMap.get(id);
|
|
98
|
+
if (prev === undefined || ms > prev) turnEndMsMap.set(id, ms);
|
|
99
|
+
};
|
|
85
100
|
|
|
86
101
|
for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
|
87
102
|
const line = lines[lineIdx];
|
|
88
103
|
if (!line) continue;
|
|
89
|
-
if (!line.includes('SKILL.md') && !line.includes('truncated_fields')) continue;
|
|
90
104
|
|
|
91
105
|
let obj;
|
|
92
106
|
try {
|
|
@@ -98,38 +112,52 @@ export function backfillAntigravity({ homeDir = homedir(), since = null } = {})
|
|
|
98
112
|
const ts = obj.created_at;
|
|
99
113
|
const stepIdx = obj.step_index ?? lineIdx;
|
|
100
114
|
|
|
101
|
-
if (obj.type === 'USER_INPUT' && typeof obj.content === 'string'
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
allowShell: false,
|
|
113
|
-
});
|
|
114
|
-
promptHits.forEach((h, hitIdx) => {
|
|
115
|
-
pendingUserSkills.push({
|
|
116
|
-
v: 1,
|
|
117
|
-
id: `${item.host}:${item.sessionId}:${stepIdx}#${hitIdx}`,
|
|
118
|
-
ts: ts || new Date(0).toISOString(),
|
|
119
|
-
host: item.host,
|
|
120
|
-
skill: h.skill,
|
|
121
|
-
...(h.skill_path ? { skill_path: h.skill_path } : {}),
|
|
122
|
-
source: h.source,
|
|
123
|
-
via: h.via,
|
|
115
|
+
if (obj.type === 'USER_INPUT' && typeof obj.content === 'string') {
|
|
116
|
+
turnId += 1;
|
|
117
|
+
lastUserPrompt = obj.content;
|
|
118
|
+
recordTurnTs(turnId, ts);
|
|
119
|
+
|
|
120
|
+
if (obj.content.includes('<SKILL>')) {
|
|
121
|
+
if (sinceMs !== null && ts) {
|
|
122
|
+
const tsMs = Date.parse(ts);
|
|
123
|
+
if (Number.isFinite(tsMs) && tsMs < sinceMs) continue;
|
|
124
|
+
}
|
|
125
|
+
const promptHits = detectSkillCalls({
|
|
124
126
|
tool: 'USER_INPUT',
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
args: {},
|
|
128
|
+
prompt: obj.content,
|
|
129
|
+
cwd: '',
|
|
130
|
+
homeDir,
|
|
131
|
+
allowShell: false,
|
|
128
132
|
});
|
|
129
|
-
|
|
133
|
+
promptHits.forEach((h, hitIdx) => {
|
|
134
|
+
pendingUserSkills.push({
|
|
135
|
+
v: 1,
|
|
136
|
+
id: `${item.host}:${item.sessionId}:${stepIdx}#${hitIdx}`,
|
|
137
|
+
ts: ts || new Date(0).toISOString(),
|
|
138
|
+
host: item.host,
|
|
139
|
+
skill: h.skill,
|
|
140
|
+
...(h.skill_path ? { skill_path: h.skill_path } : {}),
|
|
141
|
+
source: h.source,
|
|
142
|
+
via: h.via,
|
|
143
|
+
tool: 'USER_INPUT',
|
|
144
|
+
session_id: item.sessionId,
|
|
145
|
+
_turnId: turnId,
|
|
146
|
+
_promptText: lastUserPrompt,
|
|
147
|
+
origin: 'backfill',
|
|
148
|
+
ok: obj.status !== 'ERROR',
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
130
152
|
continue;
|
|
131
153
|
}
|
|
132
154
|
|
|
155
|
+
recordTurnTs(turnId, ts);
|
|
156
|
+
const stepUsage = extractUsageMetrics(obj.usageMetadata ?? obj.usage);
|
|
157
|
+
if (stepUsage) turnUsageMap.set(turnId, stepUsage);
|
|
158
|
+
|
|
159
|
+
if (!line.includes('SKILL.md') && !line.includes('truncated_fields')) continue;
|
|
160
|
+
|
|
133
161
|
if (Array.isArray(obj.truncated_fields) && obj.truncated_fields.includes('tool_calls')) {
|
|
134
162
|
const fullObj = loadFullRecord(fullCache, item.fullPath, lineIdx, obj.step_index);
|
|
135
163
|
if (fullObj) obj = fullObj;
|
|
@@ -170,6 +198,9 @@ export function backfillAntigravity({ homeDir = homedir(), since = null } = {})
|
|
|
170
198
|
tool: tc.name,
|
|
171
199
|
session_id: item.sessionId,
|
|
172
200
|
...(cwd ? { project: basename(cwd) } : {}),
|
|
201
|
+
_turnId: turnId,
|
|
202
|
+
_usage: stepUsage,
|
|
203
|
+
_promptText: lastUserPrompt,
|
|
173
204
|
origin: 'backfill',
|
|
174
205
|
ok: obj.status !== 'ERROR',
|
|
175
206
|
});
|
|
@@ -183,7 +214,30 @@ export function backfillAntigravity({ homeDir = homedir(), since = null } = {})
|
|
|
183
214
|
convEvents.push(uEv);
|
|
184
215
|
}
|
|
185
216
|
}
|
|
186
|
-
|
|
217
|
+
|
|
218
|
+
for (const ev of convEvents) {
|
|
219
|
+
const tid = ev._turnId;
|
|
220
|
+
const usage = ev._usage || turnUsageMap.get(tid) || null;
|
|
221
|
+
const pText = ev._promptText;
|
|
222
|
+
delete ev._turnId;
|
|
223
|
+
delete ev._usage;
|
|
224
|
+
delete ev._promptText;
|
|
225
|
+
|
|
226
|
+
const tsMs = ev.ts ? Date.parse(ev.ts) : NaN;
|
|
227
|
+
const endMs = turnEndMsMap.get(tid);
|
|
228
|
+
const durationSeconds =
|
|
229
|
+
Number.isFinite(tsMs) &&
|
|
230
|
+
Number.isFinite(endMs) &&
|
|
231
|
+
endMs >= tsMs &&
|
|
232
|
+
endMs - tsMs <= 86400_000
|
|
233
|
+
? Math.round((endMs - tsMs) / 1000)
|
|
234
|
+
: 0;
|
|
235
|
+
if (durationSeconds > 0) ev.duration_seconds = durationSeconds;
|
|
236
|
+
if (usage) Object.assign(ev, usage);
|
|
237
|
+
const preview = storePrompts && pText ? sanitizePromptPreview(pText) : '';
|
|
238
|
+
if (preview) ev.prompt_preview = preview;
|
|
239
|
+
events.push(ev);
|
|
240
|
+
}
|
|
187
241
|
}
|
|
188
242
|
|
|
189
243
|
return {
|
package/src/backfill/claude.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { basename, join } from 'node:path';
|
|
4
|
-
import { detectSkillCalls } from '../core/detect.mjs';
|
|
4
|
+
import { detectSkillCalls, extractUsageMetrics, sanitizePromptPreview } from '../core/detect.mjs';
|
|
5
5
|
|
|
6
6
|
const TARGET_TOOLS = new Set(['Skill', 'Read', 'View', 'Bash']);
|
|
7
7
|
|
|
@@ -25,7 +25,7 @@ function walkJsonlFiles(dir, out = []) {
|
|
|
25
25
|
return out;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export function backfillClaude({ homeDir = homedir(), since = null } = {}) {
|
|
28
|
+
export function backfillClaude({ homeDir = homedir(), since = null, storePrompts = false } = {}) {
|
|
29
29
|
const files = walkJsonlFiles(join(homeDir, '.claude', 'projects')).sort();
|
|
30
30
|
const sinceMs = since instanceof Date ? since.getTime() : since ? Date.parse(since) : null;
|
|
31
31
|
const events = [];
|
|
@@ -43,6 +43,18 @@ export function backfillClaude({ homeDir = homedir(), since = null } = {}) {
|
|
|
43
43
|
let cwd = '';
|
|
44
44
|
const pendingCalls = [];
|
|
45
45
|
const failedIds = new Set();
|
|
46
|
+
let turnId = 0;
|
|
47
|
+
let lastUserPrompt = '';
|
|
48
|
+
const turnEndMsMap = new Map();
|
|
49
|
+
const turnUsageMap = new Map();
|
|
50
|
+
|
|
51
|
+
const recordTurnTs = (id, tsStr) => {
|
|
52
|
+
if (!tsStr) return;
|
|
53
|
+
const ms = Date.parse(tsStr);
|
|
54
|
+
if (!Number.isFinite(ms)) return;
|
|
55
|
+
const prev = turnEndMsMap.get(id);
|
|
56
|
+
if (prev === undefined || ms > prev) turnEndMsMap.set(id, ms);
|
|
57
|
+
};
|
|
46
58
|
|
|
47
59
|
for (const line of raw.split('\n')) {
|
|
48
60
|
if (!line) continue;
|
|
@@ -59,14 +71,19 @@ export function backfillClaude({ homeDir = homedir(), since = null } = {}) {
|
|
|
59
71
|
const content = obj.message?.content;
|
|
60
72
|
if (obj.type === 'user') {
|
|
61
73
|
if (typeof content === 'string') {
|
|
74
|
+
turnId += 1;
|
|
75
|
+
lastUserPrompt = content;
|
|
76
|
+
recordTurnTs(turnId, obj.timestamp);
|
|
62
77
|
if (content.includes('Base directory for this skill:') || content.includes('SKILL.md') || content.includes('<skill>')) {
|
|
63
78
|
pendingCalls.push({
|
|
64
79
|
idx: pendingCalls.length,
|
|
65
80
|
ts: obj.timestamp,
|
|
81
|
+
turnId,
|
|
66
82
|
tool: 'UserPromptSubmit',
|
|
67
83
|
callId: obj.uuid || `user_${pendingCalls.length}`,
|
|
68
84
|
input: {},
|
|
69
85
|
prompt: content,
|
|
86
|
+
promptText: content,
|
|
70
87
|
cwd,
|
|
71
88
|
model: undefined,
|
|
72
89
|
});
|
|
@@ -74,10 +91,21 @@ export function backfillClaude({ homeDir = homedir(), since = null } = {}) {
|
|
|
74
91
|
continue;
|
|
75
92
|
}
|
|
76
93
|
if (!Array.isArray(content)) continue;
|
|
94
|
+
const textParts = [];
|
|
77
95
|
for (const block of content) {
|
|
78
96
|
if (block?.type === 'tool_result' && block.is_error === true && block.tool_use_id) {
|
|
79
97
|
failedIds.add(block.tool_use_id);
|
|
80
|
-
} else if (
|
|
98
|
+
} else if (block?.type === 'text' && typeof block.text === 'string') {
|
|
99
|
+
textParts.push(block.text);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (textParts.length > 0) {
|
|
103
|
+
turnId += 1;
|
|
104
|
+
lastUserPrompt = textParts.join(' ');
|
|
105
|
+
}
|
|
106
|
+
recordTurnTs(turnId, obj.timestamp);
|
|
107
|
+
for (const block of content) {
|
|
108
|
+
if (
|
|
81
109
|
block?.type === 'text' &&
|
|
82
110
|
typeof block.text === 'string' &&
|
|
83
111
|
(block.text.includes('Base directory for this skill:') ||
|
|
@@ -87,10 +115,12 @@ export function backfillClaude({ homeDir = homedir(), since = null } = {}) {
|
|
|
87
115
|
pendingCalls.push({
|
|
88
116
|
idx: pendingCalls.length,
|
|
89
117
|
ts: obj.timestamp,
|
|
118
|
+
turnId,
|
|
90
119
|
tool: 'UserPromptSubmit',
|
|
91
120
|
callId: obj.uuid || `user_${pendingCalls.length}`,
|
|
92
121
|
input: {},
|
|
93
122
|
prompt: block.text,
|
|
123
|
+
promptText: lastUserPrompt,
|
|
94
124
|
cwd,
|
|
95
125
|
model: undefined,
|
|
96
126
|
});
|
|
@@ -99,19 +129,27 @@ export function backfillClaude({ homeDir = homedir(), since = null } = {}) {
|
|
|
99
129
|
continue;
|
|
100
130
|
}
|
|
101
131
|
|
|
102
|
-
|
|
103
|
-
|
|
132
|
+
recordTurnTs(turnId, obj.timestamp);
|
|
104
133
|
if (obj.type !== 'assistant') continue;
|
|
134
|
+
|
|
105
135
|
const model = obj.message?.model;
|
|
136
|
+
const msgUsage = extractUsageMetrics(obj.message?.usage ?? obj.usage);
|
|
137
|
+
if (msgUsage) {
|
|
138
|
+
turnUsageMap.set(turnId, msgUsage);
|
|
139
|
+
}
|
|
106
140
|
|
|
141
|
+
if (!Array.isArray(content)) continue;
|
|
107
142
|
for (const block of content) {
|
|
108
143
|
if (block?.type !== 'tool_use' || !TARGET_TOOLS.has(block.name)) continue;
|
|
109
144
|
pendingCalls.push({
|
|
110
145
|
idx: pendingCalls.length,
|
|
111
146
|
ts: obj.timestamp,
|
|
147
|
+
turnId,
|
|
112
148
|
tool: block.name,
|
|
113
149
|
callId: block.id,
|
|
114
150
|
input: block.input && typeof block.input === 'object' ? block.input : {},
|
|
151
|
+
usage: msgUsage,
|
|
152
|
+
promptText: lastUserPrompt,
|
|
115
153
|
cwd,
|
|
116
154
|
model,
|
|
117
155
|
});
|
|
@@ -134,6 +172,18 @@ export function backfillClaude({ homeDir = homedir(), since = null } = {}) {
|
|
|
134
172
|
});
|
|
135
173
|
|
|
136
174
|
const ok = call.callId ? !failedIds.has(call.callId) : true;
|
|
175
|
+
const callTsMs = call.ts ? Date.parse(call.ts) : NaN;
|
|
176
|
+
const turnEndMs = turnEndMsMap.get(call.turnId);
|
|
177
|
+
const durationSeconds =
|
|
178
|
+
Number.isFinite(callTsMs) &&
|
|
179
|
+
Number.isFinite(turnEndMs) &&
|
|
180
|
+
turnEndMs >= callTsMs &&
|
|
181
|
+
turnEndMs - callTsMs <= 86400_000
|
|
182
|
+
? Math.round((turnEndMs - callTsMs) / 1000)
|
|
183
|
+
: 0;
|
|
184
|
+
const usage = call.usage || turnUsageMap.get(call.turnId) || null;
|
|
185
|
+
const promptPreview = storePrompts && call.promptText ? sanitizePromptPreview(call.promptText) : '';
|
|
186
|
+
|
|
137
187
|
hits.forEach((h, hitIdx) => {
|
|
138
188
|
events.push({
|
|
139
189
|
v: 1,
|
|
@@ -149,6 +199,9 @@ export function backfillClaude({ homeDir = homedir(), since = null } = {}) {
|
|
|
149
199
|
session_id: sessionId,
|
|
150
200
|
...(call.cwd ? { project: basename(call.cwd) } : {}),
|
|
151
201
|
...(call.model ? { model: call.model } : {}),
|
|
202
|
+
...(durationSeconds > 0 ? { duration_seconds: durationSeconds } : {}),
|
|
203
|
+
...(usage ? usage : {}),
|
|
204
|
+
...(promptPreview ? { prompt_preview: promptPreview } : {}),
|
|
152
205
|
origin: 'backfill',
|
|
153
206
|
ok,
|
|
154
207
|
});
|
package/src/backfill/codex.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { basename, join } from 'node:path';
|
|
5
5
|
import zlib from 'node:zlib';
|
|
6
|
-
import { detectSkillCalls } from '../core/detect.mjs';
|
|
6
|
+
import { detectSkillCalls, extractUsageMetrics, sanitizePromptPreview } from '../core/detect.mjs';
|
|
7
7
|
|
|
8
8
|
function walkSessionFiles(dir, out = []) {
|
|
9
9
|
if (!existsSync(dir)) return out;
|
|
@@ -64,7 +64,7 @@ function sessionIdFromFilename(filePath) {
|
|
|
64
64
|
return m ? m[1] : basename(filePath);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
export function backfillCodex({ homeDir = homedir(), since = null } = {}) {
|
|
67
|
+
export function backfillCodex({ homeDir = homedir(), since = null, storePrompts = false } = {}) {
|
|
68
68
|
const files = [
|
|
69
69
|
...walkSessionFiles(join(homeDir, '.codex', 'sessions')),
|
|
70
70
|
...walkSessionFiles(join(homeDir, '.codex', 'archived_sessions')),
|
|
@@ -95,7 +95,18 @@ export function backfillCodex({ homeDir = homedir(), since = null } = {}) {
|
|
|
95
95
|
const pendingCalls = [];
|
|
96
96
|
const failedCalls = new Set();
|
|
97
97
|
let turnIdx = 0;
|
|
98
|
+
let turnPrompt = '';
|
|
98
99
|
const turnPromptSkills = new Set();
|
|
100
|
+
const turnEndMsMap = new Map();
|
|
101
|
+
const turnUsageMap = new Map();
|
|
102
|
+
|
|
103
|
+
const recordTurnTs = (id, tsStr) => {
|
|
104
|
+
if (!tsStr) return;
|
|
105
|
+
const ms = Date.parse(tsStr);
|
|
106
|
+
if (!Number.isFinite(ms)) return;
|
|
107
|
+
const prev = turnEndMsMap.get(id);
|
|
108
|
+
if (prev === undefined || ms > prev) turnEndMsMap.set(id, ms);
|
|
109
|
+
};
|
|
99
110
|
|
|
100
111
|
for (const line of raw.split('\n')) {
|
|
101
112
|
if (!line) continue;
|
|
@@ -119,13 +130,36 @@ export function backfillCodex({ homeDir = homedir(), since = null } = {}) {
|
|
|
119
130
|
if (obj.payload.model) model = obj.payload.model;
|
|
120
131
|
turnPromptSkills.clear();
|
|
121
132
|
turnIdx += 1;
|
|
133
|
+
turnPrompt = '';
|
|
134
|
+
recordTurnTs(turnIdx, obj.timestamp);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
recordTurnTs(turnIdx, obj.timestamp);
|
|
139
|
+
|
|
140
|
+
if (obj.type === 'event_msg' && obj.payload?.type === 'token_count') {
|
|
141
|
+
const u = extractUsageMetrics(obj.payload?.info?.last_token_usage ?? obj.payload?.usage);
|
|
142
|
+
if (u) turnUsageMap.set(turnIdx, u);
|
|
122
143
|
continue;
|
|
123
144
|
}
|
|
124
145
|
|
|
125
146
|
if (obj.type !== 'response_item' || !obj.payload) continue;
|
|
126
147
|
const p = obj.payload;
|
|
127
148
|
|
|
149
|
+
const itemUsage = extractUsageMetrics(obj.usage ?? p.usage);
|
|
150
|
+
if (itemUsage) turnUsageMap.set(turnIdx, itemUsage);
|
|
151
|
+
|
|
128
152
|
if (p.type === 'message' && p.role === 'user' && Array.isArray(p.content)) {
|
|
153
|
+
const userTextParts = [];
|
|
154
|
+
for (const part of p.content) {
|
|
155
|
+
if (typeof part?.text === 'string' && part.text.trim()) {
|
|
156
|
+
userTextParts.push(part.text);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (userTextParts.length > 0) {
|
|
160
|
+
turnPrompt = userTextParts.join(' ');
|
|
161
|
+
}
|
|
162
|
+
|
|
129
163
|
for (const part of p.content) {
|
|
130
164
|
const text = part?.text;
|
|
131
165
|
if (
|
|
@@ -153,10 +187,12 @@ export function backfillCodex({ homeDir = homedir(), since = null } = {}) {
|
|
|
153
187
|
pendingCalls.push({
|
|
154
188
|
idx: pendingCalls.length,
|
|
155
189
|
ts: obj.timestamp,
|
|
190
|
+
turnId: turnIdx,
|
|
156
191
|
tool: 'UserPromptSubmit',
|
|
157
192
|
callId: p.id || `prompt_${turnIdx}_${pendingCalls.length}`,
|
|
158
193
|
args: {},
|
|
159
194
|
precomputedHits: uniqueTurnHits,
|
|
195
|
+
promptText: turnPrompt,
|
|
160
196
|
cwd,
|
|
161
197
|
model,
|
|
162
198
|
});
|
|
@@ -198,9 +234,12 @@ export function backfillCodex({ homeDir = homedir(), since = null } = {}) {
|
|
|
198
234
|
pendingCalls.push({
|
|
199
235
|
idx: pendingCalls.length,
|
|
200
236
|
ts: obj.timestamp,
|
|
237
|
+
turnId: turnIdx,
|
|
201
238
|
tool: p.name,
|
|
202
239
|
callId: p.call_id,
|
|
203
240
|
args: argsObj,
|
|
241
|
+
usage: itemUsage,
|
|
242
|
+
promptText: turnPrompt,
|
|
204
243
|
cwd,
|
|
205
244
|
model,
|
|
206
245
|
});
|
|
@@ -223,6 +262,18 @@ export function backfillCodex({ homeDir = homedir(), since = null } = {}) {
|
|
|
223
262
|
});
|
|
224
263
|
|
|
225
264
|
const ok = call.callId ? !failedCalls.has(call.callId) : true;
|
|
265
|
+
const callTsMs = call.ts ? Date.parse(call.ts) : NaN;
|
|
266
|
+
const turnEndMs = turnEndMsMap.get(call.turnId);
|
|
267
|
+
const durationSeconds =
|
|
268
|
+
Number.isFinite(callTsMs) &&
|
|
269
|
+
Number.isFinite(turnEndMs) &&
|
|
270
|
+
turnEndMs >= callTsMs &&
|
|
271
|
+
turnEndMs - callTsMs <= 86400_000
|
|
272
|
+
? Math.round((turnEndMs - callTsMs) / 1000)
|
|
273
|
+
: 0;
|
|
274
|
+
const usage = call.usage || turnUsageMap.get(call.turnId) || null;
|
|
275
|
+
const promptPreview = storePrompts && call.promptText ? sanitizePromptPreview(call.promptText) : '';
|
|
276
|
+
|
|
226
277
|
hits.forEach((h, hitIdx) => {
|
|
227
278
|
events.push({
|
|
228
279
|
v: 1,
|
|
@@ -237,6 +288,9 @@ export function backfillCodex({ homeDir = homedir(), since = null } = {}) {
|
|
|
237
288
|
session_id: sessionId,
|
|
238
289
|
...(call.cwd ? { project: basename(call.cwd) } : {}),
|
|
239
290
|
...(call.model ? { model: call.model } : {}),
|
|
291
|
+
...(durationSeconds > 0 ? { duration_seconds: durationSeconds } : {}),
|
|
292
|
+
...(usage ? usage : {}),
|
|
293
|
+
...(promptPreview ? { prompt_preview: promptPreview } : {}),
|
|
240
294
|
origin: 'backfill',
|
|
241
295
|
ok,
|
|
242
296
|
});
|
package/src/backfill/gemini.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { basename, join } from 'node:path';
|
|
4
|
-
import { detectSkillCalls } from '../core/detect.mjs';
|
|
4
|
+
import { detectSkillCalls, extractUsageMetrics, sanitizePromptPreview } from '../core/detect.mjs';
|
|
5
5
|
|
|
6
6
|
const TARGET_TOOLS = new Set([
|
|
7
7
|
'activate_skill',
|
|
@@ -83,7 +83,20 @@ function parseChatFile(filePath, raw) {
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
function extractGeminiUserText(msg) {
|
|
87
|
+
if (!msg || typeof msg !== 'object') return '';
|
|
88
|
+
if (typeof msg.content === 'string') return msg.content;
|
|
89
|
+
if (typeof msg.text === 'string') return msg.text;
|
|
90
|
+
if (Array.isArray(msg.content)) {
|
|
91
|
+
return msg.content.map((p) => (typeof p?.text === 'string' ? p.text : '')).join(' ');
|
|
92
|
+
}
|
|
93
|
+
if (Array.isArray(msg.parts)) {
|
|
94
|
+
return msg.parts.map((p) => (typeof p?.text === 'string' ? p.text : '')).join(' ');
|
|
95
|
+
}
|
|
96
|
+
return '';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function backfillGemini({ homeDir = homedir(), since = null, storePrompts = false } = {}) {
|
|
87
100
|
const files = findGeminiChatFiles(homeDir);
|
|
88
101
|
const sinceMs = since instanceof Date ? since.getTime() : since ? Date.parse(since) : null;
|
|
89
102
|
const events = [];
|
|
@@ -99,9 +112,31 @@ export function backfillGemini({ homeDir = homedir(), since = null } = {}) {
|
|
|
99
112
|
|
|
100
113
|
const { sessionId, startTime, cwd: fileCwd, messages } = parseChatFile(file, raw);
|
|
101
114
|
let callIdx = 0;
|
|
115
|
+
let turnId = 0;
|
|
116
|
+
let lastUserPrompt = '';
|
|
117
|
+
const turnEndMsMap = new Map();
|
|
118
|
+
const turnUsageMap = new Map();
|
|
119
|
+
const pendingEvents = [];
|
|
120
|
+
|
|
121
|
+
const recordTurnTs = (id, tsStr) => {
|
|
122
|
+
if (!tsStr) return;
|
|
123
|
+
const ms = Date.parse(tsStr);
|
|
124
|
+
if (!Number.isFinite(ms)) return;
|
|
125
|
+
const prev = turnEndMsMap.get(id);
|
|
126
|
+
if (prev === undefined || ms > prev) turnEndMsMap.set(id, ms);
|
|
127
|
+
};
|
|
102
128
|
|
|
103
129
|
for (const msg of messages) {
|
|
104
130
|
if (!msg || typeof msg !== 'object') continue;
|
|
131
|
+
if (msg.type === 'user' || msg.role === 'user') {
|
|
132
|
+
turnId += 1;
|
|
133
|
+
lastUserPrompt = extractGeminiUserText(msg);
|
|
134
|
+
}
|
|
135
|
+
recordTurnTs(turnId, msg.timestamp || startTime);
|
|
136
|
+
|
|
137
|
+
const msgUsage = extractUsageMetrics(msg.tokens ?? msg.usageMetadata ?? msg.usage);
|
|
138
|
+
if (msgUsage) turnUsageMap.set(turnId, msgUsage);
|
|
139
|
+
|
|
105
140
|
const toolCalls = Array.isArray(msg.toolCalls)
|
|
106
141
|
? msg.toolCalls
|
|
107
142
|
: Array.isArray(msg.tool_calls)
|
|
@@ -114,6 +149,7 @@ export function backfillGemini({ homeDir = homedir(), since = null } = {}) {
|
|
|
114
149
|
if (!tc || !TARGET_TOOLS.has(tc.name)) continue;
|
|
115
150
|
const idx = callIdx++;
|
|
116
151
|
const ts = tc.timestamp || msg.timestamp || startTime;
|
|
152
|
+
recordTurnTs(turnId, ts);
|
|
117
153
|
if (sinceMs !== null && ts) {
|
|
118
154
|
const tsMs = Date.parse(ts);
|
|
119
155
|
if (Number.isFinite(tsMs) && tsMs < sinceMs) continue;
|
|
@@ -130,7 +166,7 @@ export function backfillGemini({ homeDir = homedir(), since = null } = {}) {
|
|
|
130
166
|
|
|
131
167
|
const ok = tc.status !== 'error' && tc.status !== 'cancelled';
|
|
132
168
|
hits.forEach((h, hitIdx) => {
|
|
133
|
-
|
|
169
|
+
pendingEvents.push({
|
|
134
170
|
v: 1,
|
|
135
171
|
id: `gemini:${sessionId}:${tc.id || idx}#${hitIdx}`,
|
|
136
172
|
ts: ts || new Date(0).toISOString(),
|
|
@@ -143,12 +179,39 @@ export function backfillGemini({ homeDir = homedir(), since = null } = {}) {
|
|
|
143
179
|
session_id: sessionId,
|
|
144
180
|
...(msgCwd ? { project: basename(msgCwd) } : {}),
|
|
145
181
|
...(msg.model ? { model: msg.model } : {}),
|
|
182
|
+
_turnId: turnId,
|
|
183
|
+
_usage: msgUsage,
|
|
184
|
+
_promptText: lastUserPrompt,
|
|
146
185
|
origin: 'backfill',
|
|
147
186
|
ok,
|
|
148
187
|
});
|
|
149
188
|
});
|
|
150
189
|
}
|
|
151
190
|
}
|
|
191
|
+
|
|
192
|
+
for (const ev of pendingEvents) {
|
|
193
|
+
const tid = ev._turnId;
|
|
194
|
+
const usage = ev._usage || turnUsageMap.get(tid) || null;
|
|
195
|
+
const pText = ev._promptText;
|
|
196
|
+
delete ev._turnId;
|
|
197
|
+
delete ev._usage;
|
|
198
|
+
delete ev._promptText;
|
|
199
|
+
|
|
200
|
+
const tsMs = ev.ts ? Date.parse(ev.ts) : NaN;
|
|
201
|
+
const endMs = turnEndMsMap.get(tid);
|
|
202
|
+
const durationSeconds =
|
|
203
|
+
Number.isFinite(tsMs) &&
|
|
204
|
+
Number.isFinite(endMs) &&
|
|
205
|
+
endMs >= tsMs &&
|
|
206
|
+
endMs - tsMs <= 86400_000
|
|
207
|
+
? Math.round((endMs - tsMs) / 1000)
|
|
208
|
+
: 0;
|
|
209
|
+
if (durationSeconds > 0) ev.duration_seconds = durationSeconds;
|
|
210
|
+
if (usage) Object.assign(ev, usage);
|
|
211
|
+
const preview = storePrompts && pText ? sanitizePromptPreview(pText) : '';
|
|
212
|
+
if (preview) ev.prompt_preview = preview;
|
|
213
|
+
events.push(ev);
|
|
214
|
+
}
|
|
152
215
|
}
|
|
153
216
|
|
|
154
217
|
return {
|
package/src/backfill/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { homedir } from 'node:os';
|
|
2
|
-
import { getHomeDir } from '../core/config.mjs';
|
|
2
|
+
import { getHomeDir, loadConfig } from '../core/config.mjs';
|
|
3
3
|
import { dedupeEvents } from '../core/normalize.mjs';
|
|
4
4
|
import { writeBackfillEvents } from '../core/store.mjs';
|
|
5
5
|
import { backfillAntigravity } from './antigravity.mjs';
|
|
@@ -16,6 +16,8 @@ export function runBackfill({
|
|
|
16
16
|
} = {}) {
|
|
17
17
|
const hostsSummary = {};
|
|
18
18
|
const collected = [];
|
|
19
|
+
const config = loadConfig(dataHome);
|
|
20
|
+
const storePrompts = Boolean(config.store_prompts);
|
|
19
21
|
|
|
20
22
|
const wantAgy = host === 'all' || String(host).startsWith('antigravity');
|
|
21
23
|
const wantCodex = host === 'all' || host === 'codex';
|
|
@@ -23,7 +25,7 @@ export function runBackfill({
|
|
|
23
25
|
const wantGemini = host === 'all' || host === 'gemini';
|
|
24
26
|
|
|
25
27
|
if (wantAgy) {
|
|
26
|
-
const res = backfillAntigravity({ homeDir, since });
|
|
28
|
+
const res = backfillAntigravity({ homeDir, since, storePrompts });
|
|
27
29
|
const filtered =
|
|
28
30
|
host === 'all' || host === 'antigravity'
|
|
29
31
|
? res.events
|
|
@@ -37,7 +39,7 @@ export function runBackfill({
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
if (wantCodex) {
|
|
40
|
-
const res = backfillCodex({ homeDir, since });
|
|
42
|
+
const res = backfillCodex({ homeDir, since, storePrompts });
|
|
41
43
|
collected.push(...res.events);
|
|
42
44
|
hostsSummary.codex = {
|
|
43
45
|
files: res.files,
|
|
@@ -48,7 +50,7 @@ export function runBackfill({
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
if (wantClaude) {
|
|
51
|
-
const res = backfillClaude({ homeDir, since });
|
|
53
|
+
const res = backfillClaude({ homeDir, since, storePrompts });
|
|
52
54
|
collected.push(...res.events);
|
|
53
55
|
hostsSummary.claude = {
|
|
54
56
|
files: res.files,
|
|
@@ -58,7 +60,7 @@ export function runBackfill({
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
if (wantGemini) {
|
|
61
|
-
const res = backfillGemini({ homeDir, since });
|
|
63
|
+
const res = backfillGemini({ homeDir, since, storePrompts });
|
|
62
64
|
collected.push(...res.events);
|
|
63
65
|
hostsSummary.gemini = {
|
|
64
66
|
files: res.files,
|
package/src/core/config.mjs
CHANGED
|
@@ -7,6 +7,7 @@ export const DEFAULT_CONFIG = Object.freeze({
|
|
|
7
7
|
exclude_sources: [],
|
|
8
8
|
aliases: {},
|
|
9
9
|
store_cwd: false,
|
|
10
|
+
store_prompts: false,
|
|
10
11
|
});
|
|
11
12
|
|
|
12
13
|
export function getHomeDir(env = process.env) {
|
|
@@ -26,6 +27,7 @@ export function loadConfig(homeDir = getHomeDir()) {
|
|
|
26
27
|
? { ...parsed.aliases }
|
|
27
28
|
: {},
|
|
28
29
|
store_cwd: parsed.store_cwd === true,
|
|
30
|
+
store_prompts: parsed.store_prompts === true,
|
|
29
31
|
};
|
|
30
32
|
} catch {
|
|
31
33
|
return { ...DEFAULT_CONFIG };
|