123 lines
3.4 KiB
PHP
123 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Core\Agentic\Mcp\Tools\Agent\Phase;
|
|
|
|
use Core\Mod\Mcp\Dependencies\ToolDependency;
|
|
use Core\Agentic\Mcp\Tools\Agent\AgentTool;
|
|
use Core\Agentic\Models\AgentPhase;
|
|
use Core\Agentic\Models\AgentPlan;
|
|
|
|
/**
|
|
* Update the status of a phase.
|
|
*/
|
|
class PhaseUpdateStatus extends AgentTool
|
|
{
|
|
protected string $category = 'phase';
|
|
|
|
protected array $scopes = ['write'];
|
|
|
|
/**
|
|
* Get the dependencies for this tool.
|
|
*
|
|
* @return array<ToolDependency>
|
|
*/
|
|
public function dependencies(): array
|
|
{
|
|
return [
|
|
ToolDependency::entityExists('plan', 'Plan must exist', ['arg_key' => 'plan_slug']),
|
|
];
|
|
}
|
|
|
|
public function name(): string
|
|
{
|
|
return 'phase_update_status';
|
|
}
|
|
|
|
public function description(): string
|
|
{
|
|
return 'Update the status of a phase';
|
|
}
|
|
|
|
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)',
|
|
],
|
|
'status' => [
|
|
'type' => 'string',
|
|
'description' => 'New status',
|
|
'enum' => ['pending', 'in_progress', 'completed', 'blocked', 'skipped'],
|
|
],
|
|
'notes' => [
|
|
'type' => 'string',
|
|
'description' => 'Optional notes about the status change',
|
|
],
|
|
],
|
|
'required' => ['plan_slug', 'phase', 'status'],
|
|
];
|
|
}
|
|
|
|
public function handle(array $args, array $context = []): array
|
|
{
|
|
try {
|
|
$planSlug = $this->require($args, 'plan_slug');
|
|
$phaseIdentifier = $this->require($args, 'phase');
|
|
$status = $this->require($args, 'status');
|
|
} 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}");
|
|
}
|
|
|
|
if (! empty($args['notes'])) {
|
|
$phase->addCheckpoint($args['notes'], ['status_change' => $status]);
|
|
}
|
|
|
|
$phase->update(['status' => $status]);
|
|
|
|
return $this->success([
|
|
'phase' => [
|
|
'order' => $phase->order,
|
|
'name' => $phase->name,
|
|
'status' => $phase->fresh()->status,
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 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();
|
|
}
|
|
}
|