/** * Stopping subagents from the terminal: the key, the selection, the command. * * A run is stoppable because `liveRun` hands its {@link StopSwitch} over here * while it lasts. Which one a key acts on is the only thing this file decides, * and it decides it the plain way: **the run that started last**. Two at once is * already the unusual case - a command launched while a tool call works - and * the newest is the one whose dots are on screen. * * The keys are `keys.ts`'s, rebindable in pi's `keybindings.json`; their * defaults are named below. The stop key is **listened to, never consumed**. * By default it is Escape, which pi binds to `app.interrupt`: that aborts the * turn a tool call runs inside, and swallowing the key would leave the model * free to delegate again the moment the tool returned. During a command pi's * own handler finds no run to abort, and this is what stops the subagents * then. One key, one meaning, wherever it is pressed - with one exception, a * question card, which owns the key for as long as it is on screen; that is * `asking.ts`. */ import type { StopSwitch, RunSnapshot } from "../../src/index.ts"; import type { KeyUi, PiApi, StopCtx } from "../pi.ts"; /** A run that can still be stopped, as the terminal sees it. */ export type LiveRun = { /** What actually stops it. */ readonly stop: StopSwitch; /** Its current state - the list a selection moves through. */ snapshot(): RunSnapshot; /** Redraws the widget, so a moved selection shows at once. */ repaint(): void; /** The subagent the next bare `/stop` acts on. */ selected?: string; }; /** Registers `/stop`. The key listener needs no registration: a run brings it. */ export default function registerStopCommand(pi: PiApi): void; /** * Watches a run for as long as it lasts. * * The listener is attached with the first run and dropped with the last: outside * a run this file reads no keys at all, which is what keeps Escape behaving * exactly as pi means it to. */ export declare function watchRun(run: LiveRun, ui: KeyUi | undefined): void; /** Stops watching. Call it in the same `finally` that takes the widget down. */ export declare function forgetRun(run: LiveRun): void; /** The run a key or a bare `/stop` acts on: the one that started last. */ export declare function currentRun(): LiveRun | undefined; /** Stops every live run. Returns how many were going. */ export declare function stopEverything(): number; /** * Moves the selection by `delta` among the subagents still working. * * It wraps, and it starts at the first one: with nothing selected the first * key lands somewhere rather than on nothing. A selection whose * subagent has finished in the meantime is treated as no selection - the row it * pointed at is no longer stoppable. */ export declare function moveSelection(delta: number): string | undefined; /** The ids a stop would reach, in the order the widget draws them. */ export declare function stoppable(snapshot: RunSnapshot): string[]; /** * `/stop` - the selected subagent, one named by id, or the lot. * * A command beside the keys because a key cannot name anything: this is how a * branch is called off by id rather than by pointing at it. It runs at once * while a tool call works - pi executes an extension command instead of queueing * it - and the selected-subagent key covers the rest. */ export declare function stopCommand(args: string, ctx: StopCtx): string; //# sourceMappingURL=stop.d.ts.map