@inbrace-tech/tokenline 1.5.0 → 1.5.2
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 +1 -1
- package/package.json +1 -1
- package/tokenline.sh +29 -9
package/README.md
CHANGED
|
@@ -192,7 +192,7 @@ Other commands: `update` (replace the installed script, see [Updating](#updating
|
|
|
192
192
|
|
|
193
193
|
## How it works
|
|
194
194
|
|
|
195
|
-
On every refresh the host CLI pipes a JSON snapshot of the session to the script over stdin. `tokenline` parses it in a single `jq` pass (to keep the per-second refresh cheap), reads the last turn's timestamp from the transcript to drive the cache countdown, and renders up to three lines. Per-turn timestamps (and, for subagent rows, each subagent's last-turn time, TTL and last tool name) are cached in a per-user `0700` directory under `$XDG_RUNTIME_DIR` (tmpfs, cleared on logout); the payload itself never touches disk.
|
|
195
|
+
On every refresh the host CLI pipes a JSON snapshot of the session to the script over stdin. `tokenline` parses it in a single `jq` pass (to keep the per-second refresh cheap), reads the last turn's timestamp from the transcript to drive the cache countdown, and renders up to three lines. Per-turn timestamps (and, for subagent rows, each subagent's last-turn time, TTL and last tool name) are cached in a per-user `0700` directory under `$XDG_RUNTIME_DIR` (tmpfs, cleared on logout), or under `$TMPDIR` / `/tmp` when that is unset or doesn't exist (WSL2 without systemd, containers, macOS); the payload itself never touches disk.
|
|
196
196
|
|
|
197
197
|
## Troubleshooting
|
|
198
198
|
|
package/package.json
CHANGED
package/tokenline.sh
CHANGED
|
@@ -91,11 +91,28 @@ file_mtime() {
|
|
|
91
91
|
# Per-turn timestamp / TTL are cached between the 1s refreshes. Prefer a
|
|
92
92
|
# per-user dir (0700) under XDG_RUNTIME_DIR: it avoids predictable, world-
|
|
93
93
|
# readable paths in shared /tmp (and the symlink/collision risks they carry),
|
|
94
|
-
# and is tmpfs cleared on logout — so no orphan-file cleanup is needed.
|
|
95
|
-
#
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
# and is tmpfs cleared on logout — so no orphan-file cleanup is needed.
|
|
95
|
+
# XDG_RUNTIME_DIR can be unset, or set to a dir that doesn't exist (WSL2
|
|
96
|
+
# without systemd, containers, su/sudo shells), so the candidates are tried in
|
|
97
|
+
# order: $XDG_RUNTIME_DIR/tokenline-<uid> when that parent is a dir we own, then
|
|
98
|
+
# ${TMPDIR:-/tmp}/tokenline-<uid>. Bare /tmp is the last resort, and every
|
|
99
|
+
# feature that needs a private dir (update notice, subagent state) stays off there.
|
|
100
|
+
_use_runtime_dir() {
|
|
101
|
+
# Accepts $1 only as a real directory (not a symlink) owned by this user,
|
|
102
|
+
# creating it 0700 when missing. No -p: the parent must already exist.
|
|
103
|
+
local d="$1"
|
|
104
|
+
[ -d "$d" ] || mkdir -m 700 "$d" 2>/dev/null
|
|
105
|
+
[ -d "$d" ] && [ ! -L "$d" ] && [ -O "$d" ] || return 1
|
|
106
|
+
chmod 700 "$d" 2>/dev/null
|
|
107
|
+
_runtime_dir="$d"
|
|
108
|
+
}
|
|
109
|
+
_runtime_dir="/tmp"
|
|
110
|
+
_uid="${UID:-$(id -u)}"
|
|
111
|
+
if ! { [ -n "${XDG_RUNTIME_DIR:-}" ] && [ -d "$XDG_RUNTIME_DIR" ] && [ -O "$XDG_RUNTIME_DIR" ] \
|
|
112
|
+
&& _use_runtime_dir "${XDG_RUNTIME_DIR%/}/tokenline-$_uid"; }; then
|
|
113
|
+
_tmp_base="${TMPDIR:-/tmp}"
|
|
114
|
+
_use_runtime_dir "${_tmp_base%/}/tokenline-$_uid"
|
|
115
|
+
fi
|
|
99
116
|
|
|
100
117
|
# --- 1. Parse JSON Standard Input and Prepare State Variables ---
|
|
101
118
|
parse_and_prepare_paths() {
|
|
@@ -871,9 +888,9 @@ render_subagent_rows() {
|
|
|
871
888
|
# the rows line up under each other.
|
|
872
889
|
local -a ids types glyphs models efforts elapsed ctx cache activity descs
|
|
873
890
|
local w_type=0 w_model=0 w_effort=0 w_elapsed=0 w_ctx=0 w_cache=0 w_act=0
|
|
874
|
-
local line id name type status desc start_ms tokens window model effort aid
|
|
891
|
+
local line id name type status desc start_ms tokens window model effort agent_type aid
|
|
875
892
|
for line in "${rows[@]}"; do
|
|
876
|
-
IFS="$_sa_sep" read -r id name type status desc start_ms tokens window model effort <<< "$line"
|
|
893
|
+
IFS="$_sa_sep" read -r id name type status desc start_ms tokens window model effort agent_type <<< "$line"
|
|
877
894
|
[ -z "$id" ] && continue
|
|
878
895
|
|
|
879
896
|
aid="${id#agent-}"
|
|
@@ -886,7 +903,10 @@ render_subagent_rows() {
|
|
|
886
903
|
# cache still matters — show it as running (activity, blinking COLD).
|
|
887
904
|
[ "$sa_mode" = "waiting-bg" ] && status="running"
|
|
888
905
|
|
|
889
|
-
|
|
906
|
+
# `type` is the task kind (always "local_agent" for a subagent); the
|
|
907
|
+
# subagent's own type ("Explore", "code-reviewer") is `agentType`, which
|
|
908
|
+
# only newer Claude Code versions send. Fall back to name, then kind.
|
|
909
|
+
local t="${agent_type:-${name:-$type}}"
|
|
890
910
|
t=$(fit "${t:-agent}" 24)
|
|
891
911
|
|
|
892
912
|
# A finished subagent's clock stops at its last turn, not at "now".
|
|
@@ -1012,7 +1032,7 @@ maybe_render_subagents() {
|
|
|
1012
1032
|
| [ (.id // ""), (.name // ""), (.type // ""), (.status // ""),
|
|
1013
1033
|
(.description // .label // ""), (.startTime // 0),
|
|
1014
1034
|
(.tokenCount // 0), (.contextWindowSize // 0),
|
|
1015
|
-
(.model // ""), (.effort // "") ]
|
|
1035
|
+
(.model // ""), (.effort // ""), (.agentType // "") ]
|
|
1016
1036
|
| map(clean) | join("\u001f"))
|
|
1017
1037
|
else empty end' 2>/dev/null)
|
|
1018
1038
|
[[ "$extracted" == subagents* ]] || return 1
|