Skip to content

feat(notifications): take_over decision in mechanical-action dispatcher#85

Open
alex-fedotyev wants to merge 2 commits into
ClickHouse:mainfrom
alex-fedotyev:alex/conflict-resolution-take-over-dispatcher
Open

feat(notifications): take_over decision in mechanical-action dispatcher#85
alex-fedotyev wants to merge 2 commits into
ClickHouse:mainfrom
alex-fedotyev:alex/conflict-resolution-take-over-dispatcher

Conversation

@alex-fedotyev
Copy link
Copy Markdown
Contributor

Stacks on #77. Adds take_over as a fourth accepted decision in the
mechanical-action dispatcher, alongside approve, decline, and
snooze_24h. The dispatcher shells out to
mechanical-action.sh take-over <id> --note <text>, which moves a
cron'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
options argument on propose_action.

Test plan

  • pytest tests/test_notifications_actionable.py (17 tests pass)
  • New test_dispatcher_accepts_take_over asserts:
    • dispatcher returns ok=True for take_over
    • audit event records decision=take_over
    • shell argv is [take-over, <id>, --note, <text>]
  • Manual smoke after merge: file a synthetic propose_action with the
    four-button option set, click Take over from Telegram, confirm the
    audit log gets a took-over event and the queue file moves to
    decisions/.

Dependency

nerve/notifications/handlers.py doesn't exist on main yet; #77
introduces 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.

alex-fedotyev and others added 2 commits May 19, 2026 19:51
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.
Sign up for free to 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.

1 participant