feat(notifications): take_over decision in mechanical-action dispatcher#85
Open
alex-fedotyev wants to merge 2 commits 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.
Adds 'take_over' as a fourth accepted decision (alongside approve,
decline, snooze_24h) in the mechanical-action dispatcher registry.
Routes to 'mechanical-action.sh take-over <id> --note <text>', which
moves the cron's scratch draft worktree into the per-PR worktrees
directory so the user can finish the resolution by hand.
This unblocks the third button on conflict-resolution TAP cards.
The button itself is filed by the watcher cron's draft orchestrator
once the workspace-side conflict-resolution pipeline lands; this PR
ships the server-side handler so the button has somewhere to route.
The default approval options exposed by propose_action stay at
{approve, decline, snooze_24h} - callers that want the four-button
set explicitly opt in via the 'options' argument.
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.
Stacks on #77. Adds
take_overas a fourth accepted decision in themechanical-action dispatcher, alongside
approve,decline, andsnooze_24h. The dispatcher shells out tomechanical-action.sh take-over <id> --note <text>, which moves acron's scratch draft worktree into the per-PR worktrees directory so
the user can finish a conflict resolution by hand.
This is the server-side handler for the third button on
conflict-resolution TAP cards. The button itself is filed by a
watcher cron's draft orchestrator once the workspace-side
conflict-resolution pipeline lands; this PR ships the dispatch
target so the button has somewhere to route.
The default approval options stay at
{approve, decline, snooze_24h}.Callers that want the four-button set opt in explicitly via the
optionsargument onpropose_action.Test plan
pytest tests/test_notifications_actionable.py(17 tests pass)test_dispatcher_accepts_take_overasserts:ok=Truefortake_overdecision=take_over[take-over, <id>, --note, <text>]four-button option set, click Take over from Telegram, confirm the
audit log gets a
took-overevent and the queue file moves todecisions/.Dependency
nerve/notifications/handlers.pydoesn't exist on main yet; #77introduces it. This PR adds to the same file. If #77 lands first
this becomes a clean stacked addition; if review prefers to land
both as one, fold the diff into #77 and close this one.