/**
 * Routine execution context + readiness resolution.
 *
 * A scheduled routine has to run *somewhere*. This module is the single,
 * target-aware answer to "which directory does this routine's run land in, and
 * is the chosen harness able to start there?" — computed for the eventual
 * execution TARGET, never from the daemon process's own cwd.
 *
 * Two layers, both pure of global state (every input is injected, so a test
 * exercises the real code path against real temp directories rather than a mock):
 *
 *  - {@link resolveRoutineExecutionContext} — resolve the working directory from
 *    the routine's singular `project` anchor and/or portable `cwd`, following the
 *    locked resolution table (see below), and verify the structural + filesystem
 *    readiness of that directory (existence, portability, writability, cloud
 *    portability). This layer owns the *context* readiness codes.
 *  - {@link evaluateRoutineReadiness} — take a resolved context and layer the
 *    *harness/target* readiness codes (agent installed, Codex workspace trust,
 *    live auth, target reachability) via injected probes.
 *
 * Resolution table (target `$HOME` = the execution device's home):
 *
 *  | project | cwd            | resolved dir            | readiness |
 *  |---------|----------------|-------------------------|-----------|
 *  | usable  | —              | project base            | continue  |
 *  | usable  | relative       | base + cwd (inside base)| continue if inside base + exists |
 *  | rootless| relative       | $HOME + cwd             | continue if exists |
 *  | —       | relative       | $HOME + cwd             | continue if exists |
 *  | —       | ~/…            | $HOME-relative          | continue if exists |
 *  | —       | abs under home | normalized to ~/…       | continue  |
 *  | —       | abs outside home| local-pinned only      | pause (cwd_not_portable) for host/fleet/cloud |
 *  | named+unusable | —       | no fallback             | pause (project_path_missing) |
 *  | —       | — (agent/workflow) | no implicit home     | pause (execution_context_missing) |
 *  | —       | — (command)    | $HOME                   | continue (housekeeping) |
 */
/** Stable, machine-readable readiness codes. A routine is activated only when ready. */
export type RoutineReadinessCode = 'project_not_found' | 'project_path_missing' | 'cwd_missing' | 'cwd_not_directory' | 'cwd_not_portable' | 'execution_context_missing' | 'cloud_context_unsupported' | 'workspace_not_writable' | 'codex_workspace_untrusted' | 'agent_unavailable' | 'agent_auth_failed' | 'target_unreachable' | 'placement_unsupported' | 'migration_conflict';
export interface RoutineReadiness {
    code: RoutineReadinessCode;
    /** Human-readable one-line explanation of the failing check. */
    message: string;
    /** A single safe command that repairs the blocker, when one exists. */
    repair?: string;
}
/** Where the routine body executes — mirrors {@link HostStrategy} placement. */
export type PlacementMode = 'local' | 'host' | 'fleet' | 'cloud';
/**
 * What the caller resolved about the routine's singular `project` anchor.
 * `undefined` (the field on the input) means the routine names no project.
 */
export type ProjectResolution = {
    defined: false;
}
/** Defined project; `base` is its portable base dir (`~/…` or absolute), or
 *  undefined for a rootless Linear-imported project with no checkout. */
 | {
    defined: true;
    base?: string;
};
export type RoutineKind = 'agent' | 'workflow' | 'command';
/** A filesystem probe against the execution TARGET. */
export interface ContextFsProbe {
    exists(absPath: string): boolean;
    isDirectory(absPath: string): boolean;
    isWritable(absPath: string): boolean;
}
export interface ExecutionContextInput {
    /** Routine name (for messages only). */
    name?: string;
    /** Singular execution anchor (`JobConfig.project`). */
    project?: string;
    /** Portable execution directory (`JobConfig.cwd`). */
    cwd?: string;
    /** Exactly one of agent/workflow/command determines the fallback rules. */
    kind: RoutineKind;
    /** Placement of the run — governs portability enforcement and cloud rules. */
    mode: PlacementMode;
    /** Execution target's absolute `$HOME`. Local: `os.homedir()`; remote: the target home. */
    targetHome: string;
    /** Resolution of the `project` anchor; omit when the routine names no project. */
    projectResolution?: ProjectResolution;
    /**
     * Filesystem probe for the target, present only when this process can inspect
     * it (a local run, or add/edit/doctor invoked on the target box). Absent for a
     * remote/cloud target we cannot reach — then only structural + portability
     * checks run (existence is deferred, never assumed).
     */
    probe?: ContextFsProbe;
}
export interface ResolvedExecutionContext {
    project?: string;
    /** `config.cwd` echoed for the run record. */
    requestedCwd?: string;
    /** Portable resolved cwd for the run record: `~/…` when under target home, else absolute. */
    resolvedCwd?: string;
    /** The resolved cwd expanded to an absolute path on the target. Undefined when unresolved. */
    absoluteCwd?: string;
    targetHome: string;
    ready: boolean;
    /** Present when `ready` is false. */
    readiness?: RoutineReadiness;
}
/** Expand a leading `~`/`$HOME` against the target home; pass other values through. */
export declare function expandTargetHome(home: string, p: string): string;
/** Rewrite an absolute path under the target home to its portable `~/…` form; pass others through. */
export declare function toTargetPortable(home: string, abs: string): string;
/**
 * True for a bare relative path (not absolute, not home-anchored) ON THE TARGET.
 *
 * `isAbsolute` is evaluated in the TARGET's own path flavour (see
 * {@link targetPath}), not this process's platform — a Windows-shaped absolute
 * cwd (`C:\Users\x\override`) dispatched from a POSIX daemon must still be
 * recognized as absolute, or it is misread as project-relative.
 */
export declare function isBareRelative(home: string, p: string): boolean;
/**
 * Resolve the working directory a routine's run lands in and verify its
 * structural + filesystem readiness for the given placement. Pure of global
 * state — every dependency (target home, project resolution, filesystem probe)
 * is injected.
 */
export declare function resolveRoutineExecutionContext(input: ExecutionContextInput): ResolvedExecutionContext;
/** Injected harness/target probes for {@link evaluateRoutineReadiness}. */
export interface HarnessReadinessProbes {
    /** Is the resolved agent+version installed on the target? */
    agentInstalled?(): boolean;
    /** Is the absolute execution dir a trusted Codex workspace? (Codex agent only.) */
    codexTrusted?(absoluteCwd: string): boolean;
    /** Live auth verdict for the resolved account/version. `ok:false` → agent_auth_failed. */
    authOk?(): {
        ok: boolean;
        reason?: string;
    };
    /** Is the execution target reachable? (host/fleet/cloud placement only.) */
    targetReachable?(): boolean;
}
export interface RoutineReadinessResult {
    context: ResolvedExecutionContext;
    ready: boolean;
    readiness?: RoutineReadiness;
}
/**
 * Layer the harness/target readiness codes onto a resolved execution context.
 * Context blockers short-circuit (no point probing auth for a routine that has
 * no directory to run in). Every probe is optional and injected; an omitted
 * probe is treated as "not applicable / passes" so a caller only pays for the
 * checks it wires up.
 */
export declare function evaluateRoutineReadiness(context: ResolvedExecutionContext, probes?: HarnessReadinessProbes, opts?: {
    agent?: string;
    version?: string;
}): RoutineReadinessResult;
