php-agentic/Mcp/Tools/Agent/Phase/PhaseGet.php
Snider ad83825f93 refactor: rename namespace Core\Agentic to Core\Mod\Agentic
Updates all classes to use the new modular namespace convention.
Adds Service/ layer with Core\Service\Agentic for service definition.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 16:12:58 +00:00

98 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Mod\Agentic\Mcp\Tools\Agent\Phase;
use Core\Mod\Agentic\Models\AgentPhase;
use Core\Mod\Agentic\Models\AgentPlan;
use Core\Mod\Agentic\Mcp\Tools\Agent\AgentTool;
/**
* Get details of a specific phase within a plan.
*/
class PhaseGet extends AgentTool
{
protected string $category = 'phase';
protected array $scopes = ['read'];
public function name(): string
{
return 'phase_get';
}
public function description(): string
{
return 'Get details of a specific phase within a plan';
}
public function inputSchema(): array
{
return [
'type' => 'object',
'properties' => [
'plan_slug' => [
'type' => 'string',
'description' => 'Plan slug identifier',
],
'phase' => [
'type' => 'string',
'description' => 'Phase identifier (number or name)',
],
],
'required' => ['plan_slug', 'phase'],
];
}
public function handle(array $args, array $context = []): array
{
try {
$planSlug = $this->require($args, 'plan_slug');
$phaseIdentifier = $this->require($args, 'phase');
} catch (\InvalidArgumentException $e) {
return $this->error($e->getMessage());
}
$plan = AgentPlan::where('slug', $planSlug)->first();
if (! $plan) {
return $this->error("Plan not found: {$planSlug}");
}
$phase = $this->findPhase($plan, $phaseIdentifier);
if (! $phase) {
return $this->error("Phase not found: {$phaseIdentifier}");
}
return [
'phase' => [
'order' => $phase->order,
'name' => $phase->name,
'description' => $phase->description,
'status' => $phase->status,
'tasks' => $phase->tasks,
'checkpoints' => $phase->checkpoints,
'dependencies' => $phase->dependencies,
],
];
}
/**
* Find a phase by order number or name.
*/
protected function findPhase(AgentPlan $plan, string|int $identifier): ?AgentPhase
{
if (is_numeric($identifier)) {
return $plan->agentPhases()->where('order', (int) $identifier)->first();
}
return $plan->agentPhases()
->where(function ($query) use ($identifier) {
$query->where('name', $identifier)
->orWhere('order', $identifier);
})
->first();
}
}