where('slug', $planSlug) ->first(); if (! $plan) { throw new \InvalidArgumentException("Plan not found: {$planSlug}"); } $resolved = $this->resolvePhase($plan, $phase); if (! $resolved) { throw new \InvalidArgumentException("Phase not found: {$phase}"); } $resolved->addCheckpoint($note, $context); return $resolved->fresh(); } private function resolvePhase(AgentPlan $plan, string|int $identifier): ?AgentPhase { if (is_numeric($identifier)) { return $plan->agentPhases()->where('order', (int) $identifier)->first(); } return $plan->agentPhases() ->where('name', $identifier) ->first(); } }