Skip to content

Commit 1463381

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/powerline-font-detection
# Conflicts: # bun.lock # docs/USAGE.md # src/widgets/CurrentWorkingDir.tsx # src/widgets/CustomCommand.tsx # src/widgets/CustomSymbol.tsx # src/widgets/Link.tsx # src/widgets/Skills.tsx # src/widgets/shared/max-width.tsx # src/widgets/shared/speed-widget.tsx # src/widgets/shared/symbol-override.tsx
2 parents d621a3b + a2c1161 commit 1463381

206 files changed

Lines changed: 22624 additions & 1470 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
3333

3434
# Finder (MacOS) folder config
3535
.DS_Store
36+
__pycache__/
37+
*.pyc
38+
39+
# mutation testing (Stryker)
40+
.stryker-tmp
41+
/reports/

‎AGENTS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ echo '{"model":{"id":"claude-sonnet-4-5-20250929[1m]"},"transcript_path":"test.j
2424
bun run example
2525

2626
# Build for npm distribution
27-
bun run build # Creates dist/ccstatusline.js with Node.js 14+ compatibility
27+
bun run build # Creates dist/ccstatusline.js with Node.js 18+ compatibility
2828

2929
# Run tests
3030
bun test
@@ -135,7 +135,7 @@ Default to using Bun instead of Node.js:
135135
- Applied automatically during `bun install` via `patchedDependencies` in package.json
136136
- Patch file: `patches/[email protected]`
137137
- **Build process**: Two-step build using `bun run build`
138-
1. `bun build`: Bundles src/ccstatusline.ts into dist/ccstatusline.js targeting Node.js 14+
138+
1. `bun build`: Bundles src/ccstatusline.ts into dist/ccstatusline.js targeting Node.js 18+
139139
2. `postbuild`: Runs scripts/replace-version.ts to replace `__PACKAGE_VERSION__` placeholder with actual version from package.json
140140
- **ESLint configuration**: Uses flat config format (eslint.config.js) with TypeScript and React plugins
141141
- **Dependencies**: All runtime dependencies are bundled using `--packages=external` for npm package

