Verifying the sleep-mode loop surfaced this gap: cloud-mode dispatches go
through pending_commands and never created an orchestration_runs row, so
agent-hook-bridge.sh:finish_orchestration_run silently no-opped on Vercel
(no /tmp/cockpit-run-<tab> sentinel was ever written).
- InjectPayload gains an optional runId so the run id can be threaded from
server-side dispatch to the local daemon over the pending-commands queue.
- /api/orchestration/run cloud-mode block now creates a tracked run row
before enqueueing (mirroring the local-mode path), excluding lifecycle
intents. runId is returned to the caller so the client can correlate.
- cockpit-daemon.sh:inject case reads payload.runId and writes the
/tmp/cockpit-run-<tab> sentinel before execute_inject, so the existing
stop hook closes the loop unchanged.
With this, the next live agent run dispatched from cockpitapp.vercel.app
will produce its first end-to-end outcome row.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Close the loop on Sleep Mode v1. The web-app side (Moon toggle in /control)
already writes /tmp/cockpit-sleep-mode via POST /api/control/sleep-mode and
short-circuits the ReadyBanner countdown to 0 in the browser. The local
stop hook was still launching the popup regardless — so a user who flipped
sleep mode and closed the lid would come back to a stale popup.
Adds a single check between the popup-mode and min-idle gates: if the
sentinel exists, log + exit 0 (matching the existing 'disabled' semantic).
The browser-side ReadyBanner continues to auto-inject as long as Cockpit
is open in any tab — no other change needed for the loop to close.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Foundation for the autonomous-dispatch loop — every prompt dispatched into a
zellij tab now produces an outcome row that downstream logic can learn from.
- orchestration_runs gains an `outcome` column (success/partial/error/hang/
user_abort/timeout) plus a partial index on (user_id, project_key, finished_at)
scoped to finished rows, sized for the "last 5 outcomes" lookup.
- inferOutcome() classifies a session handoff (done/next/tests/todos/health)
+ durationMs + error into one of the six outcomes. Pure, no I/O.
- Every dispatch for claude/codex/gemini adapters now creates a run row at
inject time and writes the run id to /tmp/cockpit-run-<tab>. Lifecycle
intents (hard_stop / close_session) are deliberately not tracked.
- New endpoint POST /api/orchestration/runs/[id]/finish closes a run with
inferred (or explicit) outcome + summary.
- agent-hook-bridge.sh:handle_stop reads the run sentinel and posts the
session handoff back. Fire-and-forget, never blocks the stop hook.
The visible side of this loop (dispatch reasoner ingestion + ProjectCard
streak chip) ships in the next commit.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the 10s polling loop (20 × 0.5s sleeps) with `xdotool search --sync
--onlyvisible` which blocks until the window actually appears — no fixed
timeout, no race on slow machines. Guard the xdotool block so the script
stays functional without it installed.
beacon.py no longer cold-spawns its own browser window (that path created
rogue, untargetable windows when the service wasn't running). Instead it
ensures the cockpit-beacon-window.service unit is active (idempotent systemctl
start) and pings /api/beacon/window/show — SSE drives the same path from React,
this is belt-and-suspenders to minimise perceived latency.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Three issues with the off-screen pre-warm approach:
1. cockpit-beacon-window.sh was using exec (replaced process), so the
background unmap watcher couldn't run. Changed to background & with
an explicit wait so the watcher subshell can poll for the window
and unmap it the moment it appears, preventing any initial flash.
2. hide/route.ts was using windowmove -32000,-32000 to "hide" the
window. KDE Plasma/KWin clamps offscreen positions back to the
nearest visible screen edge, so the window was never truly hidden.
Switched to windowunmap (X11 visibility off) — works reliably.
3. show/route.ts was calling windowmap after windowmove. Moving an
unmapped window is silently ignored by the WM. Reordered to
windowmap --sync first, then windowmove/activate/raise.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two bugs in the beacon popup:
1. Race condition in BeaconLiveClient: handleClose scheduled
setSession(null) after 1500ms unconditionally. If a new SSE session
arrived during that window, the setTimeout would overwrite it with
null, silently killing the next popup. Fixed with a functional
updater that only clears if the closing session's ID still matches.
2. Wayland/xdotool invisibility: cockpit-beacon-window.sh was launching
chromium as a native Wayland window (on KDE Plasma, chromium defaults
to Wayland for --app windows). xdotool is X11-only and cannot find
or move Wayland-native windows, making /api/beacon/window/show and
/hide silently no-op. Fixed by unsetting WAYLAND_DISPLAY and passing
--ozone-platform=x11 so the window runs through XWayland instead.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
/api/beacon/window/show moves the pre-warmed chromium window on-screen
and raises it; /api/beacon/window/hide moves it off-screen (-32000,-32000).
BeaconLiveClient calls these whenever session state changes, so the popup
appears fully populated with no Standby flash visible to the user.
The service script already launches chromium with --class=cockpit-beacon
and --window-position=-32000,-32000 so xdotool targets the right window.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When cockpit-beacon-window.service manages the pre-warmed Chromium window,
it never writes _LIVE_PID_FILE. The old code would fail the PID check and
spawn a duplicate window alongside the running one. Now: try xdotool/wmctrl
focus first, only cold-start if no window is found.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Split ProfileSettings into Profile (public identity) and Account (auth/security) tabs
- Add LocationSettings with two-tier model: homeCity/timezone/locale + currentCity/timezone/until for travelers
- Add AccountSettings with email display, password change, connected OAuth providers, danger zone
- New SettingsTabs with 7-tab horizontal nav (Profile · Account · Location · Agent · Projects · Team · Billing)
- New user_preferences DB table with getUserPreferences/upsertUserPreferences query functions
- New API routes: GET/PATCH /api/me/preferences, GET/DELETE /api/me/connected-accounts/[provider]
- Wire user's active city into weather API; active timezone into cron default
- beacon: replace "Waiting for Claude…" spinner with clean Standby screen (logo + text)
- beacon: fix grep pipeline crash in agent-hook-bridge.sh (|| true guards), fix token lookup
- beacon: fix _PROJECT_ROOT via agent-projects.conf, fix auto-start without zenity dialog
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Web popup at /beacon/live is the sole popup surface. Deletes the dead
PyQt vendored modules, the foreign-UI zenity/kdialog/notify-send dialog
that asked the user whether to start Cockpit, and the PyQt-import gates
in the install/smoke/runtime check scripts. The session JSON is now
written unconditionally; if Cockpit is unreachable, beacon.py
fire-and-forgets `systemctl --user start cockpit-app` and exits — the
session surfaces via SSE once the service is up.
Also fixes a pre-existing react-hooks/purity error in StuckGoalsCard
(impure Date.now() inside server component body) that was blocking the
pre-commit lint hook for the whole repo.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Moves beacon settings from a shared machine file to a per-user `beacon_settings`
Postgres table so every account has independent control. Adds `popup_mode` (web /
pyqt / both / disabled) with pros/cons shown in the settings UI.
- New `beacon_settings` table (userId unique FK, all existing fields + popup_mode)
- `db/queries/beacon-settings.ts` — getBeaconSettings / upsertBeaconSettings
- GET /api/beacon-settings now requires auth; both verbs read/write DB
- beacon.py reads popup_mode via get_popup_mode() and gates PyQt / web accordingly
- _beacon_config.load_settings() fetches from API with 5-min /tmp cache, falls back
to legacy file when Cockpit is offline
- agent-hook-bridge.sh fetches settings via Bearer token; exports BEACON_POPUP_MODE;
both stop and notification handlers gate immediately on popup_mode=disabled
- Settings page: 4-card popup mode selector with per-option pros/cons descriptions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace hardcoded 60s idle threshold with min_idle_seconds setting.
Default is 0 which fires the popup every session end regardless of
keyboard activity. Setting lives in beacon.json, surfaced in Settings UI.
Both the stop-hook beacon and the notification auto-inject respect it.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Command pickup latency: 5s → ~100ms. The API now holds requests for up to
25s (local) / 8s (remote Vercel) until a command arrives, eliminating the
sleep-then-poll cycle. The push loop skips the POST when state is unchanged
(md5 hash comparison), cutting idle DB writes from ~30/min to near zero.
After each command execution, a background push fires immediately so the UI
reflects results without waiting for the next push cycle.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Non-lifecycle cloud-queued injects had the same gap as the run route (fixed
in 0bc9cd8): stale closing sentinel persisted, keeping UI in "Closing…" state.
Also cancels any open web-beacon popup for the tab (mirrors cancelActiveBeaconSessions)
so the React beacon client self-closes when a new task is injected remotely.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Route used getSessionUserId() (cookie-only); hook bridge sent no auth header.
Switch route to getApiUserId() (cookie + Bearer) and read COCKPIT_DAEMON_TOKEN
from env or .env.local fallback in patch_project_state curl call.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The notification auto-inject path dequeued queue items before reading session
health, so a critical/degraded health state was ignored and queue items fired
when they shouldn't. Moved the health read before the queue dequeue check and
gates the dequeue on auto_key=next_best — mirroring sessionHealthBlocksQueue()
on the client and the server-side gate in /api/orchestration/run.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
In cloud mode (Vercel), session content was never populated in DB —
the runtime-state route only accepted agent/lifecycle fields, and the
daemon only pushed those. The UI showed empty done/next/health/tests
in the ReadyBanner and ClosedBanner for all cloud-mode users.
Daemon reads ~/.claude/sessions/<tab>.md per project each push cycle and
merges sessionDone/Next/Tests/Todos/Health/UpdatedAt into the payload when
the file exists. Route extended to accept and pass these fields through to
upsertProjectState (absent = skip, present = update).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
execute_inject injected prompts but never wrote /tmp/agent-current-prompt-<tab>,
so the UI showed no running banner for cloud-queued tasks. Now reads promptLabel
from the payload (already stored by enqueueInjectCommand) and writes the file
after a successful inject, mirroring what the local inject/run routes do.
Skipped for hard_stop and close_session (session-ending, not task-starting).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Cycle 2 used tab_lower (lowercase) for all /tmp sentinel writes, but the
stop hook and push_runtime_state both read them with the original-cased tab
name (from zellij / conf). The case mismatch meant the stop hook never found
the close_session sentinel, so it showed the beacon popup and wrote readyAt
instead of closedAt — defeating the cycle 2 fix entirely.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When the daemon processes an inject command from the cloud queue, it had
the promptKey but never wrote the sentinel or closing files. The stop
hook would then treat the session end as a normal completion (readyAt +
beacon popup) instead of writing closedAt.
Mirrors the same fix applied to /api/orchestration/run for the local path.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
agent-config.ts (buildPromptWithSession), renderers.ts (openclaw path),
and cockpit-daemon.sh (_resolve_prompt) all emitted "todos: <count>"
while agent-hook-bridge.sh, install-beacon.sh, and prompt-library.ts
all emitted "todos: <count> TODOs". Agents dispatched from the web UI
would write "todos: 0" while beacon-fired agents wrote "todos: 0 TODOs",
producing inconsistent session files depending on which dispatch path ran.
Standardised on "todos: <count> TODOs" (the format present in all actual
session files and the majority of the emit sites).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The daemon runs directly from the repo scripts/, so after committing
changes to cockpit-daemon.sh or agent-hook-lib.sh the service must be
restarted to load the new code. Without this flag there was no quick
path — the full installer re-generates the service file unnecessarily.
Also restarted the running daemon which had been running stale code
since before the bc07b0a / 3ac1f01 reliability fixes were committed.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Both files are referenced by agent-hook-bridge.sh via \$SCRIPT_DIR and
were already present in the installed location from a prior install, but
were missing from _copy_scripts() — meaning --sync would never update
them when they change. Added to the canonical copy list alongside the
other bridge-referenced scripts.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
run-codex-task.sh passed --ask-for-approval which only exists on the
interactive codex CLI, not codex exec — causing immediate failure on
every switch. Also both runner scripts computed ROOT=parent-of-scripts-dir
which resolves to ~/.local/share when installed, making the stop-hook
call (agent-hook-bridge.sh) silently fail every run. Fixed to use
SCRIPT_DIR (same directory as the runners) which works both in the
repo and from the installed ~/.local/share/cockpit-beacon/ location.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
install-beacon.sh was missing three scripts that agent-hook-bridge.sh
references via \$SCRIPT_DIR:
- run-codex-task.sh / run-gemini-task.sh — agent-hook-bridge.sh
constructs 'bash \$SCRIPT_DIR/run-{agent}-task.sh ...' and injects
it into the terminal for Codex/Gemini switches; without the file
present the injected command fails silently
- sync-agent-runtime-config.py — called at bridge startup (non-fatal
but missing from the install location)
Also DRY the install: extract _copy_scripts() so --sync and the full
install share a single list, eliminating the previous duplication.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Full install is too heavy for day-to-day script updates — it re-creates
hook files and reruns dependency checks. --sync copies only the runtime
scripts (beacon.py, _beacon_config.py, agent-hook-bridge.sh, etc.) to
~/.local/share/cockpit-beacon without touching hooks or config.
Also synced the installed scripts to pick up all 4 recent fixes:
- agent-hook-bridge.sh: reliable switch (send_raw_key_to_tab+inject_prompt)
+ capacity sentinel write in handle_notification
- agent-hook-lib.sh: grep -qxF exact-line fix in _find_session_for_tab
- beacon.py: nextAgent/capacityIssue computed in local session creation
+ _check_capacity_sentinel
- _beacon_config.py: looks_like_capacity_issue() + resolve_next_agent()
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Notification hook receives a 'message' field from Claude Code (e.g.
"Claude is at capacity. Please try again in 60 seconds.") but the bridge
never read it, so capacity issues were invisible to the auto-switch system.
Fix: handle_notification now extracts 'message', regex-matches it against
rate-limit phrases (same set as looksLikeAgentCapacityIssue), and writes
/tmp/agent-capacity-issue-<tab> with a timestamp when matched.
beacon.py reads and clears this sentinel in _write_beacon_session so the
beacon session gets capacityIssue=true, triggering the auto-switch countdown
instead of the normal continue prompt. Sentinel expires after 5 minutes so
a missed stop hook doesn't poison the next unrelated session.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
beacon.py writes sessions directly to /tmp when Cockpit is running locally,
bypassing the TypeScript API. It hardcoded nextAgent: null and
capacityIssue: false, silently breaking the auto-switch-on-capacity-issue
flow that the user specifically asked for.
Add looks_like_capacity_issue() and resolve_next_agent() to _beacon_config.py
as Python mirrors of the TypeScript equivalents in src/lib/agent-registry.ts,
and wire them into _write_beacon_session(). The "capacity issue" banner and
auto-continue switch now fire correctly in the local path.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
switch_agent_and_continue had the same fragile fixed-sleep pattern as the
TypeScript route and daemon already fixed: manual go-to-tab + sleep 0.2 +
write 3 + sleep 0.1 + write-chars + sleep 0.1 + write 13 racing against
async tab focus.
Replace with:
- send_raw_key_to_tab for Ctrl+C (handles session discovery + tab focus)
- inject_prompt for launch command (polls dump-layout until focused)
This is the third and final execution path for agent switching. All three
paths (TypeScript route, daemon, beacon hook) now use the same reliable
pattern.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- grep -qixF (exact-line, case-insensitive) in tab_open check and
_find_session_for_tab — -qiF was a substring match so 'cockpit'
incorrectly matched 'cockpit-dev'
- --max-time 15/10/8 on claim_next, mark_done, push_runtime_state
curl calls — missing timeouts let the main loop hang indefinitely
if the server is unresponsive
- codex default model: codex-4-5 → gpt-5.4 to match agent-registry.ts SSOT
- _is_agent_running_in_dir rewritten to delegate to _scan_agents,
eliminating the duplicate /proc walking logic
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Mirrors the reliability fix applied to the TypeScript switch-agent route
(aa3a743) for the daemon execution path (cloud → daemon → local zellij).
Previously execute_switch_agent used a fixed `sleep 1` after injecting
the quit command, with no verification the old agent actually exited.
If the agent was stuck on a permission dialog the new agent's launch
command would be typed straight into the running session.
Changes:
- cockpit-daemon.sh: adds _is_agent_running_in_dir() to scan /proc for
the outgoing agent by basename+cwd; replaces sleep 1 with a 2s poll
loop, then sends Ctrl+C (key 3) + 600ms grace if still alive.
- agent-hook-lib.sh: adds send_raw_key_to_tab() — raw keycode injection
reusing existing session-discovery logic, parallel to inject_prompt().
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Auto-discovers COCKPIT_DAEMON_TOKEN from .env.local, snapshots the current
login PATH so zellij/jq/ffmpeg are reachable, writes ~/.config/cockpit/daemon.env
(chmod 600) and a user service file, then enables and starts it. Supports
--uninstall. Replaces manual `COCKPIT_DAEMON_TOKEN=... ./scripts/cockpit-daemon.sh`
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Hook changes:
- handle_notification now reads session health before picking which prompt
to auto-inject: health=needs attention|critical → unblock, else → next_best
- Log line and write_inject_state both carry the chosen key and health value
New prompts in agent-prompts.json:
- orient: context reload — reads git log, tsc, session; outputs brief;
no code changes. For resuming after breaks or context-limit compactions.
- unblock: stabilize before advancing — runs tsc + tests, fixes highest-
severity failure, stops when baseline is green. Never auto-injects on
healthy projects.
Thoughts article: "Prompts, Timing, and Orchestration: Where Agent Value
Actually Lives" — covers the decision tree, prompt taxonomy (auto-inject
candidates vs human-selected vs situational), queue-based injection
semantics, and what's still missing (velocity, time-of-day, multi-item
queue drain, inter-project coordination).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two structural gaps:
1. handle_notification didn't check the queue before injecting next_best.
If user dispatched a task from Control while Claude was running, the
notification path would ignore it and inject next_best instead. Now
mirrors handle_stop's slot-1 queue logic: dequeues and injects the
first item atomically, skipping next_best entirely when a task is waiting.
2. next_best prompt was underspecified for the "nothing urgent" case.
Added explicit priority order (type errors → uncommitted → session.next
→ discovery), expanded git log to -10, added tsc check as step 1, and
replaced the vague "highest-impact gap" directive with a concrete
discovery method: scan recent commits, find the adjacent broken thing.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
continue prompt gave Claude zero context on what was in progress. next_best already
loads git state and prompts a context-aware resume; same rich session-file append
pattern as handle_stop. Also switches to emit_or_inject_prompt for AGENT_BRIDGE_EMIT_PROMPT
test compatibility and calls write_inject_state so Control panel reflects the injection.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- _beacon_config.py: add read_project_git_branch() (mirrors server-side parseProjectsConf logic)
- beacon.py: embed gitBranch in session JSON at write time so SSE/web consumers get it without a server-side lookup
- _beacon_popups.py: rewrite ContinuePopup header — green dot, project name, "Ready" badge, then chips row with agent chip + git branch chip; matches web beacon header exactly
- sse/route.ts: add git branch fallback enrichment for sessions written before this change
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Four issues fixed:
- BeaconSession now carries countdownSeconds (read from settings file in both
the API route and beacon.py), so the web popup always shows the user-configured
value instead of a hardcoded fallback
- DEFAULT_BEACON_COUNTDOWN_S changed from 30 → 12 to match Python COUNTDOWN_SECONDS;
fallback is now consistent across all surfaces when no settings file exists
- BeaconClient uses session.countdownSeconds instead of AUTO_INJECT_S / URL param,
eliminating the split between readyAt-path (12s) and URL-param-path (30s)
- useAutoContinue default changed false → true so new tabs start with auto-continue
enabled, matching Python popup behaviour and isAutoContinueEnabledSync
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
GET /api/projects/[id] is the most-called endpoint in the app — every
project drawer open hits it. The static smoke test had no coverage for
it because the ID is runtime-derived. Reuses the same jq+curl pattern
used for /api/people/<id>: fetches the first entity project ID from
/api/user-projects, then hits the detail route and verifies it returns
2xx (or 401 without a session).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a smoke route check for /api/invitations/<bogus-token> that must return
404, not 401. If it returns 401 it means the middleware exclusion (api/invitations/)
regressed and new users can no longer accept team invitations. The check fails
loudly on 401, passing only on the expected 404 for an invalid token.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
`npm run build` alone left .next/standalone/ with stale CSS/JS chunks,
causing the production server to serve 404s until `install-app` was run
manually. The new postbuild hook runs deploy-local.sh automatically after
every build: copies .next/static and public/ into standalone, then
conditionally restarts the cockpit-app systemd service if installed.
No-ops cleanly on CI (no standalone dir) and on machines without the
service (systemctl check skipped). install-app is preserved for first-time
setup.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Transient popup windows should not control app-wide theme — removing
ThemeToggle from the beacon header prevents the next session from
waking up in light mode when the user clicked the toggle there.
Smoke test gains /api/orgs, /api/agent-tokens, /api/agent/register
(all three new multi-tenancy + agent-token endpoints).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace cold-open-per-session with a persistent /beacon/live tab that
stays open in the --app= frameless window. New SSE endpoint polls
/tmp/cockpit-beacon/ at 150ms and pushes fresh sessions to the tab,
so the popup appears in < 150ms with no browser cold start.
beacon.py now tracks the live-browser PID and focuses the existing
window instead of launching a new one. BeaconPageClient accepts onClose
so the live tab resets to standby instead of calling window.close().
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Notification hook was unconditionally injecting "Resolve the pending
question..." whenever Claude Code sent a notification event — even if the
user was actively at the keyboard typing their own reply. This caused the
double-prompt problem independently of the Stop hook fix.
Two changes:
1. handle_notification now applies the same 60s idle gate as handle_stop.
If the user is active, the hook plays the attention sound only and exits —
the user responds themselves. Auto-inject only fires when they're away.
2. The "continue" prompt entry in agent-prompts.json had style "internal"
and slot null, making it invisible in the prompt library UI despite being
the SSOT for this behavior. Changed to style "more" / slot 14 so it
appears under the More button and can be read, used, and edited from the
same place as every other prompt.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Layer 1 (< 100ms): notify-choice.py shows a native KDE notification with
action buttons built from the first 3 prompt slots. Uses gi.repository.Notify
+ GLib event loop so actions are properly wired (plain notify-send --action
is not supported by the KDE notification server). When clicked:
- prints the slot number (choice)
- patches /tmp/cockpit-beacon/{id}.json so the browser beacon sees
choice != null and window.close()s itself within 500ms
Layer 2 (1-4s): beacon_python opens the full browser beacon in parallel.
Both layers write to a shared tempfile via atomic mv — first write wins.
The main loop polls every 200ms, kills both processes on first result.
If neither layer produces a choice (user is at keyboard, typing manually),
the hook exits cleanly without injecting anything.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two fixes to make the beacon popup work without requiring the browser to
be logged into Cockpit:
1. Server-side initial session read — page.tsx is now a Server Component
that reads the beacon session directly from /tmp/cockpit-beacon/{id}.json
before sending HTML to the browser. The client receives a fully-populated
initialSession prop and shows session content immediately — no client-side
GET /api/beacon/{id} needed on page load. The PATCH (recording the user's
choice) and the cancel-detection poll still go through the API, which
works as long as the browser that opens the popup has a Cockpit session.
2. Prefer Brave browser for the popup — beacon.py now checks for brave-browser
before google-chrome in the candidate list. The user's Cockpit session
lives in Brave (the primary browser), so opening there means API calls
from the beacon page are authenticated automatically.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The XScreenSaver extension is unavailable on this machine's X11 display.
Add /dev/pts youngest-atime as a fallback: the most recently accessed
pseudo-terminal is a reliable proxy for 'user is active in a terminal'
and needs no extra packages or group membership.
Detection order: libXss (XScreenSaver) → /dev/pts atime → 9999 (show beacon).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Three targeted fixes for the "prompt injection even when at keyboard" problem:
1. Remove the `choice="1"` fallback — when the beacon times out or Chrome fails
to open, the hook now exits cleanly instead of auto-injecting slot 1 on top of
whatever the user typed manually.
2. X11 idle gate — skip beacon entirely when the user has been active within the
last 60 s (uses xprintidle if installed, falls back to libXss via ctypes, falls
back to 9999 = always show beacon when neither is available). Install
xprintidle with `sudo apt install xprintidle` to enable on systems without the
MIT-SCREEN-SAVER X11 extension.
3. Instant notify-send notification fires before Chrome launches so the user gets
immediate visual feedback while the browser beacon popup loads (1–4 s on first
Chrome launch, near-instant when Chrome is already running).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
beacon.py now writes sessions to /tmp/cockpit-beacon/{uuid}.json
directly instead of POSTing to /api/beacon, and polls the file instead
of GET /api/beacon/{id}. No API auth is needed — the browser popup (which
has the user's session cookie) still calls the API to load the beacon UI
and write the choice. Works immediately without any dev server restart.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two bugs preventing the popup from working:
1. /api/beacon was matched by the auth middleware (401 for unauthenticated
beacon.py). Added api/beacon to the middleware exclusion list — sessions
are /tmp UUIDs with no sensitive data.
2. FocusCancelTextEdit(QPlainTextEdit) called setAcceptRichText which does
not exist on QPlainTextEdit (it's a QTextEdit method). Removed the
redundant call — QPlainTextEdit is plain-text-only by definition.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>