Skip to content

feat(notifications): approval kind + handler registry - #77

Merged
pufit merged 2 commits into
ClickHouse:mainfrom
alex-fedotyev:alex/actionable-inbox-approval-kind
May 29, 2026
Merged

feat(notifications): approval kind + handler registry#77
pufit merged 2 commits into
ClickHouse:mainfrom
alex-fedotyev:alex/actionable-inbox-approval-kind

Conversation

@alex-fedotyev

Copy link
Copy Markdown
Contributor

Summary

Adds an actionable approval notification 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

  • v028 migration.notifications gains 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 code 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. Dispatcher registry keyed by target_kind. PR 1 registers one entry, mechanical-action, which shells into <workspace>/scripts/mechanical-action.sh for approve / decline / snooze_24h. Workspace resolves from $NERVE_WORKSPACE_PATH (test override) or config.workspace.
  • NotificationService.propose_action(target_kind, target_id, ...). Creates an approval notification, 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_action MCP tool. Mirrors notify / ask_user for callers that want their answer to route through a dispatcher instead of being injected back into the originating session.
  • Telegram callback parser + web card wired to the new approval kind.
  • 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.
  • Code map at 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_user already proves the actionable primitive exists end-to-end (web buttons + Telegram inline keyboard); this extends it to the approval use case so dispatching can happen server-side without needing a live agent session.

Out of scope (follow-ups)

  • Executor cron rewrite to file propose_action for 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.
  • Plan dispatcher (target_kind="plan").
  • Snooze re-delivery scheduler tick.

Test plan

  • pytest tests/test_notifications_actionable.py ; 16 tests pass locally.
  • Wider-suite check: 596 / 598 tests pass; the 2 failures are pre-existing env-detection cases in test_bootstrap and test_cli_upgrade, unrelated to this change.
  • Fresh-DB migration run: discover_migrations() returns unique versions; run_migrations() advances schema_version to 28 and creates target_kind + target_id columns plus the idx_notifications_target index.
  • End-to-end smoke from a separate agent session: 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 to mechanical-action.sh.

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.
Resolve conflicts from the runtime-agnostic tool registry refactor (ClickHouse#79)
and a migration version collision.
- nerve/agent/tools.py was deleted on main and split into the
nerve/agent/tools/ package. Ported the propose_action tool into the
new structure: PROPOSE_ACTION_SCHEMA in schemas.py, and
_parse_action_options + propose_action_handler + PROPOSE_ACTION_SPEC
in handlers/notifications.py (auto-registered via NOTIFICATION_SPECS).
The old module-level + session-scoped tool wiring is dropped; the
registry/ToolContext supply session_id, so no per-tool special-casing.
- Migration v028_notification_approval_kind collided with main's
v028_codex_message_external_id. Renamed to v029 (both are additive
ALTERs on different tables); updated docstrings, log line, test names.
- notifications/service.py auto-merged cleanly: approval answers route
through the dispatcher early in handle_answer; main's external-session
branch stays on the question path.
754 backend tests pass; frontend builds clean.
@pufit
pufit merged commit 6e117c2 into ClickHouse:mainMay 29, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@alex-fedotyev@pufit