import { createInterface, type Interface as ReadLineInterface } from 'node:readline/promises'; /** * Generic interface for program-like objects that can parse arguments. * Allows decoupling from commander's Command type. */ export interface ProgramLike { getOptionValue(key: string): unknown; parseAsync(args?: string[]): Promise; } export declare const waitForEscape: (callback: () => void, enabled: boolean, showHint?: boolean) => void; export declare const stopWaitingForEscape: () => void; export declare const setRawMode: (rawMode: boolean) => void; /** * Ref stdin so it keeps the event loop alive, WITHOUT changing raw mode. * * EXT-18: the ref/unref of stdin used to be coupled to raw mode (only setRawMode(true) * re-ref'd, see above), but some interactive prompts run in COOKED mode after a stream * end. When an agent run suspends on a tool-approval interrupt, the stream's finally * calls stopWaitingForEscape(), which unref's stdin. The readline approval prompt then * does setRawMode(false) (cooked, so typed input echoes) and awaits rl.question(...) - * but with stdin unref'd and nothing else holding the loop open the process exits to the * shell before the user can answer. Refing stdin (decoupled from raw mode) before such a * prompt keeps the loop alive so rl.question() can wait for input. This is intentionally * NOT folded into setRawMode(false): the cooked-path unref is load-bearing for one-shot * commands (e.g. `gth pr`) to exit, so only the interactive-prompt sites opt back in. */ export declare const refStdin: () => void; export declare const initLogStream: (logFileName: string) => void; export declare const writeToLogStream: (message: string) => void; export declare const closeLogStream: () => void; /** * The process.cwd() has a weird behaviour when the app is a part of monorepo, * always returning the directory of this specific project, * this causes integration tests to fail, because they are specifically testing ability to respect actual current dirs. * Gaunt Sloth is a command line tool and it is always supposed to function in the current directory. * Using INIT_CWD forces to always use actual CWD. cwd() fallback is just in case. * In environments where INIT_CWD is available (npm and alike) - INIT_CWD is the correct choice, * since they are likely to juggle the process.cwd(), where it is unavailable process.cwd() is used. */ export declare const getCurrentWorkDir: () => string; /** * The raw process working directory, ignoring `INIT_CWD`. {@link getCurrentWorkDir} prefers * npm's `INIT_CWD` (correct for a CLI invoked via an npm bin), but that leaks into long-lived * subprocesses (e.g. an ACP agent spawned by an IDE), so server entry points that get their * real workspace from the protocol should use this instead. */ export declare const getProcessCwd: () => string; /** * The directory of the DISCOVERED project config (the up-tree match, or the `--config` * override). It governs ONLY post-config, project-relative artifact resolution (project * guidelines, prompts, `.gsloth-settings`, outputs). When unset (a global-only config, no * config at all, or before discovery has run) callers fall back to cwd via {@link getProjectDir}. * * This is NOT the global-config dir (`~/.gsloth`): the global config stays cwd-anchored by * design, so it must never be routed through this value. */ export declare const setProjectDir: (dir: string | undefined) => void; /** * The discovered project root for project-relative artifact resolution, falling back to * {@link getCurrentWorkDir} when no project config has been discovered (see {@link setProjectDir}). * Config DISCOVERY and DETECTION must NOT use this; they stay cwd-bound. */ export declare const getProjectDir: () => string; /** * CFG-26 — the RAW project dir, WITHOUT {@link getProjectDir}'s cwd fallback, so a caller that * must temporarily run a subsidiary `initConfig` (which re-runs discovery and calls * `setProjectDir` as a side effect) can snapshot and restore the exact prior state — including the * "unset, fall back to cwd dynamically" state, which `getProjectDir()` would otherwise collapse * into an explicit cwd. See `resolveRaterModel`. */ export declare const peekProjectDir: () => string | undefined; /** * EXT-199: The session's startup work directory, captured ONCE and realpath-resolved. * Represents "the project" boundary for shell cwd containment and approvals. * Unlike getProjectDir() or getCurrentWorkDir(), it is never a moving value. */ export declare const getStartupWorkDir: () => string; /** * EXT-199: Set or reset the startup work directory. Used for explicit initialization or tests. */ export declare const setStartupWorkDir: (dir: string | undefined) => void; export declare const getInstallDir: () => string; /** * Cached string from stdin. Should only be called after readStdin completes execution. */ export declare const getStringFromStdin: () => string; /** * Get the current useColour setting. */ export declare const getUseColour: () => boolean; /** * Set the useColour setting. */ export declare const setUseColour: (useColour: boolean) => void; export declare const isTTY: () => boolean; /** * Whether STDOUT is a terminal — distinct from {@link isTTY}, which reports on STDIN. * * Colour is a property of where output GOES, so the colour auto-detection (CFG-30 rung 4, see * `config/colour.ts`) asks this one: `gth ask … > out.txt` keeps an interactive stdin while stdout * is a file, and that run must not emit escapes. Read at call time so a test can declare the * terminal it wants in setup. */ export declare const isStdoutTTY: () => boolean; export declare const exit: (code?: number) => never; export declare const stdin: NodeJS.ReadStream & { fd: 0; }; export declare const stdout: NodeJS.WriteStream & { fd: 1; }; export declare const stderr: NodeJS.WriteStream & { fd: 2; }; export declare const argv: string[]; export declare const env: NodeJS.ProcessEnv; export declare const setExitCode: (code: number) => void; export { createInterface }; export type { ReadLineInterface }; /** * Provide the path to the entry point of the application. * This is used to set the install directory. * This is called from cli.js root entry point. */ export declare const setEntryPoint: (indexJs: string) => void; /** * Whether this run will block on piped stdin — and therefore whether {@link readStdin} will draw * its `reading STDIN` line before the command line is parsed. * * Exported so the CLI can ask the same question {@link readStdin} branches on instead of restating * it: what happens before the parse is decided here, and a second copy of the condition is how the * caller ends up preparing for a branch the reader does not take (or missing the one it does). * * `--no-pipe` is registered as a plain negated Option (cli.ts), so Commander maps it to * `pipe === false` rather than `nopipe === true` — see EXT-39. Both spellings mean the same thing: * skip the piped-stdin wait. */ export declare function willWaitForPipedStdin(program: ProgramLike): boolean; /** * Asynchronously reads the stdin and stores it as a string, * it can later be retrieved with getStringFromStdin. */ export declare function readStdin(program: ProgramLike): Promise; export declare const log: (message: string) => void; export declare const error: (message: string) => void; export declare const warn: (message: string) => void; export declare const info: (message: string) => void; export declare const debug: (message: string) => void; export declare const stream: (chunk: string) => boolean; export declare function execAsync(command: string): Promise; export declare function getSlothVersion(): string;