/** * pi-pretty-task — background processes and scheduled agent wake-ups for pi. * * One session hub owns every Task record, whatever its kind. The process store * and the loop store share it, so a save from either kind keeps the other kind's * records. The extension's pump is the only clock: a timer and the turn * boundaries call it, and tests call it with a fake instant. * * @author mystery4f <40482524+mystery4f@users.noreply.github.com> */ import { type ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { ChainTasks } from "./tasks/chain/chain-tasks.js"; import { type LoopFire, LoopTasks } from "./tasks/loop/loop-tasks.js"; import { WakeDesk } from "./tasks/loop/wake-desk.js"; import { ForegroundRunner } from "./tasks/process/foreground.js"; import { ProcessTasks } from "./tasks/process/process-tasks.js"; export interface ExtensionOptions { /** Clock seam for tests; defaults to `Date.now`. */ readonly now?: () => number; /** Pump period in milliseconds; `0` disables the timer so tests drive the pump. */ readonly pumpIntervalMs?: number; /** The environment the configuration is read from; defaults to `process.env`. */ readonly env?: NodeJS.ProcessEnv; /** * Tool calls one Iteration keeps; defaults to ITERATION_CALL_LIMIT. Lowering it * is how a test sees a truncated record without a hundred calls. */ readonly iterationCallLimit?: number; /** Iterations one Loop keeps; defaults to ITERATION_HISTORY_LIMIT. */ readonly iterationHistoryLimit?: number; /** * Grace a stop lets the polite signal have before it forces; defaults to the * supervisor's three seconds. A test passes a few milliseconds: the sequence a * stop proves — ask, wait, force, confirm the tree is gone — is the same, and * three seconds per kill is what made the suite slow (issue #32). */ readonly killGraceMs?: number; /** How long a forced kill gets to clear the tree; defaults to the supervisor's five seconds. */ readonly killConfirmMs?: number; /** * How often a follow read looks at the output file while it waits for bytes; * defaults to 50ms. A test lowers it so a follow answers the moment the bytes * land instead of on the next tick of a timer. */ readonly followPollMs?: number; /** * How long a stop that lost to a surviving tree waits before retrying; * defaults to a second. */ readonly survivedRetryMs?: number; /** Project root holding `.pi/pretty-task.json`; defaults to `process.cwd()`. */ readonly projectDir?: string; /** Agent settings directory; defaults to `PI_CODING_AGENT_DIR`, then pi's own default. */ readonly agentDir?: string; /** * Where the terminal notification bytes go; defaults to stdout, and then only * when stdout is a terminal. A test captures the bytes instead of a terminal. */ readonly writeTerminal?: (text: string) => void; /** * Receives a configuration problem as one line, without the `pi-pretty-task:` * prefix. Defaults to stderr: a bad template file must be loud at load and * still leave the extension running. */ readonly reportProblem?: (message: string) => void; } /** The wired extension, returned so tests can drive its clock explicitly. */ export interface ExtensionController { readonly loops: LoopTasks; readonly processTasks: ProcessTasks; /** The commands still being waited for, and the one seam that lets them go. */ readonly foreground: ForegroundRunner; /** The queues that run process tasks one at a time (ADR-0013). */ readonly chainTasks: ChainTasks; /** The wakes a fire produced that pi has not been given yet (ADR-0009). */ readonly wakes: WakeDesk; /** Handle every loop due at `at` in this extension's loaded sessions. */ pump(at: number): Promise; /** * Hand the queued wakes to pi if the agent is idle. The pump enqueues, and * `agent_settled`, `session_start` and this call flush; a busy agent keeps * its wakes queued until it settles (ADR-0009). */ flushWakes(): Promise; } /** Build the stores, tools, renderers and pump; shared by production and tests. */ export declare function createExtension(pi: ExtensionAPI, options?: ExtensionOptions): ExtensionController; /** Extension entry: register this package's tools and commands on the running pi. */ export default function extension(pi: ExtensionAPI, env?: NodeJS.ProcessEnv): void;