/** * Run-level bookkeeping shared by the pi `--mode json` and `--mode rpc` * runners (pi 0.87.1): * - PiRunTracker: token usage summed over assistant messages, the run's * final failure (pi exits 0 even when every auto-retry failed, so the * error only shows in the stream), and completion on `agent_settled` * (an `agent_end` with `willRetry:true` is followed by `auto_retry_*` * and another agent run). * - PiTurnBudget: `--max-turns` emulation. pi has no turn cap, so the * runner counts `turn_start` events per mailbox message and aborts when * the count passes the cap; a turn pi replays after `auto_retry_start` * is not counted twice. * - PiTextStream: `text_delta` streaming with the tool_call fences held * back (computeSafeChunk), reconciled at each message_end. * - piCliArgs: the flags both runners share. */ import type { AgentRunArgs } from './agent-runner.js'; import type { OrgEffortLevel } from './cost-tier.js'; import type { PiMessageUsage, PiParsedLine } from './pi-runner-parse.js'; /** `pi --thinking` levels (off|minimal|low|medium|high|xhigh|max) cover * every abstract effort level 1:1. */ export declare const PI_THINKING: Record; /** Built-in pi tools a `--access read` turn keeps (#388). */ export declare const PI_READ_TOOLS = "read,grep,find,ls"; /** * Flags shared by `--mode json` and `--mode rpc`: * - `--session-id ` opens that exact project session or creates it * (pi docs/cli.md), in pi's own session store — nothing is written into * the user's project. The runner picks the id, so resume needs no * output parsing and every tool round reopens the same session. * - Project trust: coder mode with `--settings` sources passes * `--approve` (load the project's `.pi/` settings, extensions, skills, * prompts). Otherwise the run is isolated: `--no-approve` plus no * extensions/skills/prompt templates/context files (`-ne -ns -np -nc`), * matching the Claude runner's isolated default. pi has no tool * approval to bypass, so full access needs no flag of its own. */ export declare function piCliArgs(mode: 'json' | 'rpc', sessionId: string, args: AgentRunArgs): string[]; /** Usage, completion and failure of one pi agent run (see header). */ export declare class PiRunTracker { inputTokens: number; outputTokens: number; cacheReadTokens: number; cacheWriteTokens: number; costUsd?: number; /** agent_settled seen (or a legacy agent_end without willRetry). */ settled: boolean; /** The last assistant message ended with stopReason "aborted". */ aborted: boolean; private lastError?; private retryError?; /** pi's auto-retries since its last success — tags a failure so agent * exec does not retry a 429 pi already retried (provider-limit.ts). */ retries: number; addUsage(u: PiMessageUsage): void; /** Fold one parsed event in. `countUsage` false leaves usage to the * caller (the rpc runner sums agent_end.messages instead). */ observe(p: PiParsedLine, countUsage?: boolean): void; /** The run's final failure, if it ended in one. */ failure(): string | undefined; } /** Emulated max turns for one mailbox message (see header). */ export declare class PiTurnBudget { readonly max: number; used: number; hit: boolean; constructor(max: number); /** Count a turn_start / auto_retry_start; true exactly once, when the * turn that just started is past the cap and must be aborted. */ observe(p: PiParsedLine): boolean; } /** computeSafeChunk's fence safety plus a trailing-whitespace holdback, * diffed against what is already visible: the new increment (if any) and * the new high-water mark. */ export declare function nextIncrement(totalRaw: string, visibleSoFar: string): { increment?: string; visibleSoFar: string; }; /** * Visible assistant text of one pi invocation / rpc prompt round. * `partials` false (the org runtime): nothing streams; each message_end * yields that message's fence-stripped text. `partials` true (agent exec): * text_delta increments stream as they arrive, per contentIndex, reset on * each assistant message_start; messages join with '\n'. */ export declare class PiTextStream { private readonly partials; private completed; private current; private visible; constructor(partials: boolean); messageStart(): void; delta(index: number, delta: string): string | undefined; /** A completed assistant message's raw text (may be empty). */ messageEnd(rawText: string): string | undefined; /** Whatever of `rawText` (default: every completed message) has not been * shown yet — the end-of-round reconciliation. */ remainder(rawText?: string): string | undefined; /** Streaming only: the end-of-invocation remainder(). */ flush(): string | undefined; private advance; } //# sourceMappingURL=pi-runner-state.d.ts.map