import { Type } from "typebox"; export type RunStatus = "queued" | "running" | "succeeded" | "failed" | "terminated" | "checkpointed_stop" | "lost" | "superseded"; export type FailureClass = "nonzero_exit" | "signal" | "cuda_oom" | "timeout" | "terminated" | "runner_error" | "dependency_failed" | "resource_unavailable" | "disk_insufficient" | "checkpoint_invalid" | "superseded" | null; export type EventType = "process.exit" | "log.regex" | "timer.timeout" | "file.created" | "progress.stalled" | "resource.intrusion" | "dependency.failed" | "resource.timeout" | "run.superseded"; export type EventAction = "record" | "terminate" | "wake_agent"; export interface EventSpec { id: string; type: EventType; pattern?: string; source?: "stdout" | "stderr" | "both"; path?: string; after_seconds?: number; cooldown_seconds?: number; max_matches?: number; max_triggers?: number; stable_seconds?: number; critical?: boolean; milestone?: "first_update"; actions: EventAction[]; } export interface EventRecord { event_id: string; type: EventType; status: string; matched?: string; log_excerpt?: string; actions: EventAction[]; triggered_at: string; notification_id?: string; critical?: boolean; } export interface RunDependency { run_id: string; require_status: "succeeded" | "checkpointed_stop"; allowed_statuses: Array<"succeeded" | "checkpointed_stop">; allowed_failure_classes?: Array>; checkpoint_path?: string; checkpoint_checksum?: string; checkpoint_complete_marker?: string; artifact_id?: string; } export interface RunResources { gpu_ids: string[]; wait_timeout_seconds: number; poll_ms: number; retry_backoff_seconds: number; allow_foreign_processes: boolean; min_free_memory_mb?: number; mode?: "exclusive" | "shared"; min_free_memory_mib?: number; memory_safety_mib?: number; observed_foreign_pids?: number[]; observed_gpu_processes?: string[]; } export interface TerminationPolicy { checkpoint_signal?: NodeJS.Signals; checkpoint_event_id?: string; graceful_timeout_seconds: number; terminate_signal: NodeJS.Signals; force_kill_timeout_seconds: number; allow_sigkill: boolean; } export interface TerminationAudit { request_id: string; requested_by: { session_id?: string; actor: "user" | "event" | "system"; reason: string; }; requested_at: string; source: "control" | "event" | "external"; force: boolean; signals: Array<{ signal: string; sent_at: string; target: string; }>; checkpoint_observed_at?: string; completed_at?: string; } export interface NotificationRecord { notification_id: string; run_id: string; event_id: string; owner_session_id?: string; state: "matched" | "queued" | "sending" | "delivered" | "acknowledged"; critical: boolean; message: string; attempts: number; created_at: string; queued_at: string; delivered_at?: string; acknowledged_at?: string; next_attempt_at?: string; last_error?: string; history: Array<{ state: "matched" | "queued" | "sending" | "delivered" | "acknowledged"; at: string; detail?: string; }>; } export interface ArtifactRecord { artifact_id: string; run_id: string; type: "checkpoint"; path: string; bytes: number; sha256: string; state: "complete" | "failed" | "checksum_verified" | "durable_complete"; created_at: string; } export interface ProgressWatchdog { pattern: string; no_progress_seconds: number; actions: Array<"record" | "wake_agent">; } export interface RunStorage { path?: string; estimated_checkpoint_bytes?: number; reserve_multiplier: number; min_free_bytes: number; } export interface RunOwner { session_id: string; cwd: string; bound_at: string; } export interface ActiveRunSummary { run_id: string; task_id: string; status: "queued" | "running"; waiting_for?: string; command_argv: string[]; owner?: RunOwner; updated_at: string; } export interface RunRecord { run_id: string; task_id: string; hypothesis_id: string | null; parent_run_id?: string; status: RunStatus; command: { argv: string[]; cwd: string; }; git: { branch: string; commit: string; worktree: string; snapshot?: string; file_checksums?: Record; }; config: Record; tracking: { mlflow_run_id?: string | null; mlflow_experiment_id?: string | null; wandb_run_id?: string | null; wandb_url?: string | null; wandb_name?: string | null; wandb_group?: string | null; wandb_tags?: string[]; prl_wandb_run_id?: string | null; application_wandb_run_id?: string | null; application_wandb_url?: string | null; }; event_plan: EventSpec[]; events: EventRecord[]; wakeups: number; result: { exit_code: number | null; failure_class: FailureClass; signal?: string; }; lifecycle?: { process_status: string; trainer_status: string; checkpoint_status: string; durable_replica_status: string; tracking_status: string; notification_status: string; }; termination?: TerminationPolicy; termination_audit?: TerminationAudit[]; artifacts?: ArtifactRecord[]; progress_watchdog?: ProgressWatchdog; storage?: RunStorage; experiment?: { family?: string; parent_run?: string; overrides?: Record; compatibility?: string; resume_mode?: string; }; performance?: Record; owner_audit?: Array<{ from?: string; to: string; actor: string; reason: string; transferred_at: string; }>; timestamps: { created_at: string; started_at: string | null; finished_at: string | null; }; pid?: number; runner_pid?: number; dependency?: RunDependency; resources?: RunResources; waiting_for?: string; superseded_by?: string; owner?: RunOwner; } export declare const NEW_WORKTREE_REASONS: readonly ["stable_baseline", "concurrent_agents", "disposable_experiment"]; export type NewWorktreeReason = typeof NEW_WORKTREE_REASONS[number]; export interface TaskRecord { task_id: string; hypothesis_id: string | null; name: string; branch: string; worktree: string; status: "active" | "finished"; created_at: string; finished_at?: string; checkpoint_commits: string[]; new_worktree_reason?: NewWorktreeReason; } export interface TaskStartResult extends TaskRecord { reused: boolean; } export interface TaskCheckpointResult { task_id: string; worktree: string; commit: string; created: boolean; } export interface PrlConfig { version: number; tracking: { mlflow: { enabled: boolean; tracking_uri_env: string; experiment_name: string; required: boolean; }; wandb: { enabled: boolean; group: string | null; tags: string[]; }; }; runner: { termination_grace_seconds: number; max_wakeups_per_run: number; event_poll_ms: number; force_kill_timeout_seconds: number; allow_sigkill: boolean; log_flush_ms: number; max_console_log_bytes: number; notification_retry_seconds: number; max_notification_attempts: number; }; safety: { max_auto_commit_bytes: number; max_untracked_files: number; min_free_bytes: number; checkpoint_stability_seconds: number; }; } export declare const RunSchema: Type.TObject<{ run_id: Type.TString; task_id: Type.TString; hypothesis_id: Type.TUnion<[Type.TString, Type.TNull]>; status: Type.TString; command: Type.TObject<{ argv: Type.TArray; cwd: Type.TString; }>; git: Type.TObject<{ branch: Type.TString; commit: Type.TString; worktree: Type.TString; }>; config: Type.TRecord<"^.*$", Type.TUnknown>; tracking: Type.TRecord<"^.*$", Type.TUnknown>; event_plan: Type.TArray; }>>; events: Type.TArray>; wakeups: Type.TNumber; result: Type.TObject<{ exit_code: Type.TUnion<[Type.TNumber, Type.TNull]>; failure_class: Type.TUnion<[Type.TString, Type.TNull]>; }>; timestamps: Type.TObject<{ created_at: Type.TString; started_at: Type.TUnion<[Type.TString, Type.TNull]>; finished_at: Type.TUnion<[Type.TString, Type.TNull]>; }>; dependency: Type.TOptional; resources: Type.TOptional; waiting_for: Type.TOptional; superseded_by: Type.TOptional; lifecycle: Type.TOptional; termination: Type.TOptional; termination_audit: Type.TOptional; artifacts: Type.TOptional; progress_watchdog: Type.TOptional; storage: Type.TOptional; experiment: Type.TOptional; performance: Type.TOptional; owner_audit: Type.TOptional; owner: Type.TOptional>; }>; export declare function isGitRepository(cwd?: string): boolean; export declare function projectRoot(cwd?: string): string; export declare function prlPaths(cwd?: string): { root: string; agents: string; research: string; config: string; tasks: string; worktrees: string; pending: string; notifications: string; snapshots: string; runtime: string; activeRuns: string; notificationQueue: string; runs: string; }; export declare function checkpointCommit(cwd: string, message?: string): string; export declare function initProject(cwd?: string): { root: string; initialized: boolean; commit: string; }; export declare function readConfig(cwd?: string): PrlConfig; export declare function readTask(taskId: string, cwd?: string): TaskRecord; export declare function listTasks(cwd?: string): TaskRecord[]; export declare function taskStart(input: { hypothesisId?: string; name: string; cwd?: string; newWorktreeReason?: NewWorktreeReason; }): TaskStartResult; export declare function taskCheckpoint(taskId: string, message?: string, cwd?: string): TaskCheckpointResult; export declare function taskFinish(taskId: string, cwd?: string): TaskRecord; export declare function readRun(runId: string, cwd?: string): RunRecord; export declare function listRuns(cwd?: string): RunRecord[]; export declare function listActiveRuns(cwd?: string): ActiveRunSummary[]; export declare function runOwnedBy(run: RunRecord, owner: RunOwner): boolean; export declare function runClaim(runId: string, owner: RunOwner, cwd?: string): RunRecord; export declare function runTransfer(runId: string, owner: RunOwner, reason: string, confirmed: boolean, cwd?: string): RunRecord; export declare function runArtifactRegister(runId: string, pathValue: string, options?: { completeMarker?: string; owner?: RunOwner; cwd?: string; }): Promise; export declare function runLaunch(input: { taskId: string; argv: string[]; events?: unknown; cwd?: string; parentRunId?: string; workerEntry?: string; dependsOn?: unknown; resources?: unknown; owner?: unknown; termination?: unknown; progressWatchdog?: unknown; storage?: unknown; experiment?: RunRecord["experiment"]; sourceCommit?: string; }): Promise; export declare function notificationIds(message: string): string[]; export declare function pendingNotificationMessage(message: string, cwd: string, owner: RunOwner, seen: Set): { message: string; ids: string[]; } | undefined; export declare function listNotifications(cwd?: string, runId?: string): NotificationRecord[]; export declare function runWorkerEntry(runId: string, cwd?: string): Promise; export declare function runInspect(runId: string, options?: { mode?: string; tail?: number; query?: string; cwd?: string; owner?: RunOwner; }): string | string[] | RunRecord | { mlflow_run_id?: string | null; mlflow_experiment_id?: string | null; wandb_run_id?: string | null; wandb_url?: string | null; wandb_name?: string | null; wandb_group?: string | null; wandb_tags?: string[]; prl_wandb_run_id?: string | null; application_wandb_run_id?: string | null; application_wandb_url?: string | null; } | EventRecord[] | ArtifactRecord[] | Record | NotificationRecord[] | { run_id: string; task_id: string; status: RunStatus; lifecycle: { process_status: string; trainer_status: string; checkpoint_status: string; durable_replica_status: string; tracking_status: string; notification_status: string; } | undefined; termination: TerminationPolicy | undefined; termination_audit: TerminationAudit[] | undefined; owner: RunOwner | undefined; waiting_for: string | undefined; dependency: RunDependency | undefined; resources: RunResources | undefined; superseded_by: string | undefined; result: { exit_code: number | null; failure_class: FailureClass; signal?: string; }; timestamps: { created_at: string; started_at: string | null; finished_at: string | null; }; pid: number | undefined; runner_pid: number | undefined; hypothesis_id?: undefined; command?: undefined; git?: undefined; event_count?: undefined; notifications?: undefined; wakeups?: undefined; tracking?: undefined; performance?: undefined; } | { run_id: string; task_id: string; hypothesis_id: string | null; status: RunStatus; lifecycle: { process_status: string; trainer_status: string; checkpoint_status: string; durable_replica_status: string; tracking_status: string; notification_status: string; } | undefined; owner: RunOwner | undefined; waiting_for: string | undefined; dependency: RunDependency | undefined; resources: RunResources | undefined; superseded_by: string | undefined; command: { argv: string[]; cwd: string; }; git: { branch: string; commit: string; worktree: string; snapshot?: string; file_checksums?: Record; }; result: { exit_code: number | null; failure_class: FailureClass; signal?: string; }; timestamps: { created_at: string; started_at: string | null; finished_at: string | null; }; event_count: number; notifications: { notification_id: string; state: "queued" | "matched" | "sending" | "delivered" | "acknowledged"; critical: boolean; }[]; wakeups: number; tracking: { mlflow_run_id?: string | null; mlflow_experiment_id?: string | null; wandb_run_id?: string | null; wandb_url?: string | null; wandb_name?: string | null; wandb_group?: string | null; wandb_tags?: string[]; prl_wandb_run_id?: string | null; application_wandb_run_id?: string | null; application_wandb_url?: string | null; }; performance: Record | undefined; termination?: undefined; termination_audit?: undefined; pid?: undefined; runner_pid?: undefined; }; export declare function runLogs(runId: string, tail?: number, cwd?: string, owner?: RunOwner): string; export declare function runControl(runId: string, action: "terminate" | "retry", cwd?: string, owner?: RunOwner, options?: { reason?: string; force?: boolean; }): Promise; export declare function runForkPreview(runId: string, input?: { overrides?: Record; owner?: RunOwner; cwd?: string; resumeMode?: "auto" | "exact" | "weights_only" | "fresh"; }): { parent_run_id: string; git_commit: string; compatibility: string; resume_mode: "auto" | "exact" | "weights_only" | "fresh"; overrides: { key: string; value: unknown; }[]; argv_before: string[]; argv_after: string[]; }; export declare function runFork(runId: string, input: { overrides?: Record; resumeFrom?: "latest_complete_checkpoint" | "none" | string; resumeMode?: "auto" | "exact" | "weights_only" | "fresh"; owner?: RunOwner; cwd?: string; workerEntry?: string; }): Promise; export declare function rebuildExperiments(cwd?: string): { count: number; path: string; }; export declare function context(cwd?: string, owner?: RunOwner, options?: { full?: boolean; task_id?: string; }): { root: string; context_root: string; session: { session_id: string; cwd: string; } | null; active_task: { latest_commit: string | undefined; checkpoint_count: number; task_id: string; hypothesis_id: string | null; name: string; branch: string; worktree: string; status: "active" | "finished"; created_at: string; finished_at?: string; new_worktree_reason?: NewWorktreeReason; } | null; active_tasks: { latest_commit: string | undefined; checkpoint_count: number; task_id: string; hypothesis_id: string | null; name: string; branch: string; worktree: string; status: "active" | "finished"; created_at: string; finished_at?: string; new_worktree_reason?: NewWorktreeReason; }[]; active_task_count: number; active_runs: ActiveRunSummary[]; other_active_task_count: number; state: { current_task: unknown; active_hypotheses: unknown; updated_at: unknown; next_step: unknown; latest: { [k: string]: unknown; }; recent_results: unknown[]; }; agents: string; project: string; hypotheses: string; expand: { full: boolean; state_path: string; note: string; }; decisions?: undefined; } | { root: string; session: { session_id: string; cwd: string; } | null; active_task: TaskRecord; active_tasks: TaskRecord[]; active_runs: RunRecord[]; other_active_task_count: number; agents: string; project: string; state: string; decisions: string; hypotheses: string; context_root?: undefined; active_task_count?: undefined; expand?: undefined; }; export declare function projectStatus(cwd?: string): { root: string; initialized: boolean; branch: string; commit: string | null; tasks: TaskRecord[]; runs: { run_id: string; task_id: string; status: RunStatus; created_at: string; }[]; pending_events: number; }; export declare function doctor(cwd?: string): { root: string; checks: { name: string; ok: boolean; }[]; ok: boolean; }; export declare function recoverRuns(cwd?: string, workerEntry?: string): number; export declare function drainPending(pi: { sendUserMessage: (text: string, options?: { deliverAs?: "followUp" | "steer"; }) => unknown; }, ctx: { isIdle: () => boolean; notificationSeen?: (id: string) => boolean; }, cwd?: string, owner?: RunOwner): Promise; export declare function launchReceipt(run: RunRecord): { run_id: string; task_id: string; status: RunStatus; commit: string; owner_session_id: string | undefined; resources: RunResources | undefined; dependency: RunDependency | undefined; launch_prepare_ms: number | undefined; inspect: string; note: string; }; export declare function toolText(value: unknown): string;