‎README.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- [Features](#-features)
3737
- [Localizations](#-localizations)
3838
- [Quick Start](#-quick-start)
39+
- [Non-Interactive CLI (for agents & scripts)](#-non-interactive-cli-for-agents--scripts)
3940
- [Windows Support](docs/WINDOWS.md)
4041
- [Usage](docs/USAGE.md)
4142
- [Development](docs/DEVELOPMENT.md)
@@ -425,6 +426,37 @@ For pinned installs, launch the TUI with `npx -y ccstatusline@latest` or `bunx -
425426

426427
</details>
427428

429+
## 🤖 Non-Interactive CLI (for agents & scripts)
430+
431+
Every TUI setting is also scriptable without launching the interactive UI. All
432+
subcommands operate on the same `settings.json` (honor `--config <path>`),
433+
refuse to modify an unreadable/invalid config, and validate every change
434+
before writing. Errors are single-line; add `--json` to any command for a
435+
machine-readable single-line payload.
436+
437+
```bash
438+
ccstatusline get [--json] # print the effective (post-migration) config
439+
ccstatusline widget add <line> <widget> [--index N] [--option value ...]
440+
ccstatusline widget remove <line> <index-or-type>
441+
ccstatusline widget move <line> <index> --to <index>
442+
ccstatusline set <option-path> <value> # global options; value is JSON or a plain string
443+
ccstatusline validate [--file <path>] # exit 0/1 with a machine-readable report
444+
ccstatusline help
445+
```
446+
447+
Indices are 0-based. `widget add` accepts the widget options the TUI exposes
448+
(`--color`, `--customText`, `--bold`, `--maxWidth`, `--metadata key=value`, …).
449+
450+
`set theme <name>` applies one of the built-in powerline themes (`nord`,
451+
`dracula`, `tokyonight`, …) to regular (non-powerline) mode as foreground
452+
colors only, cycling the theme's segment palette across widgets. Explicit
453+
per-widget colors win; separators are left untouched; `custom` or an unknown
454+
name disables theming.
455+
456+
> **Note:** `get` and `validate` read through the same loader the TUI uses, so
457+
> on a missing `settings.json` they write the default config on that first run
458+
> (the file is never overwritten when it exists but is unreadable or invalid).
459+
428460
## 🤝 Contributing
429461

430462
Contributions are welcome! Please feel free to submit a Pull Request.

‎bun.lock‎

Lines changed: 796 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎client/ccstatusline-ipc‎

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
#!/bin/sh
2+
# ccstatusline IPC client (protocol v1, issue #16).
3+
#
4+
# Reads the Claude Code status JSON from stdin, forwards it to the local
5+
# ccstatusline daemon over its private Unix socket, and prints the rendered
6+
# status line on stdout. All diagnostics go to stderr; on any failure stdout
7+
# stays empty, so a partial or error response can never become a status line.
8+
#
9+
# Shell + curl only: no Node, jq, or Python on the repaint path. The auth
10+
# token reaches curl through its config read from stdin — never argv, a URL,
11+
# or a temp credential file. User curl config, proxy routing, and redirects
12+
# are disabled; connection and total deadlines are explicit.
13+
#
14+
# Environment:
15+
# CCSTATUSLINE_RUNTIME_DIR override the daemon runtime directory
16+
# CCSTATUSLINE_IPC_CONNECT_TIMEOUT seconds to connect (default 2)
17+
# CCSTATUSLINE_IPC_TIMEOUT total seconds (default 10)
18+
# CCSTATUSLINE_DAEMON_START override the lazy-start command (see
19+
# start_daemon below)
20+
# CCSTATUSLINE_NO_AUTOSTART when set, never start a daemon lazily
21+
#
22+
# On-demand lifecycle (#53): this wrapper runs only in installed shared mode
23+
# (`daemon install`), so its lazy start is opt-in by construction — one-shot
24+
# users never execute this file. On a missing daemon it starts one (`daemon
25+
# start`, serialized by the #47 cold-start lock) and retries into it.
26+
#
27+
# Exit status: 0 on a rendered status line, 1 on any failure (stdout empty).
28+
29+
set -u
30+
31+
connect_timeout=${CCSTATUSLINE_IPC_CONNECT_TIMEOUT:-2}
32+
total_timeout=${CCSTATUSLINE_IPC_TIMEOUT:-10}
33+
max_context_bytes=16384
34+
35+
die() {
36+
printf 'ccstatusline-ipc: %s\n' "$1" >&2
37+
exit 1
38+
}
39+
40+
if [ -n "${CCSTATUSLINE_RUNTIME_DIR:-}" ]; then
41+
runtime_dir=$CCSTATUSLINE_RUNTIME_DIR
42+
elif [ -n "${XDG_RUNTIME_DIR:-}" ]; then
43+
runtime_dir=$XDG_RUNTIME_DIR/ccstatusline
44+
else
45+
runtime_dir=${TMPDIR:-/tmp}/ccstatusline-$(id -u)
46+
fi
47+
discovery=$runtime_dir/daemon.env
48+
49+
# Endpoint discovery: flat KEY=VALUE lines written by the daemon. Prefix
50+
# matching keeps values (socket paths may contain '=') intact.
51+
read_discovery() {
52+
protocol=''
53+
socket=''
54+
token=''
55+
[ -r "$discovery" ] || return 1
56+
while IFS= read -r line || [ -n "$line" ]; do
57+
case $line in
58+
'#'*) continue ;;
59+
protocol=*) protocol=${line#protocol=} ;;
60+
socket=*) socket=${line#socket=} ;;
61+
token=*) token=${line#token=} ;;
62+
esac
63+
done < "$discovery"
64+
return 0
65+
}
66+
67+
# Lazy start (#53): run `ccstatusline daemon start` — the #47 cold-start lock
68+
# serializes concurrent starters onto one server, so racing clients each run
69+
# this and converge on the same daemon. Tried at most once per invocation,
70+
# bounded by the starter's own startup timeout. Opt out with
71+
# CCSTATUSLINE_NO_AUTOSTART; override the command with
72+
# CCSTATUSLINE_DAEMON_START (a full command line, split on whitespace).
73+
autostart_attempted=0
74+
start_daemon() {
75+
[ -z "${CCSTATUSLINE_NO_AUTOSTART:-}" ] || return 1
76+
[ "$autostart_attempted" -eq 0 ] || return 1
77+
autostart_attempted=1
78+
if [ -n "${CCSTATUSLINE_DAEMON_START:-}" ]; then
79+
$CCSTATUSLINE_DAEMON_START >/dev/null 2>&1
80+
return $?
81+
fi
82+
# Same install root as this wrapper: the npm package ships
83+
# client/ccstatusline-ipc next to dist/ccstatusline.js (node), a dev
84+
# checkout next to src/ccstatusline.ts (bun).
85+
install_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) || return 1
86+
if [ -f "$install_root/dist/ccstatusline.js" ]; then
87+
node "$install_root/dist/ccstatusline.js" daemon start >/dev/null 2>&1
88+
elif [ -f "$install_root/src/ccstatusline.ts" ]; then
89+
bun "$install_root/src/ccstatusline.ts" daemon start >/dev/null 2>&1
90+
else
91+
return 1
92+
fi
93+
}
94+
95+
if ! read_discovery; then
96+
# No live daemon: start one on demand and re-read what it published.
97+
start_daemon || die "no readable discovery file at $discovery; is the daemon running?"
98+
read_discovery || die "lazy daemon start left no discovery file at $discovery"
99+
fi
100+
101+
[ "$protocol" = "1" ] || die "unsupported daemon protocol '${protocol:-none}'; want 1"
102+
[ -n "$socket" ] || die "discovery file has no socket path"
103+
[ -n "$token" ] || die "discovery file has no auth token"
104+
105+
# Invocation context: base64 over NUL-delimited KEY=VALUE entries. Mirrors
106+
# ENV_ALLOWLIST in src/daemon/protocol.ts — keep the two lists in sync. Only
107+
# set variables are encoded; the server clears its own copy of any allowlisted
108+
# name the client omits, which preserves absent-vs-empty exactly. The NUL
109+
# bytes live only inside the pipeline; base64 output is shell-safe.
110+
context=$(
111+
{
112+
[ -n "${CLAUDE_CONFIG_DIR+x}" ] && printf 'CLAUDE_CONFIG_DIR=%s\0' "$CLAUDE_CONFIG_DIR"
113+
[ -n "${CLAUDE_SECURESTORAGE_CONFIG_DIR+x}" ] && printf 'CLAUDE_SECURESTORAGE_CONFIG_DIR=%s\0' "$CLAUDE_SECURESTORAGE_CONFIG_DIR"
114+
[ -n "${CCSTATUSLINE_CONTEXT_SIZE_FALLBACK+x}" ] && printf 'CCSTATUSLINE_CONTEXT_SIZE_FALLBACK=%s\0' "$CCSTATUSLINE_CONTEXT_SIZE_FALLBACK"
115+
[ -n "${CCSTATUSLINE_WIDTH+x}" ] && printf 'CCSTATUSLINE_WIDTH=%s\0' "$CCSTATUSLINE_WIDTH"
116+
[ -n "${COLUMNS+x}" ] && printf 'COLUMNS=%s\0' "$COLUMNS"
117+
[ -n "${HTTPS_PROXY+x}" ] && printf 'HTTPS_PROXY=%s\0' "$HTTPS_PROXY"
118+
[ -n "${NO_PROXY+x}" ] && printf 'NO_PROXY=%s\0' "$NO_PROXY"
119+
printf 'cwd=%s\0' "$(pwd -P)"
120+
} | base64 | tr -d '\n'
121+
)
122+
123+
[ "${#context}" -le "$max_context_bytes" ] \
124+
|| die "invocation context too large (${#context} > $max_context_bytes bytes)"
125+
126+
# Buffer the piped status JSON once: retry attempts below must re-send the
127+
# same payload, and stdin cannot be rewound. Both temp files hold no secrets
128+
# (payload + rendered line are what the caller piped/asked for); the auth
129+
# token still travels only through the curl config on stdin.
130+
payload_tmp=$(mktemp "${TMPDIR:-/tmp}/ccstatusline-ipc-payload.XXXXXX") || die "cannot buffer stdin"
131+
body_tmp=$(mktemp "${TMPDIR:-/tmp}/ccstatusline-ipc-body.XXXXXX") || { rm -f "$payload_tmp"; die "cannot create temp file"; }
132+
cleanup() { rm -f "$payload_tmp" "$body_tmp"; }
133+
trap cleanup EXIT
134+
# Signal exits must not resume the retry loop (a handler without exit would
135+
# return into the backoff sleep); the EXIT trap still removes the temp files.
136+
trap 'exit 129' HUP
137+
trap 'exit 130' INT
138+
trap 'exit 143' TERM
139+
cat > "$payload_tmp"
140+
141+
attempt=0
142+
while :; do
143+
code=$(curl -q -sS --fail \
144+
--unix-socket "$socket" \
145+
--config - \
146+
--data-binary @"$payload_tmp" \
147+
-o "$body_tmp" \
148+
-w '%{http_code}' \
149+
-H 'Content-Type: application/json' \
150+
--noproxy '*' \
151+
--connect-timeout "$connect_timeout" \
152+
--max-time "$total_timeout" \
153+
'http://localhost/v1/render' \
154+
<<CONFIG
155+
header = "Authorization: Bearer $token"
156+
header = "X-CCStatusLine-Context: $context"
157+
CONFIG
158+
)
159+
curl_rc=$?
160+
[ "$curl_rc" -eq 0 ] && break
161+
# Connect failure (curl exit 7): the daemon died after discovery was
162+
# read. Transparently lazy-start a fresh one and retry into it — the
163+
# autostart guard inside start_daemon bounds this to one restart.
164+
if [ "$curl_rc" -eq 7 ]; then
165+
if start_daemon && read_discovery && [ "$protocol" = "1" ]; then
166+
continue
167+
fi
168+
fi
169+
attempt=$((attempt + 1))
170+
# 503 busy: the render queue is momentarily full (a burst of repaints
171+
# across sessions). Back off on a growing ladder — 8s total budget — so
172+
# even a cold burst of dozens of large renders waits out the queue, the
173+
# same thing the next Claude Code repaint tick would do. Any other
174+
# failure (dead daemon, bad request, render error) fails fast so stdout
175+
# stays empty.
176+
if [ "$curl_rc" -eq 22 ] && [ "$code" = "503" ] && [ "$attempt" -lt 14 ]; then
177+
case $attempt in
178+
1 | 2) sleep 0.05 ;;
179+
3 | 4) sleep 0.1 ;;
180+
5 | 6) sleep 0.25 ;;
181+
7 | 8) sleep 0.5 ;;
182+
*) sleep 1 ;;
183+
esac
184+
continue
185+
fi
186+
die "daemon request failed (curl exit $curl_rc)"
187+
done
188+
189+
# An empty 200 body is a successful "nothing to render" answer — it matches
190+
# piped mode, which prints nothing. Report success with no output rather than
191+
# falling off the end with the failed [ -n test as the exit status.
192+
body=$(cat "$body_tmp")
193+
if [ -n "$body" ]; then
194+
printf '%s\n' "$body"
195+
fi
196+
exit 0

