portable-agent-layer 0.54.2 → 0.54.3

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.
@@ -9,6 +9,27 @@ $USED_RAW = $data.context_window.used_percentage
9
9
  $USED = if ($USED_RAW -ne $null) { [int]$USED_RAW } else { 0 }
10
10
  $REM_RAW = $data.context_window.remaining_percentage
11
11
  $REM = if ($REM_RAW -ne $null) { [int]$REM_RAW } else { 0 }
12
+ $TOTAL_INPUT = $data.context_window.total_input_tokens
13
+ $WINDOW_SIZE = $data.context_window.context_window_size
14
+
15
+ # Honor CLAUDE_CODE_AUTO_COMPACT_WINDOW: Claude's used_percentage is measured
16
+ # against the full model window, but auto-compact triggers at this token cap -
17
+ # so recompute usage against the effective (capped) window when it is set.
18
+ # Gated on CLAUDECODE (injected only by Claude Code) - the cap is a user shell
19
+ # export that would otherwise leak into Cursor, which does not auto-compact.
20
+ $autoCompact = $env:CLAUDE_CODE_AUTO_COMPACT_WINDOW
21
+ if ($env:CLAUDECODE -and $autoCompact -and ($autoCompact -as [int]) -gt 0) {
22
+ $effectiveWindow = [int]$autoCompact
23
+ if (($WINDOW_SIZE -ne $null) -and ($effectiveWindow -gt [int]$WINDOW_SIZE)) { $effectiveWindow = [int]$WINDOW_SIZE }
24
+ $usedTokens = $null
25
+ if ($TOTAL_INPUT -ne $null) { $usedTokens = [int]$TOTAL_INPUT }
26
+ elseif (($WINDOW_SIZE -ne $null) -and ($USED_RAW -ne $null)) { $usedTokens = [int]([int]$USED_RAW * [int]$WINDOW_SIZE / 100) }
27
+ if ($usedTokens -ne $null) {
28
+ $USED = [int]($usedTokens * 100 / $effectiveWindow)
29
+ if ($USED -gt 100) { $USED = 100 }
30
+ $REM = 100 - $USED
31
+ }
32
+ }
12
33
  $COST_RAW = $data.cost.total_cost_usd
13
34
  $COST = if ($COST_RAW -ne $null) { [double]$COST_RAW } else { 0 }
14
35
  $CWD = if ($data.workspace.current_dir) { $data.workspace.current_dir } else { "~" }
@@ -15,6 +15,8 @@ USED_RAW=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
15
15
  REM_RAW=$(echo "$input" | jq -r '.context_window.remaining_percentage // empty')
16
16
  USED=$( [ -n "$USED_RAW" ] && echo "${USED_RAW%.*}" || echo 0 )
17
17
  REMAINING=$( [ -n "$REM_RAW" ] && echo "${REM_RAW%.*}" || echo 0 )
18
+ TOTAL_INPUT=$(echo "$input" | jq -r '.context_window.total_input_tokens // empty')
19
+ WINDOW_SIZE=$(echo "$input" | jq -r '.context_window.context_window_size // empty')
18
20
  CWD=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // "~"')
19
21
  REPO=$(echo "$input" | jq -r '.workspace.repo.name // ""')
20
22
 
@@ -24,6 +26,27 @@ if [ -z "$USED_RAW" ] && [ -z "$REM_RAW" ]; then
24
26
  REMAINING=100
25
27
  fi
26
28
 
29
+ # Honor CLAUDE_CODE_AUTO_COMPACT_WINDOW: Claude's used_percentage is measured
30
+ # against the full model window, but auto-compact triggers at this token cap —
31
+ # so recompute usage against the effective (capped) window when it is set.
32
+ # Gated on CLAUDECODE (injected only by Claude Code) — the cap is a user shell
33
+ # export that would otherwise leak into Cursor, which does not auto-compact.
34
+ if [ -n "$CLAUDECODE" ] && [ -n "$CLAUDE_CODE_AUTO_COMPACT_WINDOW" ] && [ "$CLAUDE_CODE_AUTO_COMPACT_WINDOW" -gt 0 ] 2>/dev/null; then
35
+ EFFECTIVE_WINDOW=$CLAUDE_CODE_AUTO_COMPACT_WINDOW
36
+ if [ -n "$WINDOW_SIZE" ] && [ "$EFFECTIVE_WINDOW" -gt "$WINDOW_SIZE" ] 2>/dev/null; then
37
+ EFFECTIVE_WINDOW=$WINDOW_SIZE
38
+ fi
39
+ USED_TOKENS="$TOTAL_INPUT"
40
+ if [ -z "$USED_TOKENS" ] && [ -n "$WINDOW_SIZE" ] && [ -n "$USED_RAW" ]; then
41
+ USED_TOKENS=$(( ${USED_RAW%.*} * WINDOW_SIZE / 100 ))
42
+ fi
43
+ if [ -n "$USED_TOKENS" ]; then
44
+ USED=$(( USED_TOKENS * 100 / EFFECTIVE_WINDOW ))
45
+ [ "$USED" -gt 100 ] && USED=100
46
+ REMAINING=$(( 100 - USED ))
47
+ fi
48
+ fi
49
+
27
50
  # Git branch — payload first, then git in cwd
28
51
  BRANCH=$(echo "$input" | jq -r '.worktree.branch // .worktree.name // ""')
29
52
  if [ -z "$BRANCH" ] || [ "$BRANCH" = "null" ]; then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "portable-agent-layer",
3
- "version": "0.54.2",
3
+ "version": "0.54.3",
4
4
  "description": "PAL — Portable Agent Layer: persistent personal context for AI coding assistants",
5
5
  "type": "module",
6
6
  "bin": {