gemkit-cli 0.2.3 → 0.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.
- package/README.md +141 -7
- package/dist/commands/agent/index.d.ts +9 -0
- package/dist/commands/agent/index.js +1329 -0
- package/dist/commands/cache/index.d.ts +5 -0
- package/dist/commands/cache/index.js +43 -0
- package/dist/commands/catalog/index.d.ts +2 -0
- package/dist/commands/catalog/index.js +57 -0
- package/dist/commands/config/index.d.ts +7 -0
- package/dist/commands/config/index.js +122 -0
- package/dist/commands/convert/index.d.ts +8 -0
- package/dist/commands/convert/index.js +391 -0
- package/dist/commands/doctor/index.d.ts +2 -0
- package/dist/commands/doctor/index.js +243 -0
- package/dist/commands/extension/index.d.ts +5 -0
- package/dist/commands/extension/index.js +52 -0
- package/dist/commands/index.d.ts +5 -0
- package/dist/commands/index.js +37 -0
- package/dist/commands/init/index.d.ts +6 -0
- package/dist/commands/init/index.js +345 -0
- package/dist/commands/new/index.d.ts +5 -0
- package/dist/commands/new/index.js +49 -0
- package/dist/commands/office/index.d.ts +5 -0
- package/dist/commands/office/index.js +283 -0
- package/dist/commands/paste/index.d.ts +10 -0
- package/dist/commands/paste/index.js +533 -0
- package/dist/commands/plan/index.d.ts +8 -0
- package/dist/commands/plan/index.js +247 -0
- package/dist/commands/session/index.d.ts +8 -0
- package/dist/commands/session/index.js +289 -0
- package/dist/commands/tokens/index.d.ts +6 -0
- package/dist/commands/tokens/index.js +148 -0
- package/dist/commands/update/index.d.ts +26 -0
- package/dist/commands/update/index.js +199 -0
- package/dist/commands/versions/index.d.ts +5 -0
- package/dist/commands/versions/index.js +39 -0
- package/dist/domains/agent/index.d.ts +8 -0
- package/dist/domains/agent/index.js +8 -0
- package/dist/domains/agent/mappings.d.ts +32 -0
- package/dist/domains/agent/mappings.js +164 -0
- package/dist/domains/agent/profile.d.ts +26 -0
- package/dist/domains/agent/profile.js +225 -0
- package/dist/domains/agent/pty-context.d.ts +11 -0
- package/dist/domains/agent/pty-context.js +83 -0
- package/dist/domains/agent/pty-providers.d.ts +18 -0
- package/dist/domains/agent/pty-providers.js +66 -0
- package/dist/domains/agent/pty-session.d.ts +33 -0
- package/dist/domains/agent/pty-session.js +82 -0
- package/dist/domains/agent/pty-types.d.ts +127 -0
- package/dist/domains/agent/pty-types.js +4 -0
- package/dist/domains/agent/search.d.ts +45 -0
- package/dist/domains/agent/search.js +614 -0
- package/dist/domains/agent/types.d.ts +78 -0
- package/dist/domains/agent/types.js +5 -0
- package/dist/domains/agent-office/documents-scanner.d.ts +9 -0
- package/dist/domains/agent-office/documents-scanner.js +143 -0
- package/dist/domains/agent-office/event-emitter.d.ts +43 -0
- package/dist/domains/agent-office/event-emitter.js +86 -0
- package/dist/domains/agent-office/file-watcher.d.ts +40 -0
- package/dist/domains/agent-office/file-watcher.js +173 -0
- package/dist/domains/agent-office/icons.d.ts +11 -0
- package/dist/domains/agent-office/icons.js +36 -0
- package/dist/domains/agent-office/index.d.ts +12 -0
- package/dist/domains/agent-office/index.js +20 -0
- package/dist/domains/agent-office/renderer/web/assets.d.ts +11 -0
- package/dist/domains/agent-office/renderer/web/assets.js +3419 -0
- package/dist/domains/agent-office/renderer/web/server.d.ts +42 -0
- package/dist/domains/agent-office/renderer/web/server.js +228 -0
- package/dist/domains/agent-office/renderer/web.d.ts +30 -0
- package/dist/domains/agent-office/renderer/web.js +111 -0
- package/dist/domains/agent-office/session-bridge.d.ts +23 -0
- package/dist/domains/agent-office/session-bridge.js +171 -0
- package/dist/domains/agent-office/state-machine.d.ts +5 -0
- package/dist/domains/agent-office/state-machine.js +82 -0
- package/dist/domains/agent-office/types.d.ts +91 -0
- package/dist/domains/agent-office/types.js +4 -0
- package/dist/domains/cache/index.d.ts +1 -0
- package/dist/domains/cache/index.js +1 -0
- package/dist/domains/cache/manager.d.ts +22 -0
- package/dist/domains/cache/manager.js +84 -0
- package/dist/domains/config/index.d.ts +5 -0
- package/dist/domains/config/index.js +5 -0
- package/dist/domains/config/manager.d.ts +24 -0
- package/dist/domains/config/manager.js +85 -0
- package/dist/domains/config/schema.d.ts +17 -0
- package/dist/domains/config/schema.js +96 -0
- package/dist/domains/convert/converter.d.ts +78 -0
- package/dist/domains/convert/converter.js +471 -0
- package/dist/domains/convert/index.d.ts +5 -0
- package/dist/domains/convert/index.js +5 -0
- package/dist/domains/convert/types.d.ts +88 -0
- package/dist/domains/convert/types.js +18 -0
- package/dist/domains/github/download.d.ts +12 -0
- package/dist/domains/github/download.js +51 -0
- package/dist/domains/github/index.d.ts +2 -0
- package/dist/domains/github/index.js +2 -0
- package/dist/domains/github/releases.d.ts +16 -0
- package/dist/domains/github/releases.js +68 -0
- package/dist/domains/installation/conflict.d.ts +13 -0
- package/dist/domains/installation/conflict.js +38 -0
- package/dist/domains/installation/file-sync.d.ts +16 -0
- package/dist/domains/installation/file-sync.js +77 -0
- package/dist/domains/installation/index.d.ts +3 -0
- package/dist/domains/installation/index.js +3 -0
- package/dist/domains/installation/metadata.d.ts +20 -0
- package/dist/domains/installation/metadata.js +52 -0
- package/dist/domains/plan/index.d.ts +2 -0
- package/dist/domains/plan/index.js +2 -0
- package/dist/domains/plan/resolver.d.ts +24 -0
- package/dist/domains/plan/resolver.js +164 -0
- package/dist/domains/plan/types.d.ts +13 -0
- package/dist/domains/plan/types.js +4 -0
- package/dist/domains/session/env.d.ts +51 -0
- package/dist/domains/session/env.js +118 -0
- package/dist/domains/session/index.d.ts +8 -0
- package/dist/domains/session/index.js +8 -0
- package/dist/domains/session/manager.d.ts +56 -0
- package/dist/domains/session/manager.js +205 -0
- package/dist/domains/session/paths.d.ts +6 -0
- package/dist/domains/session/paths.js +6 -0
- package/dist/domains/session/types.d.ts +121 -0
- package/dist/domains/session/types.js +5 -0
- package/dist/domains/session/writer.d.ts +82 -0
- package/dist/domains/session/writer.js +431 -0
- package/dist/domains/tokens/index.d.ts +5 -0
- package/dist/domains/tokens/index.js +5 -0
- package/dist/domains/tokens/pricing.d.ts +38 -0
- package/dist/domains/tokens/pricing.js +129 -0
- package/dist/domains/tokens/scanner.d.ts +42 -0
- package/dist/domains/tokens/scanner.js +168 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +87 -58
- package/dist/services/aipty.d.ts +76 -0
- package/dist/services/aipty.js +276 -0
- package/dist/services/archive.d.ts +22 -0
- package/dist/services/archive.js +53 -0
- package/dist/services/auto-update.d.ts +26 -0
- package/dist/services/auto-update.js +117 -0
- package/dist/services/hash.d.ts +36 -0
- package/dist/services/hash.js +63 -0
- package/dist/services/logger.d.ts +28 -0
- package/dist/services/logger.js +102 -0
- package/dist/services/music.d.ts +67 -0
- package/dist/services/music.js +290 -0
- package/dist/services/npm.d.ts +22 -0
- package/dist/services/npm.js +65 -0
- package/dist/services/pty-client.d.ts +66 -0
- package/dist/services/pty-client.js +154 -0
- package/dist/services/pty-server.d.ts +102 -0
- package/dist/services/pty-server.js +613 -0
- package/dist/types/index.d.ts +155 -0
- package/dist/types/index.js +4 -0
- package/dist/utils/colors.d.ts +43 -0
- package/dist/utils/colors.js +98 -0
- package/dist/utils/errors.d.ts +24 -0
- package/dist/utils/errors.js +56 -0
- package/dist/utils/paths.d.ts +46 -0
- package/dist/utils/paths.js +89 -0
- package/dist/utils/platform.d.ts +11 -0
- package/dist/utils/platform.js +31 -0
- package/package.json +55 -54
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token scanner - Reads Gemini session files for token usage
|
|
3
|
+
*/
|
|
4
|
+
import { existsSync, readFileSync, readdirSync } from 'fs';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import { homedir } from 'os';
|
|
7
|
+
import { getGeminiProjectHash } from '../session/env.js';
|
|
8
|
+
/**
|
|
9
|
+
* Get token usage for current session only (MVP limitation)
|
|
10
|
+
*/
|
|
11
|
+
export async function getCurrentSessionTokens() {
|
|
12
|
+
const projectHash = getGeminiProjectHash();
|
|
13
|
+
if (!projectHash) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return getLatestSessionAnalysis(projectHash);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get full session analysis from latest Gemini session file
|
|
20
|
+
*/
|
|
21
|
+
export function getLatestSessionAnalysis(projectHash) {
|
|
22
|
+
const chatsDir = join(homedir(), '.gemini', 'tmp', projectHash, 'chats');
|
|
23
|
+
if (!existsSync(chatsDir)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
// Find latest session file
|
|
27
|
+
const files = readdirSync(chatsDir)
|
|
28
|
+
.filter(f => f.startsWith('session-') && f.endsWith('.json'))
|
|
29
|
+
.sort()
|
|
30
|
+
.reverse();
|
|
31
|
+
if (files.length === 0) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const filePath = join(chatsDir, files[0]);
|
|
36
|
+
return analyzeSessionFile(filePath);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Analyze a session file and extract all stats
|
|
44
|
+
*/
|
|
45
|
+
export function analyzeSessionFile(filePath) {
|
|
46
|
+
try {
|
|
47
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
48
|
+
const session = JSON.parse(content);
|
|
49
|
+
if (!session.messages || session.messages.length === 0) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const modelsUsed = new Set();
|
|
53
|
+
let sumOutput = 0;
|
|
54
|
+
let sumThoughts = 0;
|
|
55
|
+
let sumTool = 0;
|
|
56
|
+
let lastTokens = undefined;
|
|
57
|
+
let messagesWithTokens = 0;
|
|
58
|
+
for (const msg of session.messages) {
|
|
59
|
+
if (msg.model) {
|
|
60
|
+
modelsUsed.add(msg.model);
|
|
61
|
+
}
|
|
62
|
+
if (msg.tokens) {
|
|
63
|
+
sumOutput += msg.tokens.output || 0;
|
|
64
|
+
sumThoughts += msg.tokens.thoughts || 0;
|
|
65
|
+
sumTool += msg.tokens.tool || 0;
|
|
66
|
+
lastTokens = msg.tokens;
|
|
67
|
+
messagesWithTokens++;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!lastTokens || messagesWithTokens === 0) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
// Get cumulative values from last message
|
|
74
|
+
const finalTotal = lastTokens.total || 0;
|
|
75
|
+
const finalCached = lastTokens.cached || 0;
|
|
76
|
+
// Calculate actual input (derived from total - output - thoughts)
|
|
77
|
+
let actualInput = finalTotal - sumOutput - sumThoughts;
|
|
78
|
+
if (actualInput < 0)
|
|
79
|
+
actualInput = 0;
|
|
80
|
+
const tokens = {
|
|
81
|
+
input: actualInput,
|
|
82
|
+
output: sumOutput,
|
|
83
|
+
cached: finalCached,
|
|
84
|
+
thoughts: sumThoughts,
|
|
85
|
+
tool: sumTool,
|
|
86
|
+
total: finalTotal
|
|
87
|
+
};
|
|
88
|
+
// Calculate duration
|
|
89
|
+
let duration = null;
|
|
90
|
+
if (session.startTime && session.lastUpdated) {
|
|
91
|
+
try {
|
|
92
|
+
const start = new Date(session.startTime);
|
|
93
|
+
const end = new Date(session.lastUpdated);
|
|
94
|
+
const seconds = Math.floor((end.getTime() - start.getTime()) / 1000);
|
|
95
|
+
const mins = Math.floor(seconds / 60);
|
|
96
|
+
const secs = seconds % 60;
|
|
97
|
+
duration = {
|
|
98
|
+
seconds,
|
|
99
|
+
formatted: `${mins}m ${secs}s`
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Ignore date parsing errors
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Get primary model
|
|
107
|
+
const models = Array.from(modelsUsed);
|
|
108
|
+
const primaryModel = models[0] || 'unknown';
|
|
109
|
+
return {
|
|
110
|
+
sessionId: session.sessionId,
|
|
111
|
+
startTime: session.startTime || null,
|
|
112
|
+
lastUpdated: session.lastUpdated || null,
|
|
113
|
+
duration,
|
|
114
|
+
model: primaryModel,
|
|
115
|
+
modelsUsed: models,
|
|
116
|
+
messageCount: messagesWithTokens,
|
|
117
|
+
tokens,
|
|
118
|
+
averages: {
|
|
119
|
+
outputPerMessage: messagesWithTokens > 0 ? Math.round(sumOutput / messagesWithTokens) : 0,
|
|
120
|
+
thoughtsPerMessage: messagesWithTokens > 0 ? Math.round(sumThoughts / messagesWithTokens) : 0,
|
|
121
|
+
toolPerMessage: messagesWithTokens > 0 ? Math.round(sumTool / messagesWithTokens) : 0
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get token usage by session ID
|
|
131
|
+
*/
|
|
132
|
+
export function getAgentTokenUsage(sessionId, projectHash) {
|
|
133
|
+
const chatsDir = join(homedir(), '.gemini', 'tmp', projectHash, 'chats');
|
|
134
|
+
if (!existsSync(chatsDir)) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const files = readdirSync(chatsDir).filter(f => f.endsWith('.json'));
|
|
138
|
+
for (const file of files) {
|
|
139
|
+
try {
|
|
140
|
+
const filePath = join(chatsDir, file);
|
|
141
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
142
|
+
const session = JSON.parse(content);
|
|
143
|
+
if (session.sessionId === sessionId ||
|
|
144
|
+
(session.sessionId && sessionId.startsWith(session.sessionId.substring(0, 8)))) {
|
|
145
|
+
const analysis = analyzeSessionFile(filePath);
|
|
146
|
+
return analysis?.tokens || null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Legacy format function for backward compatibility
|
|
157
|
+
*/
|
|
158
|
+
export function formatTokenUsage(usage) {
|
|
159
|
+
const lines = [
|
|
160
|
+
`Input: ${usage.input.toLocaleString()}`,
|
|
161
|
+
`Output: ${usage.output.toLocaleString()}`,
|
|
162
|
+
`Cached: ${usage.cached.toLocaleString()}`,
|
|
163
|
+
`Thoughts: ${usage.thoughts.toLocaleString()}`,
|
|
164
|
+
`Tool: ${usage.tool.toLocaleString()}`,
|
|
165
|
+
`Total: ${usage.total.toLocaleString()}`,
|
|
166
|
+
];
|
|
167
|
+
return lines.join('\n');
|
|
168
|
+
}
|