import { CausalTrajectoryRecord } from './causal-trajectory.js';
import './objective-state.js';

/**
 * causal-chain.ts — Cross-session causal chain persistence for CMC.
 *
 * Stitches causal trajectories across session boundaries by detecting
 * when a trajectory in one session follows up on a trajectory from
 * another session. Persists edges in a graph index for later retrieval.
 */

interface CausalEdge {
    schemaVersion: 1;
    edgeId: string;
    fromTrajectoryId: string;
    toTrajectoryId: string;
    edgeType: "follow_up_to_goal" | "retry" | "continuation" | "correction";
    confidence: number;
    stitchMethod: "lexical" | "entity" | "temporal" | "explicit";
    createdAt: string;
    metadata?: Record<string, string>;
}
interface CausalChainIndex {
    outgoing: Record<string, string[]>;
    incoming: Record<string, string[]>;
    edges: Record<string, CausalEdge>;
    updatedAt: string;
}
interface StitchConfig {
    lookbackDays: number;
    minScore: number;
    maxEdgesPerTrajectory: number;
}
interface StitchCandidate {
    trajectory: CausalTrajectoryRecord;
    score: number;
    edgeType: CausalEdge["edgeType"];
    stitchMethod: CausalEdge["stitchMethod"];
}
declare function validateCausalEdge(raw: unknown): CausalEdge;
declare function makeEdgeId(fromId: string, toId: string): string;
declare function resolveChainsDir(memoryDir: string, causalTrajectoryStoreDir?: string): string;
declare function readChainIndex(chainsDir: string): Promise<CausalChainIndex>;
declare function writeChainIndex(chainsDir: string, index: CausalChainIndex): Promise<void>;
/**
 * Score how strongly a candidate trajectory from another session
 * relates to the new trajectory being recorded.
 */
declare function scoreStitchCandidate(newTrajectory: CausalTrajectoryRecord, candidate: CausalTrajectoryRecord): StitchCandidate;
/**
 * After a new trajectory is recorded, attempt to stitch it to
 * existing trajectories from other sessions.
 */
declare function stitchCausalChain(options: {
    memoryDir: string;
    causalTrajectoryStoreDir?: string;
    newTrajectory: CausalTrajectoryRecord;
    config: StitchConfig;
}): Promise<CausalEdge[]>;

export { type CausalChainIndex, type CausalEdge, type StitchCandidate, type StitchConfig, makeEdgeId, readChainIndex, resolveChainsDir, scoreStitchCandidate, stitchCausalChain, validateCausalEdge, writeChainIndex };
