import { type MeshRefineValidationCommandPlan, type RepoMeshRefineValidationCommandConfig } from './refine-config.js';
import type { MeshAsyncJobLifecycle } from '../repo-mesh-types.js';
export type WorktreeBootstrapStatus = 'ready' | 'complete' | 'running' | 'failed' | 'not_configured' | 'disabled' | 'stale';
export interface RepoMeshWorktreeBootstrapConfig {
    version: 1;
    enabled?: boolean;
    runOnClone?: boolean;
    required?: boolean;
    commands?: RepoMeshRefineValidationCommandConfig[];
    staleInputs?: string[];
}
export interface WorktreeBootstrapState extends MeshAsyncJobLifecycle {
    status: WorktreeBootstrapStatus;
    required: boolean;
    configSource?: string;
    configSourceType?: 'repo_file' | 'mesh_policy' | 'unavailable' | 'invalid';
    lastCommand?: string;
    exitCode?: number | null;
    commandsRun?: Array<Record<string, unknown>>;
    staleInputs?: string[];
    /**
     * M2-1: sha256 per staleInputs path recorded when the bootstrap reached
     * 'ready'. evaluateWorktreeBootstrapState compares current file hashes
     * against this to detect staleness (e.g. base merge changed a lockfile).
     * Missing files hash to the literal 'absent'.
     */
    staleInputsDigest?: Record<string, string>;
    /** M2-1: why an evaluated state resolved to stale (digest_mismatch | never_ran). */
    staleReason?: string;
}
export declare const WORKTREE_BOOTSTRAP_STALE_RUNNING_MS: number;
/**
 * Enumerate registered submodule paths for a worktree, generically (no hardcoded
 * 'oss'/'adhdev-providers'). Reads `.gitmodules` via `git config --file .gitmodules
 * --get-regexp path`, whose lines are `submodule.<name>.path <relativePath>`. Paths
 * are returned normalized to forward slashes (git porcelain always emits '/'),
 * trailing slash stripped. Returns an empty set when there are no submodules or the
 * lookup fails — callers must then treat any change as dirty (conservative).
 */
export declare function getRegisteredSubmodulePaths(workspace: string): Set<string>;
/**
 * Read each registered submodule's configured `branch` from `.gitmodules`, keyed
 * by the submodule's normalized path (matching {@link getRegisteredSubmodulePaths}).
 *
 * `.gitmodules` stores `submodule.<name>.path` and (optionally)
 * `submodule.<name>.branch`; this joins the two on `<name>`. The special branch
 * value `.` ("track the superproject's branch") is deliberately OMITTED so callers
 * fall through to remote-HEAD detection instead of treating `.` as a literal branch
 * name. Returns an empty map when there are no submodules, no `.gitmodules`, or the
 * lookup fails (conservative — callers then detect or fall back).
 */
export declare function getSubmoduleConfiguredBranches(workspace: string): Map<string, string>;
/** Fallback submodule branch when no configured/detected default can be resolved. */
export declare const SUBMODULE_DEFAULT_BRANCH_FALLBACK = "main";
/**
 * Resolve the default branch a submodule's commits are published to / checked for
 * reachability against. Generalizes the previously hardcoded `main` so a submodule
 * whose default branch is `master`/`trunk`/etc. is handled. Priority (each tier
 * falls through to the next on miss/error):
 *
 *   1. `.gitmodules` `submodule.<name>.branch` (via {@link getSubmoduleConfiguredBranches};
 *      `.` is ignored) — an explicit, local, zero-cost declaration.
 *   2. the submodule checkout's LOCAL remote HEAD: `git symbolic-ref --short
 *      refs/remotes/<remote>/HEAD` → strip the `<remote>/` prefix (no network).
 *   3. the submodule remote's advertised HEAD: `git ls-remote --symref <remote> HEAD`
 *      → `ref: refs/heads/<branch>` (one network round-trip).
 *   4. fallback {@link SUBMODULE_DEFAULT_BRANCH_FALLBACK} (`'main'`).
 *
 * Because the final fallback is `'main'` and every earlier tier that resolves `'main'`
 * yields the same string, a repo whose submodules default to `main` (the common case)
 * produces byte-identical downstream fetch/merge-base/push ref targets — only a
 * read-only resolution probe is added.
 */
