Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A soft fork of [[https://github.com/xenodium/agent-shell][agent-shell]] with ext
- Per-shell debug logging infrastructure ([[https://github.com/timvisher-dd/agent-shell-plus/pull/2][#2]])
- Regression tests for shell buffer selection ordering ([[https://github.com/timvisher-dd/agent-shell-plus/pull/3][#3]])
- CI check that README.org is updated when code changes ([[https://github.com/timvisher-dd/agent-shell-plus/pull/4][#4]])
- Usage tests and defense against ACP =used > size= bug ([[https://github.com/timvisher-dd/agent-shell-plus/pull/5][#5]])

-----

Expand Down
55 changes: 30 additions & 25 deletions agent-shell-usage.el
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ When MULTILINE is non-nil, format as right-aligned labeled rows."
(if (> (or (map-elt usage :context-size) 0) 0)
(agent-shell--format-number-compact (or (map-elt usage :context-size) 0))
"?")
(if (and (map-elt usage :context-size)
(> (map-elt usage :context-size) 0))
(format " (%.1f%%)" (* 100.0 (/ (float (or (map-elt usage :context-used) 0))
(map-elt usage :context-size))))
"")))
(let ((used (or (map-elt usage :context-used) 0))
(size (or (map-elt usage :context-size) 0)))
(cond
((< size used) " (?)")
((< 0 size) (format " (%.1f%%)" (* 100.0 (/ (float used) size))))
(t "")))))
(total
(let ((n (or (map-elt usage :total-tokens) 0)))
(if (> n 0)
Expand Down Expand Up @@ -201,26 +202,30 @@ Only returns an indicator if enabled and usage data is available."
(context-used (map-elt usage :context-used))
(context-size (map-elt usage :context-size))
((> context-size 0)))
(let* ((percentage (/ (* 100.0 context-used) context-size))
;; Unicode vertical block characters from empty to full
(indicator (cond
((>= percentage 100) "█") ; Full
((>= percentage 87.5) "▇")
((>= percentage 75) "▆")
((>= percentage 62.5) "▅")
((>= percentage 50) "▄")
((>= percentage 37.5) "▃")
((>= percentage 25) "▂")
((> percentage 0) "▁")
(t nil))) ; Return nil for no usage
(face (cond
((>= percentage 85) 'error) ; Red for critical
((>= percentage 60) 'warning) ; Yellow/orange for warning
(t 'success)))) ; Green for normal
(when indicator
(propertize indicator
'face face
'help-echo (agent-shell--format-usage usage))))))
(if (< context-size context-used)
(propertize "?"
'face 'warning
'help-echo (agent-shell--format-usage usage))
(let* ((percentage (/ (* 100.0 context-used) context-size))
;; Unicode vertical block characters from empty to full
(indicator (cond
((>= percentage 100) "█") ; Full
((>= percentage 87.5) "▇")
((>= percentage 75) "▆")
((>= percentage 62.5) "▅")
((>= percentage 50) "▄")
((>= percentage 37.5) "▃")
((>= percentage 25) "▂")
((> percentage 0) "▁")
(t nil))) ; Return nil for no usage
(face (cond
((>= percentage 85) 'error) ; Red for critical
((>= percentage 60) 'warning) ; Yellow/orange for warning
(t 'success)))) ; Green for normal
(when indicator
(propertize indicator
'face face
'help-echo (agent-shell--format-usage usage)))))))

(provide 'agent-shell-usage)
;;; agent-shell-usage.el ends here
Loading
Loading