import type { Db } from "@paperclipai/db";
import { type ExecutionWorkspace, type ExecutionWorkspaceConfig, type ModelProfileKey, type SourceTrustMetadata } from "@paperclipai/shared";
import { agents, heartbeatRuns } from "@paperclipai/db";
import type { AdapterExecutionResult, AdapterModelProfileDefinition, AdapterSessionCodec } from "../adapters/index.js";
import { type BudgetEnforcementScope } from "./budgets.js";
import { secretService } from "./secrets.js";
import { type ExecutionWorkspaceInput, type RealizedExecutionWorkspace } from "./workspace-runtime.js";
import { resolveExecutionWorkspaceMode } from "./execution-workspace-policy.js";
import { type CurrentUserRedactionOptions } from "../log-redaction.js";
import { type SessionCompactionPolicy } from "@paperclipai/adapter-utils";
import { environmentRuntimeService } from "./environment-runtime.js";
import { type TrustPresetResolution } from "./trust-preset-resolver.js";
import type { PluginWorkerManager } from "./plugin-worker-manager.js";
export declare function redactDetectedSuccessfulRunProgressSummaryForBoard(summary: string, currentUserRedactionOptions?: CurrentUserRedactionOptions): string;
export { ACTIVE_RUN_OUTPUT_CONTINUE_REARM_MS, ACTIVE_RUN_OUTPUT_CRITICAL_THRESHOLD_MS, ACTIVE_RUN_OUTPUT_SUSPICION_THRESHOLD_MS, } from "./recovery/service.js";
export declare const ACTIVE_RUN_OUTPUT_PROGRESS_FLUSH_INTERVAL_MS: number;
export declare const BOUNDED_TRANSIENT_HEARTBEAT_RETRY_DELAYS_MS: readonly [number, number, number, number];
export declare const MAX_TURN_CONTINUATION_RETRY_REASON = "max_turns_continuation";
export declare const MAX_TURN_CONTINUATION_WAKE_REASON = "max_turns_continuation_retry";
export declare class WorkspaceValidationFailure extends Error {
    code: string;
    resultJson: Record<string, unknown>;
    constructor(message: string, resultJson: Record<string, unknown>);
}
type RuntimeConfigSecretResolver = Pick<ReturnType<typeof secretService>, "resolveAdapterConfigForRuntime" | "resolveEnvBindings">;
export declare function resolveExecutionRunAdapterConfig(input: {
    companyId: string;
    agentId?: string | null;
    issueId?: string | null;
    heartbeatRunId?: string | null;
    projectId?: string | null;
    routineId?: string | null;
    executionRunConfig: Record<string, unknown>;
    projectEnv: unknown;
    routineEnv?: unknown;
    secretsSvc: RuntimeConfigSecretResolver;
    trustPreset?: TrustPresetResolution;
}): Promise<{
    resolvedConfig: Record<string, unknown>;
    secretKeys: Set<string>;
    secretManifest: import("./secrets.js").RuntimeSecretManifestEntry[];
}>;
export declare function extractMentionedSkillIdsFromSources(sources: Array<string | null | undefined>): string[];
export declare function applyRunScopedMentionedSkillKeys(config: Record<string, unknown>, skillKeys: string[]): Record<string, unknown>;
export declare function computeBoundedTransientHeartbeatRetrySchedule(attempt: number, now?: Date, random?: () => number): {
    attempt: number;
    baseDelayMs: number;
    delayMs: number;
    dueAt: Date;
    maxAttempts: 4;
} | null;
export declare function applyPersistedExecutionWorkspaceConfig(input: {
    config: Record<string, unknown>;
    workspaceConfig: ExecutionWorkspaceConfig | null;
    mode: ReturnType<typeof resolveExecutionWorkspaceMode>;
}): {
    [x: string]: unknown;
};
export declare function mergeExecutionWorkspaceMetadataForPersistence(input: {
    existingMetadata: Record<string, unknown> | null | undefined;
    source: string;
    createdByRuntime: boolean;
    configSnapshot: Record<string, unknown> | null;
    shouldReuseExisting: boolean;
    baseRef: string | null | undefined;
    baseRefSha: string | null | undefined;
}): Record<string, unknown> | null;
export declare function stripWorkspaceRuntimeFromExecutionRunConfig(config: Record<string, unknown>): {
    [x: string]: unknown;
};
export declare function buildRealizedExecutionWorkspaceFromPersisted(input: {
    base: ExecutionWorkspaceInput;
    workspace: ExecutionWorkspace;
}): RealizedExecutionWorkspace | null;
export declare function stripHostWorkspaceProvisionForLowTrustSandbox(input: {
    config: Record<string, unknown>;
    trustPreset: TrustPresetResolution;
    selectedEnvironmentDriver: string | null | undefined;
}): Record<string, unknown>;
export declare function preflightLowTrustWorkspaceIsolation(input: {
    db?: Db;
    trustPreset: TrustPresetResolution;
    isolatedWorkspacesEnabled: boolean;
    effectiveExecutionWorkspaceMode: string | null | undefined;
    issue: {
        companyId: string;
        id?: string | null;
        projectId?: string | null;
    } | null;
    resolveSelectedEnvironmentDriver: () => Promise<string | null | undefined>;
}): Promise<string | null>;
export declare function resolveWorkspaceAfterLowTrustPreflight<TWorkspace>(input: {
    db?: Db;
    trustPreset: TrustPresetResolution;
    isolatedWorkspacesEnabled: boolean;
    effectiveExecutionWorkspaceMode: string | null | undefined;
    issue: {
        companyId: string;
        id?: string | null;
        projectId?: string | null;
    } | null;
    resolveSelectedEnvironmentDriver: () => Promise<string | null | undefined>;
    resolveWorkspace: () => Promise<TWorkspace>;
}): Promise<{
    selectedEnvironmentDriver: string | null;
    workspace: TWorkspace;
}>;
export declare function assertGitSensitiveAdapterWorkspaceValid(input: {
    adapterType: string;
    agentId: string;
    issue: {
        id: string;
        identifier: string | null;
        projectId: string | null;
        projectWorkspaceId: string | null;
    } | null;
    resolvedWorkspace: ResolvedWorkspaceForRun;
    executionWorkspace: RealizedExecutionWorkspace;
    persistedExecutionWorkspace: ExecutionWorkspace | null;
    executionTarget: unknown;
    environmentDriver?: string | null;
    leaseMetadata?: unknown;
}): Promise<void>;
export declare function boundHeartbeatRunEventPayloadForStorage(payload: Record<string, unknown>): Record<string, unknown>;
export declare function compactRunLogChunk(chunk: string, maxChars?: number): string;
interface WakeupOptions {
    source?: "timer" | "assignment" | "on_demand" | "automation";
    triggerDetail?: "manual" | "ping" | "callback" | "system";
    reason?: string | null;
    payload?: Record<string, unknown> | null;
    idempotencyKey?: string | null;
    requestedByActorType?: "user" | "agent" | "system";
    requestedByActorId?: string | null;
    contextSnapshot?: Record<string, unknown>;
}
type ModelProfileRequestSource = "issue_override" | "wake_context";
type AppliedModelProfileConfigSource = "agent_runtime" | "adapter_default";
export interface ModelProfileApplication {
    requested: ModelProfileKey | null;
    requestedBy: ModelProfileRequestSource | null;
    applied: ModelProfileKey | null;
    configSource: AppliedModelProfileConfigSource | null;
    fallbackReason: string | null;
    adapterConfig: Record<string, unknown> | null;
}
export type ResolvedWorkspaceForRun = {
    cwd: string;
    source: "project_primary" | "task_session" | "agent_home";
    projectId: string | null;
    workspaceId: string | null;
    repoUrl: string | null;
    repoRef: string | null;
    workspaceHints: Array<{
        workspaceId: string;
        cwd: string | null;
        repoUrl: string | null;
        repoRef: string | null;
    }>;
    warnings: string[];
};
type ProjectWorkspaceCandidate = {
    id: string;
};
export declare function prioritizeProjectWorkspaceCandidatesForRun<T extends ProjectWorkspaceCandidate>(rows: T[], preferredWorkspaceId: string | null | undefined): T[];
export declare function normalizeModelProfileWakeContext(input: {
    contextSnapshot: Record<string, unknown>;
    payload: Record<string, unknown> | null | undefined;
}): Record<string, unknown>;
export declare function resolveModelProfileApplication(input: {
    adapterModelProfiles: AdapterModelProfileDefinition[];
    agentRuntimeConfig: unknown;
    issueModelProfile: ModelProfileKey | null | undefined;
    contextSnapshot: Record<string, unknown> | null | undefined;
    profileResolutionFallbackReason?: string | null;
}): ModelProfileApplication;
export declare function mergeModelProfileAdapterConfig(input: {
    baseConfig: Record<string, unknown>;
    modelProfile: ModelProfileApplication;
    issueAdapterConfig: Record<string, unknown> | null | undefined;
}): Record<string, unknown>;
export declare function summarizeHeartbeatRunContextSnapshot(contextSnapshot: Record<string, unknown> | null | undefined): Record<string, unknown> | null;
export declare function summarizeHeartbeatRunListResultJson(input: {
    summary?: string | null;
    result?: string | null;
    message?: string | null;
    error?: string | null;
    totalCostUsd?: string | null;
    costUsd?: string | null;
    costUsdCamel?: string | null;
}): Record<string, unknown> | null;
type ResumeSessionRow = {
    sessionParamsJson: Record<string, unknown> | null;
    sessionDisplayId: string | null;
    lastRunId: string | null;
};
export declare function buildExplicitResumeSessionOverride(input: {
    adapterType?: string | null;
    resumeFromRunId: string;
    resumeRunSessionIdBefore: string | null;
    resumeRunSessionIdAfter: string | null;
    resumeRunSessionParams?: Record<string, unknown> | null;
    taskSession: ResumeSessionRow | null;
    sessionCodec: AdapterSessionCodec;
}): {
    sessionDisplayId: string | null;
    sessionParams: Record<string, unknown> | null;
} | null;
export declare function parseSessionCompactionPolicy(agent: typeof agents.$inferSelect): SessionCompactionPolicy;
export declare function resolveRuntimeSessionParamsForWorkspace(input: {
    agentId: string;
    previousSessionParams: Record<string, unknown> | null;
    resolvedWorkspace: ResolvedWorkspaceForRun;
}): {
    sessionParams: Record<string, unknown> | null;
    warning: string | null;
};
/**
 * Extended task key derivation that falls back to a stable synthetic key
 * for timer/heartbeat wakes. The synthetic key keeps the
 * `agentTaskSessions` row addressable across heartbeats so the row can be
 * cleared and re-keyed deterministically; it does NOT mean the prior
 * session is resumed. Since PF-4 (#4838), `heartbeat_timer` wakes always
 * go through `shouldResetTaskSessionForWake` and start a fresh session —
 * see `describeSessionResetReason` for the paired log message.
 *
 * The synthetic key is only used when:
 * - No explicit task/issue key exists in the context
 * - The wake source is "timer" (scheduled heartbeat)
 */
