namespace ClaudeDo.Worker.State; public interface ITaskStateService { Task EnqueueAsync(string taskId, CancellationToken ct); Task StartRunningAsync(string taskId, DateTime startedAt, CancellationToken ct); Task CompleteAsync(string taskId, DateTime finishedAt, string? result, CancellationToken ct); Task SubmitForReviewAsync(string taskId, DateTime finishedAt, string? result, CancellationToken ct); Task SubmitInteractiveForReviewAsync(string taskId, DateTime finishedAt, CancellationToken ct); Task SubmitForChildrenAsync(string taskId, DateTime finishedAt, string? result, CancellationToken ct); Task FailAsync( string taskId, DateTime finishedAt, string? error, CancellationToken ct, string failureReason = "error", int? turnsUsed = null, int? maxTurns = null); Task CancelAsync(string taskId, DateTime finishedAt, CancellationToken ct, bool allowFromIdle = false); Task ResetToIdleAsync(string taskId, CancellationToken ct); Task ApproveReviewAsync(string taskId, CancellationToken ct); Task RejectToQueueAsync(string taskId, string feedback, CancellationToken ct); Task RejectToIdleAsync(string taskId, CancellationToken ct); Task ClearReviewFeedbackAsync(string taskId, CancellationToken ct); Task ForceSetStatusAsync(string taskId, ClaudeDo.Data.Models.TaskStatus status, CancellationToken ct); Task StartPlanningAsync(string parentId, CancellationToken ct); Task FinalizePlanningAsync(string parentId, CancellationToken ct); Task BlockOnAsync(string taskId, string predecessorTaskId, CancellationToken ct); Task UnblockAsync(string taskId, CancellationToken ct); // dependsOnTaskId null clears the dependency. Rejects self-reference, an unknown dependency // id, and a link that would create a cycle -- see TaskStateService for the walk. Task SetDependsOnAsync(string taskId, string? dependsOnTaskId, CancellationToken ct); // Surfaces a WaitingForChildren parent for review once all its children are terminal. // Best-effort (swallows and logs failures) — safe to call after any child mutation, // e.g. deleting the last non-terminal child (no terminal transition fires for a delete). Task TryAdvanceParentAsync(string parentId); Task RecoverStaleRunningAsync(string reason, CancellationToken ct); }