Skip to content

PoC: consume the wordpress/abilities package for the core-facing abilities (roadmap step 2 of #1289) - #1333

Draft
nikmclaughlin wants to merge 5 commits into
WordPress:developfrom
nikmclaughlin:poc/consume-wordpress-abilities
Draft

nikmclaughlin wants to merge 5 commits into
WordPress:developfrom
nikmclaughlin:poc/consume-wordpress-abilities

Conversation

@nikmclaughlin

@nikmclaughlin nikmclaughlin commented Nov 8, 2026 •

Copy link
Copy Markdown

Summary

Tests consumption of the wordpress-abilities package from its current location to provide core-facing abilities for the Custom Abilities experiment.

⚠️ This PR is not a merge candidate. It is a design-feedback draft. The package (wordpress-abilities) is still under personal ownership (nikmclaughlin/wordpress-abilities). On approval, the package will be moved to a WordPress-owned repository.

The vendored set of abilities in includes/Vendor/Abilities/ pins 3afb1e7 of nikmclaughlin/wordpress-abilities, which is the same package as the sibling MCP-adapter PoC WordPress/mcp-adapter#430, but a different pin. The version used here includes two additional PRs on top of the MCP Adapter ref (15 and 16) which cover gaps discovered in this work.

Why?

The AI plugin is the original staging ground for core abilities. core/content-query, core/users-query, and core/settings-get are maintained here as near-verbatim class copies of core's WP_Abilities_{Content,Users,Settings} (synced by hand at 1.5.0 through #1206/#1207/#1208), with the rest of the core-facing set in flight as open PRs. Every option integrators have today (wait for core; depend on the whole AI plugin; fork and re-sync) is a downside the central package removes. That argument is in #1289. This PoC proves the consumption pattern end to end in this plugin to aid in that discussion.

What the PoC demonstrates:

  1. No more sync churn — the package provides a backport pipeline (coreify tooling) that centralizes and streamlines drift maintenance
  2. Conflict policy lands wholesale — decisions such as "stand down when core (or anyone) already provides the ability" (Only register the plugin's copies of core/settings-get, core/users-query and core/content-query when WordPress core does not provide them #1240 / PR Abilities: Only register the plugin's copies of core abilities when WordPress core does not provide them #1251) are made in one place and encoded in the package Registrar's Gate. The Registrar resolves availability before any consumer selection, so a consumer filter can never veto a core-provided name.
  3. Multi-copy arbitration works — This plugin and the MCP Adapter companion bundle the package differently, so running both together allows us to confirm arbitration behavior (Action-Scheduler-inspired pattern: newest-registered-copy-wins, frozen function contract, lazy resolution).

How?

Everything rides on the Custom Abilities experiment (its default-off gating is unchanged):

  • ai.php — after the autoloader require, requires the vendored copy's wordpress-abilities-loader.php and calls wordpress_abilities_register( '0.1.0', ... ) at plugin file scope. The loader only records the copy, classes resolve lazily, and no WordPress\Abilities\ PSR-4 prefix is added to includes/autoload.php. The loader's spl autoloader handles multi-copy arbitration.
  • Custom_Abilities::register() — after the gated-ability loop, registers the package via Registrar::register_all(), behind two new filters: wpai_register_wordpress_abilities (bool, default true) and wpai_wordpress_abilities_args. These adapt the existing wpai_gated_abilities behavior, though constitute a breaking change (discussed below).
  • Gated_Abilities — the default registry trims to Post_Utilities only. ai/get-post-terms + the deprecated ai/get-post-details keep working exactly as before.
  • Deleted: — the trio classes (includes/Abilities/{Content,Users,Settings}/), their gated wrappers, Show_In_Abilities, and their PHPUnit suites. The package ships the equivalent polyfills, its Registrar carries the stand-down, and its per-ability suites plus this plugin's consumption test. The plugin's e2e specs are untouched to ensure parity across migration.
  • Unchanged — internal consumers: the core abilities/v1 REST routes, the Abilities Explorer, the MCP Access experiment, the CLI, and the whole ai/* feature surface. No new abilities, no UI.

⚠️ Changes to the wpai_gated_abilities semantics

Today the wpai_gated_abilities filter can add, remove, and replace the core-facing abilities because their classes are in-repo. After this migration they are not plugin classes anymore, so the filter keeps a narrower shape:

  • Additions keep working unchanged — a third-party class-string extending Abstract_Gated_Ability registers as before, including through the requires_core_object_exposure() path.
  • Removals/replacements of package abilities no longer work through this filter — there is no plugin class to remove. The PoC ships the replacement shape: wpai_wordpress_abilities_args → Registrar::register_all() args, whose filter callable does the per-ability selection. This selection filter can never veto core-provided names, matching Only register the plugin's copies of core/settings-get, core/users-query and core/content-query when WordPress core does not provide them #1240, and public_only narrows to meta.public. The wordpress_abilities_declare_categories filter (package-side contract) provides a filtering options for category declarations.
  • . The wpai_gated_abilities examples in the docs and the Gated_Abilities tests were updated to the new boundary with a breaking-change note in the changelog entry.

Use of AI Tools

AI assistance: Yes
Tools: goose agent for planning and implementation
Models (via Ollama cloud):

  • GLM 5.3 for planning and orchestration,
  • GLM 5.3 Flash for implementation, validation, and testing.

Used for: Implementation and tests of this PoC, driven fully by an approved written plan. The orchestrator and validator agents reviewed the work, while test gates were run on the plugin's own tooling.

Testing Instructions

Gates used for this branch (all four from the repo's own tooling):

  1. composer install + asset build first (npm run build — the asset-dependent suites fail without it, identically on develop, so it is a dev-setup step, not a PoC result).
  2. npm run lint:php → phpcs clean (the vendored path is pre-excluded).
  3. npm run lint:php:stan → PHPStan level 8 clean.
  4. npm run test:php → 2441 tests, 0 errors, 0 failures, 53 skipped. The three ability test classes are the PoC's core: WordpressAbilitiesConsumptionTest (12 tests: registration + provenance, Only register the plugin's copies of core/settings-get, core/users-query and core/content-query when WordPress core does not provide them #1240/Abilities: Only register the plugin's copies of core abilities when WordPress core does not provide them #1251 conflict semantics, Registrar-declared categories + Gate-8 opt-out, REST list/run parity incl. a core/content-create → core/content-query round-trip, experiment gating, both new filters + the wpai_gated_abilities boundary, polyfill exposure, idempotence), Custom_AbilitiesTest, Gated_AbilitiesTest.
  5. npm run test:e2e -- tests/e2e/specs/abilities/ → all 23 existing specs pass, untouched — identical names, schemas, and permission behavior is the strongest parity signal the migration is behavior-preserving.
  6. Quick sanity in the running wp-env: wp eval 'var_dump( wordpress_abilities_loaded_version() );' → 0.1.0 after any package class resolution; with the experiment enabled, wp_has_ability( 'core/content-query' ) → true with provenance meta (source = wordpress/abilities, package_version = 0.1.0).

Manual checks mirroring the plan's §8 are listed in the updated docs/experiments/custom-abilities.md (enable/disable, Explorer listing, wpai_gated_abilities extension, selection via wpai_wordpress_abilities_args).

Changelog Entry

Changed - The core-facing abilities (the core/content-query, core/users-query, and core/settings-get queries and the rest of the core/* and wp/* ability set) are now provided by the wordpress/abilities package and registered through its Registrar when the Custom Abilities experiment is enabled. On WordPress 7.2+, core's own copies are used without overriding them. Breaking change: the wpai_gated_abilities filter can no longer remove or replace core-facing package abilities; their selection policy is the new wpai_wordpress_abilities_args filter (passed to the package Registrar, whose filter callable can never veto core-provided abilities), and the registration itself can be skipped with wpai_register_wordpress_abilities.

Cross-references

Open Questions

  • Replacing wpai_gated_abilities selection filter: is the args pass-through implemented here a suitable replacement for the existing selection?
Open WordPress Playground Preview

Pin a snapshot of nikmclaughlin/wordpress-abilities @ 3afb1e7 (main + PR WordPress#12
add/mcp-public-meta + PR WordPress#15 add/trio-show-in-rest + PR WordPress#16 add/trio-trunk-sync):
src/, the optional multi-copy arbitration loader, composer.json, LICENSE, and a
VENDORED.md recording the pin, the in/out set, the PoC swap-out path, and the
arbitration contract. This is the PoC dependency of roadmap step 2 in
WordPress/ai WordPress#1289; not a merge candidate for production (see VENDORED.md for
the named swap-out path).

PoC for WordPress#1289 (package consumption) — not for merge.
…lete the in-repo copies

- ai.php: require the vendored package's arbitration loader at file scope and
  register the copy (wordpress_abilities_register('0.1.0', ...)); newest-copy
  wins lazily, keeping the plugin + MCP adapter bundle safe.
- Custom_Abilities::register(): after the gated-ability loop, register the
  package through Registrar::register_all(), behind two new filters:
  wpai_register_wordpress_abilities (bool, default true) and
  wpai_wordpress_abilities_args (array, passed to the Registrar; its
  callable is the per-ability selection policy). The experiment's default-off
  gate is unchanged. The requires_core_object_exposure() conditional now loads
  the package's support polyfills for third-party gated abilities (the
  Show_In_Abilities replacement).
- Gated_Abilities: default registry trimmed to Post_Utilities only.
- Delete the in-repo trio and wrappers (Content, Users, Settings, their gated
  wrappers) and the Show_In_Abilities polyfill: the package ships equivalent
  polyfills, its Registrar carries the Gate-2 stand-down (WordPress#1240/WordPress#1251
  semantics), and it stamps provenance meta. Delete, don't dormant (P4).

PoC for WordPress/ai WordPress#1289 — not for merge.
- New tests/Integration/Includes/Abilities/WordpressAbilitiesConsumptionTest:
  all 18 package abilities register with provenance meta while the experiment
  is enabled; a pre-registered core/content-query is kept, not overridden
  (WordPress#1240/WordPress#1251 acceptance criteria pinned in the plugin for the first time);
  the Registrar declares the content/media categories; the declare-categories
  opt-out leaves package-categorized abilities loudly unregistered (Gate 8);
  the REST abilities v1 list route serves the package set with provenance and
  a REST run of core/content-query round-trips a post created through
  core/content-create; the experiment gate stops every package registration
  and hook when off; both wpai filters and the wpai_gated_abilities boundary
  behavior; polyfill exposure for third-party gated abilities; idempotent
  re-registration with no notices. Mirrors the MCP-adapter PoC's consumption
  suite, adapted to the experiment gating (fresh registration windows via
  reflection, as the package's own RegistrarTest does).
- Update Custom_AbilitiesTest for the queued package registration.
- Update Gated_AbilitiesTest for the trimmed registry.
- Delete the trio's and Show_In_Abilities's PHPUnit suites with their classes.

PoC for WordPress/ai WordPress#1289 — not for merge.
Rewrite docs/experiments/custom-abilities.md for the new shape: the registry
resolves to plugin-owned utilities plus the package registration via the
Registrar; document wpai_register_wordpress_abilities and
wpai_wordpress_abilities_args, the wpai_gated_abilities boundary change
(additions still work; package abilities are no longer in that filter), the
Registrar's category declarations, core-provided stand-down, provenance meta,
and the removal of Show_In_Abilities in favor of the package's polyfills.

CHANGELOG: note the core-facing abilities move to the wordpress/abilities
package, the core-provided stand-down on 7.2+, and the wpai_gated_abilities
breaking change.

PoC for WordPress/ai WordPress#1289 — not for merge.
@codecov

codecov Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.93%. Comparing base (4aea8f6) to head (05faafd).

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #1333      +/-   ##
=============================================
- Coverage      85.03%   83.93%   -1.11%     
+ Complexity      4832     4471     -361     
=============================================
  Files            190      183       -7     
  Lines          17950    16590    -1360     
=============================================
- Hits           15263    13924    -1339     
+ Misses          2687     2666      -21     
Flag Coverage Δ
unit 83.93% <100.00%> (-1.11%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

The sibling PoC (WordPress/mcp-adapter WordPress#430) pins the package at 00d65cf
(main + PR WordPress#12); this PoC pins 3afb1e7 (main + WordPress#12 + the trio stack WordPress#15/WordPress#16).
Same package, same lineage base, different pin — correct the earlier
'shared single integration ref' wording.
@dkotter

dkotter commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Left this comment on the issue and realized I should have left it here but any reason to not consume this package as a composer dependency as opposed to copying all the code in?

@euvoor

euvoor commented Nov 10, 2026

Copy link
Copy Markdown

I found a gap in the shared loading contract when comparing this with WordPress/mcp-adapter#430. The snapshots differ (3afb1e7 here, 00d65cf there), but both declare 0.1.0. With the actual pinned classes and this loader, reversing the registration order selects a different Content_Query implementation while reporting the same loaded version.

The adapter draft also exposes WordPress\Abilities\ through Composer/Jetpack instead of this registration path. A separate PSR-4 loader can serve the older class before the arbitrator gets a chance; I reproduced that in a small PHP test. I haven't tested a full two-plugin boot.

Could we give different runtime revisions distinct versions and test both plugins active in both load orders before settling on the loading contract? Those tests should also cover the AI experiment being disabled while the adapter remains active.

Checked against 05faafd here and 3176cc8 in the adapter.

@jeffpaul jeffpaul added this to the 1.6.0 milestone Nov 10, 2026
@jeffpaul jeffpaul linked an issue Nov 10, 2026 that may be closed by this pull request
1 task done
@nikmclaughlin

Copy link
Copy Markdown
Author

Thanks @euvoor, the two PoCs were pinned to different commits to account for historical drift so that each individual PoC could function in the current "staging" state while my abilities package is an untagged, personally-owned, stacked-on-open-PRs package. Basically, all of that is why this PoC is marked as "not a merge candidate" 😅 Once we move the package to a WP-owned repo we can begin versioning and including as a composer dependency rather than the vendoring approach used here.

In my own tests, the package's arbitration loader and JP autoloader used in the MCP Adapter were both able to ensure only the latest version was loaded, though further testing is welcome there, especially once the package moves to core ownership.

@euvoor

euvoor commented Nov 10, 2026

Copy link
Copy Markdown

Thanks @nikmclaughlin, that explains the temporary pins. I checked the package loader with distinct version labels, and it selects the newer copy in either registration order.

The case I’d like to verify next is the interaction with the plugins’ actual autoloaders. In a small Composer-only reproduction, prepending the older copy’s loader serves its Content_Query before arbitration runs. I haven’t reproduced that through the full MCP/Jetpack bootstrap.

I can put together a co-installation test covering both plugin load orders, different bundled versions, and the AI experiment disabled while MCP stays active. It would check the files actually defining the classes and the resulting ability registration/discovery. That should give us concrete coverage for the Composer migration.

@nikmclaughlin

Copy link
Copy Markdown
Author

Thanks @euvoor , I'm preparing the repo for transfer now, then we'll need a proper composer publish under the 'WordPress' org before it can be consumed there. Any reason for your tests to be needed before any of that, or would you be okay running the test on the final PR before the new dependency gets merged into the plugin?

@euvoor

euvoor commented Nov 11, 2026

Copy link
Copy Markdown

That timing works for me, @nikmclaughlin. No need to hold up the transfer or Composer publication for these tests.

I’ll run the co-installation checks against the final dependency PR before it merges: both plugin load orders, different bundled versions, and the AI experiment disabled while MCP stays active. That will let us verify class loading and ability registration/discovery with the package and autoloaders that will actually ship.

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.

Proposal: Use wordpress-abilities as central ability provider

4 participants