@alyibrahim/claude-statusline 1.3.1 → 1.4.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 +4 -4
- package/bin/cli.js +40 -4
- package/package.json +16 -6
- package/scripts/history.js +204 -0
- package/scripts/setup.js +57 -1
- package/scripts/uninstall.js +7 -2
- package/statusline.js +15 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@alyibrahim/claude-statusline)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
|
|
7
|
-
**A rich, fast statusline for [Claude Code](https://claude.ai/code)** — shows model, git branch, context usage, rate limits, session cost, and
|
|
7
|
+
**A rich, fast statusline for [Claude Code](https://claude.ai/code)** — shows model, git branch, context usage, rate limits, session cost, and split input/output token counts after every response.
|
|
8
8
|
|
|
9
9
|
Runs as a **compiled Rust binary** (~5ms startup vs ~100ms for Node.js). Zero shell dependencies. One install command.
|
|
10
10
|
|
|
@@ -28,14 +28,14 @@ Done. The statusline configures itself automatically. Restart Claude Code to see
|
|
|
28
28
|
|
|
29
29
|
**Line 1** — Model name · Effort level · Active subagents · Current task · Directory `(branch +commits)` · Context bar
|
|
30
30
|
|
|
31
|
-
**Line 2** — Weekly token usage · 5h usage · Reset countdown *(Pro/Max)* — or — Session cost *(API key)* · Session
|
|
31
|
+
**Line 2** — Weekly token usage · 5h usage · Reset countdown *(Pro/Max)* — or — Session cost *(API key)* · Session tokens `X↓ Y↑`
|
|
32
32
|
|
|
33
33
|
| Feature | Details |
|
|
34
34
|
|---|---|
|
|
35
35
|
| Context bar | Normalized to usable % — accounts for the auto-compact buffer |
|
|
36
36
|
| Rate limits | Shows 5h and weekly usage with color-coded thresholds |
|
|
37
37
|
| Session cost | Displayed only for API key users, hidden for subscribers |
|
|
38
|
-
| Session tokens | Real-time
|
|
38
|
+
| Session tokens | Real-time via JSONL offset caching — split input/output display (`X↓ Y↑`), formatted as `k` or `M` for large counts |
|
|
39
39
|
| Active agents | Counts running subagents from your `~/.claude/todos/` directory |
|
|
40
40
|
| Effort level | Reads `CLAUDE_CODE_EFFORT_LEVEL` env var or `settings.json` |
|
|
41
41
|
| Git branch | Detected automatically, silently absent if not a git repo |
|
|
@@ -70,7 +70,7 @@ npm picks the right one automatically. If your platform isn't listed, the JS fal
|
|
|
70
70
|
| Subscription-aware | Shows usage/resets for Pro/Max, cost for API | Treat everyone as API user |
|
|
71
71
|
| Context bar | Usable % after auto-compact buffer | Raw remaining % |
|
|
72
72
|
| Subagent counter | Counts active agents from todos dir | — |
|
|
73
|
-
| Session tokens | Real-time via JSONL offset cache | Stale stdin snapshot or none |
|
|
73
|
+
| Session tokens | Real-time via JSONL offset cache, split I/O (`X↓ Y↑`) | Stale stdin snapshot or none |
|
|
74
74
|
| Session commits | Tracks git commits made this session | — |
|
|
75
75
|
|
|
76
76
|
---
|
package/bin/cli.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
|
-
const { setup } = require('../scripts/setup');
|
|
3
|
+
const { setup, toggleHistory } = require('../scripts/setup');
|
|
4
4
|
const { uninstall } = require('../scripts/uninstall');
|
|
5
|
-
const
|
|
5
|
+
const config = require('../scripts/config');
|
|
6
|
+
const { getSettingsPath } = config;
|
|
7
|
+
const { spawnSync } = require('child_process');
|
|
8
|
+
const path = require('path');
|
|
6
9
|
|
|
7
10
|
const USAGE = `
|
|
8
11
|
claude-statusline <command>
|
|
9
12
|
|
|
10
13
|
Commands:
|
|
11
|
-
setup
|
|
12
|
-
uninstall
|
|
14
|
+
setup Configure ~/.claude/settings.json to use this statusline
|
|
15
|
+
uninstall Remove this statusline from ~/.claude/settings.json
|
|
16
|
+
enable-history Enable tracking session analytics to SQLite (default on setup)
|
|
17
|
+
disable-history Remove history tracking hooks from Claude settings
|
|
18
|
+
history Open the session analytics dashboard
|
|
13
19
|
`.trim();
|
|
14
20
|
|
|
15
21
|
const cmd = process.argv[2];
|
|
@@ -30,6 +36,36 @@ if (cmd === 'setup') {
|
|
|
30
36
|
}
|
|
31
37
|
console.log(`✓ Removed statusline from ${getSettingsPath()}`);
|
|
32
38
|
|
|
39
|
+
} else if (cmd === 'enable-history') {
|
|
40
|
+
const result = toggleHistory(true);
|
|
41
|
+
if (!result.ok) {
|
|
42
|
+
console.error('Error:', result.error);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
console.log(`✓ History tracking enabled in ${result.settingsPath}`);
|
|
46
|
+
|
|
47
|
+
} else if (cmd === 'disable-history') {
|
|
48
|
+
const result = toggleHistory(false);
|
|
49
|
+
if (!result.ok) {
|
|
50
|
+
console.error('Error:', result.error);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
console.log(`✓ History tracking disabled from ${result.settingsPath}`);
|
|
54
|
+
|
|
55
|
+
} else if (cmd === 'hook' || cmd === 'history') {
|
|
56
|
+
const binaryPath = config.resolveBinary();
|
|
57
|
+
const scriptPath = path.resolve(__dirname, '../statusline.js');
|
|
58
|
+
|
|
59
|
+
if (binaryPath) {
|
|
60
|
+
// Run Rust binary
|
|
61
|
+
const child = spawnSync(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
|
|
62
|
+
process.exit(child.status || 0);
|
|
63
|
+
} else {
|
|
64
|
+
// Run JS fallback
|
|
65
|
+
const child = spawnSync(process.execPath, [scriptPath, ...process.argv.slice(2)], { stdio: 'inherit' });
|
|
66
|
+
process.exit(child.status || 0);
|
|
67
|
+
}
|
|
68
|
+
|
|
33
69
|
} else if (cmd === undefined) {
|
|
34
70
|
console.log(USAGE);
|
|
35
71
|
process.exit(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alyibrahim/claude-statusline",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Rich statusline for Claude Code — model, context bar, real-time token tracking, git branch, rate limits, and session stats. Rust binary, ~5ms startup.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude",
|
|
@@ -39,6 +39,12 @@
|
|
|
39
39
|
"preuninstall": "node scripts/preuninstall.js",
|
|
40
40
|
"test": "jest"
|
|
41
41
|
},
|
|
42
|
+
"jest": {
|
|
43
|
+
"testPathIgnorePatterns": [
|
|
44
|
+
"/node_modules/",
|
|
45
|
+
"/.worktrees/"
|
|
46
|
+
]
|
|
47
|
+
},
|
|
42
48
|
"files": [
|
|
43
49
|
"statusline.js",
|
|
44
50
|
"bin/",
|
|
@@ -46,12 +52,16 @@
|
|
|
46
52
|
"README.md"
|
|
47
53
|
],
|
|
48
54
|
"license": "MIT",
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"open": "^10.1.0"
|
|
57
|
+
},
|
|
49
58
|
"optionalDependencies": {
|
|
50
|
-
"
|
|
51
|
-
"@alyibrahim/claude-statusline-linux-
|
|
52
|
-
"@alyibrahim/claude-statusline-
|
|
53
|
-
"@alyibrahim/claude-statusline-darwin-
|
|
54
|
-
"@alyibrahim/claude-statusline-
|
|
59
|
+
"better-sqlite3": "^11.3.0",
|
|
60
|
+
"@alyibrahim/claude-statusline-linux-x64": "1.4.0",
|
|
61
|
+
"@alyibrahim/claude-statusline-linux-arm64": "1.4.0",
|
|
62
|
+
"@alyibrahim/claude-statusline-darwin-x64": "1.4.0",
|
|
63
|
+
"@alyibrahim/claude-statusline-darwin-arm64": "1.4.0",
|
|
64
|
+
"@alyibrahim/claude-statusline-win32-x64": "1.4.0"
|
|
55
65
|
},
|
|
56
66
|
"devDependencies": {
|
|
57
67
|
"jest": "^29.0.0"
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const open = require('open');
|
|
5
|
+
|
|
6
|
+
// Returns undefined if better-sqlite3 is not available
|
|
7
|
+
function getDb() {
|
|
8
|
+
try {
|
|
9
|
+
const Database = require('better-sqlite3');
|
|
10
|
+
const home = process.env.HOME || process.env.USERPROFILE || '.';
|
|
11
|
+
const dbDir = path.join(home, '.claude');
|
|
12
|
+
fs.mkdirSync(dbDir, { recursive: true });
|
|
13
|
+
|
|
14
|
+
const db = new Database(path.join(dbDir, 'statusline-history.db'));
|
|
15
|
+
db.exec(`
|
|
16
|
+
CREATE TABLE IF NOT EXISTS sessions (
|
|
17
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
18
|
+
session_id TEXT UNIQUE NOT NULL,
|
|
19
|
+
project_dir TEXT NOT NULL,
|
|
20
|
+
project_name TEXT NOT NULL,
|
|
21
|
+
model TEXT NOT NULL,
|
|
22
|
+
start_time DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
23
|
+
end_time DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
24
|
+
tokens_in INTEGER DEFAULT 0,
|
|
25
|
+
tokens_out INTEGER DEFAULT 0,
|
|
26
|
+
cost_usd REAL DEFAULT 0.0,
|
|
27
|
+
duration_seconds INTEGER DEFAULT 0,
|
|
28
|
+
exit_reason TEXT
|
|
29
|
+
)
|
|
30
|
+
`);
|
|
31
|
+
return db;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function handleHookStart() {
|
|
38
|
+
const db = getDb();
|
|
39
|
+
if (!db) return; // Silent fallback
|
|
40
|
+
|
|
41
|
+
const projectDir = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
42
|
+
const projectName = path.basename(projectDir);
|
|
43
|
+
const tempSessionId = `pending-${projectName}-${Date.now()}`;
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const stmt = db.prepare('INSERT INTO sessions (session_id, project_dir, project_name, model, exit_reason) VALUES (?, ?, ?, ?, ?)');
|
|
47
|
+
stmt.run(tempSessionId, projectDir, projectName, 'pending', 'pending');
|
|
48
|
+
} catch (e) {}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function handleHookEnd() {
|
|
52
|
+
let input = '';
|
|
53
|
+
process.stdin.setEncoding('utf8');
|
|
54
|
+
process.stdin.on('data', chunk => input += chunk);
|
|
55
|
+
process.stdin.on('end', () => {
|
|
56
|
+
const db = getDb();
|
|
57
|
+
if (!db) return process.exit(0);
|
|
58
|
+
|
|
59
|
+
let reason = 'unknown';
|
|
60
|
+
try {
|
|
61
|
+
const data = JSON.parse(input);
|
|
62
|
+
reason = data.reason || 'unknown';
|
|
63
|
+
} catch(e) {}
|
|
64
|
+
|
|
65
|
+
const projectDir = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
66
|
+
const home = process.env.HOME || process.env.USERPROFILE || '.';
|
|
67
|
+
const slug = projectDir.replace(/[\/\\]/g, '-');
|
|
68
|
+
const projectsDir = path.join(home, '.claude', 'projects', slug);
|
|
69
|
+
|
|
70
|
+
let newestFile = null;
|
|
71
|
+
let newestTime = 0;
|
|
72
|
+
|
|
73
|
+
if (fs.existsSync(projectsDir)) {
|
|
74
|
+
try {
|
|
75
|
+
const files = fs.readdirSync(projectsDir);
|
|
76
|
+
for (const file of files) {
|
|
77
|
+
if (file.endsWith('.jsonl')) {
|
|
78
|
+
const p = path.join(projectsDir, file);
|
|
79
|
+
const mtime = fs.statSync(p).mtimeMs;
|
|
80
|
+
if (mtime > newestTime) {
|
|
81
|
+
newestTime = mtime;
|
|
82
|
+
newestFile = p;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
} catch(e) {}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (newestFile) {
|
|
90
|
+
const sessionId = path.basename(newestFile, '.jsonl');
|
|
91
|
+
let totalIn = 0;
|
|
92
|
+
let totalOut = 0;
|
|
93
|
+
let cost = 0.0;
|
|
94
|
+
let model = '';
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
const content = fs.readFileSync(newestFile, 'utf8');
|
|
98
|
+
const lines = content.split('\n');
|
|
99
|
+
for (const line of lines) {
|
|
100
|
+
if (!line.trim()) continue;
|
|
101
|
+
try {
|
|
102
|
+
const entry = JSON.parse(line);
|
|
103
|
+
if (entry.type === 'assistant' && entry.message?.usage) {
|
|
104
|
+
const u = entry.message.usage;
|
|
105
|
+
totalIn += (u.input_tokens || 0) + Math.round((u.cache_read_input_tokens || 0) * 0.1) + (u.cache_creation_input_tokens || 0);
|
|
106
|
+
totalOut += (u.output_tokens || 0);
|
|
107
|
+
if (!model) model = entry.message.model || 'Claude';
|
|
108
|
+
} else if (entry.type === 'cost') {
|
|
109
|
+
cost += (entry.cost_usd || 0.0);
|
|
110
|
+
} else if (entry.type === 'message_start' && !model) {
|
|
111
|
+
model = entry.message?.model || 'Claude';
|
|
112
|
+
}
|
|
113
|
+
} catch(e) {}
|
|
114
|
+
}
|
|
115
|
+
} catch(e) {}
|
|
116
|
+
|
|
117
|
+
if (!model) model = 'Claude';
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
const stmt = db.prepare(`
|
|
121
|
+
UPDATE sessions
|
|
122
|
+
SET session_id = ?, model = ?, end_time = CURRENT_TIMESTAMP,
|
|
123
|
+
tokens_in = ?, tokens_out = ?, cost_usd = ?, exit_reason = ?,
|
|
124
|
+
duration_seconds = CAST((julianday('now') - julianday(start_time)) * 86400 as integer)
|
|
125
|
+
WHERE id = (SELECT id FROM sessions WHERE project_dir = ? AND exit_reason = 'pending' ORDER BY start_time DESC LIMIT 1)
|
|
126
|
+
`);
|
|
127
|
+
stmt.run(sessionId, model, totalIn, totalOut, cost, reason, projectDir);
|
|
128
|
+
} catch (e) {}
|
|
129
|
+
}
|
|
130
|
+
process.exit(0);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function handleHistory() {
|
|
135
|
+
const db = getDb();
|
|
136
|
+
if (!db) {
|
|
137
|
+
console.error('SQLite is not available. Please install @alyibrahim/claude-statusline with native modules, or ensure better-sqlite3 is successfully installed.');
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let html = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Claude Statusline History</title>';
|
|
142
|
+
html += `<style>
|
|
143
|
+
body { font-family: 'Inter', sans-serif; background: #121212; color: #eee; margin: 0; padding: 40px; }
|
|
144
|
+
h1 { font-size: 24px; font-weight: 600; margin-bottom: 20px; color: #fff; }
|
|
145
|
+
.dashboard { max-width: 1000px; margin: 0 auto; }
|
|
146
|
+
.totals { display: flex; gap: 20px; margin-bottom: 30px; }
|
|
147
|
+
.card { background: #1e1e1e; padding: 20px; border-radius: 12px; flex: 1; border: 1px solid #333; }
|
|
148
|
+
.card h3 { margin: 0 0 10px 0; font-size: 14px; color: #999; text-transform: uppercase; letter-spacing: 0.5px; }
|
|
149
|
+
.card p { margin: 0; font-size: 28px; font-weight: 600; color: #fff; }
|
|
150
|
+
table { width: 100%; border-collapse: collapse; background: #1e1e1e; border-radius: 12px; overflow: hidden; border: 1px solid #333; }
|
|
151
|
+
th, td { padding: 15px; text-align: left; border-bottom: 1px solid #333; }
|
|
152
|
+
th { background: #252525; color: #aaa; font-weight: 500; font-size: 13px; text-transform: uppercase; }
|
|
153
|
+
tr:last-child td { border-bottom: none; }
|
|
154
|
+
.badge { background: #2b3a4a; color: #61afef; padding: 4px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
|
|
155
|
+
.model { color: #98c379; }
|
|
156
|
+
.tokens { font-family: monospace; color: #e5c07b; }
|
|
157
|
+
.cost { color: #d19a66; }
|
|
158
|
+
</style></head><body>`;
|
|
159
|
+
|
|
160
|
+
html += `<div class="dashboard"><h1>Claude Statusline Analytics</h1>`;
|
|
161
|
+
|
|
162
|
+
try {
|
|
163
|
+
const rows = db.prepare('SELECT project_name, model, start_time, duration_seconds, tokens_in, tokens_out, cost_usd, exit_reason FROM sessions ORDER BY start_time DESC LIMIT 100').all();
|
|
164
|
+
let totalCost = 0.0, totalIn = 0, totalOut = 0;
|
|
165
|
+
|
|
166
|
+
let rowsHtml = '';
|
|
167
|
+
for (const s of rows) {
|
|
168
|
+
if (s.exit_reason !== 'pending') {
|
|
169
|
+
totalCost += (s.cost_usd || 0);
|
|
170
|
+
totalIn += (s.tokens_in || 0);
|
|
171
|
+
totalOut += (s.tokens_out || 0);
|
|
172
|
+
}
|
|
173
|
+
rowsHtml += `<tr>
|
|
174
|
+
<td><span class="badge">${s.project_name}</span></td>
|
|
175
|
+
<td class="model">${s.model}</td>
|
|
176
|
+
<td>${s.start_time}</td>
|
|
177
|
+
<td>${s.duration_seconds}s</td>
|
|
178
|
+
<td class="tokens">${s.tokens_in}↓ ${s.tokens_out}↑</td>
|
|
179
|
+
<td class="cost">$${Number(s.cost_usd).toFixed(4)}</td>
|
|
180
|
+
<td>${s.exit_reason}</td>
|
|
181
|
+
</tr>`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
html += `<div class="totals">
|
|
185
|
+
<div class="card"><h3>Total Input Tokens</h3><p>${totalIn}</p></div>
|
|
186
|
+
<div class="card"><h3>Total Output Tokens</h3><p>${totalOut}</p></div>
|
|
187
|
+
<div class="card"><h3>Total Spend</h3><p>$${totalCost.toFixed(2)}</p></div>
|
|
188
|
+
</div>`;
|
|
189
|
+
|
|
190
|
+
html += `<table><thead><tr>
|
|
191
|
+
<th>Project</th><th>Model</th><th>Start Time</th><th>Duration</th><th>Tokens</th><th>Cost</th><th>Reason</th>
|
|
192
|
+
</tr></thead><tbody>${rowsHtml}</tbody></table></div></body></html>`;
|
|
193
|
+
|
|
194
|
+
const tempPath = path.join(os.tmpdir(), 'claude-statusline-dashboard.html');
|
|
195
|
+
fs.writeFileSync(tempPath, html);
|
|
196
|
+
|
|
197
|
+
console.log(`Opened dashboard at ${tempPath}`);
|
|
198
|
+
await open(tempPath);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
console.error(`Failed to load database: ${e.message}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
module.exports = { handleHookStart, handleHookEnd, handleHistory };
|
package/scripts/setup.js
CHANGED
|
@@ -38,6 +38,8 @@ function setup({ force = false } = {}) {
|
|
|
38
38
|
: `"${process.execPath}" "${scriptPath}"`;
|
|
39
39
|
settings.statusLine = { type: 'command', command };
|
|
40
40
|
|
|
41
|
+
updateHooks(settings, command, true);
|
|
42
|
+
|
|
41
43
|
fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
|
|
42
44
|
|
|
43
45
|
try {
|
|
@@ -49,4 +51,58 @@ function setup({ force = false } = {}) {
|
|
|
49
51
|
return { ok: true, settingsPath };
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
function updateHooks(settings, command, enable) {
|
|
55
|
+
if (!settings.hooks) settings.hooks = {};
|
|
56
|
+
|
|
57
|
+
const startCmd = `${command} hook start`;
|
|
58
|
+
const endCmd = `${command} hook end`;
|
|
59
|
+
|
|
60
|
+
function toggleHook(hookName, cmdString) {
|
|
61
|
+
if (!settings.hooks[hookName]) settings.hooks[hookName] = [];
|
|
62
|
+
settings.hooks[hookName] = settings.hooks[hookName].filter(h =>
|
|
63
|
+
!(h.command && (h.command.includes('hook start') || h.command.includes('hook end')))
|
|
64
|
+
);
|
|
65
|
+
if (enable) {
|
|
66
|
+
settings.hooks[hookName].push({ type: 'command', command: cmdString });
|
|
67
|
+
}
|
|
68
|
+
if (settings.hooks[hookName].length === 0) {
|
|
69
|
+
delete settings.hooks[hookName];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
toggleHook('SessionStart', startCmd);
|
|
74
|
+
toggleHook('SessionEnd', endCmd);
|
|
75
|
+
|
|
76
|
+
if (Object.keys(settings.hooks).length === 0) {
|
|
77
|
+
delete settings.hooks;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function toggleHistory(enable) {
|
|
82
|
+
const scriptPath = path.resolve(__dirname, '../statusline.js');
|
|
83
|
+
const binaryPath = config.resolveBinary();
|
|
84
|
+
const safeBinary = binaryPath && !UNSAFE_CHARS.test(binaryPath) ? binaryPath : null;
|
|
85
|
+
const command = safeBinary ? `"${safeBinary}"` : `"${process.execPath}" "${scriptPath}"`;
|
|
86
|
+
|
|
87
|
+
const settingsPath = getSettingsPath();
|
|
88
|
+
let settings = {};
|
|
89
|
+
if (fs.existsSync(settingsPath)) {
|
|
90
|
+
try {
|
|
91
|
+
settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
92
|
+
} catch (e) {
|
|
93
|
+
return { ok: false, error: 'settings.json contains invalid JSON — fix manually then re-run.' };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
updateHooks(settings, command, enable);
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
atomicWrite(settingsPath, settings);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
return { ok: false, error: err.message };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return { ok: true, settingsPath };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = { setup, toggleHistory, updateHooks };
|
package/scripts/uninstall.js
CHANGED
|
@@ -13,8 +13,13 @@ function uninstall() {
|
|
|
13
13
|
return { ok: false, error: 'settings.json contains invalid JSON — cannot safely modify.' };
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
if (
|
|
17
|
-
|
|
16
|
+
if (settings.statusLine) {
|
|
17
|
+
delete settings.statusLine;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Also strip our hooks if they exist
|
|
21
|
+
const { updateHooks } = require('./setup');
|
|
22
|
+
updateHooks(settings, '', false);
|
|
18
23
|
|
|
19
24
|
try {
|
|
20
25
|
atomicWrite(settingsPath, settings);
|
package/statusline.js
CHANGED
|
@@ -7,6 +7,21 @@ const path = require('path');
|
|
|
7
7
|
const os = require('os');
|
|
8
8
|
const { execSync, execFileSync } = require('child_process');
|
|
9
9
|
|
|
10
|
+
const cmd = process.argv[2];
|
|
11
|
+
if (cmd === 'history') {
|
|
12
|
+
require('./scripts/history').handleHistory();
|
|
13
|
+
return;
|
|
14
|
+
} else if (cmd === 'hook') {
|
|
15
|
+
const hookcmd = process.argv[3];
|
|
16
|
+
if (hookcmd === 'start') {
|
|
17
|
+
require('./scripts/history').handleHookStart();
|
|
18
|
+
return;
|
|
19
|
+
} else if (hookcmd === 'end') {
|
|
20
|
+
require('./scripts/history').handleHookEnd();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
10
25
|
// Reads cumulative token totals from the session JSONL file, using a byte-offset
|
|
11
26
|
// cache so only new bytes are parsed on each invocation (O(new bytes) not O(file)).
|
|
12
27
|
// Returns { totalIn, totalOut } or null on any error.
|