@umang-boss/claudemon 1.5.0 → 1.5.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umang-boss/claudemon",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Pokemon coding companion for Claude Code — Gotta code 'em all!",
5
5
  "type": "module",
6
6
  "main": "dist/server.mjs",
@@ -26,20 +26,29 @@ fi
26
26
  CC_MODEL="" CC_CONTEXT=""
27
27
  if [ -n "$STDIN_DATA" ]; then
28
28
  CC_MODEL=$(echo "$STDIN_DATA" | jq -r '.model.display_name // empty' 2>/dev/null)
29
+ MODEL_ID=$(echo "$STDIN_DATA" | jq -r '.model.id // empty' 2>/dev/null)
29
30
 
30
- # Context memory: count conversation messages from transcript
31
+ # Max context tokens based on model
32
+ MAX_TOKENS=200000
33
+ echo "$MODEL_ID" | grep -qi "\[1m\]" && MAX_TOKENS=1000000
34
+
35
+ # Read actual token usage from transcript JSONL
31
36
  TRANSCRIPT=$(echo "$STDIN_DATA" | jq -r '.transcript_path // empty' 2>/dev/null)
32
37
  if [ -n "$TRANSCRIPT" ] && [ -f "$TRANSCRIPT" ]; then
33
- # Count message objects in transcript as a rough context indicator
34
- MSG_COUNT=$(jq '[.[] | select(.type == "message" or .type == "human" or .type == "assistant")] | length' "$TRANSCRIPT" 2>/dev/null || echo 0)
35
- # Rough estimate: ~50 messages fills a 200K context window
36
- # (each message averages ~4K tokens including tool calls)
37
- MAX_MSGS=50
38
- if [ "$MSG_COUNT" -gt 0 ]; then
39
- USED_PCT=$(( (MSG_COUNT * 100) / MAX_MSGS ))
38
+ # Last message's input+cache tokens = current context size
39
+ CONTEXT_TOKENS=$(tail -20 "$TRANSCRIPT" 2>/dev/null | jq -r 'select(.message.usage) | .message.usage | ((.input_tokens // 0) + (.cache_read_input_tokens // 0) + (.cache_creation_input_tokens // 0))' 2>/dev/null | tail -1)
40
+
41
+ if [ -n "$CONTEXT_TOKENS" ] && [ "$CONTEXT_TOKENS" != "0" ] && [ "$CONTEXT_TOKENS" != "null" ]; then
42
+ USED_PCT=$(( (CONTEXT_TOKENS * 100) / MAX_TOKENS ))
40
43
  [ "$USED_PCT" -gt 100 ] && USED_PCT=100
41
- LEFT_PCT=$(( 100 - USED_PCT ))
42
- CC_CONTEXT="${LEFT_PCT}% context"
44
+
45
+ # Format: 258K/1M (26%)
46
+ if [ "$MAX_TOKENS" -ge 1000000 ]; then
47
+ TOKEN_DISPLAY="$(awk "BEGIN{printf \"%.0fK/%.0fM\", ${CONTEXT_TOKENS}/1000, ${MAX_TOKENS}/1000000}")"
48
+ else
49
+ TOKEN_DISPLAY="$(awk "BEGIN{printf \"%.0fK/%.0fK\", ${CONTEXT_TOKENS}/1000, ${MAX_TOKENS}/1000}")"
50
+ fi
51
+ CC_CONTEXT="${TOKEN_DISPLAY} (${USED_PCT}%)"
43
52
  fi
44
53
  fi
45
54
  fi