import type { Database } from "bun:sqlite";
import type { EventSource, JsonObject, Workspace, WorkspaceLocation } from "../types/workspace.js";
import type { GuardedProjectMutationResult } from "../types/workspace.js";
import type { ProjectStore } from "../store/project-store.js";
import { type ProjectStoreSummary } from "../db/project-store.js";
import { type WorkspaceRuntimeAction, type WorkspaceTmuxResult, type WorkspaceTmuxWindowSpec } from "./workspace-runtime.js";
import { PROJECTS_HOME_ENV } from "./project-store-paths.js";
export interface ProjectStorePaths {
    home: string;
    workspace_path: string;
    data_path: string;
    project_db_path: string;
    assets_path: string;
    logs_path: string;
    artifacts_path: string;
    context_path: string;
}
export interface ProjectStoreInspection {
    project: Workspace;
    env: {
        projects_home_env: typeof PROJECTS_HOME_ENV;
        projects_home: string;
    };
    paths: ProjectStorePaths;
    primary_path: string | null;
    primary_is_canonical: boolean;
    exists: {
        workspace: boolean;
        data: boolean;
        logs: boolean;
        artifacts: boolean;
        context: boolean;
    };
    migration_recommended: boolean;
}
export interface ProjectStoreEnsureResult {
    project: Workspace;
    paths: ProjectStorePaths;
    created: string[];
    primary_updated: boolean;
    dry_run: boolean;
    /**
     * The per-project app store (`data/<id>/project.db`) summary, or `null` when
     * this run did not touch it: the hosted transport provisions the filesystem
     * layout only and never opens or creates on-box SQLite (owner ruling
     * 2026-09-07, hasna/apps#1720). Use the explicit local opt-in to initialize it.
     */
    app_store: ProjectStoreSummary | null;
    registry_mutation: GuardedProjectMutationResult | null;
}
export declare const PROJECT_STORE_ENSURE_RESPONSE_BYTE_LIMIT: 65536;
export declare const PROJECT_STORE_ENSURE_TIME_BUDGET_MS: 10000;
export interface ProjectStoreMigrationAction {
    type: "file" | "db" | "verification";
    action: string;
    source?: string;
    target: string;
    status: "planned" | "completed" | "skipped";
    metadata?: JsonObject;
}
export interface ProjectStoreMigrationPlan {
    project: Workspace;
    paths: ProjectStorePaths;
    source_path: string | null;
    target_path: string;
    /**
     * The machine recorded on the location rows this migration writes. Null
     * when the registry resolves its own machine (the on-box store) or when no
     * machine resolved, in which case `warnings` says so and `can_apply` is false.
     */
    machine_id: string | null;
    dry_run: boolean;
    can_apply: boolean;
    no_op: boolean;
    warnings: string[];
    actions: ProjectStoreMigrationAction[];
}
export interface ProjectStoreMigrationPlanOptions {
    dryRun?: boolean;
    /**
     * The machine to record on the migrated locations. Leave undefined to let the
     * registry pick its own machine (the on-box store does); pass a string or
     * null to have the plan check it, which the hosted path always does because
     * the hosted registry refuses a location without a machine.
     */
    machineId?: string | null;
}
export interface ProjectStoreMigrationResult extends ProjectStoreMigrationPlan {
    project: Workspace;
    plan_artifact_path: string | null;
    verified: boolean;
    previous_location: WorkspaceLocation | null;
    primary_location: WorkspaceLocation | null;
}
export declare function projectStorePaths(workspaceId: string): ProjectStorePaths;
export declare function inspectProjectStore(project: Workspace): ProjectStoreInspection;
export declare function ensureProjectStore(project: Workspace, options?: {
    db?: Database;
    dryRun?: boolean;
    setPrimaryIfMissing?: boolean;
    recordRegistryEvent?: boolean;
    /**
     * `false` provisions the filesystem layout only and never opens or creates
     * the on-box `project.db` (the hosted transport: no SQLite under a hosted
     * credential). Default `true` (local transport) initializes the app store.
     */
    appStore?: boolean;
    agentId?: string;
    source?: EventSource;
    command?: string;
}): ProjectStoreEnsureResult;
export declare function ensureProjectStoreForTarget(store: ProjectStore, target: string, options?: {
    dryRun?: boolean;
    setPrimaryIfMissing?: boolean;
    agentId?: string;
    source?: EventSource;
    command?: string;
    responseByteLimit?: number;
    timeBudgetMs?: number;
}): Promise<ProjectStoreEnsureResult>;
export declare function planProjectStoreMigration(project: Workspace, options?: ProjectStoreMigrationPlanOptions): ProjectStoreMigrationPlan;
export declare function migrateProjectToStore(project: Workspace, options?: {
    db?: Database;
    apply?: boolean;
    agentId?: string;
    source?: EventSource;
    command?: string;
    machineId?: string;
}): ProjectStoreMigrationResult;
/**
 * Store-routed migration for the hosted backend. The file half (moving the
 * machine-local primary directory into the canonical workspace store) runs on
 * the invoking machine — the server cannot move files on a client box — while
 * the registry half (previous + canonical locations, migration event) routes
 * through the Store so it lands on the hosted project. Mirrors the local
 * `migrateProjectToStore` semantics: same plan, same verification, same
 * file-move rollback with a primary-location restore.
 *
 * The hosted registry refuses a location without a machine, and it cannot know
 * which box the folder is on, so every location write here carries one: the
 * explicit `machineId`, or this station's machine id. The plan refuses an empty
 * machine, and a project whose canonical machine is another station, before
 * anything moves (A3-00894).
 */
export declare function migrateProjectToStoreViaStore(store: ProjectStore, project: Workspace, options?: {
    apply?: boolean;
    agentId?: string;
    source?: EventSource;
    command?: string;
    machineId?: string | null;
}): Promise<ProjectStoreMigrationResult>;
/**
 * Machine-local runtime half of a hosted create (the hosted backend). The registry row is
 * created through the Store by the caller; this applies the on-invoking-box
 * effects — directory, git init, marker, tmux session — with events routed to
 * the hosted project through `store.recordEvent`. Tmux profiles resolve through
 * the machine-local store methods (the established hosted-backend precedent: tmux is
 * a runtime resource of THIS box even when the registry is cloud).
 */
export declare function applyMachineLocalCreationRuntime(store: ProjectStore, project: Workspace, input?: {
    createDirectory?: boolean;
    gitInit?: boolean;
    writeMarker?: boolean;
    tmux?: {
        session?: string;
        windows?: WorkspaceTmuxWindowSpec[];
    };
    tmuxProfile?: string;
    agentId?: string;
    source?: EventSource;
    command?: string;
}): Promise<{
    actions: WorkspaceRuntimeAction[];
    tmux: WorkspaceTmuxResult | null;
}>;
//# sourceMappingURL=project-store.d.ts.map