@gabrihhh/jarvis 2.5.0 → 2.6.1
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 +24 -8
- package/bin/jarvis.js +87 -0
- package/package.json +1 -1
- package/src/calculator.js +12 -0
- package/src/statusline.js +37 -15
- package/src/theme.js +31 -0
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Reinicie o Claude Code após o setup.
|
|
|
22
22
|
| Comando | Descrição |
|
|
23
23
|
|---|---|
|
|
24
24
|
| `jarvis` | Mostra a versão |
|
|
25
|
-
| `jarvis --usage` | Dashboard completo de uso (tokens
|
|
25
|
+
| `jarvis --usage` | Dashboard completo de uso (tokens e custo) |
|
|
26
26
|
| `jarvis --watch` | Dashboard com auto-refresh a cada 30s |
|
|
27
27
|
| `jarvis --setup` | Configura status bar, instala slash commands e define trigger padrão |
|
|
28
28
|
| `jarvis --graph` | Abre o Neo4j Browser em localhost:7474 |
|
|
@@ -30,6 +30,14 @@ Reinicie o Claude Code após o setup.
|
|
|
30
30
|
| `jarvis --trigger session` | Hook de memória roda uma vez por sessão *(padrão)* |
|
|
31
31
|
| `jarvis --trigger prompt` | Hook de memória roda a cada prompt |
|
|
32
32
|
| `jarvis --trigger off` | Desativa o carregamento automático de memória |
|
|
33
|
+
| `jarvis --theme` | Mostra o tema atual da status bar |
|
|
34
|
+
| `jarvis --theme <name>:<#hex>` | Define a cor de um box (`context`, `trigger`, `memory`, `tokens`) |
|
|
35
|
+
| `jarvis --theme <name>:reset` | Reseta a cor de um box para o padrão |
|
|
36
|
+
| `jarvis --theme reset` | Reseta todas as cores para o padrão |
|
|
37
|
+
| `jarvis --token` | Mostra o modo de exibição de tokens atual |
|
|
38
|
+
| `jarvis --token on` | Ativa box com total de tokens do último turno (`◈`) |
|
|
39
|
+
| `jarvis --token complete` | Ativa box `◈` + linha de breakdown abaixo da status bar |
|
|
40
|
+
| `jarvis --token off` | Desativa exibição de tokens |
|
|
33
41
|
| `jarvis --line` | Saída de uma linha usada internamente pela status bar |
|
|
34
42
|
| `jarvis --help` | Lista todos os comandos |
|
|
35
43
|
|
|
@@ -62,13 +70,6 @@ Reinicie o Claude Code após o setup.
|
|
|
62
70
|
│ │
|
|
63
71
|
├──────────────────────────────────────────────────────────────┤
|
|
64
72
|
│ │
|
|
65
|
-
│ ⬡ Context Window (current session) │
|
|
66
|
-
│ │
|
|
67
|
-
│ ████████████░░░░░░░░░░░░ 52% 103.6K / 200.0K │
|
|
68
|
-
│ 146 turns · model: sonnet-4-6 │
|
|
69
|
-
│ │
|
|
70
|
-
├──────────────────────────────────────────────────────────────┤
|
|
71
|
-
│ │
|
|
72
73
|
│ Monthly breakdown │
|
|
73
74
|
│ Input: 62.5K Output: 1.53M │
|
|
74
75
|
│ Cache read: 232.48M Cache write: 11.25M │
|
|
@@ -82,3 +83,18 @@ Reinicie o Claude Code após o setup.
|
|
|
82
83
|
│ CONTEXT ████░░░░ 52% │
|
|
83
84
|
╰──────────────────────╯
|
|
84
85
|
```
|
|
86
|
+
|
|
87
|
+
**Status bar com `--token on`** (box com total de tokens do último turno):
|
|
88
|
+
```
|
|
89
|
+
╭──────────────────────╮╭──────────╮
|
|
90
|
+
│ CONTEXT ████░░░░ 52% ││ ◈ 50.0K │
|
|
91
|
+
╰──────────────────────╯╰──────────╯
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Status bar com `--token complete`** (box + breakdown detalhado):
|
|
95
|
+
```
|
|
96
|
+
╭──────────────────────╮╭──────────╮
|
|
97
|
+
│ CONTEXT ████░░░░ 52% ││ ◈ 50.0K │
|
|
98
|
+
╰──────────────────────╯╰──────────╯
|
|
99
|
+
INPUT 800 │ HISTORY 45.0K │ CACHE 1.2K │ RESPONSE 3.2K
|
|
100
|
+
```
|
package/bin/jarvis.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { run } from '../src/index.js';
|
|
3
3
|
import { renderLine } from '../src/statusline.js';
|
|
4
|
+
import { readTheme, writeTheme, isValidHex, DEFAULT_COLORS, VALID_NAMES, THEME_PATH } from '../src/theme.js';
|
|
4
5
|
import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync } from 'fs';
|
|
5
6
|
import { join, dirname } from 'path';
|
|
6
7
|
import { homedir } from 'os';
|
|
@@ -76,6 +77,14 @@ if (args.includes('--help') || args.includes('-h')) {
|
|
|
76
77
|
jarvis --trigger session Hook runs once per session (default)
|
|
77
78
|
jarvis --trigger prompt Hook runs on every prompt
|
|
78
79
|
jarvis --trigger off Disable automatic memory loading
|
|
80
|
+
jarvis --theme Show current statusline theme
|
|
81
|
+
jarvis --theme <name>:<hex> Set a box color (context, trigger, memory, tokens)
|
|
82
|
+
jarvis --theme <name>:reset Reset a single box to default color
|
|
83
|
+
jarvis --theme reset Reset all colors to default
|
|
84
|
+
jarvis --token Show current token display mode
|
|
85
|
+
jarvis --token on Show total tokens box (◈)
|
|
86
|
+
jarvis --token complete Show token box + INPUT/HISTORY/CACHE/RESPONSE breakdown
|
|
87
|
+
jarvis --token off Disable token display
|
|
79
88
|
jarvis --help Show this help
|
|
80
89
|
|
|
81
90
|
Slash commands (inside Claude Code):
|
|
@@ -189,6 +198,84 @@ if (args.includes('--graph')) {
|
|
|
189
198
|
if (mode !== 'off') console.log(` Hook configured in ~/.claude/settings.json`);
|
|
190
199
|
else console.log(` Hook removed from ~/.claude/settings.json`);
|
|
191
200
|
console.log(`\n Restart Claude Code to activate.\n`);
|
|
201
|
+
} else if (args.includes('--theme')) {
|
|
202
|
+
const { Chalk } = await import('chalk');
|
|
203
|
+
const chalk = new Chalk({ level: 3 });
|
|
204
|
+
const value = args[args.indexOf('--theme') + 1];
|
|
205
|
+
|
|
206
|
+
// jarvis --theme → mostra tema atual
|
|
207
|
+
if (!value || value.startsWith('--')) {
|
|
208
|
+
const theme = readTheme();
|
|
209
|
+
console.log('\n Current theme:\n');
|
|
210
|
+
for (const name of VALID_NAMES) {
|
|
211
|
+
const hex = theme[name];
|
|
212
|
+
const isDefault = hex === DEFAULT_COLORS[name];
|
|
213
|
+
const tag = isDefault ? chalk.dim(' (default)') : '';
|
|
214
|
+
console.log(` ${chalk.bold(name.padEnd(8))} ${chalk.hex(hex).bold('██')} ${hex}${tag}`);
|
|
215
|
+
}
|
|
216
|
+
console.log(`\n Config: ${THEME_PATH}\n`);
|
|
217
|
+
process.exit(0);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// jarvis --theme reset → reseta tudo
|
|
221
|
+
if (value === 'reset') {
|
|
222
|
+
writeTheme({ ...DEFAULT_COLORS });
|
|
223
|
+
console.log('\n ✓ Theme reset to defaults\n');
|
|
224
|
+
process.exit(0);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// jarvis --theme name:value
|
|
228
|
+
const sep = value.indexOf(':');
|
|
229
|
+
if (sep === -1) {
|
|
230
|
+
console.error(`\n ✗ Invalid format. Use: jarvis --theme <context|trigger|memory>:<#hexcolor|reset>\n`);
|
|
231
|
+
process.exit(1);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const name = value.slice(0, sep);
|
|
235
|
+
const color = value.slice(sep + 1);
|
|
236
|
+
|
|
237
|
+
if (!VALID_NAMES.includes(name)) {
|
|
238
|
+
console.error(`\n ✗ Unknown name "${name}". Valid names: ${VALID_NAMES.join(', ')}\n`);
|
|
239
|
+
process.exit(1);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const theme = readTheme();
|
|
243
|
+
|
|
244
|
+
if (color === 'reset') {
|
|
245
|
+
theme[name] = DEFAULT_COLORS[name];
|
|
246
|
+
writeTheme(theme);
|
|
247
|
+
console.log(`\n ✓ ${name} reset to default (${DEFAULT_COLORS[name]})\n`);
|
|
248
|
+
process.exit(0);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (!isValidHex(color)) {
|
|
252
|
+
console.error(`\n ✗ Invalid hex color "${color}". Use format: #rgb or #rrggbb\n`);
|
|
253
|
+
process.exit(1);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
theme[name] = color;
|
|
257
|
+
writeTheme(theme);
|
|
258
|
+
console.log(`\n ✓ ${name} set to ${chalk.hex(color).bold(color)}\n`);
|
|
259
|
+
process.exit(0);
|
|
260
|
+
} else if (args.includes('--token')) {
|
|
261
|
+
const value = args[args.indexOf('--token') + 1];
|
|
262
|
+
const validValues = ['on', 'off', 'complete'];
|
|
263
|
+
|
|
264
|
+
if (!value || !validValues.includes(value)) {
|
|
265
|
+
const cfg = loadMemoryConfig();
|
|
266
|
+
const current = cfg.tokenDisplay || 'off';
|
|
267
|
+
console.log(`\n Token display: ${current}\n`);
|
|
268
|
+
console.log(` Usage: jarvis --token <on|complete|off>\n`);
|
|
269
|
+
process.exit(0);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const cfg = loadMemoryConfig();
|
|
273
|
+
cfg.tokenDisplay = value === 'on' ? 'simple' : value;
|
|
274
|
+
saveMemoryConfig(cfg);
|
|
275
|
+
|
|
276
|
+
const labels = { simple: 'on (◈ total tokens)', off: 'off', complete: 'complete (breakdown)' };
|
|
277
|
+
console.log(`\n ✓ Token display set to: ${labels[cfg.tokenDisplay]}\n`);
|
|
278
|
+
process.exit(0);
|
|
192
279
|
} else if (args.includes('--query')) {
|
|
193
280
|
try {
|
|
194
281
|
const { queryByPath } = await import('../src/memory/query-by-path.js');
|
package/package.json
CHANGED
package/src/calculator.js
CHANGED
|
@@ -109,6 +109,18 @@ export function formatTokens(n) {
|
|
|
109
109
|
return `${n}`;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
export function getLastTurnTokens(entries) {
|
|
113
|
+
if (!entries.length) return null;
|
|
114
|
+
const last = entries[entries.length - 1];
|
|
115
|
+
return {
|
|
116
|
+
input: last.inputTokens,
|
|
117
|
+
history: last.cacheReadTokens,
|
|
118
|
+
cache: last.cacheWriteTokens,
|
|
119
|
+
response: last.outputTokens,
|
|
120
|
+
total: last.inputTokens + last.outputTokens + last.cacheReadTokens + last.cacheWriteTokens,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
112
124
|
export function formatCost(n) {
|
|
113
125
|
if (n >= 1) return `$${n.toFixed(2)}`;
|
|
114
126
|
if (n >= 0.01) return `$${n.toFixed(3)}`;
|
package/src/statusline.js
CHANGED
|
@@ -3,14 +3,11 @@ import { readFileSync, existsSync, unlinkSync } from 'fs';
|
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
import { homedir, tmpdir } from 'os';
|
|
5
5
|
import { readAllUsage, getCurrentSessionFile, readCurrentSessionUsage } from './reader.js';
|
|
6
|
-
import { aggregateStats, aggregateSession } from './calculator.js';
|
|
6
|
+
import { aggregateStats, aggregateSession, getLastTurnTokens, formatTokens } from './calculator.js';
|
|
7
|
+
import { readTheme } from './theme.js';
|
|
7
8
|
|
|
8
9
|
const chalk = new Chalk({ level: 3 });
|
|
9
10
|
|
|
10
|
-
const PINK = '#f472b6';
|
|
11
|
-
const CYAN = '#22d3ee';
|
|
12
|
-
const GREEN = '#4ade80';
|
|
13
|
-
|
|
14
11
|
function bar(percent, width = 8) {
|
|
15
12
|
const filled = Math.round((percent / 100) * width);
|
|
16
13
|
const empty = width - filled;
|
|
@@ -24,6 +21,13 @@ function readTriggerMode() {
|
|
|
24
21
|
} catch { return 'off'; }
|
|
25
22
|
}
|
|
26
23
|
|
|
24
|
+
function readTokenMode() {
|
|
25
|
+
try {
|
|
26
|
+
const cfg = JSON.parse(readFileSync(join(homedir(), '.claude-memory.json'), 'utf8'));
|
|
27
|
+
return cfg.tokenDisplay || 'off';
|
|
28
|
+
} catch { return 'off'; }
|
|
29
|
+
}
|
|
30
|
+
|
|
27
31
|
function buildBox(inner, color, width = inner.length) {
|
|
28
32
|
return [
|
|
29
33
|
chalk.hex(color).bold(`╭${'─'.repeat(width)}╮`),
|
|
@@ -57,36 +61,54 @@ function isMemoryLoaded(sessionId) {
|
|
|
57
61
|
|
|
58
62
|
export function renderLine() {
|
|
59
63
|
const mode = readTriggerMode();
|
|
64
|
+
const tokenMode = readTokenMode();
|
|
65
|
+
const theme = readTheme();
|
|
60
66
|
|
|
61
67
|
const sessionMeta = getCurrentSessionFile();
|
|
62
68
|
const sessionId = sessionMeta?.sessionId;
|
|
63
69
|
const loaded = isMemoryLoaded(sessionId);
|
|
64
|
-
const loadedBox = loaded ? buildBox(' ⬡ ',
|
|
70
|
+
const loadedBox = loaded ? buildBox(' ⬡ ', theme.memory, 4) : null;
|
|
65
71
|
|
|
66
72
|
const allEntries = readAllUsage();
|
|
67
73
|
|
|
68
|
-
const
|
|
74
|
+
const buildOutput = (contextBox, turnTokens) => {
|
|
69
75
|
const toJoin = [contextBox];
|
|
70
|
-
if (mode !== 'off') toJoin.push(buildBox(` TRIGGER ${mode.toUpperCase()} `,
|
|
76
|
+
if (mode !== 'off') toJoin.push(buildBox(` TRIGGER ${mode.toUpperCase()} `, theme.trigger));
|
|
71
77
|
if (loadedBox) toJoin.push(loadedBox);
|
|
72
|
-
|
|
78
|
+
if (turnTokens) toJoin.push(buildBox(` ◈ ${formatTokens(turnTokens.total)} `, theme.tokens));
|
|
79
|
+
|
|
80
|
+
let out = joinBoxes(...toJoin);
|
|
81
|
+
|
|
82
|
+
if (tokenMode === 'complete' && turnTokens) {
|
|
83
|
+
const col = (s) => chalk.hex(theme.tokens).bold(s);
|
|
84
|
+
const parts = [
|
|
85
|
+
`INPUT ${formatTokens(turnTokens.input)}`,
|
|
86
|
+
`HISTORY ${formatTokens(turnTokens.history)}`,
|
|
87
|
+
`CACHE ${formatTokens(turnTokens.cache)}`,
|
|
88
|
+
`RESPONSE ${formatTokens(turnTokens.response)}`,
|
|
89
|
+
];
|
|
90
|
+
out += '\n' + parts.map(col).join(col(' │ '));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return out;
|
|
73
94
|
};
|
|
74
95
|
|
|
75
96
|
if (!allEntries.length) {
|
|
76
|
-
const contextBox = buildBox(` CONTEXT ${'░'.repeat(8)} 0% `,
|
|
77
|
-
process.stdout.write(
|
|
97
|
+
const contextBox = buildBox(` CONTEXT ${'░'.repeat(8)} 0% `, theme.context);
|
|
98
|
+
process.stdout.write(buildOutput(contextBox, null));
|
|
78
99
|
return;
|
|
79
100
|
}
|
|
80
101
|
|
|
81
102
|
const sessionEntries = sessionId ? readCurrentSessionUsage(sessionId) : [];
|
|
82
103
|
const session = aggregateSession(sessionEntries);
|
|
104
|
+
const turnTokens = tokenMode !== 'off' ? getLastTurnTokens(sessionEntries) : null;
|
|
83
105
|
|
|
84
106
|
if (!session) {
|
|
85
|
-
const contextBox = buildBox(` CONTEXT ${'░'.repeat(8)} 0% `,
|
|
86
|
-
process.stdout.write(
|
|
107
|
+
const contextBox = buildBox(` CONTEXT ${'░'.repeat(8)} 0% `, theme.context);
|
|
108
|
+
process.stdout.write(buildOutput(contextBox, turnTokens));
|
|
87
109
|
return;
|
|
88
110
|
}
|
|
89
111
|
|
|
90
|
-
const contextBox = buildBox(` CONTEXT ${bar(session.percent)} ${session.percent}% `,
|
|
91
|
-
process.stdout.write(
|
|
112
|
+
const contextBox = buildBox(` CONTEXT ${bar(session.percent)} ${session.percent}% `, theme.context);
|
|
113
|
+
process.stdout.write(buildOutput(contextBox, turnTokens));
|
|
92
114
|
}
|
package/src/theme.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
|
|
5
|
+
export const THEME_PATH = join(homedir(), '.claude', 'jarvis-theme.json');
|
|
6
|
+
|
|
7
|
+
export const DEFAULT_COLORS = {
|
|
8
|
+
context: '#22d3ee',
|
|
9
|
+
trigger: '#f472b6',
|
|
10
|
+
memory: '#4ade80',
|
|
11
|
+
tokens: '#ef4444',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const VALID_NAMES = Object.keys(DEFAULT_COLORS);
|
|
15
|
+
|
|
16
|
+
export function readTheme() {
|
|
17
|
+
try {
|
|
18
|
+
const raw = JSON.parse(readFileSync(THEME_PATH, 'utf8'));
|
|
19
|
+
return { ...DEFAULT_COLORS, ...raw };
|
|
20
|
+
} catch {
|
|
21
|
+
return { ...DEFAULT_COLORS };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function writeTheme(theme) {
|
|
26
|
+
writeFileSync(THEME_PATH, JSON.stringify(theme, null, 2));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function isValidHex(value) {
|
|
30
|
+
return /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(value);
|
|
31
|
+
}
|