export declare function resolveSubmoduleDefaultBranch(opts: {
    /** The submodule's local checkout — cwd for symbolic-ref / ls-remote. */
    submoduleRepoPath: string;
    /** The superproject workspace — for the `.gitmodules` branch lookup (tier 1). */
    superprojectWorkspace?: string;
    /** The submodule's path relative to the superproject (key into `.gitmodules`). */
    submodulePath?: string;
    /** Remote name (default `origin`). */
    remote?: string;
    /** Timeout for the local probe (tier 2); the network probe (tier 3) gets max(this, 30s). */
    timeoutMs?: number;
}): Promise<string>;
export declare function isWorktreeBootstrapStaleRunning(node: {
    worktreeBootstrap?: {
        status?: string;
        startedAt?: string;
        updatedAt?: string;
        completedAt?: string;
    };
    workspace?: string;
} | undefined, nowMs?: number): boolean;
/**
 * COMPLETION-PROPAGATION F7 (C2): the single shared consume-ready / bootstrap-pending defer
 * predicate. A task must NOT be injected into a worktree node whose bootstrap is still 'running'
 * — the provider is not yet ready to consume input, so the inject lands in the input buffer and
 * is silently swallowed (empty session). Both the remote dispatch guard (the router agent_command
 * handler) and the local queue-claim gate (tryAssignQueueTask) route through THIS predicate so
 * they agree on exactly when to defer. Returns true = defer. The stale-'running' backstop
 * (isWorktreeBootstrapStaleRunning) is honored here too: a 'running' state far older than any real
 * bootstrap whose worktree is git-clean is treated as silently complete (do NOT defer), so a node
 * whose terminal stamp never reached this daemon is not stranded forever.
 */
export declare function shouldDeferDispatchForBootstrap(node: {
    worktreeBootstrap?: {
        status?: string;
        startedAt?: string;
        updatedAt?: string;
        completedAt?: string;
    };
    workspace?: string;
} | undefined, nowMs?: number): boolean;
export interface WorktreeBootstrapConfigLoadResult {
    config?: RepoMeshWorktreeBootstrapConfig;
    source: string;
    sourceType: 'repo_file' | 'mesh_policy' | 'unavailable' | 'invalid';
    path?: string;
    error?: string;
}
export declare const MESH_WORKTREE_BOOTSTRAP_CONFIG_LOCATIONS: string[];
export declare const MESH_WORKTREE_BOOTSTRAP_CONFIG_SCHEMA: {
    readonly $schema: "https://json-schema.org/draft/2020-12/schema";
    readonly title: "ADHDev Repo Mesh Worktree Bootstrap Config";
    readonly type: "object";
    readonly additionalProperties: false;
    readonly required: readonly ["version"];
    readonly properties: {
        readonly version: {
            readonly const: 1;
        };
        readonly enabled: {
            readonly type: "boolean";
            readonly default: true;
        };
        readonly runOnClone: {
            readonly type: "boolean";
            readonly default: true;
        };
        readonly required: {
            readonly type: "boolean";
            readonly default: true;
        };
        readonly staleInputs: {
            readonly type: "array";
            readonly maxItems: 16;
            readonly items: {
                readonly type: "string";
                readonly minLength: 1;
            };
        };
        readonly commands: {
            readonly type: "array";
            readonly minItems: 1;
            readonly maxItems: 4;
            readonly items: {
                readonly type: "object";
                readonly additionalProperties: false;
                readonly required: readonly ["command"];
                readonly properties: {
                    readonly command: {
                        readonly type: "string";
                        readonly minLength: 1;
                    };
                    readonly args: {
                        readonly type: "array";
                        readonly items: {
                            readonly type: "string";
                        };
                    };
                    readonly category: {
                        readonly enum: readonly ["typecheck", "test", "lint", "build", "custom"];
                    };
                    readonly cwd: {
                        readonly type: "string";
                    };
                    readonly timeoutMs: {
                        readonly type: "number";
                        readonly minimum: 1000;
                        readonly maximum: 600000;
                    };
                    readonly outputLimitBytes: {
                        readonly type: "number";
                        readonly minimum: 1024;
                        readonly maximum: 1048576;
                    };
                    readonly env: {
                        readonly type: "object";
                        readonly additionalProperties: {
                            readonly type: "string";
                        };
                    };
                };
            };
        };
    };
};
export declare function validateMeshWorktreeBootstrapConfig(config: unknown, source?: string): {
    valid: boolean;
    errors: string[];
    commands: MeshRefineValidationCommandPlan[];
    rejectedCommands: Array<Record<string, unknown>>;
};
export declare function loadMeshWorktreeBootstrapConfig(mesh: any, workspace: string): WorktreeBootstrapConfigLoadResult;
/** M2-1: hash staleInputs files so 'ready' can be invalidated when they change. */
export declare function computeStaleInputsDigest(workspace: string, staleInputs: string[] | undefined): Record<string, string>;
/**
 * M2-1: the official bootstrap state contract. Resolves the effective state
 * for a node workspace from config presence + the persisted last-run state +
 * a staleInputs digest comparison. Read-only — never runs commands.
 *
 *   ready          — last run succeeded and staleInputs are unchanged
 *   stale          — never ran, or a staleInputs file changed since 'ready'
 *   running/failed — persisted lifecycle state passes through
 *   not_configured / disabled / (invalid → failed) — from config resolution
 */
export declare function evaluateWorktreeBootstrapState(mesh: any, workspace: string, persisted?: WorktreeBootstrapState | null): WorktreeBootstrapState;
export declare function runMeshWorktreeBootstrap(mesh: any, workspace: string): Promise<WorktreeBootstrapState>;
