feat(notifications): approval kind + handler registry#77
Open
alex-fedotyev wants to merge 1 commit into
Open
Conversation
Adds an actionable notification kind that routes the user's answer to
a server-side dispatcher instead of injecting it back into the
originating session. PR 1 of the actionable-inbox series.
What it ships:
- v028 migration: notifications gain target_kind + target_id columns
and an index on (target_kind, target_id). Existing rows are left
with NULL target_kind, which the answer routing treats as the
legacy session-injection path. type=approval is the third valid
type value alongside notify and question.
- NotificationStore: create_notification accepts target_kind +
target_id. New snooze_notification(id, expires_at) advances the
row's expiry while keeping it pending so a later re-delivery tick
can surface it again.
- nerve/notifications/handlers.py: a dispatcher registry keyed by
target_kind. PR 1 registers one entry, mechanical-action, which
shells into <workspace>/scripts/mechanical-action.sh for the
approve / decline / snooze_24h decisions. Workspace resolves from
\$NERVE_WORKSPACE_PATH (test override) or config.workspace.
- NotificationService gains propose_action(target_kind, target_id,
title, options, ...). handle_answer detects type=approval and
routes through the registry, appending an approval-acted event to
~/.nerve/mechanical-actions/audit.jsonl so the proposal lifecycle
(proposed -> approval-acted -> approved/declined/executed) is
visible in one place. The legacy question path is unchanged.
- propose_action MCP tool (module-level + session-scoped) mirrors
ask_user with target_kind + target_id required and an options arg
accepting {label, value} pairs.
- Telegram delivery reuses the existing notif:{id}:{value} callback
format and the existing CallbackQueryHandler. Approval buttons
render with emoji prefixes (Approve / Decline / Snooze 24h);
the canonical value still flows back on the callback so the
dispatcher sees a stable key.
- Web NotificationCard renders type=approval with kind-styled buttons
(emerald approve, red decline, neutral snooze) and surfaces the
target identifier under the body. NotificationToast picks up the
same approval styling. The notification store now ships option
labels alongside option values so labels can be renamed without
changing callback payloads.
- 16 backend tests cover schema, store, propose_action shape, the
approve / decline / snooze dispatch paths, the no-dispatcher
fallback, and confirm the question path still flows through the
session-injection branch.
Out of scope (PR 2): workspace executor cron rewrite to file
propose_action for mechanical-action TAPs, the plan dispatcher, and
the snooze re-delivery scheduler tick. PR 1 ships only the Nerve-
side surface so the cron rewrite has a stable contract to call.
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
Adds an actionable
approvalnotification kind to Nerve so cron-filed TAPs surface on Telegram + web as inline Approve / Decline / Snooze buttons instead of plain copy-paste prose. PR 1 of the actionable-inbox series; ships the server-side surface so a follow-up cron-prompt rewrite can route the four urgent TAP action types through it.What this PR ships
notificationsgainstarget_kind+target_idcolumns and an index on(target_kind, target_id). Existing rows are left withNULL target_kind, which the answer-routing code treats as the legacy session-injection path.type=approvalis the third validtypevalue alongsidenotifyandquestion.create_notificationacceptstarget_kind+target_id. Newsnooze_notification(id, expires_at)advances the row's expiry while keeping it pending so a later re-delivery tick can surface it again.nerve/notifications/handlers.py. Dispatcher registry keyed bytarget_kind. PR 1 registers one entry,mechanical-action, which shells into<workspace>/scripts/mechanical-action.shforapprove/decline/snooze_24h. Workspace resolves from$NERVE_WORKSPACE_PATH(test override) orconfig.workspace.NotificationService.propose_action(target_kind, target_id, ...). Creates anapprovalnotification, delivers to Telegram with an inline keyboard and to the web with the same approval styling. Option labels live alongside option values so labels can be renamed without changing callback payloads.propose_actionMCP tool. Mirrorsnotify/ask_userfor callers that want their answer to route through a dispatcher instead of being injected back into the originating session.approvalkind.propose_actionshape, the approve / decline / snooze dispatch paths, the no-dispatcher fallback, and confirm thequestionpath still flows through the session-injection branch.notes/repo-conventions/nerve/notifications.md.Why first
Today the executor cron emits plain
[TAP]notifications whose bodies are shell commands. On Telegram that means copy-paste into a terminal; no inline button.ask_useralready proves the actionable primitive exists end-to-end (web buttons + Telegram inline keyboard); this extends it to theapprovaluse case so dispatching can happen server-side without needing a live agent session.Out of scope (follow-ups)
propose_actionfor the four urgent TAP action types (ci.fix-mechanical,ee.merge-followup,meta.config-edit,github.rebase-pr). Single YAML edit in/root/.nerve/cron/jobs.yaml; tracked separately because it touches the live cron prompt rather than Nerve code.target_kind="plan").Test plan
pytest tests/test_notifications_actionable.py; 16 tests pass locally.test_bootstrapandtest_cli_upgrade, unrelated to this change.discover_migrations()returns unique versions;run_migrations()advancesschema_versionto 28 and createstarget_kind+target_idcolumns plus theidx_notifications_targetindex.propose_action(target_kind="mechanical-action", target_id=<id>, ...)creates an approval notification, delivers to Telegram + web with the inline keyboard, and the dispatcher routes the answer tomechanical-action.sh.