cc-context-stats 1.7.0 → 1.8.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/package.json +9 -1
- package/scripts/context-stats.sh +1 -1
- package/scripts/statusline.js +128 -18
- package/.editorconfig +0 -60
- package/.eslintrc.json +0 -35
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -49
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -31
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -33
- package/.github/dependabot.yml +0 -44
- package/.github/workflows/ci.yml +0 -294
- package/.github/workflows/release.yml +0 -151
- package/.pre-commit-config.yaml +0 -74
- package/.prettierrc +0 -33
- package/.shellcheckrc +0 -10
- package/CHANGELOG.md +0 -163
- package/CLAUDE.md +0 -66
- package/CODE_OF_CONDUCT.md +0 -59
- package/CONTRIBUTING.md +0 -240
- package/RELEASE_NOTES.md +0 -19
- package/SECURITY.md +0 -44
- package/TODOS.md +0 -72
- package/assets/logo/favicon.svg +0 -19
- package/assets/logo/logo-black.svg +0 -24
- package/assets/logo/logo-full.svg +0 -40
- package/assets/logo/logo-icon.svg +0 -27
- package/assets/logo/logo-mark.svg +0 -28
- package/assets/logo/logo-white.svg +0 -24
- package/assets/logo/logo-wordmark.svg +0 -6
- package/config/settings-example.json +0 -7
- package/config/settings-node.json +0 -7
- package/config/settings-python.json +0 -7
- package/docs/ARCHITECTURE.md +0 -128
- package/docs/CSV_FORMAT.md +0 -42
- package/docs/DEPLOYMENT.md +0 -71
- package/docs/DEVELOPMENT.md +0 -161
- package/docs/configuration.md +0 -118
- package/docs/context-stats.md +0 -143
- package/docs/installation.md +0 -255
- package/docs/scripts.md +0 -140
- package/docs/troubleshooting.md +0 -278
- package/images/claude-statusline-token-graph.gif +0 -0
- package/images/claude-statusline.png +0 -0
- package/images/context-status-dumbzone.png +0 -0
- package/images/context-status.png +0 -0
- package/images/statusline-detail.png +0 -0
- package/images/token-graph.jpeg +0 -0
- package/images/token-graph.png +0 -0
- package/images/v1.6.1.png +0 -0
- package/install +0 -351
- package/install.sh +0 -298
- package/jest.config.js +0 -11
- package/pyproject.toml +0 -115
- package/requirements-dev.txt +0 -12
- package/scripts/statusline-full.sh +0 -304
- package/scripts/statusline-git.sh +0 -88
- package/scripts/statusline-minimal.sh +0 -67
- package/scripts/statusline.py +0 -485
- package/src/claude_statusline/__init__.py +0 -11
- package/src/claude_statusline/__main__.py +0 -6
- package/src/claude_statusline/cli/__init__.py +0 -1
- package/src/claude_statusline/cli/context_stats.py +0 -512
- package/src/claude_statusline/cli/explain.py +0 -228
- package/src/claude_statusline/cli/statusline.py +0 -169
- package/src/claude_statusline/core/__init__.py +0 -1
- package/src/claude_statusline/core/colors.py +0 -124
- package/src/claude_statusline/core/config.py +0 -148
- package/src/claude_statusline/core/git.py +0 -78
- package/src/claude_statusline/core/state.py +0 -323
- package/src/claude_statusline/formatters/__init__.py +0 -1
- package/src/claude_statusline/formatters/layout.py +0 -67
- package/src/claude_statusline/formatters/time.py +0 -50
- package/src/claude_statusline/formatters/tokens.py +0 -70
- package/src/claude_statusline/graphs/__init__.py +0 -1
- package/src/claude_statusline/graphs/renderer.py +0 -366
- package/src/claude_statusline/graphs/statistics.py +0 -92
- package/src/claude_statusline/ui/__init__.py +0 -1
- package/src/claude_statusline/ui/icons.py +0 -93
- package/src/claude_statusline/ui/waiting.py +0 -62
- package/tests/bash/test_delta_parity.bats +0 -199
- package/tests/bash/test_install.bats +0 -29
- package/tests/bash/test_parity.bats +0 -315
- package/tests/bash/test_statusline_full.bats +0 -139
- package/tests/bash/test_statusline_git.bats +0 -42
- package/tests/bash/test_statusline_minimal.bats +0 -37
- package/tests/fixtures/json/comma_in_path.json +0 -31
- package/tests/fixtures/json/high_usage.json +0 -17
- package/tests/fixtures/json/low_usage.json +0 -17
- package/tests/fixtures/json/medium_usage.json +0 -17
- package/tests/fixtures/json/valid_full.json +0 -30
- package/tests/fixtures/json/valid_minimal.json +0 -9
- package/tests/node/rotation.test.js +0 -89
- package/tests/node/statusline.test.js +0 -240
- package/tests/python/conftest.py +0 -84
- package/tests/python/test_colors.py +0 -105
- package/tests/python/test_config_colors.py +0 -78
- package/tests/python/test_data_pipeline.py +0 -446
- package/tests/python/test_explain.py +0 -177
- package/tests/python/test_icons.py +0 -152
- package/tests/python/test_layout.py +0 -127
- package/tests/python/test_state_rotation_validation.py +0 -232
- package/tests/python/test_statusline.py +0 -215
- package/tests/python/test_waiting.py +0 -127
package/docs/troubleshooting.md
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
# Troubleshooting
|
|
2
|
-
|
|
3
|
-
## Common Issues
|
|
4
|
-
|
|
5
|
-
### Status line not appearing
|
|
6
|
-
|
|
7
|
-
**macOS/Linux:**
|
|
8
|
-
|
|
9
|
-
1. Check script is executable:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
chmod +x ~/.claude/statusline.sh
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
2. Test the script:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
echo '{"model":{"display_name":"Test"}}' | ~/.claude/statusline.sh
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
3. Verify settings.json configuration:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
cat ~/.claude/settings.json
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
**pip/npm install:**
|
|
28
|
-
|
|
29
|
-
1. Verify the command is available:
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
which claude-statusline
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
2. Test it:
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
echo '{"model":{"display_name":"Test"}}' | claude-statusline
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
3. Ensure your settings.json uses `"command": "claude-statusline"` (not a file path).
|
|
42
|
-
|
|
43
|
-
**Windows (Python):**
|
|
44
|
-
|
|
45
|
-
```powershell
|
|
46
|
-
echo {"model":{"display_name":"Test"}} | python %USERPROFILE%\.claude\statusline.py
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### jq not found
|
|
50
|
-
|
|
51
|
-
The bash scripts require `jq` for JSON parsing. Python and Node.js scripts do **not** need `jq`.
|
|
52
|
-
|
|
53
|
-
**macOS:**
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
brew install jq
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
**Linux (Debian/Ubuntu):**
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
sudo apt install jq
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
**Linux (Fedora/RHEL):**
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
sudo dnf install jq
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Alternatively, use the Python or Node.js version which don't require `jq`.
|
|
72
|
-
|
|
73
|
-
### context-stats command not found
|
|
74
|
-
|
|
75
|
-
**If installed via pip or npm:**
|
|
76
|
-
|
|
77
|
-
1. Verify installation:
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
which context-stats
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
2. Reinstall if missing:
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
pip install cc-context-stats # or: npm install -g cc-context-stats
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
**If installed via shell installer:**
|
|
90
|
-
|
|
91
|
-
1. Verify installation:
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
ls -la ~/.local/bin/context-stats
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
2. Check PATH:
|
|
98
|
-
|
|
99
|
-
```bash
|
|
100
|
-
echo $PATH | grep -q "$HOME/.local/bin" && echo "In PATH" || echo "Not in PATH"
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
3. Add to PATH if needed:
|
|
104
|
-
|
|
105
|
-
```bash
|
|
106
|
-
# zsh
|
|
107
|
-
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
|
|
108
|
-
source ~/.zshrc
|
|
109
|
-
|
|
110
|
-
# bash
|
|
111
|
-
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
|
|
112
|
-
source ~/.bashrc
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### pip install fails
|
|
116
|
-
|
|
117
|
-
1. Ensure Python 3.9+:
|
|
118
|
-
|
|
119
|
-
```bash
|
|
120
|
-
python3 --version
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
2. Try with `--user` flag:
|
|
124
|
-
|
|
125
|
-
```bash
|
|
126
|
-
pip install --user cc-context-stats
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
3. Or use `uv`:
|
|
130
|
-
|
|
131
|
-
```bash
|
|
132
|
-
uv pip install cc-context-stats
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### npm install fails
|
|
136
|
-
|
|
137
|
-
1. Ensure Node.js 18+:
|
|
138
|
-
|
|
139
|
-
```bash
|
|
140
|
-
node --version
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
2. Try with sudo (Linux/macOS):
|
|
144
|
-
|
|
145
|
-
```bash
|
|
146
|
-
sudo npm install -g cc-context-stats
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
3. Or fix npm permissions:
|
|
150
|
-
|
|
151
|
-
```bash
|
|
152
|
-
mkdir -p ~/.npm-global
|
|
153
|
-
npm config set prefix '~/.npm-global'
|
|
154
|
-
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.zshrc
|
|
155
|
-
source ~/.zshrc
|
|
156
|
-
npm install -g cc-context-stats
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### No token graph data
|
|
160
|
-
|
|
161
|
-
Token history requires:
|
|
162
|
-
|
|
163
|
-
1. Python or Node.js statusline script (bash scripts do **not** write state files)
|
|
164
|
-
2. `show_delta=true` in `~/.claude/statusline.conf` (default)
|
|
165
|
-
3. Active Claude Code session generating state files
|
|
166
|
-
4. State files at `~/.claude/statusline/statusline.<session_id>.state`
|
|
167
|
-
|
|
168
|
-
Check for state files:
|
|
169
|
-
|
|
170
|
-
```bash
|
|
171
|
-
ls -la ~/.claude/statusline/statusline.*.state
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### Git info not showing
|
|
175
|
-
|
|
176
|
-
1. Verify you're in a git repository:
|
|
177
|
-
|
|
178
|
-
```bash
|
|
179
|
-
git rev-parse --is-inside-work-tree
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
2. Check git is installed:
|
|
183
|
-
|
|
184
|
-
```bash
|
|
185
|
-
which git
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
3. Git commands have a 5-second timeout. If your repo is very large, git operations may time out silently.
|
|
189
|
-
|
|
190
|
-
### Wrong token colors
|
|
191
|
-
|
|
192
|
-
Token colors depend on availability percentage:
|
|
193
|
-
|
|
194
|
-
| Availability | Expected Color |
|
|
195
|
-
| ------------ | -------------- |
|
|
196
|
-
| > 50% | Green |
|
|
197
|
-
| > 25% | Yellow |
|
|
198
|
-
| <= 25% | Red |
|
|
199
|
-
|
|
200
|
-
If colors look wrong, check terminal color support.
|
|
201
|
-
|
|
202
|
-
### Delta always shows zero
|
|
203
|
-
|
|
204
|
-
Token delta requires multiple statusline refreshes. The first refresh establishes a baseline; subsequent refreshes show the delta.
|
|
205
|
-
|
|
206
|
-
If delta is always zero after multiple refreshes, check that the state file is being written:
|
|
207
|
-
|
|
208
|
-
```bash
|
|
209
|
-
wc -l ~/.claude/statusline/statusline.*.state
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
### Configuration not taking effect
|
|
213
|
-
|
|
214
|
-
1. Check config file location:
|
|
215
|
-
|
|
216
|
-
```bash
|
|
217
|
-
cat ~/.claude/statusline.conf
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
2. Verify syntax (no spaces around `=`):
|
|
221
|
-
|
|
222
|
-
```bash
|
|
223
|
-
# Correct
|
|
224
|
-
show_delta=true
|
|
225
|
-
|
|
226
|
-
# Wrong
|
|
227
|
-
show_delta = true
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
3. Restart Claude Code after config changes.
|
|
231
|
-
|
|
232
|
-
## Debug Mode
|
|
233
|
-
|
|
234
|
-
### Test script output
|
|
235
|
-
|
|
236
|
-
```bash
|
|
237
|
-
# Create test input
|
|
238
|
-
cat << 'EOF' > /tmp/test-input.json
|
|
239
|
-
{
|
|
240
|
-
"model": {"display_name": "Opus 4.5"},
|
|
241
|
-
"cwd": "/test/project",
|
|
242
|
-
"session_id": "test123",
|
|
243
|
-
"context": {
|
|
244
|
-
"tokens_remaining": 64000,
|
|
245
|
-
"context_window": 200000,
|
|
246
|
-
"autocompact_buffer_tokens": 45000
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
EOF
|
|
250
|
-
|
|
251
|
-
# Test each script
|
|
252
|
-
cat /tmp/test-input.json | ~/.claude/statusline.sh
|
|
253
|
-
cat /tmp/test-input.json | python3 ~/.claude/statusline.py
|
|
254
|
-
cat /tmp/test-input.json | node ~/.claude/statusline.js
|
|
255
|
-
|
|
256
|
-
# Test pip/npm installed version
|
|
257
|
-
cat /tmp/test-input.json | claude-statusline
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
### Check state files
|
|
261
|
-
|
|
262
|
-
```bash
|
|
263
|
-
# View state file content
|
|
264
|
-
cat ~/.claude/statusline/statusline.*.state
|
|
265
|
-
|
|
266
|
-
# Watch state file updates
|
|
267
|
-
watch -n 1 'tail -5 ~/.claude/statusline/statusline.*.state'
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
## Getting Help
|
|
271
|
-
|
|
272
|
-
- Check [existing issues](https://github.com/luongnv89/cc-context-stats/issues)
|
|
273
|
-
- Open a new issue with:
|
|
274
|
-
- Operating system
|
|
275
|
-
- Shell type (bash/zsh)
|
|
276
|
-
- Installation method (pip, npm, shell installer, manual)
|
|
277
|
-
- Script version being used
|
|
278
|
-
- Error messages or unexpected behavior
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/images/token-graph.jpeg
DELETED
|
Binary file
|
package/images/token-graph.png
DELETED
|
Binary file
|
package/images/v1.6.1.png
DELETED
|
Binary file
|
package/install
DELETED
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
#
|
|
3
|
-
# Claude Code Status Line Installer
|
|
4
|
-
# Installs and configures a status line for Claude Code
|
|
5
|
-
#
|
|
6
|
-
# Usage:
|
|
7
|
-
# Local: ./install.sh
|
|
8
|
-
# Remote: curl -fsSL https://raw.githubusercontent.com/luongnv89/claude-statusline/main/install.sh | bash
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
set -e
|
|
12
|
-
|
|
13
|
-
# Colors for output
|
|
14
|
-
RED='\033[0;31m'
|
|
15
|
-
GREEN='\033[0;32m'
|
|
16
|
-
YELLOW='\033[0;33m'
|
|
17
|
-
BLUE='\033[0;34m'
|
|
18
|
-
RESET='\033[0m'
|
|
19
|
-
|
|
20
|
-
CLAUDE_DIR="$HOME/.claude"
|
|
21
|
-
SETTINGS_FILE="$CLAUDE_DIR/settings.json"
|
|
22
|
-
LOCAL_BIN="$HOME/.local/bin"
|
|
23
|
-
|
|
24
|
-
# GitHub repository info for remote installation
|
|
25
|
-
GITHUB_RAW_URL="https://raw.githubusercontent.com/luongnv89/claude-statusline/main"
|
|
26
|
-
GITHUB_API_URL="https://api.github.com/repos/luongnv89/claude-statusline"
|
|
27
|
-
|
|
28
|
-
# Detect if running from pipe (curl) or locally
|
|
29
|
-
detect_install_mode() {
|
|
30
|
-
# Check if we have a valid script file with scripts directory
|
|
31
|
-
if [ -n "${BASH_SOURCE[0]}" ] && [ -f "${BASH_SOURCE[0]}" ]; then
|
|
32
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
33
|
-
if [ -d "$SCRIPT_DIR/scripts" ]; then
|
|
34
|
-
INSTALL_MODE="local"
|
|
35
|
-
INTERACTIVE=true
|
|
36
|
-
[ -t 0 ] || INTERACTIVE=false
|
|
37
|
-
return
|
|
38
|
-
fi
|
|
39
|
-
fi
|
|
40
|
-
# Running from curl/pipe or script directory not found
|
|
41
|
-
INSTALL_MODE="remote"
|
|
42
|
-
INTERACTIVE=false
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
echo -e "${BLUE}Claude Code Status Line Installer${RESET}"
|
|
46
|
-
echo "=================================="
|
|
47
|
-
echo
|
|
48
|
-
|
|
49
|
-
detect_install_mode
|
|
50
|
-
|
|
51
|
-
if [ "$INSTALL_MODE" = "remote" ]; then
|
|
52
|
-
echo -e "${YELLOW}Remote installation mode${RESET}"
|
|
53
|
-
echo "Downloading from GitHub..."
|
|
54
|
-
echo
|
|
55
|
-
else
|
|
56
|
-
echo -e "${GREEN}Local installation mode${RESET}"
|
|
57
|
-
echo
|
|
58
|
-
fi
|
|
59
|
-
|
|
60
|
-
# Check for curl (required for remote installation)
|
|
61
|
-
check_curl() {
|
|
62
|
-
if [ "$INSTALL_MODE" = "remote" ]; then
|
|
63
|
-
if ! command -v curl &>/dev/null; then
|
|
64
|
-
echo -e "${RED}Error: 'curl' is required for remote installation${RESET}"
|
|
65
|
-
exit 1
|
|
66
|
-
fi
|
|
67
|
-
fi
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
# Check for jq (required for bash scripts)
|
|
71
|
-
check_jq() {
|
|
72
|
-
if ! command -v jq &>/dev/null; then
|
|
73
|
-
echo -e "${YELLOW}Warning: 'jq' is not installed.${RESET}"
|
|
74
|
-
echo "jq is required for bash status line scripts."
|
|
75
|
-
echo
|
|
76
|
-
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
77
|
-
echo "Install with: brew install jq"
|
|
78
|
-
else
|
|
79
|
-
echo "Install with: sudo apt install jq (Debian/Ubuntu)"
|
|
80
|
-
echo " or: sudo yum install jq (RHEL/CentOS)"
|
|
81
|
-
fi
|
|
82
|
-
echo
|
|
83
|
-
if [ "$INTERACTIVE" = true ]; then
|
|
84
|
-
read -p "Continue anyway? (y/n) " -n 1 -r
|
|
85
|
-
echo
|
|
86
|
-
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
87
|
-
exit 1
|
|
88
|
-
fi
|
|
89
|
-
fi
|
|
90
|
-
else
|
|
91
|
-
echo -e "${GREEN}✓${RESET} jq is installed"
|
|
92
|
-
fi
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
# Download a file from GitHub
|
|
96
|
-
download_file() {
|
|
97
|
-
local remote_path="$1"
|
|
98
|
-
local dest_path="$2"
|
|
99
|
-
local url="$GITHUB_RAW_URL/$remote_path"
|
|
100
|
-
|
|
101
|
-
if curl -fsSL "$url" -o "$dest_path"; then
|
|
102
|
-
chmod +x "$dest_path"
|
|
103
|
-
return 0
|
|
104
|
-
else
|
|
105
|
-
echo -e "${RED}Error: Failed to download $remote_path${RESET}"
|
|
106
|
-
return 1
|
|
107
|
-
fi
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
# Get latest commit hash from GitHub
|
|
111
|
-
get_remote_commit_hash() {
|
|
112
|
-
local hash
|
|
113
|
-
hash=$(curl -fsSL "$GITHUB_API_URL/commits/main" 2>/dev/null | grep -m1 '"sha"' | cut -d'"' -f4 | head -c7)
|
|
114
|
-
echo "${hash:-unknown}"
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
# Select script type
|
|
118
|
-
select_script() {
|
|
119
|
-
echo
|
|
120
|
-
echo "Available status line scripts:"
|
|
121
|
-
echo " 1) minimal - Simple: model + directory"
|
|
122
|
-
echo " 2) git - With git branch info"
|
|
123
|
-
echo " 3) full - Full featured with context usage (recommended)"
|
|
124
|
-
echo " 4) python - Python version (full featured)"
|
|
125
|
-
echo " 5) node - Node.js version (full featured)"
|
|
126
|
-
echo
|
|
127
|
-
|
|
128
|
-
if [ "$INTERACTIVE" = true ]; then
|
|
129
|
-
read -rp "Select script [1-5, default: 3]: " choice
|
|
130
|
-
else
|
|
131
|
-
echo "Non-interactive mode detected. Using default: full (3)"
|
|
132
|
-
choice=3
|
|
133
|
-
fi
|
|
134
|
-
|
|
135
|
-
case ${choice:-3} in
|
|
136
|
-
1)
|
|
137
|
-
SCRIPT_REMOTE="scripts/statusline-minimal.sh"
|
|
138
|
-
SCRIPT_NAME="statusline.sh"
|
|
139
|
-
;;
|
|
140
|
-
2)
|
|
141
|
-
SCRIPT_REMOTE="scripts/statusline-git.sh"
|
|
142
|
-
SCRIPT_NAME="statusline.sh"
|
|
143
|
-
;;
|
|
144
|
-
3)
|
|
145
|
-
SCRIPT_REMOTE="scripts/statusline-full.sh"
|
|
146
|
-
SCRIPT_NAME="statusline.sh"
|
|
147
|
-
;;
|
|
148
|
-
4)
|
|
149
|
-
SCRIPT_REMOTE="scripts/statusline.py"
|
|
150
|
-
SCRIPT_NAME="statusline.py"
|
|
151
|
-
;;
|
|
152
|
-
5)
|
|
153
|
-
SCRIPT_REMOTE="scripts/statusline.js"
|
|
154
|
-
SCRIPT_NAME="statusline.js"
|
|
155
|
-
;;
|
|
156
|
-
*)
|
|
157
|
-
echo -e "${RED}Invalid choice${RESET}"
|
|
158
|
-
exit 1
|
|
159
|
-
;;
|
|
160
|
-
esac
|
|
161
|
-
|
|
162
|
-
if [ "$INSTALL_MODE" = "local" ]; then
|
|
163
|
-
SCRIPT_SRC="$SCRIPT_DIR/$SCRIPT_REMOTE"
|
|
164
|
-
fi
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
# Create .claude directory if needed
|
|
168
|
-
ensure_claude_dir() {
|
|
169
|
-
if [ ! -d "$CLAUDE_DIR" ]; then
|
|
170
|
-
echo -e "${YELLOW}Creating $CLAUDE_DIR directory...${RESET}"
|
|
171
|
-
mkdir -p "$CLAUDE_DIR"
|
|
172
|
-
fi
|
|
173
|
-
echo -e "${GREEN}✓${RESET} Claude directory exists: $CLAUDE_DIR"
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
# Install/copy script
|
|
177
|
-
install_script() {
|
|
178
|
-
DEST="$CLAUDE_DIR/$SCRIPT_NAME"
|
|
179
|
-
|
|
180
|
-
if [ -f "$DEST" ]; then
|
|
181
|
-
echo
|
|
182
|
-
echo -e "${YELLOW}Warning: $DEST already exists${RESET}"
|
|
183
|
-
if [ "$INTERACTIVE" = true ]; then
|
|
184
|
-
read -p "Overwrite? (y/n) " -n 1 -r
|
|
185
|
-
echo
|
|
186
|
-
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
187
|
-
echo "Keeping existing script."
|
|
188
|
-
return
|
|
189
|
-
fi
|
|
190
|
-
else
|
|
191
|
-
echo "Overwriting in non-interactive mode..."
|
|
192
|
-
fi
|
|
193
|
-
fi
|
|
194
|
-
|
|
195
|
-
if [ "$INSTALL_MODE" = "local" ]; then
|
|
196
|
-
cp "$SCRIPT_SRC" "$DEST"
|
|
197
|
-
chmod +x "$DEST"
|
|
198
|
-
else
|
|
199
|
-
download_file "$SCRIPT_REMOTE" "$DEST"
|
|
200
|
-
fi
|
|
201
|
-
echo -e "${GREEN}✓${RESET} Installed: $DEST"
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
# Install token-graph CLI tool
|
|
205
|
-
install_token_graph() {
|
|
206
|
-
echo
|
|
207
|
-
|
|
208
|
-
# Create ~/.local/bin if it doesn't exist
|
|
209
|
-
if [ ! -d "$LOCAL_BIN" ]; then
|
|
210
|
-
echo -e "${YELLOW}Creating $LOCAL_BIN directory...${RESET}"
|
|
211
|
-
mkdir -p "$LOCAL_BIN"
|
|
212
|
-
fi
|
|
213
|
-
|
|
214
|
-
DEST="$LOCAL_BIN/token-graph"
|
|
215
|
-
|
|
216
|
-
if [ -f "$DEST" ]; then
|
|
217
|
-
echo -e "${YELLOW}Warning: $DEST already exists${RESET}"
|
|
218
|
-
if [ "$INTERACTIVE" = true ]; then
|
|
219
|
-
read -p "Overwrite? (y/n) " -n 1 -r
|
|
220
|
-
echo
|
|
221
|
-
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
222
|
-
echo "Keeping existing token-graph."
|
|
223
|
-
return
|
|
224
|
-
fi
|
|
225
|
-
else
|
|
226
|
-
echo "Overwriting in non-interactive mode..."
|
|
227
|
-
fi
|
|
228
|
-
fi
|
|
229
|
-
|
|
230
|
-
# Get commit hash for version embedding
|
|
231
|
-
local commit_hash
|
|
232
|
-
if [ "$INSTALL_MODE" = "local" ]; then
|
|
233
|
-
commit_hash=$(git -C "$SCRIPT_DIR" rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
|
234
|
-
cp "$SCRIPT_DIR/scripts/token-graph.sh" "$DEST"
|
|
235
|
-
else
|
|
236
|
-
commit_hash=$(get_remote_commit_hash)
|
|
237
|
-
download_file "scripts/token-graph.sh" "$DEST"
|
|
238
|
-
fi
|
|
239
|
-
|
|
240
|
-
# Embed version and commit hash
|
|
241
|
-
local pkg_version
|
|
242
|
-
if [ "$INSTALL_MODE" = "local" ]; then
|
|
243
|
-
pkg_version=$(grep -o '"version": *"[^"]*"' "$SCRIPT_DIR/package.json" | head -1 | grep -o '"[^"]*"$' | tr -d '"')
|
|
244
|
-
else
|
|
245
|
-
pkg_version=$(curl -fsSL "${GITHUB_RAW_URL}/package.json" 2>/dev/null | grep -o '"version": *"[^"]*"' | head -1 | grep -o '"[^"]*"$' | tr -d '"')
|
|
246
|
-
fi
|
|
247
|
-
[ -n "$pkg_version" ] && sed -i.bak "s/VERSION=\"[^\"]*\"/VERSION=\"$pkg_version\"/" "$DEST" && rm -f "$DEST.bak"
|
|
248
|
-
sed -i.bak "s/COMMIT_HASH=\"dev\"/COMMIT_HASH=\"$commit_hash\"/" "$DEST" && rm -f "$DEST.bak"
|
|
249
|
-
chmod +x "$DEST"
|
|
250
|
-
echo -e "${GREEN}✓${RESET} Installed: $DEST (v${pkg_version:-1.6.0}-$commit_hash)"
|
|
251
|
-
|
|
252
|
-
# Check if ~/.local/bin is in PATH
|
|
253
|
-
if [[ ":$PATH:" != *":$LOCAL_BIN:"* ]]; then
|
|
254
|
-
echo
|
|
255
|
-
echo -e "${YELLOW}Note: $LOCAL_BIN is not in your PATH${RESET}"
|
|
256
|
-
echo "Add it to your shell configuration:"
|
|
257
|
-
echo
|
|
258
|
-
if [[ "$SHELL" == *"zsh"* ]]; then
|
|
259
|
-
echo " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.zshrc"
|
|
260
|
-
echo " source ~/.zshrc"
|
|
261
|
-
else
|
|
262
|
-
echo " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.bashrc"
|
|
263
|
-
echo " source ~/.bashrc"
|
|
264
|
-
fi
|
|
265
|
-
fi
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
# Create config file with defaults if it doesn't exist
|
|
269
|
-
create_config() {
|
|
270
|
-
CONFIG_FILE="$CLAUDE_DIR/statusline.conf"
|
|
271
|
-
|
|
272
|
-
if [ -f "$CONFIG_FILE" ]; then
|
|
273
|
-
echo -e "${GREEN}✓${RESET} Config file exists: $CONFIG_FILE"
|
|
274
|
-
return
|
|
275
|
-
fi
|
|
276
|
-
|
|
277
|
-
cat >"$CONFIG_FILE" <<'EOF'
|
|
278
|
-
# Autocompact setting - sync with Claude Code's /config
|
|
279
|
-
autocompact=true
|
|
280
|
-
|
|
281
|
-
# Token display format
|
|
282
|
-
token_detail=true
|
|
283
|
-
|
|
284
|
-
# Show token delta since last refresh (adds file I/O on every refresh)
|
|
285
|
-
# Disable if you don't need it to reduce overhead
|
|
286
|
-
show_delta=true
|
|
287
|
-
|
|
288
|
-
# Show session_id in status line
|
|
289
|
-
show_session=true
|
|
290
|
-
EOF
|
|
291
|
-
echo -e "${GREEN}✓${RESET} Created config file: $CONFIG_FILE"
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
# Update settings.json
|
|
295
|
-
update_settings() {
|
|
296
|
-
echo
|
|
297
|
-
|
|
298
|
-
# Create settings file if it doesn't exist
|
|
299
|
-
if [ ! -f "$SETTINGS_FILE" ]; then
|
|
300
|
-
echo '{}' >"$SETTINGS_FILE"
|
|
301
|
-
echo -e "${GREEN}✓${RESET} Created $SETTINGS_FILE"
|
|
302
|
-
fi
|
|
303
|
-
|
|
304
|
-
# Check if jq is available for JSON manipulation
|
|
305
|
-
if command -v jq &>/dev/null; then
|
|
306
|
-
# Backup existing settings
|
|
307
|
-
cp "$SETTINGS_FILE" "$SETTINGS_FILE.backup"
|
|
308
|
-
|
|
309
|
-
# Add/update statusLine configuration
|
|
310
|
-
SCRIPT_PATH="$HOME/.claude/$SCRIPT_NAME"
|
|
311
|
-
jq --arg cmd "$SCRIPT_PATH" '.statusLine = {"type": "command", "command": $cmd}' \
|
|
312
|
-
"$SETTINGS_FILE.backup" >"$SETTINGS_FILE"
|
|
313
|
-
|
|
314
|
-
rm "$SETTINGS_FILE.backup"
|
|
315
|
-
echo -e "${GREEN}✓${RESET} Updated settings.json with statusLine configuration"
|
|
316
|
-
else
|
|
317
|
-
echo -e "${YELLOW}Note: Could not update settings.json (jq not installed)${RESET}"
|
|
318
|
-
echo
|
|
319
|
-
echo "Please add this to $SETTINGS_FILE manually:"
|
|
320
|
-
echo
|
|
321
|
-
echo ' "statusLine": {'
|
|
322
|
-
echo ' "type": "command",'
|
|
323
|
-
echo " \"command\": \"~/.claude/$SCRIPT_NAME\""
|
|
324
|
-
echo ' }'
|
|
325
|
-
fi
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
# Main installation
|
|
329
|
-
main() {
|
|
330
|
-
check_curl
|
|
331
|
-
check_jq
|
|
332
|
-
ensure_claude_dir
|
|
333
|
-
select_script
|
|
334
|
-
install_script
|
|
335
|
-
install_token_graph
|
|
336
|
-
create_config
|
|
337
|
-
update_settings
|
|
338
|
-
|
|
339
|
-
echo
|
|
340
|
-
echo -e "${GREEN}Installation complete!${RESET}"
|
|
341
|
-
echo
|
|
342
|
-
echo "Your status line is now configured."
|
|
343
|
-
echo "Restart Claude Code to see the changes."
|
|
344
|
-
echo
|
|
345
|
-
echo "To customize, edit: $CLAUDE_DIR/$SCRIPT_NAME"
|
|
346
|
-
echo "To change settings, edit: $CLAUDE_DIR/statusline.conf"
|
|
347
|
-
echo
|
|
348
|
-
echo "Run 'token-graph' to visualize token usage for any session."
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
main
|