‎docs/DEVELOPMENT.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ If you want the main project overview, return to [README.md](../README.md).
88

99
- [Bun](https://bun.sh) (v1.0+)
1010
- Git
11-
- Node.js 14+ (optional, for running the built `dist/ccstatusline.js` binary or npm publishing)
11+
- Node.js 18+ (optional, for running the built `dist/ccstatusline.js` binary or npm publishing)
1212

1313
## Setup
1414

@@ -125,7 +125,7 @@ Update checks and global package installs both validate release-version strings
125125
## Build Notes
126126

127127
- The entry point imports the TUI lazily for interactive mode; keep the Ink initialization path out of piped rendering. The distribution build uses code splitting, so ship the complete `dist/` directory.
128-
- Build target is Node.js 14+ (`dist/ccstatusline.js`)
128+
- Build target is Node.js 18+ (`dist/ccstatusline.js`); Bun's bundler does not lower modern syntax, so older Node versions reject the bundle (`??=` needs Node 15+, bundled deps need `Array.prototype.at`, Node 16.6+). Node 14 (EOL since 2023) is not supported. See [performance-397-verification.md](performance-397-verification.md) for the measured floor
129129
- `postbuild` replaces the bundled `__PACKAGE_VERSION__` placeholder from `package.json`; `ccstatusline --version` reads that value and exits before mode detection
130130
- During install, `[email protected]` is patched to fix backspace handling on macOS terminals
131131
- React and React DOM are exact-version pins; dependency refreshes should update `package.json` and `bun.lock` together

0 commit comments

Comments
 (0)