/**
 * Watches the Claude Code session jsonl for each active PTY session and
 * emits a synthetic `task_complete` event when the agent produces an
 * assistant message with `stop_reason === "end_turn"`. This is the
 * ground-truth completion signal from Claude Code's own session record —
 * independent of PTY buffer state, TUI ready events, or the stall
 * classifier's buffer-text heuristics.
 *
 * ## Why this exists
 *
 * The orchestrator's historical completion detection leaned on PTY-side
 * heuristics (buffer silence + ready event + stall-classifier LLM), all of
 * which misfire for long open-ended tasks. Claude Code's own hooks are a
 * more reliable signal and remain the primary path, but hooks can fail
 * silently if the user's hook config is broken or a future Claude Code
 * release changes the contract. The jsonl is a durable, parseable record
 * of every turn written by the CLI itself — using it as an additional
 * ground truth makes completion detection robust across those failure
 * modes.
 *
 * ## Dedup contract with the hook path
 *
 * pty-service.handleHookEvent emits `task_complete` on the authoritative
 * hook signal. This watcher emits a synthetic `task_complete` with an
 * `internal: { source: "jsonl-watcher" }` marker. The orchestrator's
 * downstream consumers (coordinator's handleTurnComplete, the eliza
 * task-progress-streamer) already dedupe `task_complete` per session
 * (`finalSent` in the streamer, `inFlightDecisions` in the coordinator).
 * Whichever signal fires first wins; the second is a no-op.
 *
 * ## Polling vs fs.watch
 *
 * This uses polling (1s interval) rather than `fs.watch` because:
 *   - jsonl files are append-only and small (~KB to MB)
 *   - polling is portable across linux / macOS file systems
 *   - fs.watch on linux has known gotchas with multiple writers and with
 *     files created after the watcher is established
 *   - the jsonl doesn't exist when the session spawns — we need retry
 *     logic anyway, which fs.watch doesn't naturally provide
 *
 * @module orchestrator/claude-jsonl-completion-watcher
 */
import type { IAgentRuntime } from "@elizaos/core";
/**
 * Install the jsonl completion watcher on a runtime's PTY service.
 * Idempotent — repeat calls on the same runtime are no-ops.
 *
 * The watcher subscribes to `onSessionEvent` to learn when sessions start
 * (first event) and stop (`stopped` event), and runs one poller per live
 * session. Pollers tear themselves down on `stopped` or after firing a
 * completion event.
 */
export declare function installClaudeJsonlCompletionWatcher(runtime: IAgentRuntime, ptyService: unknown): void;
/**
 * Locate the newest `.jsonl` file under Claude Code's project directory
 * for a given workdir. Returns null if the directory or any matching
 * file does not yet exist (e.g., the session has not produced output).
 *
 * "Newest" means most recently modified. Claude Code names session files
 * with UUIDs, which do NOT sort chronologically — a workspace that has
 * had multiple sessions will have multiple jsonl files, and picking the
 * lexicographically last name returns a stale file from an older session
 * roughly at random. We stat each file and pick the one with the greatest
 * mtime instead. Files that fail to stat (e.g., deleted between readdir
 * and stat) are skipped.
 *
 * Exported for tests.
 */
export declare function findLatestJsonl(workdir: string): Promise<string | null>;
/**
 * Scan a claude code session jsonl string tail-first for the latest
 * assistant message, returning its extracted text plus whether the turn
 * has finished (`stop_reason === "end_turn"`).
 *
 * - Returns `null` if no assistant message exists at all.
 * - Returns `{ text, isEndTurn: false }` when the latest assistant turn is
 *   still in progress (`tool_use`, `max_tokens` mid-batch, etc.) — the
 *   streamer uses this shape to post intermediate text without waiting.
 * - Returns `{ text, isEndTurn: true }` when the latest assistant turn is
 *   finished — the watcher uses this to fire a synthetic `task_complete`.
 *
 * Exported so both the completion watcher and task-progress-streamer can
 * share one jsonl parser.
 */
export declare function readLatestAssistantEntry(content: string): {
    text: string;
    isEndTurn: boolean;
} | null;
/**
 * Convenience wrapper: locate the latest session jsonl for `workdir` and
 * return the extracted assistant entry, or `null` if no file or no
 * assistant message exists yet.
 *
 * Used by the task-progress-streamer and the completion watcher so they
 * share one implementation of "read the latest claude assistant turn".
 */
export declare function readLatestAssistantFromWorkdir(workdir: string): Promise<{
    text: string;
    isEndTurn: boolean;
} | null>;
//# sourceMappingURL=claude-jsonl-completion-watcher.d.ts.map