Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a167a57
Merge branch 'develop' into trunk
jeffpaul Feb 9, 2026
ecc6673
Merge branch 'develop' into trunk
jeffpaul Feb 18, 2026
f282114
Merge branch 'develop' into trunk
jeffpaul Mar 5, 2026
f9587d2
Merge branch 'develop' into trunk
jeffpaul Mar 6, 2026
1f896e2
Merge branch 'develop' into trunk
jeffpaul Mar 12, 2026
e012381
Merge branch 'develop' into trunk
jeffpaul Mar 20, 2026
47bb586
Add content guidelines service
saarnilauri Mar 30, 2026
2cba5bb
Add content guidelines helper functions
saarnilauri Mar 30, 2026
70fa876
Add content guidelines in the abstract level to the system instructions
saarnilauri Mar 30, 2026
ca188e9
Inject site and images guidelines to alt text generation ability.
saarnilauri Mar 30, 2026
c2f2797
Inject site and copy guidelines to the excerpt generation ability.
saarnilauri Mar 30, 2026
4219966
Inject site and images guidelines to the image generation ability.
saarnilauri Mar 30, 2026
a844b18
Inject site and copy guidelines to the summarization ability.
saarnilauri Mar 30, 2026
54195c1
Inject site and copy guidelines to the title generation ability.
saarnilauri Mar 30, 2026
4e49e4d
Inject site, copy, and additional guidelines to the review notes abil…
saarnilauri Mar 30, 2026
7ba4e7a
Add tests for the Content_Guidelines service class
saarnilauri Mar 30, 2026
076734f
Add integration tests for Content Guidelines support in Abstract_Ability
saarnilauri Mar 30, 2026
56a4b30
Add content guidelines e2e tests
saarnilauri Mar 30, 2026
3003b53
Add content guideline injection to image generation prompt.
saarnilauri Apr 1, 2026
c6c9881
Add a test to check the guideline category for image creation.
saarnilauri Apr 1, 2026
ef260d6
Add missing descriptions for test abilities.
saarnilauri Apr 1, 2026
d7aaa04
Remove test cases that do not fit into the test environment.
saarnilauri Apr 1, 2026
91c0434
Add tests for the guideline_categories method
saarnilauri Apr 1, 2026
5bea6f8
Add content guideline helper function tests.
saarnilauri Apr 1, 2026
e6d6f5c
Add more tests to increase coverage for guideline service
saarnilauri Apr 1, 2026
6ab3a88
Add more tests to increase coverage for review notes content guidelines.
saarnilauri Apr 1, 2026
31a0998
Merge branch 'develop' into feature/content-guidelines
saarnilauri Apr 2, 2026
6d66d5e
Merge branch 'develop' into feature/content-guidelines
dkotter Apr 2, 2026
282f82a
use statements instead of referencing the fully qualified name
saarnilauri Apr 7, 2026
a117dc3
0.7.0 -> x.x.x
saarnilauri Apr 7, 2026
7780fdb
Clean up unsupported guideline categories if present.
saarnilauri Apr 7, 2026
bd9835f
Inject the guidelines to the system instructions rather than to the u…
saarnilauri Apr 7, 2026
b38623f
0.7.0 -> x.x.x
saarnilauri Apr 7, 2026
8fc757f
Provide the block type for the system instruction abstraction
saarnilauri Apr 7, 2026
6b43853
Strip tags to ensure that possible < or > chars do not break xml stru…
saarnilauri Apr 7, 2026
21f1cce
0.7.0 -> x.x.x
saarnilauri Apr 7, 2026
73e9660
Update tests to test content guidelines in system instructions
saarnilauri Apr 7, 2026
6f12c81
Simplify the test_get_system_instruction_includes_content_guidelines …
saarnilauri Apr 7, 2026
6452ade
Add missing test descriptions.
saarnilauri Apr 7, 2026
9552d55
Remove unneeded tests
saarnilauri Apr 7, 2026
b78879c
Chores: 0.7.0 to x.x.x
saarnilauri Apr 7, 2026
a013b0a
Merge branch 'develop' into feature/content-guidelines
dkotter Apr 7, 2026
520d21a
Bump up the max length for guidelines
saarnilauri Apr 9, 2026
6d52808
Follow naming of the Gutenberg guidelines and drop the word content.
saarnilauri Apr 9, 2026
41858e3
Inject image generation guidelines to system instructions
saarnilauri Apr 9, 2026
c62d3a8
Pass the block name in the data array parameter.
saarnilauri Apr 9, 2026
96a6d31
Update the max length in the guideline test as it was bumped up to 5000
saarnilauri Apr 9, 2026
f5b8dae
Merge branch 'develop' into feature/content-guidelines
saarnilauri Apr 9, 2026
13afef2
Merge branch 'develop' into feature/content-guidelines
dkotter Apr 9, 2026
ffd0b9b
Merge branch 'develop' into feature/content-guidelines
saarnilauri Apr 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions includes/Abilities/Excerpt_Generation/Excerpt_Generation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
*/
class Excerpt_Generation extends Abstract_Ability {

/**
* {@inheritDoc}
*
* @since x.x.x
*/
protected function guideline_categories(): array {
return array( 'site', 'copy' );
}

/**
* {@inheritDoc}
*
Expand Down
9 changes: 9 additions & 0 deletions includes/Abilities/Image/Alt_Text_Generation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ class Alt_Text_Generation extends Abstract_Ability {
*/
private const DECORATIVE_ALT_TOKEN = '[[DECORATIVE_ALT]]';

/**
* {@inheritDoc}
*
* @since x.x.x
*/
protected function guideline_categories(): array {
return array( 'site', 'images' );
}

/**
* {@inheritDoc}
*
Expand Down
17 changes: 17 additions & 0 deletions includes/Abilities/Image/Generate_Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
*/
class Generate_Image extends Abstract_Ability {

/**
* {@inheritDoc}
*
* @since x.x.x
*/
protected function guideline_categories(): array {
return array( 'site', 'images' );
}

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -244,6 +253,14 @@ private function get_prompt_builder( string $prompt, ?string $reference_image =
->as_output_file_type( FileTypeEnum::inline() )
->using_model_preference( ...get_preferred_image_models() );

// Inject guidelines as a system instruction to match other abilities.
$guidelines = $this->get_guidelines_for_prompt();
if ( $guidelines ) {
$instruction = 'The following guidelines represent the site&#039;s editorial standards. Apply them where relevant. Do not fabricate content to satisfy guidelines. If guidelines conflict with the input, prioritize accuracy.';
$instruction .= "\n\n" . $guidelines;
$prompt_builder->using_system_instruction( $instruction );
}

if ( null !== $reference_image ) {
try {
$file = new File( $reference_image );
Expand Down
9 changes: 9 additions & 0 deletions includes/Abilities/Image/Generate_Image_Prompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
*/
class Generate_Image_Prompt extends Abstract_Ability {

/**
* {@inheritDoc}
*
* @since x.x.x
*/
protected function guideline_categories(): array {
return array( 'site', 'images' );
}

/**
* {@inheritDoc}
*
Expand Down
18 changes: 14 additions & 4 deletions includes/Abilities/Review_Notes/Review_Notes.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ class Review_Notes extends Abstract_Ability {
* @var list<string>
*/
// phpcs:ignore SlevomatCodingStandard.Classes.DisallowMultiConstantDefinition.DisallowedMultiConstantDefinition
protected const SUPPORTED_REVIEW_TYPES = array( 'accessibility', 'readability', 'grammar', 'seo' );
protected const SUPPORTED_REVIEW_TYPES = array( 'accessibility', 'readability', 'grammar', 'seo', 'guidelines' );

/**
* {@inheritDoc}
*
* @since x.x.x
*/
protected function guideline_categories(): array {
return array( 'site', 'copy', 'additional' );
}

/**
* {@inheritDoc}
Expand Down Expand Up @@ -292,7 +301,7 @@ protected function generate_review(
) {
$prompt = $this->create_prompt( $block_type, $block_content, $context, $existing_notes, $review_types );

$prompt_builder = $this->get_prompt_builder( $prompt );
$prompt_builder = $this->get_prompt_builder( $prompt, $block_type );

if ( is_wp_error( $prompt_builder ) ) {
return $prompt_builder;
Expand Down Expand Up @@ -357,11 +366,12 @@ protected function generate_review(
* @since 0.7.0
*
* @param string $prompt The prompt to generate review notes from.
* @param string $block_type The block type identifier.
* @return \WP_AI_Client_Prompt_Builder|\WP_Error The prompt builder, or a WP_Error on failure.
*/
private function get_prompt_builder( string $prompt ) {
private function get_prompt_builder( string $prompt, string $block_type ) {
$prompt_builder = wp_ai_client_prompt( $prompt )
->using_system_instruction( $this->get_system_instruction() )
->using_system_instruction( $this->get_system_instruction( null, array( 'block_name' => $block_type ) ) )
->using_model_preference( ...get_preferred_models_for_text_generation() )
->as_json_response( $this->suggestions_schema() );

Expand Down
4 changes: 4 additions & 0 deletions includes/Abilities/Review_Notes/system-instruction.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@
- grammar: Flag clear grammar issues in the quoted text itself

For all other block types, apply readability, and grammar checks if text content is present.

## Guidelines Review

If guidelines are provided in <guidelines> tags, evaluate the block content against these guidelines. Flag material violations of the editorial standards as suggestions with review_type "guidelines". Only flag clear, objective violations — not minor style preferences. If block-specific guidelines are provided, prioritize those over general guidelines for the block being reviewed.
INSTRUCTION;
9 changes: 9 additions & 0 deletions includes/Abilities/Summarization/Summarization.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ class Summarization extends Abstract_Ability {
*/
protected const LENGTH_DEFAULT = 'medium';

/**
* {@inheritDoc}
*
* @since x.x.x
*/
protected function guideline_categories(): array {
return array( 'site', 'copy' );
}

/**
* {@inheritDoc}
*
Expand Down
9 changes: 9 additions & 0 deletions includes/Abilities/Title_Generation/Title_Generation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
*/
class Title_Generation extends Abstract_Ability {

/**
* {@inheritDoc}
*
* @since x.x.x
*/
protected function guideline_categories(): array {
return array( 'site', 'copy' );
}

/**
* {@inheritDoc}
*
Expand Down
71 changes: 67 additions & 4 deletions includes/Abstracts/Abstract_Ability.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use WP_Ability;
use WP_Error;

use function WordPress\AI\format_guidelines_for_prompt;

/**
* Base implementation for a WordPress Ability.
*
Expand Down Expand Up @@ -102,20 +104,81 @@ abstract protected function permission_callback( $input );
*/
abstract protected function meta(): array;

/**
* Returns the guideline categories this ability uses.
*
* Override in subclasses to opt into guidelines.
* Return an empty array to skip guidelines (default).
*
* Valid categories: 'site', 'copy', 'images', 'additional'.
*
* @since x.x.x
*
* @return list<string> Guideline category slugs.
*/
protected function guideline_categories(): array {
return array();
}

/**
* Returns formatted guidelines for prompt injection.
*
* Uses guideline_categories() to determine which categories to include.
* Unsupported categories are silently dropped.
* Returns empty string when guidelines are unavailable or no categories declared.
*
* @since x.x.x
*
* @param string|null $block_name Optional block name for block-specific guidelines.
* @return string Formatted guidelines XML string, or empty string.
*/
protected function get_guidelines_for_prompt( ?string $block_name = null ): string {
$categories = array_values(
array_intersect(
$this->guideline_categories(),
array( 'site', 'copy', 'images', 'additional' )
)
);
if ( empty( $categories ) ) {
return '';
}
return format_guidelines_for_prompt( $categories, $block_name );
}

/**
* Gets the system instruction for the feature.
*
* When guideline_categories() returns a non-empty array and guidelines are
* available, automatically appends them to the system instruction.
*
* Supports a reserved `block_name` key in `$data` for block-specific guidelines.
*
* @since 0.1.0
*
* @param string|null $filename Optional. Explicit filename to load. If not provided,
* attempts to load `system-instruction.php` or `prompt.php`.
* @param array<string, mixed> $data Optional. Data to expose to the system instruction file.
* This data will be extracted as variables available in the file scope.
* @param string|null $filename Optional. Explicit filename to load. If not provided,
* attempts to load `system-instruction.php` or `prompt.php`.
* @param array<string, mixed> $data Optional. Data to expose to the system instruction file.
* This data will be extracted as variables available in the file scope.
* @return string The system instruction for the feature.
*/
public function get_system_instruction( ?string $filename = null, array $data = array() ): string {
$block_name = null;
if ( isset( $data['block_name'] ) && is_string( $data['block_name'] ) ) {
$block_name = $data['block_name'];
unset( $data['block_name'] );
}

$instruction = $this->load_system_instruction_from_file( $filename, $data );

if ( '' !== $instruction && ! empty( $this->guideline_categories() ) ) {
$guidelines = $this->get_guidelines_for_prompt( $block_name );

if ( $guidelines ) {
$instruction .= "\n\n" . 'The following guidelines represent the site&#039;s editorial standards. Apply them where relevant. Do not fabricate content to satisfy guidelines. If guidelines conflict with the input, prioritize accuracy.';
$instruction .= "\n\n" . $guidelines;
}
}

/**
* Filters the system instruction for an ability.
*
Expand Down
Loading
Loading