< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Workflows.Sequential.StageExecutionContext
Assembly: NexusLabs.Needlr.AgentFramework.Workflows
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Workflows/Sequential/StageExecutionContext.cs
Line coverage
93%
Covered lines: 14
Uncovered lines: 1
Coverable lines: 15
Total lines: 77
Line coverage: 93.3%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Workspace()100%11100%
get_DiagnosticsAccessor()100%11100%
get_ProgressReporter()100%210%
get_StageIndex()100%11100%
get_TotalStages()100%11100%
get_StageName()100%11100%
get_CallerCancellationToken()100%11100%
get_PipelineState()100%11100%
get_PhaseName()100%11100%
get_PhaseIndex()100%11100%
get_StageIndexInPhase()100%11100%
get_TotalStagesInPhase()100%11100%
GetRequiredState()100%22100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Workflows/Sequential/StageExecutionContext.cs

#LineLine coverage
 1using NexusLabs.Needlr.AgentFramework.Diagnostics;
 2using NexusLabs.Needlr.AgentFramework.Progress;
 3using NexusLabs.Needlr.AgentFramework.Workspace;
 4
 5namespace NexusLabs.Needlr.AgentFramework.Workflows.Sequential;
 6
 7/// <summary>
 8/// Provides typed access to the pipeline's shared state during stage execution.
 9/// </summary>
 10/// <param name="Workspace">The shared workspace for reading/writing files across stages.</param>
 11/// <param name="DiagnosticsAccessor">Accessor for capturing per-stage diagnostics.</param>
 12/// <param name="ProgressReporter">Optional progress reporter for emitting pipeline events.</param>
 13/// <param name="StageIndex">Zero-based index of the current stage in the pipeline.</param>
 14/// <param name="TotalStages">Total number of stages in the pipeline.</param>
 15/// <param name="StageName">Human-readable name of the current stage.</param>
 16/// <param name="CallerCancellationToken">
 17/// The original caller's cancellation token. Decorators that create linked tokens
 18/// (e.g. <see cref="TimeoutExecutor"/>) should check this to distinguish user
 19/// cancellation from internal timeouts.
 20/// </param>
 21/// <param name="PipelineState">
 22/// Optional shared state object passed to all stages in the pipeline. Use
 23/// <see cref="GetRequiredState{T}"/> to retrieve it with type safety.
 24/// </param>
 25/// <param name="PhaseName">
 26/// The name of the pipeline phase this stage belongs to, or <see langword="null"/>
 27/// when running a flat (non-phased) pipeline.
 28/// </param>
 29/// <param name="PhaseIndex">
 30/// Zero-based index of the current phase, or <see langword="null"/> for flat pipelines.
 31/// </param>
 32/// <param name="StageIndexInPhase">
 33/// Zero-based index of the current stage within its phase, or <see langword="null"/>
 34/// for flat pipelines.
 35/// </param>
 36/// <param name="TotalStagesInPhase">
 37/// Total number of stages in the current phase, or <see langword="null"/> for flat pipelines.
 38/// </param>
 39/// <example>
 40/// <code>
 41/// public async Task&lt;StageExecutionResult&gt; ExecuteAsync(
 42///     StageExecutionContext context,
 43///     CancellationToken cancellationToken)
 44/// {
 45///     Console.WriteLine($"Running stage {context.StageIndex + 1}/{context.TotalStages}: {context.StageName}");
 46///     if (context.PhaseName is not null)
 47///         Console.WriteLine($"  Phase: {context.PhaseName} (stage {context.StageIndexInPhase + 1}/{context.TotalStages
 48///     return StageExecutionResult.Success(context.StageName, diagnostics: null, responseText: null);
 49/// }
 50/// </code>
 51/// </example>
 19152public sealed record StageExecutionContext(
 5853    IWorkspace Workspace,
 10354    IAgentDiagnosticsAccessor DiagnosticsAccessor,
 055    IProgressReporter? ProgressReporter,
 456    int StageIndex,
 157    int TotalStages,
 19258    string StageName,
 559    CancellationToken CallerCancellationToken = default,
 560    object? PipelineState = null,
 161    string? PhaseName = null,
 162    int? PhaseIndex = null,
 163    int? StageIndexInPhase = null,
 19264    int? TotalStagesInPhase = null)
 65{
 66    /// <summary>
 67    /// Gets the typed pipeline state, or throws if no state was provided or the type doesn't match.
 68    /// </summary>
 69    /// <typeparam name="T">The expected pipeline state type.</typeparam>
 70    /// <returns>The pipeline state cast to <typeparamref name="T"/>.</returns>
 71    /// <exception cref="InvalidOperationException">
 72    /// Thrown when <see cref="PipelineState"/> is <see langword="null"/> or not of type <typeparamref name="T"/>.
 73    /// </exception>
 74    public T GetRequiredState<T>() where T : class =>
 575        PipelineState as T ?? throw new InvalidOperationException(
 576            $"Pipeline state is not available or is not of type {typeof(T).Name}.");
 77}