feat(code): system tray with running-agent badge#2384
Draft
fercgomes wants to merge 8 commits into
Draft
Conversation
Adds a system tray icon (menu bar on macOS, tray on Windows/Linux) that displays the count of currently running agent sessions. On macOS the count is shown via `Tray.setTitle()` next to the icon; on Windows and Linux the icon is swapped between pre-rendered overlays in `apps/code/build/tray/`. Tooltip is always set to `"N running agent(s)"`, so the count is at least hover-discoverable on every platform until the designed overlay PNGs land. - New `ITray` platform port + `ElectronTray` adapter - New `TrayService` listens to a new `AgentService.RunningCountChanged` event and refreshes the badge live - Click on the tray icon restores and focuses the main window - Tray is initialized after services come up and disposed in graceful exit Generated-By: PostHog Code Task-Id: 01d444b5-b5d4-426a-9ae3-57ba28e54e09
The 1024×1024 source PNG was being handed to `Tray` unmodified, so it overflowed the menu bar. Resize every loaded image to 22px tall on macOS and 16px elsewhere, and set the template flag on macOS so the icon adapts to light/dark menu bars. Generated-By: PostHog Code Task-Id: 01d444b5-b5d4-426a-9ae3-57ba28e54e09
`setTemplateImage(true)` on a fully-opaque colored PNG renders the silhouette as a solid block that's nearly invisible against the dark menu bar. Drop the template flag and resize to 16px (Electron's documented tray target) with the best quality filter. Generated-By: PostHog Code Task-Id: 01d444b5-b5d4-426a-9ae3-57ba28e54e09
Adds a proper macOS template image (hedgehog silhouette extracted from the brand icon by alpha-thresholding the white background) at 22/44/66 px so Electron auto-picks the right scale. Template mode lets the icon adapt to light/dark menu bar like other system icons. Windows/Linux still use the colored `badge-N.png` set at 16 px. Generated-By: PostHog Code Task-Id: 01d444b5-b5d4-426a-9ae3-57ba28e54e09
The previous template kept the brand icon's internal white highlights as transparent cutouts, which read as a "bezelled" or carved hedgehog in the menu bar. Fill internal holes and slightly dilate the mask so the silhouette renders as one flat solid shape. Generated-By: PostHog Code Task-Id: 01d444b5-b5d4-426a-9ae3-57ba28e54e09
`promptPending` is only true while the agent is actively generating — a quick prompt flickered the badge for under a second and a longer one hid it again the moment generation finished. Switch the running count to `sessions.size`, which stays stable from session creation through idle/cancellation. Emit `RunningCountChanged` when a session is added in `getOrCreateSession` (was previously only emitted around prompt()) and unconditionally on `cleanupSession`. Generated-By: PostHog Code Task-Id: 01d444b5-b5d4-426a-9ae3-57ba28e54e09
The 2-iteration binary_dilation I added to smooth anti-aliased edges also expanded the silhouette by ~2px on every side, which read as a visible border around the hedgehog. Generate the template from just the filled-holes mask with no dilation. Generated-By: PostHog Code Task-Id: 01d444b5-b5d4-426a-9ae3-57ba28e54e09
Render the rounded-square area as the solid template and cut the hedgehog out of it instead of the other way around — the negative space reads cleaner at menu-bar size than a small lumpy hedgehog shape on its own. Generated-By: PostHog Code Task-Id: 01d444b5-b5d4-426a-9ae3-57ba28e54e09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tray.setTitle(). Windows/Linux swap between pre-rendered overlay PNGs inapps/code/build/tray/(badge-0.pngships now;badge-1..9.pngandbadge-9plus.pngare picked up automatically when design adds them — adapter falls back tobadge-0.pnguntil then). Tooltip always shows"N running agent(s)"so the count is at minimum hover-discoverable.Architecture
ITrayplatform interface in@posthog/platform/tray, fulfilled byElectronTrayadapter — services never import fromelectrondirectly.TrayService(apps/code/src/main/services/tray/service.ts) depends onITray,AgentService,IMainWindowvia constructor injection.AgentService.getRunningSessionCount()matches existinghasActiveSessions()semantics (promptPending || inFlightMcpToolCalls.size > 0).AgentServiceEvent.RunningCountChangedevent emitted at the three transition points:prompt()enter,prompt()finally, andcleanupSession()when a running session is removed.TrayServiceis the only subscriber today.TrayService.initialize()runs ininitializeServices()in main;TrayService.dispose()runs inAppLifecycleService.doShutdown().forge.config.tsextraResource now includesbuild/trayandbuild/app-icon.pngso the assets ship with packaged builds.Test plan
pnpm dev:code— tray icon appears on boot in menu bar (macOS) / system tray (Win/Linux); tooltip reads0 running agents.1next to the icon, tooltip becomes1 running agent.3. Finish one →2. Finish all → badge clears.badge-9plus.png(or falls back tobadge-0.pnguntil overlays designed), macOS shows the literal count, tooltip reads10 running agents.pnpm --filter code make→ install the packaged build → repeat the above with packaged paths (process.resourcesPath/tray/...).pnpm --filter code typecheck✅pnpm --filter code test— AgentService tests pass (1505 passing locally; archive integration failures are pre-existing sandbox-only artifacts).Follow-ups
badge-1.png…badge-9.png,badge-9plus.pngfor Windows/Linux. No code change needed — adapter picks them up automatically.badge-0.template.png) for proper dark/light menu-bar adaptation.