import type { ASIData, ExperimentStatus, MetricDef, MetricDirection, NumericMetricMap } from "./types"; export type { ASIData, ExperimentStatus, MetricDirection, NumericMetricMap }; export interface AutoresearchExperimentConfig { name: string; goal: string | null; primaryMetric: string; metricUnit: string; direction: MetricDirection; preferredCommand: string | null; branch: string | null; baselineCommit: string | null; currentSegment: number; maxIterations: number | null; scopePaths: string[]; offLimits: string[]; constraints: string[]; secondaryMetrics: string[]; notes: string; createdAt: number; closedAt: number | null; } export interface AutoresearchRunRecord { runId: string; runNumber: number; segment: number; command: string; startedAt: number; completedAt: number | null; durationMs: number | null; exitCode: number | null; timedOut: boolean; status: ExperimentStatus | null; description: string | null; metric: number | null; metrics: NumericMetricMap; asi: ASIData | null; commitHash: string | null; confidence: number | null; preRunDirtyPaths: string[]; modifiedPaths: string[]; scopeDeviations: string[]; justification: string | null; flagged: boolean; flaggedReason: string | null; loggedAt: number | null; abandonedAt: number | null; } export interface AutoresearchRunsPaths { dir: string; runsPath: string; configPath: string; } export declare function autoresearchRunsPaths(cwd: string, sessionId?: string | null): AutoresearchRunsPaths; export declare function createAutoresearchExperimentConfig(input: { name: string; goal?: string | null; primaryMetric: string; metricUnit?: string; direction?: MetricDirection; preferredCommand?: string | null; branch?: string | null; baselineCommit?: string | null; maxIterations?: number | null; scopePaths?: string[]; offLimits?: string[]; constraints?: string[]; secondaryMetrics?: string[]; notes?: string; createdAt?: number; }): AutoresearchExperimentConfig; /** * Session-scoped JSONL run store. Reads are served from a cached in-memory * snapshot; every mutation routes through the sanctioned `.gjc/**` state-writer * primitives (append for new runs, locked rewrite for updates). */ export declare class AutoresearchRunsStore { #private; private constructor(); static open(cwd: string, sessionId?: string | null): Promise; get paths(): AutoresearchRunsPaths; get config(): AutoresearchExperimentConfig | null; get runs(): AutoresearchRunRecord[]; /** Persist the experiment configuration (first write creates the file). */ saveConfig(config: AutoresearchExperimentConfig): Promise; /** Seed the in-memory config without persisting (mission-derived defaults). */ setInMemoryConfig(config: AutoresearchExperimentConfig): void; /** Start a run: append its record line and return the created record. */ startRun(input: { segment?: number; command: string; preRunDirtyPaths?: string[]; startedAt?: number; }): Promise; /** Mark a completed run (exit code, duration, parsed metrics/ASI). */ completeRun(runId: string, patch: Partial): Promise; /** Log a run: final status, description, metric, ASI, paths, confidence. */ logRun(runId: string, patch: Partial): Promise; /** Flag a run as suspect; flagged runs are excluded from baseline/best math. */ flagRun(runId: string, reason: string): Promise; updateRunConfidence(runId: string, confidence: number | null): Promise; /** Abandon every pending run; returns how many were abandoned. */ abandonPendingRuns(): Promise; /** Most recent pending (started, unlogged, unabandoned) run, or null. */ getPendingRun(): AutoresearchRunRecord | null; listRuns(): AutoresearchRunRecord[]; listLoggedRuns(): AutoresearchRunRecord[]; } /** * Minimal structural shape the math operates on; both persisted run records * and rebuilt experiment results satisfy it. */ export interface BaselineCandidate { segment: number; status: ExperimentStatus | null; metric: number | null; metrics: NumericMetricMap; flagged: boolean; runNumber: number; } export declare function currentResults(results: readonly BaselineCandidate[], segment: number): BaselineCandidate[]; /** First kept, unflagged run in the segment — the baseline. */ export declare function findBaselineResult(results: readonly BaselineCandidate[], segment: number): BaselineCandidate | null; export declare function findBaselineMetric(results: readonly BaselineCandidate[], segment: number): number | null; /** Best kept, unflagged metric in the segment, honoring direction. */ export declare function findBestKeptMetric(results: readonly BaselineCandidate[], segment: number, direction: MetricDirection): number | null; export declare function findBaselineRunNumber(results: readonly BaselineCandidate[], segment: number): number | null; /** Baseline secondary-metric values, filling gaps from other unflagged runs. */ export declare function findBaselineSecondary(results: readonly BaselineCandidate[], segment: number, knownMetrics: MetricDef[]): NumericMetricMap; export declare function sortedMedian(values: number[]): number; /** * Confidence score: how many multiples of the observed noise floor (median * absolute deviation) separate the best kept metric from the baseline. Null * when there are too few runs, no baseline, or no measurable spread. */ export declare function computeConfidence(results: readonly BaselineCandidate[], segment: number, direction: MetricDirection): number | null; export interface AutoresearchExperimentResult { runNumber: number; commit: string; metric: number | null; metrics: NumericMetricMap; status: ExperimentStatus; description: string; timestamp: number; segment: number; confidence: number | null; asi?: ASIData; modifiedPaths: string[]; scopeDeviations: string[]; justification: string | null; flagged: boolean; flaggedReason: string | null; } export interface AutoresearchExperimentState { results: AutoresearchExperimentResult[]; bestMetric: number | null; bestDirection: MetricDirection; metricName: string; metricUnit: string; secondaryMetrics: MetricDef[]; name: string | null; goal: string | null; currentSegment: number; maxExperiments: number | null; confidence: number | null; scopePaths: string[]; offLimits: string[]; constraints: string[]; notes: string; branch: string | null; baselineCommit: string | null; } /** Rebuild the experiment state view from the persisted config + logged runs. */ export declare function buildAutoresearchExperimentState(config: AutoresearchExperimentConfig, loggedRuns: AutoresearchRunRecord[]): AutoresearchExperimentState;