import type { TerminalState } from "./mirror.js"; import type { HmrActivity } from "./proxy.js"; /** How long a hot-reload server gets to react before GG reloads the page itself. */ export declare const HMR_GRACE_MS = 2000; /** At most one reload per this long. */ export declare const RELOAD_MIN_GAP_MS = 1000; export type RefreshStrategyKind = "hmr-or-reload" | "none" | "flutter" | "rebuild" | "rerun"; /** * After a change seen at `since`: reload when nothing listens for hot reload, * leave it to hot reload once the dev server spoke on its socket, else wait * until the grace period runs out and reload. */ export declare function decideReload(hmr: HmrActivity, since: number, now: number, graceMs?: number): "reload" | "hmr" | "wait"; export interface RefreshController { kind: RefreshStrategyKind; /** The project changed: these files, first seen at `since`. */ onChange: (files: string[], since: number) => void; close: () => void; } export interface HmrOrReloadDeps { hmr: () => HmrActivity; /** Tell open pages to reload; returns how many were told. */ reload: () => number; /** A reload went out to at least one page. */ onReloaded?: () => void; now?: () => number; graceMs?: number; minGapMs?: number; } export declare function createHmrOrReload(deps: HmrOrReloadDeps): RefreshController; /** Expo/React Native: Metro's Fast Refresh already updates the app. */ export declare function createNoRefresh(): RefreshController; /** Lines of a failed build shown and told to the agent. */ export declare const FAILED_LINES = 20; /** How often a pending rebuild checks whether the agent is done writing. */ export declare const WRITE_WAIT_MS = 300; export type RefreshState = "reloaded" | "rebuilding" | "failed"; /** The last lines of a command's output, without colour codes. */ export declare function lastLines(output: string, n?: number): string; export interface CommandRun { done: Promise<{ code: number | null; output: string; cancelled: boolean; }>; cancel: () => void; } export type Spawner = (command: string, cwd: string, onOutput: (chunk: string) => void) => CommandRun; /** Runs a shell command in its own process group, so cancelling stops all of it. */ export declare const spawnCommand: Spawner; export interface FlutterRefreshDeps { /** Send `r` to the running `flutter run`; returns why it couldn't, or null. */ hotReload: () => Promise; onState: (state: RefreshState, message?: string) => void; } /** Flutter: `r` to the background `flutter run` after Dart files change. */ export declare function createFlutterRefresh(deps: FlutterRefreshDeps): RefreshController; export interface CommandRefreshDeps { command: string; cwd: string; /** An agent tool is mid-write: wait, or the build sees half an edit. */ isWriting: () => boolean; onState: (state: RefreshState, message?: string) => void; /** After a good build (or each re-run start): the mirror should look again. */ onFresh?: () => void; /** The command's live output (a re-run's, or a native app's build log). */ onTerminal?: (state: TerminalState) => void; spawn?: Spawner; } /** Native apps: run the agent's rebuild command after changes settle. */ export declare function createRebuild(deps: CommandRefreshDeps): RefreshController; /** Command-line apps: run the command now, and again after each change. */ export declare function createRerun(deps: CommandRefreshDeps): RefreshController;