Skip to content

feat(chat-tools): add move_event primitive with venue-change audit trail#290

Merged
chubes4 merged 1 commit into
mainfrom
feat-287-move-event
May 20, 2026
Merged

feat(chat-tools): add move_event primitive with venue-change audit trail#290
chubes4 merged 1 commit into
mainfrom
feat-287-move-event

Conversation

@chubes4
Copy link
Copy Markdown
Member

@chubes4 chubes4 commented May 20, 2026

Closes #287

Summary

Adds a dedicated move_event chat tool wrapping a new data-machine-events/move-event ability. Today, moving a show from venue X to venue Y goes through update_event { venue: <id> } — that works but loses intent ("this is specifically a venue move") and audit ("when did the venue change, why, and from what"). The move_event primitive gives the model a named tool to reach for and records the move.

New files

  • inc/Abilities/MoveEventAbilities.php — registers data-machine-events/move-event (input: event, to_venue, optional reason; output: event_id, from_venue, to_venue, start_date, recorded_at).
  • inc/Api/Chat/Tools/MoveEvent.phpmove_event chat tool wrapper extending BaseTool.

Plus a two-line bootstrap edit in data-machine-events.php to load both alongside the existing tools/abilities.

Behavior

  1. Validates the event post exists and matches Event_Post_Type::POST_TYPE.
  2. Validates the destination venue term exists in the venue taxonomy.
  3. Captures the current ("from") venue term before the change (null if none).
  4. Rejects no-op moves (current venue already equals to_venue).
  5. Delegates the venue swap to EventUpdateAbilities::executeUpdateEvent({ event, venue })no duplicated block-update logic; the underlying updateVenue() path handles the wp_set_post_terms call.
  6. Records the audit entry (see below).

Audit-log mechanism

I chose both mechanisms because they serve different consumers:

  • Post meta _dme_venue_history (publicly declared as MoveEventAbilities::VENUE_HISTORY_META_KEY) — a serialized array of entries, each capturing { from_venue_id, from_venue_name, to_venue_id, to_venue_name, reason, actor_id, recorded_at }. This gives us a durable, per-post history that any reader (admin UI, REST endpoint, future analytics digest) can introspect without subscribing to a hook.
  • do_action( 'dme_event_venue_changed', $post_id, $from_venue, $to_venue, $reason, $actor_id, $recorded_at ) — fired immediately after the meta write so listeners (other plugins, analytics writers, Slack notifiers, etc.) can react in real time without scanning post meta.

This matches the style of MergeEventPostsAbilities, which already uses do_action( 'datamachine_log', ... ) for its merge-log entry. The post-meta layer is the new piece — there was no existing _merge_log or _dme_audit precedent for the merge ability to reuse, so the meta key is fresh.

Permission shape

permission_callback is currently current_user_can( 'manage_options' ) with a TODO referencing #288:

// TODO(#288): swap to the team-member permission helper introduced
// by the permission_callback audit. For now use manage_options to
// match the rest of the EC-events surface.

Once #288 lands the team-member helper, this callback needs to be updated to match (along with update_event, delete_event, and friends).

Relationship to sibling PRs

Out of scope (matches the issue)

How to verify

Via chat

"The Sept 12 Susto show at Refinery actually moved to The Royal American — reason: venue swap announced on the band's IG. Find it and move it."

The model should:

  1. Call get_venue_events { venue: <refinery_id> } (or similar discovery) to find the post.
  2. Call move_event { event: <post_id>, to_venue: <royal_american_id>, reason: "venue swap per band IG" }.
  3. Receive the structured result with from_venue: { id, name: "Refinery" }, to_venue: { id, name: "The Royal American" }, start_date, and recorded_at.

Via WP-CLI (direct ability invocation)

wp --allow-root --path=/var/www/extrachill.com --url=events.extrachill.com \
  eval 'print_r( wp_get_ability("data-machine-events/move-event")->execute([
    "event" => 12345,
    "to_venue" => 678,
    "reason" => "venue swap test",
  ]) );'

Verifying the audit trail

wp --allow-root --path=/var/www/extrachill.com --url=events.extrachill.com \
  post meta get 12345 _dme_venue_history --format=json

Should return the array of move records, newest appended last.

Verifying the action fires

add_action( 'dme_event_venue_changed', function( $post_id, $from, $to, $reason, $actor, $when ) {
    error_log( "move_event: {$post_id} from {$from['id']} to {$to['id']} ({$reason})" );
}, 10, 6 );

Notes for reviewer

  • No release/deploy from this PR — version bumps and changelog are owned by homeboy.
  • Conventional commit (feat(chat-tools): ...) so homeboy picks up the minor bump on the next release.

Adds data-machine-events/move-event ability and a move_event chat tool
that wraps it. Use when a single event post needs its venue changed —
the model now has a named primitive for 'the show moved venues' instead
of inferring intent from a generic update_event call.

Behavior:
- Validates the event post and destination venue term.
- Captures the current ('from') venue before the change.
- Reuses EventUpdateAbilities for the actual venue swap so the
  block-update + taxonomy assignment logic is not duplicated.
- Appends an entry to post meta _dme_venue_history capturing
  { from_venue, to_venue, reason, actor_id, recorded_at }.
- Fires the dme_event_venue_changed action so listeners
  (analytics, audit log, etc.) can react.

For wrong-venue DUPLICATES (two posts exist), use delete_event
(issue #286). For generic block-attribute updates, use update_event.

Closes #287

Refs #288 — permission_callback currently uses manage_options with a
TODO; will swap to the team-member permission helper once #288 lands.
Refs #286 — sibling tool for the duplicate-post case.
@homeboy-ci
Copy link
Copy Markdown
Contributor

homeboy-ci Bot commented May 20, 2026

Homeboy Results — data-machine-events

Audit

audit — passed

  • requested_detectors — 4 finding(s)
  • test_coverage — 2 finding(s)
  • dead_code — 1 finding(s)
  • intra-method-duplication — 1 finding(s)
  • Total: 8 finding(s)

Deep dive: homeboy audit data-machine-events --changed-since 1012091

Tooling versions
  • Homeboy CLI: homeboy 0.194.0+23c18c7
  • Extension: wordpress from https://github.com/Extra-Chill/homeboy-extensions
  • Extension revision: edb75b19
  • Action: Extra-Chill/homeboy-action@v2

@chubes4 chubes4 merged commit 3e46a57 into main May 20, 2026
1 check passed
chubes4 added a commit that referenced this pull request May 20, 2026
… move-event ability (#292)

Follow-up to #290 — adopts the shared AbilityPermissions::canWrite()
helper introduced by #288/#291. #290 merged before the helper landed,
so the move-event ability shipped with a manage_options stub and a
TODO referencing #288. This swaps it to the helper to match the rest
of the EC-events surface (e.g. EventUpdateAbilities) and removes the
stale TODO.

No functional change beyond the permission_callback shape.

Refs #287, #288, #290.

Co-authored-by: homeboy-ci[bot] <266378653+homeboy-ci[bot]@users.noreply.github.com>
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.

feat(chat-tools): add move_event primitive (single-call venue change with audit trail)

1 participant