Skip to content

Add cross-terminal attention handling for program status - #756

Merged
dakra merged 3 commits into
mainfrom
feat/status-attention
Oct 29, 2026
Merged

dakra merged 3 commits into
mainfrom
feat/status-attention

Conversation

@dakra

@dakra dakra commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Addresses #753.

A terminal counts as needing attention while it holds a record in a state of ghostel-status-notify-states (default blocked, done, error), ranked blocked > error > done. ghostel-status-buffer-state returns a terminal's most urgent such state and ghostel-status-buffers lists the attention terminals most urgent first; both are public so a list buffer like the one in the issue can be built outside the repo.

On top of that:

  • ghostel-status-next switches to the most urgent attention terminal and walks the rest on repeat, with a "Next Needing Attention" menu entry.
  • ghostel-status-indicator-mode (global, opt-in) counts the attention terminals per state in global-mode-string, e.g. [blocked: permission ×2] [done], names them on hover, and a click runs ghostel-status-next. The mode requires ghostel when enabled so it can be turned on from init before any terminal exists.
  • ghostel-annotate-buffer shows the terminal's status label before its title, so every picker (read-buffer, consult, marginalia) shows it.
  • consult-ghostel gains consult-ghostel-status and a hidden "Needs attention" source that consult-ghostel-mode registers in consult-buffer under the a narrow key, following the pattern of the hidden Ghostel source so terminals do not appear twice.

Acknowledging: ghostel-status-acknowledge-on-input (t/nil) is replaced by ghostel-status-auto-acknowledge with the values input (default, as before), seen and nil, without an alias. seen drops done and error records as soon as the terminal is the buffer being looked at, either when such a record arrives or when the buffer becomes looked at. M-x ghostel-status-acknowledge drops them by hand. "Looked at" is ghostel--buffer-focused-p, the same predicate that already suppresses notifications; it now also treats a frame whose focus Emacs cannot tell (a tty without focus reporting) as focused, so seen and notification suppression work there. Killing a terminal drops its records so nothing counts it afterwards.

Labels: ghostel-status-mode-line-labels also takes the blocked kinds permission, question and auth as keys; a kind entry replaces the state label and the appended kind text, so an icon can stand for each case. ghostel-status-mode-line-format (default " [%l%x]") frames every label, a format-spec string with %l label, %n count, %c count only when several and %x ×N only when several; " %l%n" with icons gives 🔒2 ✅1. The indicator counts terminals per distinct label, so different kinds get their own label and kinds sharing an icon merge.

All of the status code stays in lisp/ghostel-status.el; ghostel.el only gained the input, focus-change, kill-buffer and annotation call sites.

Tests: elisp tests for the ranking, the cycling order, the indicator text, the annotation, all three acknowledge modes, the kill-buffer cleanup and the unknown-focus predicate, plus the consult source items. Verified live under elate on a tty Emacs 32 where frame-focus-state is unknown: indicator text and hover, cycling, acknowledge modes, annotation, and enabling the indicator mode from init with only the autoloads loaded.

@vjohansen

Copy link
Copy Markdown
Contributor

Looks good. I can see you fixed some details: input acknowledges in seen mode, killing terminal clears it records, etc.

I named the option ghostel-status-auto-acknowledge to avoid a variable and a function with the same name.

I liked the indicator in my version better. Two issues:

  1. ghostel-status-mode-line-labels should cover all the cases. The state/kind split is a implementation detail that matters little to the user. In practice I found it important tell apart the distinct cases (blocked, permission, auth, question, error, done) with an icon.

  2. Text vs icon: in the mode line text takes up a lot of space: [blocked: permission ×2] [done] vs 🔒2 ✅1. In ghostel-status-mode-line-labels can hold icons, but the kind is still appended as text ([✋: permission ×2]). Consider an option to choose between text and icons: ghostel-status-mode-line-labels and ghostel-status-mode-line-icons

From #753 (comment)

I'm also not necessarily against adding something like
ghostel-status-list to this repo, but I would say one step at a time

I agree. It requires using it a bit to understand the issues and polish the implementaion. I found the 6 icons important because it primes you to what the "blocker" is. When I then switch to the buffer via ghostel-status-next there is some disorientation to figure out the context. Half the time I use ghostel-status-list so I can see where I am going. With wezterm I did not have the latter problem because I started tabs in specific positions and switched with Control+number.

The new "AI terminals" (herdr, orca, tuios, etc) fixes this by always showing the running agents in a window. I will probably have to experiment with showing status-list in a dedicated window (and make some support for narrow windows).

I will also try out your consult support

@dakra
dakra force-pushed the feat/status-attention branch 3 times, most recently from 937203f to 751c388 Compare October 27, 2026 08:38
@vjohansen

Copy link
Copy Markdown
Contributor

I tested consult-ghostel-status

In consult-ghostel-marginalia-annotate If I replace

          (propertize annotation 'face 'marginalia-value)

with

         (add-face-text-property 0 (length annotation)
           'marginalia-value t annotation)
          annotation)

the status color for done/busy/error/etc is preserved ( it appends the property)

@dakra

dakra commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

