refactor: DiviWriteAbility base and shared DiviErrors (H4)

The five Divi write tools extend DiviWriteAbility (final permission and
execute, change() per tool, shared output schema). DiviErrors holds the
unknown-node, position and compose-error mapping; DiviContentComposer uses
the same mapping (ledger T9). ToolNamingTest skips abstract classes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-26 18:22:51 +02:00
co-authored by Claude Opus 5.5
parent 9da236b0e3
commit ecfece719d
12 changed files with 141 additions and 187 deletions
@@ -4,8 +4,6 @@ declare(strict_types=1);
namespace LIT\MCP\Integrations\Divi\Pages;
use LIT\MCP\Abilities\Ability;
use LIT\MCP\Abilities\ToolResult;
use LIT\MCP\Integrations\Divi\BlockTree\AttrMap;
use WP_Error;
@@ -14,12 +12,8 @@ use WP_Error;
* (spec §5.7). The copy's admin label gets " (Kopie)"; read-only nodes (global modules,
* foreign blocks) are copied unchanged, as a whole, byte-identical reference.
*/
final class DiviDuplicateNodeAbility implements Ability
final class DiviDuplicateNodeAbility extends DiviWriteAbility
{
public function __construct(private DiviWriter $writer)
{
}
public function name(): string
{
return 'lit/divi-duplicate-node';
@@ -48,11 +42,6 @@ final class DiviDuplicateNodeAbility implements Ability
];
}
public function outputSchema(): ?array
{
return ToolResult::schema(['tree_rev' => ['type' => 'string']], ['tree_rev']);
}
public function annotations(): array
{
return ['readonly' => false, 'destructive' => false, 'idempotent' => false];
@@ -63,31 +52,20 @@ final class DiviDuplicateNodeAbility implements Ability
return false;
}
public function permission(array $input): bool|WP_Error
protected function change(DiviPage $page, array $input, DiviComposition $composition): DiviChange|WP_Error
{
$page = $this->writer->page($input);
return $page instanceof WP_Error ? $page : true;
}
public function execute(array $input): mixed
{
$page = $this->writer->page($input);
if ($page instanceof WP_Error) {
return $page;
}
$id = is_string($input['id'] ?? null) ? $input['id'] : '';
$node = $page->index->find($id);
if ($node === null) {
return DiviPageLoader::unknownNode($id, $page->post);
return DiviErrors::unknownNode($id, $page->post);
}
$copy = $this->writer->composition($page)->editor()->duplicate($page->index, $node);
$copy = $composition->editor()->duplicate($page->index, $node);
if ($copy->isDivi() && ! $copy->isOpaque()) {
// The raw stored desktop value (never NodeSummary::label()'s display-shortened
// text): a long or multi-line label must be copied verbatim, only " (Kopie)" added.
// Setting only the ".desktop.value" leaf keeps every other breakpoint untouched.
// No client input: the stored label plus a constant suffix, so no choke point (S39).
$raw = AttrMap::desktop($node->attrs(), 'module.meta.adminLabel');
$label = is_string($raw) ? $raw : '';
$copy->setAttrs(AttrMap::set(
@@ -97,8 +75,6 @@ final class DiviDuplicateNodeAbility implements Ability
));
}
$change = (new DiviChange(sprintf('Knoten %s dupliziert', $id)))->changed($copy, 'duplicated');
return $this->writer->save($this->name(), $page, $change, $input);
return (new DiviChange(sprintf('Knoten %s dupliziert', $id)))->changed($copy, 'duplicated');
}
}