export type ArtifactRef = { artifactId: string; sha256: string; byteLength: number; mediaType: string; typeId: string; producer: { node: string; worker: string }; lineage: { generation: number; runId: string; attempt: number }; redaction: 'public' | 'internal' | 'confidential' | 'restricted'; }; type RequestBase = { isolationProfile: string; providerProfile: string; }; export type LegacyShipRequest = RequestBase & ( | { source: 'issue'; issue: string; prompt?: null; artifacts: [] } | { source: 'prompt'; prompt: string; issue?: null; artifacts: [] } | { source: 'artifact'; issue?: null; prompt?: null; artifacts: ArtifactRef[] } ); export type LegacyShipResult = { summary: string; status: 'succeeded' | 'failed'; artifacts: ArtifactRef[]; }; export type LifecycleState = | 'idle' | 'starting' | 'running' | 'stopping' | 'completed' | 'failed' | 'timed_out' | 'stopped' | 'malformed'; export type LifecycleStatus = { state: LifecycleState; clusterId: string | null; sequence: number; stopRequested: boolean; terminal: boolean; }; export type WorkerError = | { status: 'error'; code: 'timeout' | 'crash' | 'malformed' | 'refusal'; reason: 'declared_failure'; } | { status: 'error'; code: 'refusal'; reason: 'policy_denied' | 'interactive_input_required' | 'authentication_required'; } | { status: 'error'; code: 'malformed'; reason: 'malformed_result' }; export type TerminalReceipt = | { state: 'completed'; clusterId: string; finishedAt: number; result: LegacyShipResult } | { state: 'stopped'; clusterId: string; finishedAt: number; stop: { requested: true; effective: boolean; externalEffectsRolledBack: false }; } | { state: 'failed' | 'timed_out' | 'malformed'; clusterId: string; finishedAt: number; outcome: WorkerError; }; export type LifecycleEvent = { sequence: number; state: Exclude; at: number; details?: unknown; }; export type RunPlan = Readonly<{ isolation: 'worktree' | 'docker'; delivery: 'none' | 'pr' | 'ship'; autoMerge: boolean; }>; export type ExecutionBounds = Readonly<{ executionMs: number; shutdownMs: number; frameBytes: number; }>; export type ResolvedDeploymentProfile = Readonly<{ isolationProfile: string; providerProfile: string; plan: RunPlan; deployment: Readonly>; provider: Readonly>; bounds: ExecutionBounds; }>; export type CancellationContext = Readonly<{ signal: AbortSignal }>; export type CleanupFailure = Readonly<{ phase: 'profile_resolution' | 'artifact_staging' | 'receipt_collection'; kind: 'operation' | 'cleanup'; clusterId: string | null; error: unknown; }>; export type IsolationWorkspace = Readonly<{ kind: 'worktree' | 'docker'; hostRoot: string; runtimeRoot: string; }>; export interface DeploymentProfileRegistry { readonly bounds?: ExecutionBounds; resolve( isolationProfile: string, providerProfile: string, context: CancellationContext ): ResolvedDeploymentProfile | Promise; release?(profile: ResolvedDeploymentProfile, context: CancellationContext): void | Promise; } export interface ArtifactResolver { stage( artifacts: readonly ArtifactRef[], context: Readonly<{ clusterId: string; profile: ResolvedDeploymentProfile; isolation: IsolationWorkspace; signal: AbortSignal; }> ): Readonly> | Promise>>; cleanup?( manifest: Readonly>, context: Readonly<{ clusterId: string; profile: ResolvedDeploymentProfile; isolation: IsolationWorkspace; signal: AbortSignal; }> ): void | Promise; } export interface ArtifactReceiptSink { collect( declared: readonly unknown[], context: Readonly<{ clusterId: string; profile: ResolvedDeploymentProfile; signal: AbortSignal; }> ): readonly ArtifactRef[] | Promise; cleanup?( receipts: readonly ArtifactRef[], context: Readonly<{ clusterId: string; profile: ResolvedDeploymentProfile; signal: AbortSignal; }> ): void | Promise; } export type EngineEvent = | { type: 'running' } | ({ type: 'complete'; artifacts?: readonly unknown[] } & ( | { summary: string; result?: never } | { result: LegacyShipResult; summary?: string } )) | ({ type: 'failed' } & Omit) | { type: 'malformed' }; export interface EngineAdapter { start(input: { request: LegacyShipRequest; profile: ResolvedDeploymentProfile; prepareArtifacts?(isolation: IsolationWorkspace): Promise>>; clusterId: string; onEvent(event: EngineEvent): void; }): | { clusterId?: string; artifactsStaged?: boolean } | Promise<{ clusterId?: string; artifactsStaged?: boolean }>; status?(): Readonly> | null; stop(): { effective?: boolean } | Promise<{ effective?: boolean }>; waitForCleanup?(): void | Promise; close?(): void | Promise; } export type LegacyClusterWorkerDependencies = { profileRegistry?: DeploymentProfileRegistry; artifactResolver?: ArtifactResolver | ArtifactResolver['stage']; artifactReceiptSink?: ArtifactReceiptSink | ArtifactReceiptSink['collect']; engineAdapter?: EngineAdapter; clock?: () => number; timers?: { setTimeout(callback: () => void, milliseconds: number): unknown; clearTimeout(handle: unknown): void; }; idFactory?: () => string; cleanupFailureReporter?: (failure: CleanupFailure) => void | Promise; }; export interface LegacyClusterWorker { start(request: LegacyShipRequest): Promise; status(): LifecycleStatus; events(): AsyncIterableIterator; stop(): Promise; result(): Promise; } export function createLegacyClusterWorker( dependencies?: LegacyClusterWorkerDependencies ): LegacyClusterWorker; export function createDeploymentProfileRegistry(options?: { isolationProfiles?: Readonly>>>; providerProfiles?: Readonly>>>; bounds?: Partial; }): DeploymentProfileRegistry; export function createCurrentEngineAdapter(options?: object): EngineAdapter;