import { GoalStore, type GoalState, type PersistedGoal } from "./goal-store.js";
import type { WorkflowStore, Workflow } from "./workflow-store.js";
import type { WorktreePool } from "./worktree-pool.js";
import type { Component } from "./project-config-store.js";
/**
 * Sanitize a goal title into a valid git branch name.
 * Lowercase, replace non-alphanumeric with hyphens, truncate, trim.
 *
 * Trim must run *after* the slice so truncation can't reintroduce a
 * trailing hyphen (the `e2e-speed--` artefact). Exported for pinning
 * tests; see `tests/team-branch-shape.test.ts`.
 */
export declare function toBranchName(title: string): string;
export declare class GoalManager {
    private store;
    private workflowStore?;
    /** Track in-flight worktree setups to prevent concurrent calls for the same goal. */
    private _setupsInFlight;
    /**
     * Resolver that looks up the worktree pool for this goal's project.
     * Wired by the server at startup once SessionManager owns the pools.
     * When set, `_doSetupWorktree` claims through the pool first and only
     * falls back to a fresh `createWorktree` if the pool is empty.
     */
    private poolResolver?;
    /**
     * Resolve the components[] for a goal's project. When set and the project
     * has any `repo !== "."` component, `_doSetupWorktree` uses
     * `createWorktreeSet()` instead of the single-repo `createWorktree()`
     * fallback. Single-repo behavior is unchanged.
     */
    private componentsResolver?;
    /**
     * Resolve the project's `rootPath` for multi-repo goal creation. When set
     * and the project is multi-repo, `createGoal` overrides the detected
     * `repoPath` (which would otherwise point at one of the sibling repos) to
     * the project's container directory. Single-repo behavior is unchanged.
     */
    private projectRootResolver?;
    constructor(goalStore: GoalStore, workflowStore?: WorkflowStore);
    /**
     * Wire a pool resolver. Phase 3: goal worktrees go through the pool first,
     * matching the session path so goals are observably as fast as sessions
     * when the pool is warm.
     */
    setPoolResolver(resolver: () => WorktreePool | null | undefined): void;
    /**
     * Wire the components resolver. When unset (or returning a single-component
     * list), goal worktrees use the legacy `createWorktree` fallback.
     */
    setComponentsResolver(resolver: (projectId: string) => Component[]): void;
    /** Wire a project-rootPath resolver (Phase 4a multi-repo goal creation). */
    setProjectRootResolver(resolver: (projectId: string) => string | undefined): void;
    /** Wire a project worktree_root resolver (project-level override of <rootPath>-wt/). */
    private worktreeRootResolver?;
    setWorktreeRootResolver(resolver: (projectId: string) => string | undefined): void;
    /** Wire a project base_ref resolver — the configured branch ref (`base_ref` setting)
     *  used as the worktree start-point and branch upstream. Empty/undefined falls back
     *  to today's `resolveRemotePrimary`. See docs/design/base-ref.md. */
    private baseRefResolver?;
    setBaseRefResolver(resolver: (projectId: string) => string | undefined): void;
    /**
     * On startup, scan for goals stuck in setupStatus === "preparing"
     * and mark them as "error" (setup was interrupted by server restart).
     */
    private _recoverStuckSetups;
    /**
     * Create a goal instantly — persists to disk and returns immediately.
     * Does NOT create the worktree. Call setupWorktree() separately after responding.
     */
    createGoal(title: string, cwd: string, opts?: {
        spec?: string;
        workflowId?: string;
        workflowStore?: WorkflowStore;
        resolvedWorkflow?: Workflow;
        sandboxed?: boolean;
        enabledOptionalSteps?: string[];
        projectId?: string;
    }): Promise<PersistedGoal>;
    /**
     * Async worktree setup — called after createGoal() returns.
     * Retries once on failure. Updates setupStatus accordingly.
     */
    setupWorktree(goalId: string): Promise<void>;
    private _doSetupWorktree;
    /**
     * Restore a goal to a no-worktree state when worktree setup produced no
     * worktree (e.g. createWorktreeSet skipped every non-git sub-repo). The
     * precomputed worktreePath/cwd (set in createGoal) point at a branch
     * container that was never created, so we must:
     *   - clear worktreePath + repoWorktrees, and
     *   - reset cwd to the ORIGINAL project cwd (the un-offset goal cwd, before
     *     the worktree offset was applied) = repoPath + the same subdirectory
     *     offset that createGoal computed via path.relative(repoPath, cwd).
     * setupStatus becomes "ready" with no setupError. The goal then runs in its
     * original project cwd with no worktree — mirroring resolveWorktreeSupport
     * returning unsupported.
     *
     * `store.update` strips undefined values (so it can't clear fields); mutate
     * the live goal reference directly to delete worktreePath/repoWorktrees.
     */
    private _restoreNoWorktree;
    /**
     * Setup worktree then start team. Used when autoStartTeam is enabled.
     * Uses a callback to avoid circular dependency with TeamManager.
     */
    setupWorktreeAndStartTeam(goalId: string, startTeamFn: () => Promise<any>): Promise<void>;
    /**
     * Retry setup for a goal in error state.
     * Returns true if retry was initiated, false if goal not found or not in error state.
     */
    retrySetup(goalId: string): boolean;
    archiveGoal(id: string): Promise<boolean>;
    listLiveGoals(): PersistedGoal[];
    listArchivedGoals(): PersistedGoal[];
    getGoal(id: string): PersistedGoal | undefined;
    /** Current generation counter from the underlying store. */
    getGoalGeneration(): number;
    /** Expose the underlying store for cross-cutting concerns (e.g. gate status bumping generation). */
    getGoalStore(): GoalStore;
    listGoals(): PersistedGoal[];
    updateGoal(id: string, updates: {
        title?: string;
        cwd?: string;
        state?: GoalState;
        spec?: string;
        team?: boolean;
        repoPath?: string;
        branch?: string;
        reattemptOf?: string;
        projectId?: string;
        autoStartTeam?: boolean;
    }): Promise<boolean>;
    deleteGoal(id: string): Promise<boolean>;
}
//# sourceMappingURL=goal-manager.d.ts.map