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:
@@ -4,9 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\Divi\Pages;
|
||||
|
||||
use LIT\MCP\Abilities\Ability;
|
||||
use LIT\MCP\Abilities\Errors;
|
||||
use LIT\MCP\Abilities\ToolResult;
|
||||
use WP_Error;
|
||||
|
||||
/**
|
||||
@@ -14,12 +12,8 @@ use WP_Error;
|
||||
* another row or section, as long as the structure rules allow it (spec §5.7). Read-only
|
||||
* nodes (global modules, foreign blocks) move as a whole, unchanged.
|
||||
*/
|
||||
final class DiviMoveAbility implements Ability
|
||||
final class DiviMoveAbility extends DiviWriteAbility
|
||||
{
|
||||
public function __construct(private DiviWriter $writer)
|
||||
{
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'lit/divi-move';
|
||||
@@ -50,45 +44,23 @@ final class DiviMoveAbility 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];
|
||||
}
|
||||
|
||||
public function isDirect(): bool
|
||||
protected function change(DiviPage $page, array $input, DiviComposition $composition): DiviChange|WP_Error
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function permission(array $input): bool|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);
|
||||
}
|
||||
|
||||
$editor = $this->writer->composition($page)->editor();
|
||||
$editor = $composition->editor();
|
||||
$position = $editor->position($page->index, $input);
|
||||
if (is_string($position)) {
|
||||
return Errors::invalidInput('Ungültige Position; nichts wurde gespeichert.', ['position' => $position]);
|
||||
return DiviErrors::position($position);
|
||||
}
|
||||
|
||||
$problem = $editor->move($page->index, $node, $position);
|
||||
@@ -99,8 +71,6 @@ final class DiviMoveAbility implements Ability
|
||||
);
|
||||
}
|
||||
|
||||
$change = (new DiviChange(sprintf('Knoten %s verschoben', $id)))->changed($node, 'moved');
|
||||
|
||||
return $this->writer->save($this->name(), $page, $change, $input);
|
||||
return (new DiviChange(sprintf('Knoten %s verschoben', $id)))->changed($node, 'moved');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user