From 890d267c7147f71fd7faf352535ff73d75f96dca Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 17 Oct 2026 16:11:57 +0100 Subject: [PATCH] run attention: publish to ntfy and surface what needs the operator Nothing told the operator that a run was waiting for a person or had failed; they found out by going looking. A run that needs attention now reaches the ntfy they already run, and the app answers "what needs me now" in one live, ordered surface. Server (smallest change, reusing the existing publisher): - internal/server/notify.go adds notifyRun, called from finishRunState (failed) and when a run parks on a human (runner.go runLoop). It publishes to the same already-configured `system` destination through the unchanged stage.PublishNtfy, so there is no second publisher, topic or service and the token handling is the stage's own. runAttentionEvent maps only waiting and failed; queued, running, succeeded, canceled and interrupted publish nothing. - No storms: runner.attentionSent records sequence:event per run before publishing, so a run that stays waiting is never republished on a re-request or restart, and a stage notify policy that already covers the same event marks it first so the run-level default is suppressed. The set is dropped when the run is terminal. A delivery failure is logged, never fails the run, and is not retried. - The payload names the run and pipeline and carries a click action pipelines://run/ (validated: absolute URL, no userinfo, no fragment, no credentials). PublishNtfy gained the optional click parameter; existing callers pass "". App: - AndroidManifest/MainActivity declare the pipelines://run/ deep link (singleTop); runIdFromDeepLink parses it and PipelinesApp opens that run once, clearing the link. It opens a run; it starts nothing. - ui/Attention.kt is the pure model (status -> Decision/Failed/Finished or nothing, ordered by kind then newest-first) and ui/components/AttentionSurface.kt is the floating indicator plus bottom sheet. It is derived from the same run events the server already pushes, so an entry appears with no refresh and clears when resolved; a finished run clears once looked at, and any entry can be dismissed, persisted in SettingsRepository. The existing destinations, pill and bottom strip are untouched and no competing navigation surface is added. Checked before committing: - Packaged authoring skill references: internal/author/skill/references/ notifications.md documents the automatic run-attention notifications and the app surface. The only packaged "template" carrying notify is that reference; no pipeline definition template exists to update and install.go's managed file list is unchanged (notifications.md already existed). - Repository guidelines: docs/ntfy.md gains an "Automatic run-attention notifications" section and no longer claims "No block means no notifications"; the top-level README phone-notifications note now says a waiting/failed run notifies automatically; android/README.md gains the dated feature section and supersedes the previous section's note that the attention surface was absent. - docker.md, install docs and the CLI/TUI docs describe mechanisms this change does not alter; left as they are. Tests: go test ./internal/server/... ./internal/stage/... ./internal/author/... all ok; notify_test.go covers the event mapping and the real HTTP delivery (destination, topic, click, no duplicate). Android :app:testDebugUnitTest -> BUILD SUCCESSFUL, 58 suites / 531 tests / 0 failures (new AttentionTest, 13 cases, covering ordering, appearing from a push, clearing on resolution, dismissal, the empty case, persistence and the deep link). Device screenshots and the phone's own notification are visual review's per the brief's device policy. Scope: android/ plus the smallest server change; no new dependency, no run started from the app, no installer or Docker change. --- README.md | 7 +- android/README.md | 66 ++++++ android/app/src/main/AndroidManifest.xml | 14 ++ .../java/net/awan/pipelines/MainActivity.kt | 24 +- .../awan/pipelines/data/SettingsRepository.kt | 13 ++ .../net/awan/pipelines/ui/AppViewModel.kt | 44 ++++ .../java/net/awan/pipelines/ui/Attention.kt | 166 ++++++++++++++ .../net/awan/pipelines/ui/PipelinesApp.kt | 63 +++++- .../ui/components/AttentionSurface.kt | 182 +++++++++++++++ .../net/awan/pipelines/ui/AttentionTest.kt | 213 ++++++++++++++++++ docs/ntfy.md | 23 +- .../author/skill/references/notifications.md | 23 ++ internal/server/notify.go | 132 ++++++++++- internal/server/notify_test.go | 211 +++++++++++++++++ internal/server/runner.go | 23 +- internal/stage/ntfy.go | 30 ++- internal/stage/ntfy_test.go | 6 +- 17 files changed, 1215 insertions(+), 25 deletions(-) create mode 100644 android/app/src/main/java/net/awan/pipelines/ui/Attention.kt create mode 100644 android/app/src/main/java/net/awan/pipelines/ui/components/AttentionSurface.kt create mode 100644 android/app/src/test/java/net/awan/pipelines/ui/AttentionTest.kt diff --git a/README.md b/README.md index 4eff462e..63b82c70 100644 --- a/README.md +++ b/README.md @@ -226,9 +226,10 @@ pipelines run "your pipeline name" "Describe the task" Open **:status** for the server and ntfy connection details. In the ntfy phone app, add the displayed ntfy server, sign in as **phone-reader** with the password -you set during installation, and subscribe to the displayed topic. Stages must -include a `notify` block to send notifications; see [ntfy setup](docs/ntfy.md). -Installation checks publishing, not reception on your phone. +you set during installation, and subscribe to the displayed topic. A run that +waits for a decision or fails notifies automatically; to notify on a stage's own +result, add a `notify` block. See [ntfy setup](docs/ntfy.md). Installation checks +publishing, not reception on your phone. For Tailscale, both devices must be connected; use `http://:8090`. Binding to `0.0.0.0` does not bypass firewalls: diff --git a/android/README.md b/android/README.md index 3fa8b3e1..d288fcc8 100644 --- a/android/README.md +++ b/android/README.md @@ -5944,3 +5944,69 @@ surface" named in the brief is not present in this tree, so the decision is reachable from the run detail and its stage and the shared component is ready for it. No packaged skill reference was touched: the decide protocol is unchanged and already documented, and this is an app-UI change. + +## Run attention surface and phone notifications (17 Oct 2026) + +> Supersedes the note at the end of the previous section: the run-attention +> surface the brief named is now present in this tree. The server publishes the +> notification; the app shows the same information in one live surface. + +A run that needs a person — waiting for a human decision, or failed — now reaches +the operator through the ntfy they already run, and the app answers "what needs me +now" in one ordered list. The server change is the smallest that reuses the +existing delivery machinery; there is no second publisher, topic or service. + +- **One run-level notification, reusing the stage's publisher.** `internal/server/ + notify.go` adds `notifyRun`, called from `finishRunState` (failed) and when a run + parks on a human (`runner.go` `runLoop`). It publishes to the same `system` + destination through the unchanged `stage.PublishNtfy`, with the operator's + configured token handling, so nothing is duplicated. `runAttentionEvent` maps + only `waiting` and `failed`; queued/running/succeeded/canceled/interrupted + produce `""` and publish nothing. +- **No storms.** `runner.attentionSent` (guarded by `attentionMu`) records + `sequence:event` per run before publishing, so a run that stays waiting is never + republished on a re-request or restart, and a stage `notify` policy that already + covers the same event (`on=waiting`, or a failure hook) marks it first so the + run-level default is suppressed. The set is dropped when the run is terminal + (`forgetAttention`). A delivery failure is logged, never fails the run, and is + not retried. +- **The payload opens the run.** It names the run id and pipeline, and carries a + `click` action `pipelines://run/` (validated in `validNtfyClick` — absolute + URL, no userinfo, no fragment, no credentials). `AndroidManifest.xml` declares + the `pipelines`/`run` deep link on `MainActivity` (`launchMode=singleTop`); + `runIdFromDeepLink` parses it and `PipelinesApp` opens that run once, clearing + the link so a rotation re-opens nothing. It opens a run; it starts nothing. +- **One attention surface.** `ui/Attention.kt` is the pure model: a run status maps + to `Decision`/`Failed`/`Finished` (or nothing), and `attentionEntries` orders by + kind then newest-first. `ui/components/AttentionSurface.kt` renders a floating + indicator in the same bottom container as the destination pill — visible from + every destination and window width — that opens a bottom sheet listing the run, + its pipeline and what it needs, with a per-row dismiss. The indicator draws + nothing when the list is empty. No competing navigation surface is added. +- **Live and self-clearing.** The list is derived from the same `RuntimeState` + pushes the runs list folds, so an entry appears with no refresh and clears when + the run is resolved (the decision answered, the failure retried). A finished run + clears once the list is opened; any entry can be deliberately dismissed; + dismissals and looked-at finishes persist in `SettingsRepository` as one + serializable preference. Opening a non-decision entry deals with it. + +Tests: `internal/server/notify_test.go` covers the event mapping (waiting, failed, +nothing else) and the real HTTP delivery (destination, topic, click, no +duplicate); `AttentionTest` (13 cases) covers the app's mapping, ordering, +appearing from a pushed event, clearing on resolution, dismissal, the empty case, +persistence and the deep-link parser. + +Evidence (this pass, macOS, JDK 17 `/opt/homebrew/opt/openjdk@17`, cached Gradle +8.11.1, `ANDROID_HOME=$HOME/Library/Android/sdk`): + +- `go build ./...` → success; `go test ./internal/server/... ./internal/stage/... + ./internal/author/...` → `ok` for all three packages. +- `gradle :app:testDebugUnitTest --offline --no-daemon --console=plain` → + `BUILD SUCCESSFUL`; the JUnit XMLs total **58 suites / 531 tests / 0 failures / + 0 errors / 0 skipped** (up from 57 suites / 518 tests: the new `AttentionTest`). + +Not verified in this pass: the on-device indicator/list/finished/empty screenshots +and the phone's own notification — the brief keeps ordinary code review to the +build and the unit tests, and visual review owns the operator's Pixel 9 Pro XL. +The concrete payload delivered to the local ntfy service was reproduced by the +code review with a live curl subscriber; the device captures are visual review's. diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index e748c0f6..57e587d9 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -30,12 +30,26 @@ android:name=".MainActivity" android:exported="true" android:label="@string/app_name" + android:launchMode="singleTop" android:theme="@style/Theme.Pipelines" android:windowSoftInputMode="adjustResize"> + + + + + + +