/** * wait Command - Block until agent completion or prompt detection * Issue #518: [DR1-08] Factory pattern * * Exit codes [DR1-03]: * - 0: SUCCESS (agent completed) * - 10: PROMPT_DETECTED (agent waiting for user input, including arrow-key * selection lists — Issue #1628 — and interactive frames the detection * layer could not classify at all — Issue #1708. Both are reported as * exit 10 with a distinguishing `type` rather than a new exit code, so * callers that already branch on 10 keep working. Issue #2463: a prompt * the target's own Auto-Yes is answering is held for --auto-yes-grace * seconds before it is reported.) * - 11: UPSTREAM_FAULT (--fail-on-upstream-fault only, Issue #1839: the agent * came back to its composer with an upstream API failure on the frame) * - 124: TIMEOUT (--timeout exceeded) * Issue #1544 adds --verify / --require-work, which can turn a detected * completion into 20 (VERIFY_FAILED) or 21 (NOT_STARTED). * Issue #1628 also returns 21 without --verify when the session was never * running: a wait with nothing to wait for must not report success. * Infrastructure errors use ExitCode (1, 2, 99) */ import { Command } from 'commander'; import type { WaitOptions } from '../types'; import type { WaitPromptOutput } from '../types/api-responses'; import { ApiClient } from '../utils/api-client'; /** * Structured event types that mean "a turn is under way" (Issue #1839). * * Mirrors AGENT_EVENT_TYPES in src/lib/hooks/agent-event-types.ts; duplicated * rather than imported because the CLI bundle keeps its own copy of the API * shapes (see api-responses.ts). * * `notification` is deliberately absent, and that is the one measured deviation * from the design sketched in Issue #1839. The Issue proposed accepting * `stop` **or** `idle_prompt` as the end of a turn; the live capture of * 2026-08-20 (see docs/design/upstream-fault-turn-boundary-1839.md) shows * Claude 2.1.236 emitting `Notification(idle_prompt)` 62 s into a turn that * ran nothing at all, because the composer had been idle for a minute. Reading * it as a turn boundary would have re-created the false completion this gate * exists to stop, one minute later. Only `Stop` ends a turn. * * Exported for the cross-layer pin in * `tests/unit/session/status-contract-1926.test.ts`. The server opens a turn on * the same three events (`src/lib/session/provisional-turn.ts` * TURN_ACTIVITY_EVENTS), and since Issue #1930 `adoptTurnStart` reads that * turn's `openedAt` rather than this set — so a set that drifted would change * this gate silently. The set is still read here for the pre-#1930 fallback * path, and the CLI cannot import the server module (`tsconfig.cli.json` sets * `"paths": {}`), so the test is the only thing holding the two together. */ export declare const TURN_OPENING_EVENT_TYPES: ReadonlySet; /** * The `stop` detail meaning "the agent ended its turn with its own background * work still running, and resumes by itself when that work finishes" * (Issue #2614). * * A copy of `SELF_RESUME_PENDING_DETAIL` in `src/lib/hooks/agent-event-types.ts` * for the reason {@link TURN_OPENING_EVENT_TYPES} is a copy: the CLI builds with * `"paths": {}`. `tests/unit/cli/commands/wait-self-resume-2614.test.ts` pins the * two together. */ export declare const SELF_RESUME_PENDING_DETAIL = "self_resume_pending"; /** * The capability a source declares when its `stop` can carry * {@link SELF_RESUME_PENDING_DETAIL} (Issue #2614). * * Read by name rather than through the mirrored type in `api-responses.ts`, * which predates it: `structuredEvents.source.capabilities` is published as the * source's whole declaration, so a newer server sends the key and an older one * simply does not. */ export declare const SELF_RESUME_CAPABILITY = "stopReportsSelfResume"; /** * How long `wait` holds a `stop` whose agent said it would resume by itself * (Issue #2614). * * Measured 2026-09-17 against antigravity 1.2.4: a `schedule` of 60 s closed the * turn, the agent woke 58 s after its `Stop` and did it again three more times, * and the real end came five minutes after the first `Stop` — which is where * `wait` had already reported `Completed (basis=hook_stop)` and started a * verification against a half-finished worktree. The wake is not something to * time: it is a `post_tool_use` that opens a new turn, and #1839's gate takes * over from there. What needs a bound is only the case where it never comes. * * A timer's own length is not on the wire (the `schedule` arguments reach the * permission receiver and stop there), and a command sent to the background has * no length at all, so the bound is the one the server already uses for the * same question the other way round: how long an open turn is trusted with * nothing heard (`TURN_STALE_AFTER_MS` in `src/lib/session/provisional-turn.ts`, * pinned equal by `wait-self-resume-2614.test.ts`). Every wake starts a new * `stop` and a new hold, so an agent that keeps rescheduling never reaches it. * * A constant, like {@link PENDING_PROMPT_HOLD_MS}: `--timeout` and * `--stall-timeout` below it still win. */ export declare const SELF_RESUME_HOLD_MS: number; /** * {@link pollWorktree}'s options: {@link WaitOptions} plus the Auto-Yes grace * (Issue #2463). */ export interface PollWorktreeOptions extends WaitOptions { /** * `--auto-yes-grace`, in seconds; 0 turns the hold off. Absent means * {@link AUTO_YES_GRACE_DEFAULT_SECONDS}, which is what `ask` gets: it calls * {@link pollWorktree} without the flag. */ autoYesGrace?: number; } /** * Poll a single worktree until completion, prompt, or timeout. * * Exported since Issue #2376 so `ask` can do the WAITING half of its round trip * with this function rather than a second implementation of it. `ask` is * `send` + `wait` + "read the reply", and a private copy of the turn-boundary * rules here (#1839's `basis`, #1975's unanswered-prompt hold, #1708's * unclassified dwell) is a copy that would drift into reporting a completion * this one refuses. #2463's Auto-Yes hold is shared the same way: `ask` passes * no `autoYesGrace` and holds for the default. * * `options.instance` must already be a resolved instance ID — see * {@link resolveWaitInstance}. */ export declare function pollWorktree(client: ApiClient, worktreeId: string, options: PollWorktreeOptions): Promise<{ exitCode: number; output?: WaitPromptOutput; }>; export declare function createWaitCommand(): Command; //# sourceMappingURL=wait.d.ts.map