import { type ChildProcess } from "node:child_process";
import type { Db } from "@rudderhq/db";
import type { WorkspaceOperationRecorder } from "./workspace-operations.js";
export interface ExecutionWorkspaceInput {
    baseCwd: string;
    source: "project_primary" | "task_session" | "agent_home";
    projectId: string | null;
    workspaceId: string | null;
    repoUrl: string | null;
    repoRef: string | null;
}
export interface ExecutionWorkspaceIssueRef {
    id: string;
    identifier: string | null;
    title: string | null;
}
export interface ExecutionWorkspaceAgentRef {
    id: string;
    name: string;
    orgId: string;
}
export interface RealizedExecutionWorkspace extends ExecutionWorkspaceInput {
    strategy: "project_primary" | "git_worktree";
    cwd: string;
    branchName: string | null;
    worktreePath: string | null;
    warnings: string[];
    created: boolean;
}
export interface RuntimeServiceRef {
    id: string;
    orgId: string;
    projectId: string | null;
    projectWorkspaceId: string | null;
    executionWorkspaceId: string | null;
    issueId: string | null;
    serviceName: string;
    status: "starting" | "running" | "stopped" | "failed";
    lifecycle: "shared" | "ephemeral";
    scopeType: "project_workspace" | "execution_workspace" | "run" | "agent";
    scopeId: string | null;
    reuseKey: string | null;
    command: string | null;
    cwd: string | null;
    port: number | null;
    url: string | null;
    provider: "local_process" | "adapter_managed";
    providerRef: string | null;
    ownerAgentId: string | null;
    startedByRunId: string | null;
    lastUsedAt: string;
    startedAt: string;
    stoppedAt: string | null;
    stopPolicy: Record<string, unknown> | null;
    healthStatus: "unknown" | "healthy" | "unhealthy";
    reused: boolean;
}
export interface RuntimeServiceRecord extends RuntimeServiceRef {
    db?: Db;
    child: ChildProcess | null;
    leaseRunIds: Set<string>;
    idleTimer: ReturnType<typeof globalThis.setTimeout> | null;
    envFingerprint: string;
}
export declare const runtimeServicesById: Map<string, RuntimeServiceRecord>;
export declare const runtimeServicesByReuseKey: Map<string, string>;
export declare const runtimeServiceLeasesByRun: Map<string, string[]>;
export declare function stableStringify(value: unknown): string;
export declare function sanitizeRuntimeServiceBaseEnv(baseEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
export declare function stableRuntimeServiceId(input: {
    agentRuntimeType: string;
    runId: string;
    scopeType: RuntimeServiceRef["scopeType"];
    scopeId: string | null;
    serviceName: string;
    reportId: string | null;
    providerRef: string | null;
    reuseKey: string | null;
}): string;
export declare function toRuntimeServiceRef(record: RuntimeServiceRecord, overrides?: Partial<RuntimeServiceRef>): RuntimeServiceRef;
export declare function sanitizeSlugPart(value: string | null | undefined, fallback: string): string;
export declare function renderWorkspaceTemplate(template: string, input: {
    issue: ExecutionWorkspaceIssueRef | null;
    agent: ExecutionWorkspaceAgentRef;
    projectId: string | null;
    repoRef: string | null;
}): string;
export declare function sanitizeBranchName(value: string): string;
export declare function isAbsolutePath(value: string): boolean;
export declare function resolveConfiguredPath(value: string, baseDir: string): string;
export declare function formatCommandForDisplay(command: string, args: string[]): string;
export declare function executeProcess(input: {
    command: string;
    args: string[];
    cwd: string;
    env?: NodeJS.ProcessEnv;
}): Promise<{
    stdout: string;
    stderr: string;
    code: number | null;
}>;
export declare function runGit(args: string[], cwd: string): Promise<string>;
export declare function gitErrorIncludes(error: unknown, needle: string): boolean;
export declare function directoryExists(value: string): Promise<boolean>;
export declare function terminateChildProcess(child: ChildProcess): void;
export declare function buildWorkspaceCommandEnv(input: {
    base: ExecutionWorkspaceInput;
    repoRoot: string;
    worktreePath: string;
    branchName: string;
    issue: ExecutionWorkspaceIssueRef | null;
    agent: ExecutionWorkspaceAgentRef;
    created: boolean;
}): NodeJS.ProcessEnv;
export declare function runWorkspaceCommand(input: {
    command: string;
    cwd: string;
    env: NodeJS.ProcessEnv;
    label: string;
}): Promise<void>;
export declare function recordGitOperation(recorder: WorkspaceOperationRecorder | null | undefined, input: {
    phase: "worktree_prepare" | "worktree_cleanup";
    args: string[];
    cwd: string;
    metadata?: Record<string, unknown> | null;
    successMessage?: string | null;
    failureLabel?: string | null;
}): Promise<string>;
export declare function recordWorkspaceCommandOperation(recorder: WorkspaceOperationRecorder | null | undefined, input: {
    phase: "workspace_provision" | "workspace_teardown";
    command: string;
    cwd: string;
    env: NodeJS.ProcessEnv;
    label: string;
    metadata?: Record<string, unknown> | null;
    successMessage?: string | null;
}): Promise<void>;
export declare function provisionExecutionWorktree(input: {
    strategy: Record<string, unknown>;
    base: ExecutionWorkspaceInput;
    repoRoot: string;
    worktreePath: string;
    branchName: string;
    issue: ExecutionWorkspaceIssueRef | null;
    agent: ExecutionWorkspaceAgentRef;
    created: boolean;
    recorder?: WorkspaceOperationRecorder | null;
}): Promise<void>;
export declare function buildExecutionWorkspaceCleanupEnv(input: {
    workspace: {
        cwd: string | null;
        providerRef: string | null;
        branchName: string | null;
        repoUrl: string | null;
        baseRef: string | null;
        projectId: string | null;
        projectWorkspaceId: string | null;
        sourceIssueId: string | null;
    };
    projectWorkspaceCwd?: string | null;
}): NodeJS.ProcessEnv;
export declare function resolveGitRepoRootForWorkspaceCleanup(worktreePath: string, projectWorkspaceCwd: string | null): Promise<string | null>;
//# sourceMappingURL=workspace-runtime.helpers.d.ts.map