export declare function deriveTaskKeyWithHeartbeatFallback(contextSnapshot: Record<string, unknown> | null | undefined, payload: Record<string, unknown> | null | undefined): string | null;
export declare function shouldResetTaskSessionForWake(contextSnapshot: Record<string, unknown> | null | undefined): boolean;
export declare function formatRuntimeWorkspaceWarningLog(warning: string): {
    stream: "stdout";
    chunk: string;
};
export declare function describeSessionResetReason(contextSnapshot: Record<string, unknown> | null | undefined): "forceFreshSession was requested" | "wake reason is issue_assigned" | "wake reason is execution_review_requested" | "wake reason is execution_approval_requested" | "wake reason is execution_changes_requested" | "wake reason is heartbeat_timer (timer-driven wake starts fresh)" | null;
export declare function extractWakeCommentIds(contextSnapshot: Record<string, unknown> | null | undefined): string[];
export declare function mergeCoalescedContextSnapshot(existingRaw: unknown, incoming: Record<string, unknown>): Record<string, unknown>;
export declare function buildPaperclipWakePayload(input: {
    db: Db;
    companyId: string;
    contextSnapshot: Record<string, unknown>;
    continuationSummary?: {
        key: string;
        title: string | null;
        body: string;
        sourceTrust?: SourceTrustMetadata | null;
        updatedAt: Date;
    } | null;
    issueSummary?: {
        id: string;
        identifier: string | null;
        title: string;
        status: string;
        priority: string;
        workMode: string;
        projectId?: string | null;
        executionPolicy?: unknown;
    } | null;
    exposeLowTrustRaw?: boolean;
}): Promise<{
    reason: string | null;
    issue: {
        id: string;
        identifier: string | null;
        title: string;
        status: string;
        priority: string;
        workMode: string;
    } | null;
    childIssueSummaries: any[];
    childIssueSummaryTruncated: boolean;
    livenessContinuation: {
        attempt: unknown;
        maxAttempts: unknown;
        sourceRunId: string | null;
        state: string | null;
        reason: string | null;
        instruction: string | null;
    } | null;
    interactionKind: string | null;
    interactionStatus: string | null;
    checkedOutByHarness: boolean;
    dependencyBlockedInteraction: boolean;
    treeHoldInteraction: boolean;
    activeTreeHold: Record<string, unknown>;
    unresolvedBlockerIssueIds: string[];
    unresolvedBlockerSummaries: any[];
    executionStage: Record<string, unknown> | null;
    continuationSummary: {
        key: string;
        title: string | null;
        body: string;
        bodyTruncated: boolean;
        sourceTrust: SourceTrustMetadata | null;
        updatedAt: string;
    } | null;
    commentIds: string[];
    latestCommentId: string;
    comments: Record<string, unknown>[];
    annotationDeltas: {
        id: string;
        issueId: string;
        threadId: string;
        documentKey: string;
        revisionNumber: number;
        quote: string;
        prefix: string;
        suffix: string;
        threadStatus: "resolved" | "open";
        anchorState: "active" | "stale" | "orphaned";
        anchorConfidence: "exact" | "duplicate" | "fuzzy" | "ambiguous" | "missing";
        body: string;
        bodyTruncated: boolean;
        createdAt: string;
        author: {
            type: string;
            id: string;
        } | {
            type: "user" | "agent" | "system";
            id: null;
        };
    }[];
    commentWindow: {
        requestedCount: number;
        includedCount: number;
        missingCount: number;
    };
    truncated: boolean;
    fallbackFetchNeeded: boolean;
} | null>;
export declare function buildPaperclipTaskMarkdown(input: {
    issue: {
        id: string;
        identifier: string | null;
        title: string;
        workMode?: string | null;
        description?: string | null;
    } | null;
    wakeComment?: {
        id: string;
        body: string;
    } | null;
    interaction?: {
        kind?: string | null;
        status?: string | null;
    } | null;
    acceptedPlanContinuation?: boolean;
}): string | null;
type RunSessionOutcome = "succeeded" | "failed" | "cancelled" | "timed_out";
export declare function resolveNextSessionState(input: {
    adapterType?: string | null;
    codec: AdapterSessionCodec;
    adapterResult: AdapterExecutionResult;
    outcome: RunSessionOutcome;
    previousParams: Record<string, unknown> | null;
    previousDisplayId: string | null;
    previousLegacySessionId: string | null;
}): {
    params: Record<string, unknown> | null;
    displayId: string | null;
    legacySessionId: string | null;
};
export type HeartbeatEnvironmentRuntime = ReturnType<typeof environmentRuntimeService>;
export interface HeartbeatServiceOptions {
    pluginWorkerManager?: PluginWorkerManager;
    environmentRuntime?: HeartbeatEnvironmentRuntime;
}
export declare function heartbeatService(db: Db, options?: HeartbeatServiceOptions): {
    list: (companyId: string, agentId?: string, limit?: number) => Promise<({
        contextSnapshot: Record<string, unknown> | null;
        resultJson: Record<string, unknown> | null;
        error: string | null;
        id: string;
        companyId: string;
        agentId: string;
        invocationSource: string;
        triggerDetail: string | null;
        status: string;
        startedAt: Date | null;
        finishedAt: Date | null;
        wakeupRequestId: string | null;
        exitCode: number | null;
        signal: string | null;
        usageJson: Record<string, unknown> | null;
        sessionIdBefore: string | null;
        sessionIdAfter: string | null;
        logStore: string | null;
        logRef: string | null;
        logBytes: number | null;
        logSha256: string | null;
        logCompressed: boolean;
        stdoutExcerpt: string | null;
        stderrExcerpt: string | null;
        errorCode: string | null;
        externalRunId: string | null;
        processPid: number | null;
        processGroupId: number | null;
        processStartedAt: Date | null;
        lastOutputAt: Date | null;
        lastOutputSeq: number;
        lastOutputStream: string | null;
        lastOutputBytes: number | null;
        retryOfRunId: string | null;
        processLossRetryCount: number;
        scheduledRetryAt: Date | null;
        scheduledRetryAttempt: number;
        scheduledRetryReason: string | null;
        livenessState: string | null;
        livenessReason: string | null;
        continuationAttempt: number;
        lastUsefulActionAt: Date | null;
        nextAction: string | null;
        createdAt: Date;
        updatedAt: Date;
    } | {
        contextSnapshot: Record<string, unknown> | null;
        resultJson: Record<string, unknown> | null;
        id: string;
        companyId: string;
        agentId: string;
        invocationSource: string;
        triggerDetail: string | null;
        status: string;
        startedAt: Date | null;
        finishedAt: Date | null;
        error: string | null;
        wakeupRequestId: string | null;
        exitCode: number | null;
        signal: string | null;
        usageJson: Record<string, unknown> | null;
        sessionIdBefore: string | null;
        sessionIdAfter: string | null;
        logStore: string | null;
        logRef: string | null;
        logBytes: number | null;
        logSha256: string | null;
        logCompressed: boolean;
        stdoutExcerpt: string | null;
        stderrExcerpt: string | null;
        errorCode: string | null;
        externalRunId: string | null;
        processPid: number | null;
        processGroupId: number | null;
        processStartedAt: Date | null;
        lastOutputAt: Date | null;
        lastOutputSeq: number;
        lastOutputStream: string | null;
        lastOutputBytes: number | null;
        retryOfRunId: string | null;
        processLossRetryCount: number;
        scheduledRetryAt: Date | null;
        scheduledRetryAttempt: number;
        scheduledRetryReason: string | null;
        livenessState: string | null;
        livenessReason: string | null;
        continuationAttempt: number;
        lastUsefulActionAt: Date | null;
        nextAction: string | null;
        createdAt: Date;
        updatedAt: Date;
    })[]>;
    getRun: (runId: string, opts?: {
        unsafeFullResultJson?: boolean;
    }) => Promise<{
        id: string;
        companyId: string;
        agentId: string;
        invocationSource: string;
        triggerDetail: string | null;
        status: string;
        startedAt: Date | null;
        finishedAt: Date | null;
        error: string | null;
        wakeupRequestId: string | null;
        exitCode: number | null;
        signal: string | null;
        usageJson: Record<string, unknown> | null;
        resultJson: Record<string, unknown> | null;
        sessionIdBefore: string | null;
        sessionIdAfter: string | null;
        logStore: string | null;
        logRef: string | null;
        logBytes: number | null;
        logSha256: string | null;
        logCompressed: boolean;
        stdoutExcerpt: string | null;
        stderrExcerpt: string | null;
        errorCode: string | null;
        externalRunId: string | null;
        processPid: number | null;
        processGroupId: number | null;
        processStartedAt: Date | null;
        lastOutputAt: Date | null;
        lastOutputSeq: number;
        lastOutputStream: string | null;
        lastOutputBytes: number | null;
        retryOfRunId: string | null;
        processLossRetryCount: number;
        scheduledRetryAt: Date | null;
        scheduledRetryAttempt: number;
        scheduledRetryReason: string | null;
        issueCommentStatus: string;
        issueCommentSatisfiedByCommentId: string | null;
        issueCommentRetryQueuedAt: Date | null;
        livenessState: string | null;
        livenessReason: string | null;
        continuationAttempt: number;
        lastUsefulActionAt: Date | null;
        nextAction: string | null;
        contextSnapshot: Record<string, unknown> | null;
        createdAt: Date;
        updatedAt: Date;
    } | {
        readonly processGroupId: number | null;
        readonly resultJson: Record<string, unknown> | null;
        readonly id: string;
        readonly companyId: string;
        readonly agentId: string;
        readonly invocationSource: string;
        readonly triggerDetail: string | null;
        readonly status: string;
        readonly startedAt: Date | null;
        readonly finishedAt: Date | null;
        readonly error: string | null;
        readonly wakeupRequestId: string | null;
        readonly exitCode: number | null;
        readonly signal: string | null;
        readonly usageJson: Record<string, unknown> | null;
        readonly sessionIdBefore: string | null;
        readonly sessionIdAfter: string | null;
        readonly logStore: string | null;
        readonly logRef: string | null;
        readonly logBytes: number | null;
        readonly logSha256: string | null;
        readonly logCompressed: boolean;
        readonly stdoutExcerpt: string | null;
        readonly stderrExcerpt: string | null;
        readonly errorCode: string | null;
        readonly externalRunId: string | null;
        readonly processPid: number | null;
        readonly processStartedAt: Date | null;
        readonly lastOutputAt: Date | null;
        readonly lastOutputSeq: number;
        readonly lastOutputStream: string | null;
        readonly lastOutputBytes: number | null;
        readonly retryOfRunId: string | null;
        readonly processLossRetryCount: number;
        readonly scheduledRetryAt: Date | null;
        readonly scheduledRetryAttempt: number;
        readonly scheduledRetryReason: string | null;
        readonly issueCommentStatus: string;
        readonly issueCommentSatisfiedByCommentId: string | null;
        readonly issueCommentRetryQueuedAt: Date | null;
        readonly livenessState: string | null;
        readonly livenessReason: string | null;
        readonly continuationAttempt: number;
        readonly lastUsefulActionAt: Date | null;
        readonly nextAction: string | null;
        readonly contextSnapshot: Record<string, unknown> | null;
        readonly createdAt: Date;
        readonly updatedAt: Date;
    } | {
        readonly processGroupId: number | null;
        readonly error: string | null;
        readonly resultJson: Record<string, unknown> | null;
        readonly stdoutExcerpt: string | null;
        readonly stderrExcerpt: string | null;
        readonly id: string;
        readonly companyId: string;
        readonly agentId: string;
        readonly invocationSource: string;
        readonly triggerDetail: string | null;
        readonly status: string;
        readonly startedAt: Date | null;
        readonly finishedAt: Date | null;
        readonly wakeupRequestId: string | null;
        readonly exitCode: number | null;
        readonly signal: string | null;
        readonly usageJson: Record<string, unknown> | null;
        readonly sessionIdBefore: string | null;
        readonly sessionIdAfter: string | null;
        readonly logStore: string | null;
        readonly logRef: string | null;
        readonly logBytes: number | null;
        readonly logSha256: string | null;
        readonly logCompressed: boolean;
        readonly errorCode: string | null;
        readonly externalRunId: string | null;
        readonly processPid: number | null;
        readonly processStartedAt: Date | null;
        readonly lastOutputAt: Date | null;
        readonly lastOutputSeq: number;
        readonly lastOutputStream: string | null;
        readonly lastOutputBytes: number | null;
        readonly retryOfRunId: string | null;
        readonly processLossRetryCount: number;
        readonly scheduledRetryAt: Date | null;
        readonly scheduledRetryAttempt: number;
        readonly scheduledRetryReason: string | null;
        readonly issueCommentStatus: string;
        readonly issueCommentSatisfiedByCommentId: string | null;
        readonly issueCommentRetryQueuedAt: Date | null;
        readonly livenessState: string | null;
        readonly livenessReason: string | null;
        readonly continuationAttempt: number;
        readonly lastUsefulActionAt: Date | null;
        readonly nextAction: string | null;
        readonly contextSnapshot: Record<string, unknown> | null;
        readonly createdAt: Date;
        readonly updatedAt: Date;
    }>;
    getRunLogAccess: (runId: string) => Promise<{
        readonly id: string;
        readonly companyId: string;
        readonly logStore: string | null;
        readonly logRef: string | null;
    }>;
    getRuntimeState: (agentId: string) => Promise<{
        sessionDisplayId: string | null;
        sessionParamsJson: Record<string, unknown> | null;
        agentId: string;
        companyId: string;
        adapterType: string;
        sessionId: string | null;
        stateJson: Record<string, unknown>;
        lastRunId: string | null;
        lastRunStatus: string | null;
        totalInputTokens: number;
        totalOutputTokens: number;
        totalCachedInputTokens: number;
        totalCostCents: number;
        lastError: string | null;
        createdAt: Date;
        updatedAt: Date;
    } | null>;
    listTaskSessions: (agentId: string) => Promise<{
        id: string;
        companyId: string;
        agentId: string;
        adapterType: string;
        taskKey: string;
        sessionParamsJson: Record<string, unknown> | null;
        sessionDisplayId: string | null;
        lastRunId: string | null;
        lastError: string | null;
        createdAt: Date;
        updatedAt: Date;
    }[]>;
    resetRuntimeSession: (agentId: string, opts?: {
        taskKey?: string | null;
    }) => Promise<{
        sessionDisplayId: null;
        sessionParamsJson: null;
        clearedTaskSessions: number;
        agentId: string;
        companyId: string;
        adapterType: string;
        sessionId: string | null;
        stateJson: Record<string, unknown>;
        lastRunId: string | null;
        lastRunStatus: string | null;
        totalInputTokens: number;
        totalOutputTokens: number;
        totalCachedInputTokens: number;
        totalCostCents: number;
        lastError: string | null;
        createdAt: Date;
        updatedAt: Date;
    } | null>;
    listEvents: (runId: string, afterSeq?: number, limit?: number) => Omit<import("drizzle-orm/pg-core").PgSelectBase<"heartbeat_run_events", {
        id: import("drizzle-orm/pg-core").PgColumn<{
            name: "id";
            tableName: "heartbeat_run_events";
            dataType: "number";
            columnType: "PgBigSerial53";
            data: number;
            driverParam: number;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: true;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        companyId: import("drizzle-orm/pg-core").PgColumn<{
            name: "company_id";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgUUID";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        runId: import("drizzle-orm/pg-core").PgColumn<{
            name: "run_id";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgUUID";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        agentId: import("drizzle-orm/pg-core").PgColumn<{
            name: "agent_id";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgUUID";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        seq: import("drizzle-orm/pg-core").PgColumn<{
            name: "seq";
            tableName: "heartbeat_run_events";
            dataType: "number";
            columnType: "PgInteger";
            data: number;
            driverParam: string | number;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        eventType: import("drizzle-orm/pg-core").PgColumn<{
            name: "event_type";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        stream: import("drizzle-orm/pg-core").PgColumn<{
            name: "stream";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        level: import("drizzle-orm/pg-core").PgColumn<{
            name: "level";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        color: import("drizzle-orm/pg-core").PgColumn<{
            name: "color";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        message: import("drizzle-orm/pg-core").PgColumn<{
            name: "message";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        payload: import("drizzle-orm/pg-core").PgColumn<{
            name: "payload";
            tableName: "heartbeat_run_events";
            dataType: "json";
            columnType: "PgJsonb";
            data: Record<string, unknown>;
            driverParam: unknown;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {
            $type: Record<string, unknown>;
        }>;
        createdAt: import("drizzle-orm/pg-core").PgColumn<{
            name: "created_at";
            tableName: "heartbeat_run_events";
            dataType: "date";
            columnType: "PgTimestamp";
            data: Date;
            driverParam: string;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
    }, "single", Record<"heartbeat_run_events", "not-null">, false, "limit" | "where" | "orderBy", {
        id: number;
        companyId: string;
        runId: string;
        agentId: string;
        seq: number;
        eventType: string;
        stream: string | null;
        level: string | null;
        color: string | null;
        message: string | null;
        payload: Record<string, unknown> | null;
        createdAt: Date;
    }[], {
        id: import("drizzle-orm/pg-core").PgColumn<{
            name: "id";
            tableName: "heartbeat_run_events";
            dataType: "number";
            columnType: "PgBigSerial53";
            data: number;
            driverParam: number;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: true;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        companyId: import("drizzle-orm/pg-core").PgColumn<{
            name: "company_id";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgUUID";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        runId: import("drizzle-orm/pg-core").PgColumn<{
            name: "run_id";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgUUID";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        agentId: import("drizzle-orm/pg-core").PgColumn<{
            name: "agent_id";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgUUID";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        seq: import("drizzle-orm/pg-core").PgColumn<{
            name: "seq";
            tableName: "heartbeat_run_events";
            dataType: "number";
            columnType: "PgInteger";
            data: number;
            driverParam: string | number;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        eventType: import("drizzle-orm/pg-core").PgColumn<{
            name: "event_type";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: true;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        stream: import("drizzle-orm/pg-core").PgColumn<{
            name: "stream";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        level: import("drizzle-orm/pg-core").PgColumn<{
            name: "level";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        color: import("drizzle-orm/pg-core").PgColumn<{
            name: "color";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        message: import("drizzle-orm/pg-core").PgColumn<{
            name: "message";
            tableName: "heartbeat_run_events";
            dataType: "string";
            columnType: "PgText";
            data: string;
            driverParam: string;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: [string, ...string[]];
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
        payload: import("drizzle-orm/pg-core").PgColumn<{
            name: "payload";
            tableName: "heartbeat_run_events";
            dataType: "json";
            columnType: "PgJsonb";
            data: Record<string, unknown>;
            driverParam: unknown;
            notNull: false;
            hasDefault: false;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {
            $type: Record<string, unknown>;
        }>;
        createdAt: import("drizzle-orm/pg-core").PgColumn<{
            name: "created_at";
            tableName: "heartbeat_run_events";
            dataType: "date";
            columnType: "PgTimestamp";
            data: Date;
            driverParam: string;
            notNull: true;
            hasDefault: true;
            isPrimaryKey: false;
            isAutoincrement: false;
            hasRuntimeDefault: false;
            enumValues: undefined;
            baseColumn: never;
            identity: undefined;
            generated: undefined;
        }, {}, {}>;
    }>, "limit" | "where" | "orderBy">;
    getRetryExhaustedReason: (runId: string) => Promise<string | null>;
    readLog: (runOrLookup: string | {
        id: string;
        companyId: string;
        logStore: string | null;
        logRef: string | null;
    }, opts?: {
        offset?: number;
        limitBytes?: number;
    }) => Promise<{
        content: string;
        nextOffset?: number;
        runId: string;
        store: string;
        logRef: string;
    }>;
    invoke: (agentId: string, source?: "timer" | "assignment" | "on_demand" | "automation", contextSnapshot?: Record<string, unknown>, triggerDetail?: "manual" | "ping" | "callback" | "system", actor?: {
        actorType?: "user" | "agent" | "system";
        actorId?: string | null;
    }) => Promise<{
        id: string;
        status: string;
        createdAt: Date;
        updatedAt: Date;
        companyId: string;
        error: string | null;
        startedAt: Date | null;
        agentId: string;
        nextAction: string | null;
        triggerDetail: string | null;
        retryOfRunId: string | null;
        finishedAt: Date | null;
        invocationSource: string;
        wakeupRequestId: string | null;
        exitCode: number | null;
        signal: string | null;
        usageJson: Record<string, unknown> | null;
        resultJson: Record<string, unknown> | null;
        sessionIdBefore: string | null;
        sessionIdAfter: string | null;
        logStore: string | null;
        logRef: string | null;
        logBytes: number | null;
        logSha256: string | null;
        logCompressed: boolean;
        stdoutExcerpt: string | null;
        stderrExcerpt: string | null;
        errorCode: string | null;
        externalRunId: string | null;
        processPid: number | null;
        processGroupId: number | null;
        processStartedAt: Date | null;
        lastOutputAt: Date | null;
        lastOutputSeq: number;
        lastOutputStream: string | null;
        lastOutputBytes: number | null;
        processLossRetryCount: number;
        scheduledRetryAt: Date | null;
        scheduledRetryAttempt: number;
        scheduledRetryReason: string | null;
        issueCommentStatus: string;
        issueCommentSatisfiedByCommentId: string | null;
        issueCommentRetryQueuedAt: Date | null;
        livenessState: string | null;
        livenessReason: string | null;
        continuationAttempt: number;
        lastUsefulActionAt: Date | null;
        contextSnapshot: Record<string, unknown> | null;
    } | null>;
    wakeup: (agentId: string, opts?: WakeupOptions) => Promise<{
        id: string;
        status: string;
        createdAt: Date;
        updatedAt: Date;
        companyId: string;
        error: string | null;
        startedAt: Date | null;
        agentId: string;
        nextAction: string | null;
        triggerDetail: string | null;
        retryOfRunId: string | null;
        finishedAt: Date | null;
        invocationSource: string;
        wakeupRequestId: string | null;
        exitCode: number | null;
        signal: string | null;
        usageJson: Record<string, unknown> | null;
        resultJson: Record<string, unknown> | null;
        sessionIdBefore: string | null;
        sessionIdAfter: string | null;
        logStore: string | null;
        logRef: string | null;
        logBytes: number | null;
        logSha256: string | null;
        logCompressed: boolean;
        stdoutExcerpt: string | null;
        stderrExcerpt: string | null;
        errorCode: string | null;
        externalRunId: string | null;
        processPid: number | null;
        processGroupId: number | null;
        processStartedAt: Date | null;
        lastOutputAt: Date | null;
        lastOutputSeq: number;
        lastOutputStream: string | null;
        lastOutputBytes: number | null;
        processLossRetryCount: number;
        scheduledRetryAt: Date | null;
        scheduledRetryAttempt: number;
        scheduledRetryReason: string | null;
        issueCommentStatus: string;
        issueCommentSatisfiedByCommentId: string | null;
        issueCommentRetryQueuedAt: Date | null;
        livenessState: string | null;
        livenessReason: string | null;
        continuationAttempt: number;
        lastUsefulActionAt: Date | null;
        contextSnapshot: Record<string, unknown> | null;
    } | null>;
    triggerIssueMonitor: (issueId: string, input?: {
        now?: Date;
        actorType?: "user" | "agent" | "system";
        actorId?: string | null;
        agentId?: string | null;
        runId?: string | null;
        wakeReason?: string;
    }) => Promise<{
        outcome: "triggered";
        reason?: undefined;
    } | {
        outcome: "skipped";
        reason: string;
    }>;
    reportRunActivity: (runId: string) => Promise<{
        id: string;
        companyId: string;
        agentId: string;
        invocationSource: string;
        triggerDetail: string | null;
        status: string;
        startedAt: Date | null;
        finishedAt: Date | null;
        error: string | null;
        wakeupRequestId: string | null;
        exitCode: number | null;
        signal: string | null;
        usageJson: Record<string, unknown> | null;
        resultJson: Record<string, unknown> | null;
        sessionIdBefore: string | null;
        sessionIdAfter: string | null;
        logStore: string | null;
        logRef: string | null;
        logBytes: number | null;
        logSha256: string | null;
        logCompressed: boolean;
        stdoutExcerpt: string | null;
        stderrExcerpt: string | null;
        errorCode: string | null;
        externalRunId: string | null;
        processPid: number | null;
        processGroupId: number | null;
        processStartedAt: Date | null;
        lastOutputAt: Date | null;
        lastOutputSeq: number;
        lastOutputStream: string | null;
        lastOutputBytes: number | null;
        retryOfRunId: string | null;
        processLossRetryCount: number;
        scheduledRetryAt: Date | null;
        scheduledRetryAttempt: number;
        scheduledRetryReason: string | null;
        issueCommentStatus: string;
        issueCommentSatisfiedByCommentId: string | null;
        issueCommentRetryQueuedAt: Date | null;
        livenessState: string | null;
        livenessReason: string | null;
        continuationAttempt: number;
        lastUsefulActionAt: Date | null;
        nextAction: string | null;
        contextSnapshot: Record<string, unknown> | null;
        createdAt: Date;
        updatedAt: Date;
    } | null>;
    reapOrphanedRuns: (opts?: {
        staleThresholdMs?: number;
    }) => Promise<{
        reaped: number;
        runIds: string[];
    }>;
    promoteDueScheduledRetries: (now?: Date) => Promise<{
        promoted: number;
        runIds: string[];
    }>;
    retryScheduledRetryNow: (input: {
        issueId: string;
        actor?: {
            actorType?: "user" | "agent" | "system";
            actorId?: string | null;
        };
        now?: Date;
    }) => Promise<{
        outcome: "already_promoted";
        message: string;
        scheduledRetry: {
            runId: string;
            status: "scheduled_retry" | "queued" | "running" | "cancelled";
            agentId: string;
            agentName: string | null;
            retryOfRunId: string | null;
            scheduledRetryAt: Date | null;
            scheduledRetryAttempt: number;
            scheduledRetryReason: string | null;
            error: string | null;
            errorCode: string | null;
        };
    } | {
        outcome: "no_scheduled_retry";
        message: string;
        scheduledRetry: null;
    } | {
        outcome: "promoted";
        message: string;
        scheduledRetry: {
            runId: string;
            status: "scheduled_retry" | "queued" | "running" | "cancelled";
            agentId: string;
            agentName: string | null;
            retryOfRunId: string | null;
            scheduledRetryAt: Date | null;
            scheduledRetryAttempt: number;
            scheduledRetryReason: string | null;
            error: string | null;
            errorCode: string | null;
        };
    } | {
        outcome: "gate_suppressed";
        message: string;
        scheduledRetry: {
            runId: string;
            status: "scheduled_retry" | "queued" | "running" | "cancelled";
            agentId: string;
            agentName: string | null;
            retryOfRunId: string | null;
            scheduledRetryAt: Date | null;
            scheduledRetryAttempt: number;
            scheduledRetryReason: string | null;
            error: string | null;
            errorCode: string | null;
        };
    }>;
    resumeQueuedRuns: () => Promise<void>;
    scheduleBoundedRetry: (runId: string, opts?: {
        now?: Date;
        random?: () => number;
        retryReason?: string;
        wakeReason?: string;
        maxAttempts?: number;
        delayMs?: number;
    }) => Promise<{
        outcome: "retry_exhausted";
        attempt: number;
        maxAttempts: number;
        reason?: undefined;
        errorCode?: undefined;
        issueId?: undefined;
        run?: undefined;
        dueAt?: undefined;
        reusedExisting?: undefined;
    } | {
        outcome: "not_scheduled";
        reason: string;
        errorCode: "agent_not_invokable" | "budget_blocked" | "issue_paused" | "issue_dependencies_blocked" | "issue_not_found" | "issue_reassigned" | "issue_cancelled" | "issue_terminal_status" | "issue_not_in_progress" | "issue_execution_lock_changed" | "issue_review_participant_changed";
        issueId: string | null;
        attempt?: undefined;
        maxAttempts?: undefined;
        run?: undefined;
        dueAt?: undefined;
        reusedExisting?: undefined;
    } | {
        outcome: "scheduled";
        run: {
            id: string;
            status: string;
            createdAt: Date;
            updatedAt: Date;
            companyId: string;
            error: string | null;
            startedAt: Date | null;
            agentId: string;
            nextAction: string | null;
            triggerDetail: string | null;
            retryOfRunId: string | null;
            finishedAt: Date | null;
            invocationSource: string;
            wakeupRequestId: string | null;
            exitCode: number | null;
            signal: string | null;
            usageJson: Record<string, unknown> | null;
            resultJson: Record<string, unknown> | null;
            sessionIdBefore: string | null;
            sessionIdAfter: string | null;
            logStore: string | null;
            logRef: string | null;
            logBytes: number | null;
            logSha256: string | null;
            logCompressed: boolean;
            stdoutExcerpt: string | null;
            stderrExcerpt: string | null;
            errorCode: string | null;
            externalRunId: string | null;
            processPid: number | null;
            processGroupId: number | null;
            processStartedAt: Date | null;
            lastOutputAt: Date | null;
            lastOutputSeq: number;
            lastOutputStream: string | null;
            lastOutputBytes: number | null;
            processLossRetryCount: number;
            scheduledRetryAt: Date | null;
            scheduledRetryAttempt: number;
            scheduledRetryReason: string | null;
            issueCommentStatus: string;
            issueCommentSatisfiedByCommentId: string | null;
            issueCommentRetryQueuedAt: Date | null;
            livenessState: string | null;
            livenessReason: string | null;
            continuationAttempt: number;
            lastUsefulActionAt: Date | null;
            contextSnapshot: Record<string, unknown> | null;
        };
        dueAt: Date;
        attempt: number;
        maxAttempts: number;
        reusedExisting: boolean;
        reason?: undefined;
        errorCode?: undefined;
        issueId?: undefined;
    } | {
        outcome: "scheduled";
        run: {
            id: string;
            status: string;
            createdAt: Date;
            updatedAt: Date;
            companyId: string;
            error: string | null;
            startedAt: Date | null;
            agentId: string;
            nextAction: string | null;
            triggerDetail: string | null;
            retryOfRunId: string | null;
            finishedAt: Date | null;
            invocationSource: string;
            wakeupRequestId: string | null;
            exitCode: number | null;
            signal: string | null;
            usageJson: Record<string, unknown> | null;
            resultJson: Record<string, unknown> | null;
            sessionIdBefore: string | null;
            sessionIdAfter: string | null;
            logStore: string | null;
            logRef: string | null;
            logBytes: number | null;
            logSha256: string | null;
            logCompressed: boolean;
            stdoutExcerpt: string | null;
            stderrExcerpt: string | null;
            errorCode: string | null;
            externalRunId: string | null;
            processPid: number | null;
            processGroupId: number | null;
            processStartedAt: Date | null;
            lastOutputAt: Date | null;
            lastOutputSeq: number;
            lastOutputStream: string | null;
            lastOutputBytes: number | null;
            processLossRetryCount: number;
            scheduledRetryAt: Date | null;
            scheduledRetryAttempt: number;
            scheduledRetryReason: string | null;
            issueCommentStatus: string;
            issueCommentSatisfiedByCommentId: string | null;
            issueCommentRetryQueuedAt: Date | null;
            livenessState: string | null;
            livenessReason: string | null;
            continuationAttempt: number;
            lastUsefulActionAt: Date | null;
            contextSnapshot: Record<string, unknown> | null;
        };
        dueAt: Date;
        attempt: number;
        maxAttempts: number;
        reason?: undefined;
        errorCode?: undefined;
        issueId?: undefined;
        reusedExisting?: undefined;
    } | {
        outcome: "missing_run";
    } | {
        outcome: "missing_agent";
    }>;
    reconcileStrandedAssignedIssues: () => Promise<{
        assignmentDispatched: number;
        dispatchRequeued: number;
        continuationRequeued: number;
        productiveContinuationObserved: number;
        successfulContinuationObserved: number;
        orphanBlockersAssigned: number;
        successfulRunHandoffEscalated: number;
        escalated: number;
        skipped: number;
        issueIds: string[];
    }>;
    buildIssueGraphLivenessAutoRecoveryPreview: (opts?: {
        lookbackHours?: number;
        now?: Date;
    }) => Promise<import("@paperclipai/shared").IssueGraphLivenessAutoRecoveryPreview>;
    reconcileIssueGraphLiveness: (opts?: {
        runId?: string | null;
        force?: boolean;
        lookbackHours?: number;
    }) => Promise<{
        findings: number;
        autoRecoveryEnabled: boolean;
        lookbackHours: number;
        cutoff: string;
        escalationsCreated: number;
        existingEscalations: number;
        skipped: number;
        skippedAutoRecoveryDisabled: number;
        skippedOutsideLookback: number;
        obsoleteRecoveriesRetired: number;
        obsoleteRecoveriesActiveSkipped: number;
        obsoleteRecoveryBlockerRelationsRemoved: number;
        doneRecoveryBlockerRelationsRemoved: number;
        issueIds: string[];
        escalationIssueIds: string[];
        retiredRecoveryIssueIds: string[];
    }>;
    scanSilentActiveRuns: (opts?: {
        now?: Date;
        companyId?: string;
    }) => Promise<{
        scanned: number;
        created: number;
        existing: number;
        escalated: number;
        folded: number;
        snoozed: number;
        skipped: number;
        evaluationIssueIds: string[];
    }>;
    reconcileProductivityReviews: (opts?: {
        now?: Date;
        companyId?: string;
    }) => Promise<{
        scanned: number;
        created: number;
        updated: number;
        existing: number;
        snoozed: number;
        creationCapped: number;
        skipped: number;
        failed: number;
        reviewIssueIds: string[];
        failedIssueIds: string[];
    }>;
    buildRunOutputSilence: (run: Pick<typeof heartbeatRuns.$inferSelect, "id" | "companyId" | "status" | "lastOutputAt" | "lastOutputSeq" | "lastOutputStream" | "processStartedAt" | "startedAt" | "createdAt">, now?: Date) => Promise<import("./recovery/service.js").RunOutputSilenceSummary>;
    tickTimers: (now?: Date) => Promise<{
        checked: number;
        enqueued: number;
        skipped: number;
    }>;
    cancelRun: (runId: string, reason?: string) => Promise<{
        readonly processGroupId: number | null;
        readonly resultJson: Record<string, unknown> | null;
        readonly id: string;
        readonly companyId: string;
        readonly agentId: string;
        readonly invocationSource: string;
        readonly triggerDetail: string | null;
        readonly status: string;
        readonly startedAt: Date | null;
        readonly finishedAt: Date | null;
        readonly error: string | null;
        readonly wakeupRequestId: string | null;
        readonly exitCode: number | null;
        readonly signal: string | null;
        readonly usageJson: Record<string, unknown> | null;
        readonly sessionIdBefore: string | null;
        readonly sessionIdAfter: string | null;
        readonly logStore: string | null;
        readonly logRef: string | null;
        readonly logBytes: number | null;
        readonly logSha256: string | null;
        readonly logCompressed: boolean;
        readonly stdoutExcerpt: string | null;
        readonly stderrExcerpt: string | null;
        readonly errorCode: string | null;
        readonly externalRunId: string | null;
        readonly processPid: number | null;
        readonly processStartedAt: Date | null;
        readonly lastOutputAt: Date | null;
        readonly lastOutputSeq: number;
        readonly lastOutputStream: string | null;
        readonly lastOutputBytes: number | null;
        readonly retryOfRunId: string | null;
        readonly processLossRetryCount: number;
        readonly scheduledRetryAt: Date | null;
        readonly scheduledRetryAttempt: number;
        readonly scheduledRetryReason: string | null;
        readonly issueCommentStatus: string;
        readonly issueCommentSatisfiedByCommentId: string | null;
        readonly issueCommentRetryQueuedAt: Date | null;
        readonly livenessState: string | null;
        readonly livenessReason: string | null;
        readonly continuationAttempt: number;
        readonly lastUsefulActionAt: Date | null;
        readonly nextAction: string | null;
        readonly contextSnapshot: Record<string, unknown> | null;
        readonly createdAt: Date;
        readonly updatedAt: Date;
    }>;
    cancelActiveForAgent: (agentId: string, reason?: string) => Promise<number>;
    cancelInvocationsForAgents: (agentIds: string[], reason: string) => Promise<{
        agentIds: string[];
        runsCancelled: number;
        wakeupsCancelled: number;
    }>;
    cancelBudgetScopeWork: (scope: BudgetEnforcementScope) => Promise<void>;
    getRunIssueSummary: (runId: string) => Promise<{
        readonly id: string;
        readonly status: string;
        readonly invocationSource: string;
        readonly triggerDetail: string | null;
        readonly contextCommentId: string | null;
        readonly contextWakeCommentId: string | null;
        readonly startedAt: Date | null;
        readonly finishedAt: Date | null;
        readonly createdAt: Date;
        readonly agentId: string;
        readonly logBytes: number | null;
        readonly processStartedAt: Date | null;
        readonly livenessState: string | null;
        readonly livenessReason: string | null;
        readonly continuationAttempt: number;
        readonly lastUsefulActionAt: Date | null;
        readonly nextAction: string | null;
        readonly lastOutputAt: Date | null;
        readonly lastOutputSeq: number;
        readonly lastOutputStream: string | null;
        readonly lastOutputBytes: number | null;
        readonly issueId: string | null;
    }>;
    getActiveRunForAgent: (agentId: string) => Promise<{
        id: string;
        companyId: string;
        agentId: string;
        invocationSource: string;
        triggerDetail: string | null;
        status: string;
        startedAt: Date | null;
        finishedAt: Date | null;
        error: string | null;
        wakeupRequestId: string | null;
        exitCode: number | null;
        signal: string | null;
        usageJson: Record<string, unknown> | null;
        resultJson: Record<string, unknown> | null;
        sessionIdBefore: string | null;
        sessionIdAfter: string | null;
        logStore: string | null;
        logRef: string | null;
        logBytes: number | null;
        logSha256: string | null;
        logCompressed: boolean;
        stdoutExcerpt: string | null;
        stderrExcerpt: string | null;
        errorCode: string | null;
        externalRunId: string | null;
        processPid: number | null;
        processGroupId: number | null;
        processStartedAt: Date | null;
        lastOutputAt: Date | null;
        lastOutputSeq: number;
        lastOutputStream: string | null;
        lastOutputBytes: number | null;
        retryOfRunId: string | null;
        processLossRetryCount: number;
        scheduledRetryAt: Date | null;
        scheduledRetryAttempt: number;
        scheduledRetryReason: string | null;
        issueCommentStatus: string;
        issueCommentSatisfiedByCommentId: string | null;
        issueCommentRetryQueuedAt: Date | null;
        livenessState: string | null;
        livenessReason: string | null;
        continuationAttempt: number;
        lastUsefulActionAt: Date | null;
        nextAction: string | null;
        contextSnapshot: Record<string, unknown> | null;
        createdAt: Date;
        updatedAt: Date;
    }>;
    getActiveRunIssueSummaryForAgent: (agentId: string) => Promise<{
        readonly id: string;
        readonly status: string;
        readonly invocationSource: string;
        readonly triggerDetail: string | null;
        readonly contextCommentId: string | null;
        readonly contextWakeCommentId: string | null;
        readonly startedAt: Date | null;
        readonly finishedAt: Date | null;
        readonly createdAt: Date;
        readonly agentId: string;
        readonly logBytes: number | null;
        readonly processStartedAt: Date | null;
        readonly livenessState: string | null;
        readonly livenessReason: string | null;
        readonly continuationAttempt: number;
        readonly lastUsefulActionAt: Date | null;
        readonly nextAction: string | null;
        readonly lastOutputAt: Date | null;
        readonly lastOutputSeq: number;
        readonly lastOutputStream: string | null;
        readonly lastOutputBytes: number | null;
        readonly issueId: string | null;
    }>;
};
//# sourceMappingURL=heartbeat.d.ts.map