feat: write results warn about sections built like a library section (spec §5.5)

SimilarSections compares inserted sections (not global instances) with
at most 200 editable library section entries by structure fingerprint,
read lazily once per request, only while library IDs may be named (P13).
lit/library-insert is not asked.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-27 21:16:16 +02:00
co-authored by Claude Opus 5.5
parent f82964f617
commit 4f70886006
6 changed files with 260 additions and 6 deletions
+10 -3
View File
@@ -14,6 +14,7 @@ use LIT\MCP\Integrations\Divi\BlockTree\Outline;
use LIT\MCP\Integrations\Divi\BlockTree\Serializer;
use LIT\MCP\Integrations\Divi\Design\DesignSystemReader;
use LIT\MCP\Integrations\Divi\Library\GlobalEdits;
use LIT\MCP\Integrations\Divi\Library\SimilarSections;
use LIT\MCP\Integrations\Divi\ThemeBuilder\ThemeBuilderEdits;
use LIT\MCP\Integrations\WordPress\PostSaveFollowUp;
use WP_Error;
@@ -27,13 +28,17 @@ defined('ABSPATH') || exit;
* then lit_mcp_after_save, change log and the ToolResult with changed nodes, affected outline,
* quality warnings (spec §5.5), revision_id, the new rev and tree_rev. commit() is the entry point
* of the tools: library entries additionally pass GlobalEdits (shape, dry run/confirm, backup), Theme
* Builder layouts ThemeBuilderEdits (live layouts: dry run/confirm, backup; ruling Q2/Q9).
* Builder layouts ThemeBuilderEdits (live layouts: dry run/confirm, backup; ruling Q2/Q9). SimilarSections adds
* the "similar section" warning (spec §5.5, E11) – not for lit/library-insert, whose sections come from the library.
*/
final class DiviWriter
{
public const OUTLINE_TRUNCATED = 'Die Übersicht der geänderten Abschnitte ist gekürzt; vollständig mit '
. 'lit-divi-outline lesen.';
/** Inserts library entries: no advice to use the library (SimilarSections). */
private const FROM_LIBRARY = 'lit/library-insert';
public function __construct(
private DiviPageLoader $loader,
private DiviSaver $saver,
@@ -41,7 +46,8 @@ final class DiviWriter
private DesignSystemReader $design,
private DiviComposition $composition,
private ?GlobalEdits $globals = null,
private ?ThemeBuilderEdits $themeBuilder = null
private ?ThemeBuilderEdits $themeBuilder = null,
private ?SimilarSections $similar = null
) {
}
@@ -106,7 +112,8 @@ final class DiviWriter
$index = NodeIndex::build($page->document);
$quality = $this->composition->warnings()->collect($index, $change->touched());
$warnings = array_merge($change->warnings(), $quality);
$similar = $ability === self::FROM_LIBRARY ? [] : ($this->similar?->warnings($change) ?? []);
$warnings = array_merge($change->warnings(), $quality, $similar);
try {
$saved = $this->saver->save($post, $content, $scope);