@vjohansen thanks for the feedback. I have tested many versions over the last few days and I'm still not 100% sure.
Especially what should show on the buffer local modeline and global mode-line.
But I'm thinking of merging this PR already anyway as I think it's an improvement over the main branch.

To your valuable feedback:

I named the option ghostel-status-auto-acknowledge [..]

Agreed, renamed.

  1. ghostel-status-mode-line-labels should cover all the cases. The state/kind split is a implementation detail [...]

I think you already saw how I changed it. You can now customize kind as well, and with the emojis it's even default

  1. Text vs icon [...]

Also agree, but the problem is that I do not want people reporting bugs because there font can't display the emojis (or displays them in an ugly fallback font).
But I agree that 95% of the users would prefer the short emojis over the words.
My clanker found char-displayable-p, so now I test if the user can display the emoji first and if so I choose emojis as default. This should cover 99% of the cases imho and the rest have to manually customize the labels.

In consult-ghostel-marginalia-annotate If I replace [...]

Fixed, thanks.


Do you want to have another check if what's now in this branch is already good enough for you (and you can build your status-list on top of this)?
I would say it's still not final and we can discuss more features/changes on your main issue #753

@dakra
dakra force-pushed the feat/status-attention branch from 0ed8fdd to 61b2a95 Compare October 28, 2026 16:47
@vjohansen

Copy link
Copy Markdown
Contributor

I have been rebasing (several times) my status-list commit etc on your feat/status-attention branch the last two days. It has been working without issue.

I can see you just pushed 4 commits. I will do further testing of this new code.

I can certainly understand your emoji argument. Just last month I had to debug why emojis where not showing correctly on one my windows machines. I had to fiddle with w32-non-USB-fonts and set-fontset-font t 'emoji … to get it working. On the positive side Emacs 31 added support for color font/emojis on Windows.

dakra added 3 commits October 28, 2026 22:18
Terminals holding a record in ghostel-status-notify-states count as
needing attention, ranked blocked > error > done.  ghostel-status-next
cycles through them, and ghostel-status-buffers and
ghostel-status-buffer-state expose the ranking to other packages, with
an optional list of states.  Buffer pickers show the terminal's status
in their annotation and consult-ghostel gains a "Needs attention"
source and command.

ghostel-status-indicator-mode counts terminals per state in
global-mode-string, the states in ghostel-status-indicator-states, by
default the attention states plus working, so the mode line also shows
which terminals still run.  A terminal stands by its root record when
that holds the state, else by the newest record that does, so a
child's percentage does not replace the terminal's own label.

ghostel-status-acknowledge-on-input becomes
ghostel-status-auto-acknowledge with the values input, seen and nil;
seen drops done and error records as soon as the terminal is the
buffer being looked at.  A tty frame without focus reporting now counts
as focused for that check and for notification suppression.  Killing a
terminal drops its records so nothing counts it afterwards.

ghostel-status-mode-line-format frames every status label, a
format-spec string with the label and three count specs, and
ghostel-status-mode-line-labels takes the blocked kinds as keys so an
icon can stand for each; the indicator counts terminals per distinct
label.  The default working label reads working instead of ..., which
only made sense next to the spinner.

Addresses #753.
A program speaking OSC 7501 often also sends a desktop notification
for the same event, so the permission prompt of Claude Code notified
twice.  While a terminal's program reports its status, OSC 9 and
OSC 777 no longer run `ghostel-notification-functions'; the status
changes run it through `ghostel-status-notify' instead.  A root
`clear', a new prompt, the process exit or RIS end the gate, which
also re-arms OSC 9;4 progress at those points.  The gate resets in
ghostel-status--clear for the root, so the OSC clear handler, buffer
kill and terminal restart share it.  Without shell integration a
program exiting without clear leaves it on until the shell exits.

`ghostel-status-attention-p' is the condition `ghostel-status-notify'
applies, public for members of `ghostel-program-status-functions'
that notify with more than title and text.
The terminal's mode line listed the blocked and error records, newest
first, or else the root.  It now shows one label per distinct label
among all records, most urgent first, counted when several read the
same, so it agrees with the global indicator and the picker annotation,
which build their text through the same grouping helper.  The spinner
runs only while the root is the sole record.

ghostel-status-mode-line-labels is now `emoji', `words', or an alist of
format-spec strings that carry their own frame and count spec (%p, %k,
%n, %c, %x).  The emoji preset falls back to the word labels when the
selected frame cannot display them.  The separate
ghostel-status-mode-line-format option is gone; each label carries its
own leading space.

ghostel-status-buffers ranks each buffer once, the input acknowledge
wrapper is inlined at its only call, and the README rows for the
indicator, notify states and notification hook describe what they do.
@dakra
dakra force-pushed the feat/status-attention branch from 61b2a95 to 8b3c008 Compare October 28, 2026 21:23
@dakra
dakra merged commit 8b3c008 into main Oct 29, 2026
33 checks passed
@dakra
dakra deleted the feat/status-attention branch October 29, 2026 08:39

This branch was previously deployed

1 inactive deployment
github-pages — 8b3c0084 Deployed Oct 29, 2026 by dakra via deploy #237
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants