omp packages

pi-mqtt-notify0.1.0

Publish MQTT notifications when Pi finishes a prompt or needs your input

dlawregiets Published 4 days ago Apache-2.0 ~0 downloads/mo

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.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-mqtt-notify

A Pi extension that publishes an MQTT message when Pi finishes a prompt or needs your input. Publish-only: use it to light up a phone, tablet, or dashboard while Pi runs on your laptop, desktop, or a remote box.

  • Fires when a prompt settles: finished, failed, or interrupted
  • Fires when Pi opens a blocking prompt: permission (confirm) or question (select / input / editor / custom)
  • JSON payload with a stable schemaVersion
  • Buffers messages while the broker is unreachable and flushes on reconnect
  • Skips nothing by accident: a broker outage or bad config never breaks Pi

Install

pi install ./pi-mqtt-notify        # or an absolute path

pi install writes the declaration to ~/.pi/agent/settings.json (pi install --local writes .pi/settings.json instead). Run npm install in this directory once so the mqtt runtime dependency is present.

Configuration

Settings live in <agent-dir>/pi-mqtt-notify/config.json (<agent-dir> is ~/.pi/agent, or $PI_CODING_AGENT_DIR when set). The file is created with defaults on first load; the extension stays disabled until url is set.

Edit it through the settings screen:

/mqtt-notify
 MQTT notifications
 ─────────────────────────────────────────
 › Broker URL        mqtt://127.0.0.1:1883
   Username          —
   Password          ••••
   Client ID         auto
   Topic template    pi/{kind}
   QoS               1
   Retain            false
   Protocol version  4
   Test connection   —
   Done
 esc save & close · ↑↓ move · enter edit

Text rows open an editor pre-filled with the current value; Enter saves, Esc abandons. QoS, Retain, and Protocol version cycle. Every change is written immediately, and closing the screen reconnects (or disables) publishing without a /reload. Test connection opens one connection with the saved settings and reports the result in its own row.

Config keys

Key Default Description
url — Broker URL: mqtt://, mqtts://, ws://, wss://, tcp://, or ssl://. Required.
username "" Broker username.
password "" Broker password, stored in this file.
clientId "" Full MQTT client ID; empty means pi-<random>.
topic pi/{kind} Topic template. See Topics.
qos 1 Publish QoS (0–2). QoS 1 is at-least-once.
retain false Set the MQTT retain flag.
includeSummary true Include the final assistant text in summary.
maxBodyChars 300 Maximum body length (1–4000).
maxSummaryChars 500 Maximum summary length (0–4000; 0 disables it).
maxQueuedMessages 100 Messages buffered while offline (0–10000; 0 disables buffering).
reconnectPeriodMs 5000 Broker reconnect interval. 0 disables automatic reconnect.
connectTimeoutMs 10000 Connection timeout.
keepaliveSeconds 60 MQTT keepalive. 0 disables it.
protocolVersion 4 MQTT protocol version (4 = 3.1.1, 5 = MQTT 5).
debug false Log connection and publish details.

Only the connection rows appear in /mqtt-notify; the tuning keys (maxBodyChars, timeouts, queue size, debug, …) are edited in the file and picked up on the next /reload. The file is written 0600 because it holds the broker password in plain text — the same trust level as any other credential in the agent directory.

Out-of-range or wrong-typed values fall back to the defaults above with a warning; a missing or invalid url disables publishing and says why. Publishing disabled never breaks Pi.

Triggers

Situation Pi event kind Topic (default)
Prompt finished agent_settled (aborted: false) finished pi/finished
Run failed agent_settled after an error stop failed pi/failed
Run interrupted agent_settled (aborted: true) interrupted pi/interrupted
Approval needed ui_prompt_start (confirm) permission pi/permission
Question ui_prompt_start (select / input / editor / custom) question pi/question

agent_settled is Pi's final idle signal: it fires after every retry, compaction, and queued follow-up has drained, so one prompt produces one notification.

Topics

topic is a template with these variables:

Variable Value
{kind} finished, failed, interrupted, permission, or question
{event} agent.settled or ui.prompt
{project} Directory name of the project
{directory} Absolute working directory
{sessionID} Pi session ID

Values are sanitized: /, +, and # become _, and empty topics fall back to pi/events. The extension never publishes to a wildcard topic.

Payload

{
  "source": "pi",
  "schemaVersion": 1,
  "id": "1c9b6b5e-2b0f-4a58-9d6f-4a0f8bd44a1c",
  "timestamp": "2026-02-14T09:12:44.031Z",
  "event": "agent.settled",
  "kind": "finished",
  "title": "pi-mqtt-notify: Fix the build: finished",
  "body": "Fix the build — All tests pass.",
  "project": "pi-mqtt-notify",
  "directory": "/home/ds/code/pi-mqtt-notify",
  "sessionID": "2026-02-14T09-02-11-004Z_ab12cd",
  "sessionTitle": "Fix the build",
  "model": "anthropic/claude-sonnet-4-5",
  "durationMs": 48231,
  "summary": "All tests pass."
}

Assertions on the payload types live in src/schema.ts; kind is finished, failed, interrupted, permission, or question. Question and permission notifications also carry detail: { promptKind, title }.

Development

npm install
npm test          # config, payload, and an end-to-end broker round-trip
npm run typecheck

npm test covers config loading and validation, field mapping, payload rendering, and an end-to-end broker round-trip. test/extension.test.ts starts an in-process MQTT broker (aedes), points PI_CODING_AGENT_DIR at a temp directory holding a config.json, drives the extension through Pi's event handlers, and asserts on the received messages.