/**
 * Run Workflow Use Case
 *
 * Orchestrates a multi-step workflow against an interactive session.
 * Owns the step lifecycle — ensures rows exist, transitions each
 * from pending → running → done/failed, and tags every message the
 * agent produces during a step with the step's id — so the UI can
 * render a robust tracker that survives refreshes and daemon
 * restarts without any marker parsing.
 *
 * Contract with the session service:
 *   - `setActiveStep(featureId, stepId)` BEFORE the agent turn →
 *      every `persistMessage` call during the turn tags with stepId.
 *   - `subscribeByFeature` + `waitForTurnDone` lets us sequentially
 *      walk steps: each step awaits its own agent turn completion
 *      before moving on.
 *   - `clearActiveStep(featureId)` AFTER the turn — keeps later
 *      out-of-band messages (e.g. a user message typed into the
 *      chat after the workflow finishes) from being tagged.
 *
 * Robustness properties:
 *   1. The step row transitions to `running` BEFORE `sendUserMessage`
 *      and to `done`/`failed` AFTER `waitForTurnDone`, so any crash
 *      between them leaves the row `running` — which boot-time
 *      recovery flips to `interrupted`.
 *   2. `ensureSteps` is idempotent; resuming just skips already-done
 *      steps and fails fast on any `running`/`interrupted`/`failed`
 *      row (user retry flow can reset them to `pending`).
 */
import type { IWorkflowStepRepository } from '../../ports/output/repositories/workflow-step-repository.interface.js';
import type { IInteractiveSessionService } from '../../ports/output/services/interactive-session-service.interface.js';
import type { IInteractiveSessionRepository } from '../../ports/output/repositories/interactive-session-repository.interface.js';
import type { ILogger } from '../../ports/output/services/logger.interface.js';
import type { SendInteractiveMessageUseCase } from '../interactive/send-interactive-message.use-case.js';
import type { WorkflowDefinition } from '../applications/application-creation.workflow.js';
export interface RunWorkflowInput {
    featureId: string;
    worktreePath: string;
    workflow: WorkflowDefinition;
    /**
     * Optional wrapper applied to the FIRST step's prompt. The
     * application-creation flow uses this to inject the
     * "Read `SHEP_BRIEF.md` first" directive on turn 1 without
     * polluting any of the later step prompts.
     */
    firstStepPromptWrapper?: (stepPrompt: string) => string;
    /**
     * Visible first chat bubble — what the user sees as their own
     * first message. When set, the orchestrator uses this as the
     * `content` of the first `sendMessage.execute` call (the agent
     * sees a different prompt via `agentKickoffOverride` /
     * `firstStepPromptWrapper`). Used by the application-creation
     * flow to show "build me a todo app" instead of the full step 1
     * instructions in the user bubble.
     */
    visibleFirstMessage?: string;
    /**
     * Optional model / agent overrides to thread through to the
     * session service. Used by Application chat which pins its own
     * model/agent on the Application entity.
     */
    model?: string;
    agentType?: string;
    /**
     * When true, the orchestrator SKIPS the step that would persist
     * `visibleFirstMessage` as the user's first chat bubble — the
     * caller has already written it to the DB in the foreground so
     * the UI can render it instantly. The session still boots and
     * the agent still receives the wrapped first-step prompt, but no
     * second user message row is created.
     *
     * Used by `CreateApplicationUseCase.dispatchScaffoldAndWorkflow`
     * so the user's bubble is visible from page load even though the
     * scaffold + session boot run in the background.
     */
    firstUserMessageAlreadyPersisted?: boolean;
}
export declare class RunWorkflowUseCase {
    private readonly stepRepo;
    private readonly session;
    private readonly sendMessage;
    private readonly sessionRepoForUsage;
    private readonly logger;
    constructor(stepRepo: IWorkflowStepRepository, session: IInteractiveSessionService, sendMessage: SendInteractiveMessageUseCase, sessionRepoForUsage: IInteractiveSessionRepository, logger: ILogger);
    execute(input: RunWorkflowInput): Promise<void>;
    /**
     * Poll `getChatState` for a short window to resolve the session
     * id of the session we just booted. This is a hot path that
     * runs once per workflow — tens to low hundreds of ms typically.
     */
    private resolveSessionId;
    /**
     * Capture the session's cumulative cost/token totals at a point
     * in time. Returns zeros when the session row hasn't been written
     * yet (first-ever boot) or when the repo call fails — usage is
     * strictly informational, so we never let a missing snapshot break
     * the workflow lifecycle.
     */
    private snapshotUsage;
    /**
     * Diff two usage snapshots and return the values attributable to
     * the step that ran between them. Negative diffs clamp to zero so
     * a race between two session reads can never surface a negative
     * cost in the UI.
     */
    private diffUsage;
    private refreshStep;
}
//# sourceMappingURL=run-workflow.use-case.d.ts.map