Four agents reviewed this in parallel -- correctness, GNOME integration, edge cases, security. Everything below was reproduced before being fixed; several findings that survived the first reading did not survive a probe and are not here. State machine, the two that mattered most. A pending permission prompt was erased by any subagent bookkeeping event: SubagentStop or the next PreToolUse recomputed the state from scratch, so a session sat at "working" with a dialog open and nothing ever raised it again. Blocked now outlives everything except evidence the question was answered. Separately, the stale-event guard refused whole events, including the subagent counter's increments and decrements -- but those are deltas and deltas commute, so a "+1" that lost a timestamp race left the count short and the batch freed the session while a subagent was still running. The guard now gates the state decision only. Corrupt or hostile state files could wedge the panel or take the hook down for every session: a non-numeric pid raised inside sweep_dead before the hook wrote its own file, so one bad byte stopped new sessions appearing at all. Numbers read back from disk are coerced, one unreadable file no longer aborts the sweep, and a stored timestamp far in the future -- corruption, or a clock stepped backwards by NTP -- no longer refuses every later event forever. Resource bounds, all in the compositor process. A state file was read whole with no size check: a symlink to /dev/zero took a test process past 4 GB in three seconds, which in gnome-shell ends the session. Sizes are checked before the read, sessions and zellij subprocesses are capped, labels ellipsize, and cwd and messages are truncated at the hook. Teardown hung off an overridden destroy(), which only runs when JS calls it. An actor destroyed any other way -- another extension rebuilding the panel boxes -- left the timer and the file monitor running against a disposed actor. It is a destroy signal now. The zellij child is killed rather than merely abandoned. The glyph was pinned to physical pixels and rendered half-size on HiDPI; size comes from the stylesheet, and the foreground colour is normalised by inspection rather than assuming which colour struct the shell hands back. Chip labels: non-Latin names all collapsed to "?", because the split treated every Cyrillic letter as a separator -- notable for a tool whose own README is Russian. Seniority also ranked by time-in-state rather than session age, so after a shell restart the older session could take the digit; the hook now records when the session began. zellij: a dump ends with new_tab_template and swap_tiled_layout blocks whose tab lines carry no name, and their panes were being attached to the last real tab -- which then answered for every unmatched directory, confidently and wrongly. install.py no longer widens the mode of a settings.json someone narrowed to 0600, no longer overwrites the pristine .bak on a second run, no longer replaces a symlink out of a dotfiles repository with a regular file, and quotes the hook path. The debug log is capped and README now says plainly that it records prompts verbatim. Not fixed, deliberately: the panel does push the clock about 70 px left with three labelled chips, which is inherent to putting them in the centre box; two different projects abbreviating alike still read as one project with a digit; GNOME 48 remains unverified for the colour struct and for St.BoxLayout's vertical property, both flagged rather than guessed at.
127 lines
5.2 KiB
JavaScript
127 lines
5.2 KiB
JavaScript
import Adw from 'gi://Adw';
|
|
import Gtk from 'gi://Gtk';
|
|
import Gio from 'gi://Gio';
|
|
import GLib from 'gi://GLib';
|
|
|
|
import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
|
|
|
|
export default class ClaudeCodeStatusPreferences extends ExtensionPreferences {
|
|
fillPreferencesWindow(window) {
|
|
const settings = this.getSettings();
|
|
|
|
const page = new Adw.PreferencesPage({
|
|
title: _('General'),
|
|
icon_name: 'utilities-terminal-symbolic',
|
|
});
|
|
window.add(page);
|
|
|
|
const dispGroup = new Adw.PreferencesGroup({ title: _('Panel') });
|
|
page.add(dispGroup);
|
|
|
|
dispGroup.add(this._switchRow(settings, 'show-project-name',
|
|
_('Label chips with the project'),
|
|
_('Name the sessions, not just their states.')));
|
|
dispGroup.add(this._switchRow(settings, 'abbreviate-names',
|
|
_('Shorten names to three characters'),
|
|
_('“dev-skills” becomes “ds”. Collisions get a digit by seniority, so a label already on screen never changes.')));
|
|
dispGroup.add(this._spinRow(settings, 'max-chips',
|
|
_('Chips shown'),
|
|
_('The most urgent sessions get a chip; the rest are counted as “+N”.'),
|
|
1, 12));
|
|
dispGroup.add(this._switchRow(settings, 'show-age',
|
|
_('Show time in state'),
|
|
_('Shown on the most urgent session only.')));
|
|
|
|
const zellijGroup = new Adw.PreferencesGroup({
|
|
title: _('zellij'),
|
|
description: _('Sessions running inside zellij can be located by tab name instead of by path.'),
|
|
});
|
|
page.add(zellijGroup);
|
|
|
|
zellijGroup.add(this._switchRow(settings, 'zellij-integration',
|
|
_('Resolve tab names'),
|
|
_('Name the zellij tab each session runs in. Ignored when zellij is not installed.')));
|
|
|
|
// --- Hooks ---------------------------------------------------------
|
|
// The indicator is only as good as the hooks feeding it, and a silent
|
|
// panel looks identical whether nothing is running or nothing is
|
|
// installed. Say which it is.
|
|
const hooksGroup = new Adw.PreferencesGroup({
|
|
title: _('Hooks'),
|
|
description: _('Claude Code writes one state file per session; the panel watches them.'),
|
|
});
|
|
page.add(hooksGroup);
|
|
|
|
hooksGroup.add(new Adw.ActionRow({
|
|
title: _('Status'),
|
|
subtitle: this._hooksStatus(),
|
|
}));
|
|
hooksGroup.add(new Adw.ActionRow({
|
|
title: _('State directory'),
|
|
subtitle: this._stateDir(),
|
|
}));
|
|
|
|
const installRow = new Adw.ActionRow({
|
|
title: _('Install command'),
|
|
subtitle: `${this.path}/hooks/install.py`,
|
|
});
|
|
const copyButton = new Gtk.Button({
|
|
icon_name: 'edit-copy-symbolic',
|
|
valign: Gtk.Align.CENTER,
|
|
tooltip_text: _('Copy to clipboard'),
|
|
});
|
|
copyButton.connect('clicked', () => {
|
|
window.get_clipboard().set(`${this.path}/hooks/install.py`);
|
|
});
|
|
installRow.add_suffix(copyButton);
|
|
hooksGroup.add(installRow);
|
|
}
|
|
|
|
_stateDir() {
|
|
const base = GLib.getenv('XDG_STATE_HOME') ||
|
|
GLib.build_filenamev([GLib.get_home_dir(), '.local', 'state']);
|
|
return GLib.build_filenamev([base, 'claude-code-status']);
|
|
}
|
|
|
|
_hooksStatus() {
|
|
const path = GLib.build_filenamev([GLib.get_home_dir(), '.claude', 'settings.json']);
|
|
// Checked before reading: file_get_contents throws on a missing file,
|
|
// so without this the person who has installed nothing -- the one who
|
|
// most needs the instructions -- is told the file cannot be parsed.
|
|
if (!GLib.file_test(path, GLib.FileTest.EXISTS))
|
|
return _('No ~/.claude/settings.json yet — run the install command below');
|
|
try {
|
|
const [ok, bytes] = GLib.file_get_contents(path);
|
|
if (!ok)
|
|
return _('~/.claude/settings.json is unreadable');
|
|
const settings = JSON.parse(new TextDecoder().decode(bytes));
|
|
const events = Object.entries(settings.hooks ?? {})
|
|
.filter(([, groups]) => groups.some(g =>
|
|
(g.hooks ?? []).some(h => (h.command ?? '').includes('claude-status-hook.py'))))
|
|
.map(([event]) => event);
|
|
if (!events.length)
|
|
return _('Not installed — run the install command below');
|
|
return `${_('Installed for')}: ${events.join(', ')}`;
|
|
} catch (e) {
|
|
return _('~/.claude/settings.json could not be parsed');
|
|
}
|
|
}
|
|
|
|
_spinRow(settings, key, title, subtitle, lower, upper) {
|
|
const row = new Adw.SpinRow({
|
|
title, subtitle,
|
|
adjustment: new Gtk.Adjustment({
|
|
lower, upper, step_increment: 1, page_increment: 1,
|
|
}),
|
|
});
|
|
settings.bind(key, row, 'value', Gio.SettingsBindFlags.DEFAULT);
|
|
return row;
|
|
}
|
|
|
|
_switchRow(settings, key, title, subtitle) {
|
|
const row = new Adw.SwitchRow({ title, subtitle });
|
|
settings.bind(key, row, 'active', Gio.SettingsBindFlags.DEFAULT);
|
|
return row;
|
|
}
|
|
}
|