import type { DaemonCommandRouter } from './router.js';
import type { RepoMeshSessionCleanupMode } from '../repo-mesh-types.js';
export declare function sessionMatchesMeshNode(self: DaemonCommandRouter, record: any, node: any, nodeId: string, sessionIds?: Set<string>): boolean;
/**
 * Best-effort recursive removal of a managed worktree directory.
 *
 * The git-registry de-registration is the safety-critical step of worktree
 * teardown; a leftover directory must never gate dropping the node from the
 * mesh. On Windows, `fs.rmSync` can throw EINVAL/EPERM/EBUSY on submodule
 * gitlink (`.git`) files, long paths, junctions, or while a just-stopped
 * delegate session is still releasing a handle/cwd on the directory. This
 * helper absorbs those errors (never throws), with bounded retries + backoff
 * to give handles time to release, and reports whether residue remains.
 */
export declare function bestEffortRemoveWorktreeDir(self: DaemonCommandRouter, dir: string): Promise<{
    removed: boolean;
    residue: boolean;
    error?: string;
}>;
/**
 * Non-destructive precheck mirroring every REFUSAL condition in
 * {@link cleanupLocalWorktreeNode} — missing workspace / source-repo / branch
 * metadata, unexpected (non-managed) path, branch mismatch — PLUS the
 * dirty-worktree guard that `removeWorktree(requireClean)` enforces
 * (`git status --porcelain`). It performs ZERO destructive actions: no
 * `git worktree remove`, no `git worktree prune`, no directory deletion.
 *
 * remove_mesh_node calls this BEFORE any session cleanup so that a refusal
 * (the common one being a dirty worktree) does not first stop/delete the
 * delegated session and orphan it — the original ordering bug. Success/skip
 * cases that the real cleanup handles idempotently (worktree path already
 * gone, git-de-registered residue) are NOT refusals and return `{ ok: true }`.
 *
 * `force:true` skips the dirty guard, preserving `removeWorktree`'s
 * `requireClean: !force` semantics. This is a read-only superset check; the
 * authoritative `requireClean` guard inside `removeWorktree` is intentionally
 * kept as a second line of defense against a precheck→execute race.
 */
export declare function precheckLocalWorktreeRemovable(self: DaemonCommandRouter, args: {
    mesh: any;
    node: any;
    nodeId: string;
    force?: boolean;
}): Promise<{
    ok: true;
} | {
    ok: false;
    code: string;
    error: string;
    recoveryHint: string;
}>;
export declare function cleanupLocalWorktreeNode(self: DaemonCommandRouter, args: {
    mesh: any;
    node: any;
    nodeId: string;
    force?: boolean;
}): Promise<{
    success: true;
    skipped?: boolean;
    removedPath?: string;
    repoRoot?: string;
    reason?: string;
    fallback?: string;
    forced?: boolean;
    convergence?: Record<string, unknown>;
    recovered?: boolean;
    residue?: boolean;
    residueWarning?: string;
    residueError?: string;
    branchRefDeleted?: boolean;
    branchRefReason?: string;
    branchRefForced?: boolean;
    branchRefWarning?: string;
} | {
    success: false;
    code: string;
    error: string;
    recoveryHint: string;
    convergence?: Record<string, unknown>;
}>;
export declare function getWorktreeForceCleanupConvergence(self: DaemonCommandRouter, args: {
    repoRoot: string;
    workspace: string;
    node: any;
}): Promise<{
    allow: boolean;
    status?: string;
    source?: string;
    ref?: string;
    error?: string;
}>;
export declare function isCompletedHostedSession(self: DaemonCommandRouter, record: any): boolean;
export declare function recordIntentionalMeshSessionStop(self: DaemonCommandRouter, args: {
    meshId: string;
    nodeId: string;
    node: any;
    sessionId: string;
    mode: RepoMeshSessionCleanupMode;
    source: 'mesh_cleanup_sessions' | 'mesh_remove_node' | 'magi_session_cleanup';
    action: 'stop_session' | 'delete_session_force';
}): Promise<void>;
export declare function cleanupMeshSessions(self: DaemonCommandRouter, args: {
    meshId: string;
    nodeId: string;
    node: any;
    mode: RepoMeshSessionCleanupMode;
    sessionIds?: string[];
    dryRun?: boolean;
    source?: 'mesh_cleanup_sessions' | 'mesh_remove_node' | 'magi_session_cleanup';
    /**
     * MAGI auto-cleanup safety gate: a map of sessionId → the queue task id that
     * session must have been AUTO-LAUNCHED for (record meta autoLaunchedForQueueTaskId).
     * When set, a matched explicit session is only acted on if its record carries that
     * exact marker. A reused idle session (no marker), the coordinator session, a
     * re-assigned session, or any session whose marker points at a DIFFERENT task is
     * skipped (reason 'auto_launch_marker_mismatch') — so MAGI never kills a session it
     * didn't itself spawn for this fan-out. Only consulted alongside explicit sessionIds.
     */
    requireAutoLaunchedForTaskIds?: Record<string, string>;
    /**
     * Opt-in orphan reclaim (default false). See SESSION-ACCUMULATION-LEAK.
     * When true, a workspace-only live_runtime session (no node binding) OR a
     * live_runtime session bound to a node absent from `liveMeshNodeIds` is
     * stopped instead of skipped by the conservative shared-daemon guard. A
     * session whose meshNodeId is STILL in `liveMeshNodeIds` (active sibling)
     * is never reclaimed — that is the shared-daemon safety this preserves.
     */
    reclaimOrphans?: boolean;
    liveMeshNodeIds?: string[];
}): Promise<{
    success: boolean;
    [key: string]: unknown;
}>;
