UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

53 lines • 2.86 kB
import { type Api, type AssistantMessage, type AssistantMessageDiagnostic, type Context, type Model } from "@earendil-works/pi-ai"; import type { ContentBlockParam } from "./sdk-boundary.ts"; /** * Marks an assistant turn that failed because a cold-seed (flatten/bootstrap) * request did not fit the model window. A cold-seed re-sends senpi's own * history as ONE user message, which the Claude Agent SDK cannot compact, so * the compaction lane policy reads this marker to let senpi own the recovery. * It is persisted with the message, so a restarted session still recovers. */ export declare const COLD_SEED_OVERFLOW_DIAGNOSTIC = "claude_sdk_oauth_cold_seed_overflow"; export type ColdSeedOverflowDetails = { estimatedTokens?: number; reportedTokens?: number; reportedLimit?: number; }; export declare class ColdSeedOverflowError extends Error { readonly estimatedTokens: number; readonly contextWindow: number; constructor(estimatedTokens: number, contextWindow: number); } export declare function estimateColdSeedTokens(context: Pick<Context, "systemPrompt" | "tools">, blocks: readonly ContentBlockParam[]): number; /** Tokens the API counts per token bytes/4 estimated, learned from this session's rejected cold-seeds; 1 until one is seen. */ export declare function coldSeedCalibration(sessionId: string | undefined): number; /** * A restarted process has an empty map, but the counts that taught it are persisted * on the session's cold-seed overflow markers: re-learn from the newest marker that * carries both an estimate and a provider-reported count. */ export declare function restoreColdSeedCalibration(sessionId: string, branch: readonly { type: string; message?: { role: string; diagnostics?: readonly AssistantMessageDiagnostic[]; }; }[]): void; export declare function forgetColdSeedCalibration(sessionId?: string): void; /** * Reads the counts a provider rejection reports. Claude Code words an oversized * single-exchange request as "the request is ~N tokens (limit M)"; the API itself * says "prompt is too long: N tokens > M maximum"; the pre-dispatch refusal below * says "about N tokens, limit M". */ export declare function parseReportedOverflowTokens(errorMessage: string | undefined): { reportedTokens: number; reportedLimit: number; } | undefined; export declare function coldSeedOverflow(model: Model<Api>, estimatedTokens: number, calibration?: number): ColdSeedOverflowError | undefined; export declare function markColdSeedOverflow(output: AssistantMessage, model: Model<Api>, coldSeedAttempt: boolean, estimatedTokens?: number, sessionId?: string): void; export declare function isColdSeedOverflowMessage(message: { role: string; diagnostics?: readonly AssistantMessageDiagnostic[]; }): boolean; //# sourceMappingURL=cold-seed-budget.d.ts.map