Skip to content

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Sep 3, 2025

Illustration for the ideas to make abilities more extensible:

This PR adds extensibility hooks to the ability execution flow by introducing two action hooks that fire before and after ability execution. This allows developers to hook into the ability lifecycle for monitoring, logging, or extending functionality.

  • Added before_execute_ability action hook that fires before ability execution
  • Added after_execute_ability action hook that fires after successful ability execution
  • Refactored the return logic to properly handle validation errors and execute the post-execution hook only on success. It is up for debate what to do on error.

Example Usage

Basic Logging

// Log all ability executions.
add_action( 'before_execute_ability', function( $ability_name, $input ) {
    error_log( 'Executing ability: ' . $ability_name );
    if ( $input !== null ) {
        error_log( 'Input: ' . wp_json_encode( $input ) );
    }
}, 10, 2 );

add_action( 'after_execute_ability', function( $ability_name, $input, $result ) {
    error_log( 'Completed ability: ' . $ability_name );
    error_log( 'Result: ' . wp_json_encode( $result ) );
}, 10, 3 );

@gziolo gziolo self-assigned this Sep 3, 2025
@gziolo gziolo added [Type] Enhancement New feature or request [Status] In Progress Assigned work scheduled labels Sep 3, 2025
@gziolo gziolo requested a review from Copilot September 3, 2025 11:39
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds extensibility hooks to the ability execution flow by introducing two action hooks that fire before and after ability execution. This allows developers to hook into the ability lifecycle for monitoring, logging, or extending functionality.

  • Added before_execute_ability action hook that fires before ability execution
  • Added executed_ability action hook that fires after successful ability execution
  • Refactored the return logic to properly handle validation errors and execute the post-execution hook only on success

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

codecov bot commented Sep 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.84%. Comparing base (e48d165) to head (3845992).
⚠️ Report is 1 commits behind head on trunk.

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk      #56      +/-   ##
============================================
+ Coverage     83.33%   83.84%   +0.51%     
  Complexity       96       96              
============================================
  Files             8        8              
  Lines           516      520       +4     
============================================
+ Hits            430      436       +6     
+ Misses           86       84       -2     
Flag Coverage Δ
unit 83.84% <100.00%> (+0.51%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@justlevine justlevine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gziolo I know you marked as draft, but honestly this feels pretty close to mergeable.

(Unlike my filter feedback on #37 . an action should trigger every time ::do_execute() is run vs 1x).

Only question is whether we want to pass the \WP_Error to the filter as well to allow. Not necessary (WPError have their own built-in hooks), and doing this in the future is non-breaking, but it would allow for recoverability flows.

(e.g. if we're MCP and this is an input error, filter to try and coerce the shapes, but if its REST then you to rest_ensure_response( $error ) ).

@gziolo
Copy link
Member Author

gziolo commented Sep 15, 2025

I know you marked as draft, but honestly this feels pretty close to mergeable.

I will work on tests and documentation before marking it as fully ready for review.

@gziolo gziolo force-pushed the add/execute-actions branch from 9cbf10c to 485ac3b Compare September 17, 2025 10:07
@gziolo gziolo marked this pull request as ready for review September 17, 2025 10:07
@gziolo gziolo removed the [Status] In Progress Assigned work scheduled label Sep 17, 2025
Copy link

github-actions bot commented Sep 17, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: gziolo <[email protected]>
Co-authored-by: justlevine <[email protected]>
Co-authored-by: jonathanbossenger <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@gziolo gziolo requested a review from Copilot September 17, 2025 10:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@gziolo gziolo requested a review from justlevine September 17, 2025 10:19
Copy link
Contributor

@justlevine justlevine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left some nonblocking doc nits. 🚀

@gziolo
Copy link
Member Author

gziolo commented Sep 17, 2025

I will wait for a reply about the docs before landing.

Copy link
Contributor

@jonathanbossenger jonathanbossenger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small suggestion, otherwise it all looks good from a docs perspective.

gziolo and others added 6 commits September 19, 2025 12:58
- Add before_execute_ability action that fires before ability execution
- Add after_execute_ability action that fires after successful execution
- Include comprehensive unit tests for both actions with edge cases
- Add extensibility documentation with usage examples and best practices
- Update README with new documentation link
- Fix PHPDoc formatting for action parameters

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Co-authored-by: Dovid Levine <[email protected]>
@gziolo gziolo force-pushed the add/execute-actions branch from 2df0b39 to 3845992 Compare September 19, 2025 11:06
@gziolo gziolo enabled auto-merge (squash) September 19, 2025 11:07
@gziolo
Copy link
Member Author

gziolo commented Sep 19, 2025

Just to let you know, all feedback has been addressed in 3845992. I enabled auto-merge.

@gziolo gziolo merged commit c9abf12 into trunk Sep 19, 2025
18 checks passed
@gziolo gziolo deleted the add/execute-actions branch September 19, 2025 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants