pi-winnotify-toast0.1.0
Windows toast for the Pi coding agent with the answer preview, a real window-focus gate, and Urgent toasts that survive Do Not Disturb
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-winnotify-toast
Windows toast notifications for the Pi coding agent, with three things a generic notifier does not do:
- The body is the answer, not "ready for input". At hour six of a long run the only question is do I need to come back, and the first line of the reply answers it. Markdown is stripped, the text is capped.
- A real focus check. The foreground window is read through Win32
(
GetForegroundWindow+GetWindowText) and compared with the title Pi gives the tab (π - <project>). If the tab is in front, nothing is sent — the answer is already on screen. A notifier gated on inactivity (a timeout) is a different thing: you can be active in another window and get nothing. - Urgent, so "Do Not Disturb" does not eat it. Windows turns DND on by itself
while a fullscreen app holds the session (Discord, a game), and a normal toast is
then accepted and silently dropped. This one is created with
Scenario=Urgentand a ten-minute expiry, so it also waits in the Action Center when the popup was missed.
Runs in native Windows Pi, including when launched from Git Bash.
Install
pi install npm:pi-winnotify-toast
Then /reload. Check it in one keystroke:
/wintoast-test
/wintoast-test your own body text
Windows helper and local changes
The npm package ships pifocus.cs as source. There is no prebuilt
pifocus.exe in the package and npm installation does not compile one. The
extension bootstraps Windows registration on the first notification or when you
run /wintoast-bootstrap. Bootstrap uses the Windows .NET Framework C# compiler
(%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\csc.exe) to build
pifocus.exe if it is missing or the bundled source has changed. It needs
Windows PowerShell 5.1 and runs with the current user's permissions.
The helper registers the Windows COM callback that receives the text entered
in the toast. It also handles the shortcut and piwinnotify: URI used to focus
Pi. Before submitting a toast, the sender starts or reuses a background helper
in the current Windows session and waits for its ready signal. The helper
normally exits 11 minutes after the sender last renewed its lease. Each toast
has a 10-minute expiration time.
With the defaults, bootstrap creates these per-user entries.
| Location | What it contains |
|---|---|
%APPDATA%\Microsoft\Windows\Start Menu\Programs\Pi.lnk |
Shortcut to the helper with the AppUserModelID and toast activator CLSID |
HKCU\Software\Classes\AppUserModelId\Pi.WinNotify.Toast |
Notification identity, display name, icon and activator CLSID |
HKCU\Software\Classes\CLSID\{7B0E5F3A-2C41-4D9B-8E77-3F1A6B9C0D52} |
COM registration with a LocalServer32 command pointing to the local helper |
HKCU\Software\Classes\piwinnotify |
URI handler pointing to the helper |
%LOCALAPPDATA%\pi-winnotify-toast\ |
Helper source and executable, focus marker, lease file, activation log and reply queues |
Reply queues may contain the text typed in a toast, encoded as Base64. The
default extension log is separate at %LOCALAPPDATA%\pi-notify.log.
Remove the extension
- Run
/wintoast-unregisterin Pi. It removes the shortcut and registry keys, signals the background helper to stop, and deletes the helper directory, including any replies still stored there. - Run
pi remove npm:pi-winnotify-toastin your terminal to remove the package from Pi. Use the original install source if you installed from Git or a local path. - To remove the separate decision log, delete
%LOCALAPPDATA%\pi-notify.logor the file selected byPI_WINTOAST_LOG.
Reply from a notification
Type in the toast and press Send. The background COM callback writes a UTF-8 reply as Base64 on one line of the originating process’s queue. The extension claims the queue atomically at settlement or on a 500 ms idle poll. It submits replies one at a time and waits for Pi to acknowledge each user message. Unconfirmed submissions are retained for inspection. New notifications replace the previous notification for the same Pi process. When Pi stays in the background, the result of a toast reply appears in a new banner that also accepts replies.
How it decides
On Pi's agent_settled event (once the run is over and nothing else will start on its
own; not on agent_end, which also fires for retries and compaction):
Immediately before posting an automatic toast:
read the foreground window → is it a terminal and does its title look like this session? → in front: silence · otherwise: toast
Three title rules, because Pi rewrites the tab title while a turn runs (a tool name, a progress marker) and an exact match then fails:
| rule | matches |
|---|---|
| marker | the title contains π - <project> |
| project | the title contains the project directory name |
| pi | the title starts with π (any Pi tab) |
Skipped when there is no terminal UI (pi -p, JSON, RPC): nobody to notify, and a
nested run would double-notify its parent. /wintoast-test explicitly posts a
test notification even while Pi is focused.
Configuration
All optional, all environment:
| variable | meaning |
|---|---|
PI_WINTOAST=0 |
disable the extension |
PI_WINTOAST_ALWAYS=1 |
toast even when the tab is in the foreground |
PI_WINTOAST_FOCUS=0 |
same as above |
PI_WINTOAST_MARK=… |
the title marker to look for (default π - <cwd>) |
PI_WINTOAST_TERMS=… |
comma-separated terminal process names |
PI_WINTOAST_PREVIEW=0 |
send a fixed body instead of the answer preview |
PI_WINTOAST_LOG=… |
where the decision log goes |
When nothing appears
Check %LOCALAPPDATA%\pi-notify.log or the file selected by
PI_WINTOAST_LOG. The extension logs whether it skipped a focused Pi window,
whether Windows accepted the toast via Show(), and whether Pi acknowledged a
reply. Check %LOCALAPPDATA%\pi-winnotify-toast\focus.log for COM activation
and queue writes. Windows still controls whether and when a banner appears.
Compared with the existing Pi notifiers
There are several, and they are good. Install one, not two, or you get two toasts.
pi-winnotify-toast |
pi-notify |
@raidou/pi-notify |
@pi-lab/notify |
|
|---|---|---|---|---|
| terminal notifications (OSC 777/99/9) | — | yes | yes | yes |
| Windows toast | yes | yes | yes (also WSL) | yes |
| header reads the tool's own name | yes (after bootstrap) | no | no | no |
| body is the answer | yes | fixed text | fixed text | fixed text |
| focus check | foreground window | no | inactivity timeout | no |
| click returns to the window | yes, by title match | yes for OSC | — | — |
| survives Do Not Disturb | yes (Urgent) |
no | no | no |
| delivery diagnostics | yes | no | no | no |
| macOS / Linux | no | yes | yes | yes |
If you want terminal notifications, click-to-focus, or a non-Windows OS, use
pi-notify — it covers more ground. This
package exists for the preview and the two Windows-specific behaviours above.
Measurements and limitations
- The protocol handler received only
piwinnotify:open. A 120-second in-process WinRT activation listener received no callback. - Shell automation read back both shortcut properties. The tagged toast and reply input appeared in Notification Center history. A real Notification Center reply reached the COM callback. During cold-start testing, the synthetic COM client timed out and Windows recorded DCOM event 10010. Starting the helper manually released three pending shell activations in a burst. The sender now warms the helper before it posts.
- Replies go to the Pi process that posted the notification. Keep that process running to receive them. Older notifications written before process routing use the shared legacy queue. A failed injection leaves the claimed file for inspection.
- Windows controls banner timing and visibility. Do Not Disturb or full-screen mode may leave a notification in Notification Center.
- Requires native Windows Node and Windows PowerShell 5.1. The helper uses the installed .NET Framework compiler and requires no SDK, MSIX package, or admin.
Run node acceptance.mjs from the package directory. Synthetic replies use
the test process’s queue. The checks print shortcut properties, history
observations, negative controls, and the COM result. npm test covers preview,
focus matching, and queue delivery.
License
MIT