import { WebJobProgress } from "@xenosystem/web-context-client/progress"; type TextEncoding = "utf8" | "utf8-bom" | "utf16le" | "utf16be"; type LineEnding = "LF" | "CRLF"; interface TextFileContents { content: string; encoding: TextEncoding; lineEnding: LineEnding; sizeBytes: number; } declare function hasFile(filePath: string): boolean; declare function hasDir(dirPath: string): boolean; declare function readFileSafe(filePath: string, fallback?: string): string; declare function ensureDir(dirPath: string): Promise; declare function writeAtomic(filePath: string, content: string | Buffer): Promise; declare function appendLine(filePath: string, line: string): Promise; declare function appendDurableLine(filePath: string, line: string): Promise; declare function detectTextEncoding(buffer: Buffer): TextEncoding; declare function decodeTextBuffer(buffer: Buffer, encoding: TextEncoding): string; declare function encodeTextBuffer(content: string, encoding: TextEncoding): Buffer; declare function detectLineEnding(content: string): LineEnding; declare function normalizeLineEndings(content: string, lineEnding: LineEnding): string; declare function readTextFile(filePath: string): Promise; declare function writeTextFile(filePath: string, content: string, options?: { encoding?: TextEncoding; lineEnding?: LineEnding; }): Promise; declare function detectPreferredLineEnding(baseDir: string): Promise; declare function findSimilarFile(filePath: string): string | null; declare function readIfExists(filePath: string): Promise; declare function existsSync(filePath: string): boolean; declare function listFiles(dir: string, pattern?: RegExp): Promise; declare function listDirs(dir: string): Promise; declare function deleteFile(filePath: string): Promise; declare function deleteDir(dirPath: string): Promise; declare function safeJsonParse(str: string, fallback: T): T; declare function safeJsonStringify(obj: unknown, fallback?: string): string; declare function parseJsonLines(content: string): T[]; interface ParsedDocument> { frontmatter: T; content: string; } declare function parseDocument>(raw: string): ParsedDocument; declare function stringifyDocument(frontmatter: Record, content: string): string; declare function hasFrontmatter(raw: string): boolean; declare function isPathSafe(basePath: string, targetPath: string): boolean; declare function safeResolvePath(basePath: string, targetPath: string): string; declare const PLATFORM: NodeJS.Platform; declare const IS_WINDOWS: boolean; declare const IS_MAC: boolean; declare const IS_LINUX: boolean; declare const OS_VERSION: string; declare const HOME_DIR: string; declare function getAgentHome(): string; declare function getConfigDir(): string; declare function getProjectConfigDir(cwd: string): string; declare function getShellName(): string; declare function isGitRepo(cwd: string): boolean; declare function validateRequired(params: Record, required: string[]): string | null; declare function getString(params: Record, key: string, defaultValue?: string): string; declare function getNumber(params: Record, key: string, defaultValue?: number): number; declare function getBoolean(params: Record, key: string, defaultValue?: boolean): boolean; declare function validateRegexPattern(pattern: string): string | null; declare function createSafeRegex(pattern: string, flags?: string, _timeoutMs?: number): RegExp; declare function safeRegexTest(regex: RegExp, text: string, _timeoutMs?: number): boolean; declare enum LogLevel { DEBUG = 0, INFO = 1, WARN = 2, ERROR = 3, SILENT = 4 } declare function setLogLevel(level: LogLevel): void; declare function getLogLevel(): LogLevel; declare function debug(msg: string, data?: unknown): void; declare function info(msg: string, data?: unknown): void; declare function warn(msg: string, data?: unknown): void; declare function error(msg: string, data?: unknown): void; interface RetryOptions { maxRetries?: number; baseDelayMs?: number; maxDelayMs?: number; jitterMs?: number; signal?: AbortSignal; onBeforeAttempt?: (attempt: number) => void; shouldRetry?: (error: unknown, attempt: number) => boolean; getDelayMs?: (error: unknown, attempt: number, defaultDelayMs: number) => number | null | undefined; onAbort?: () => Error; } interface RetryErrorContext { statusCode?: number; retryAfterMs?: number; requestId?: string; cfRay?: string; } declare class ApiTransientError extends Error { readonly statusCode?: number; readonly body?: string; readonly retryAfterMs?: number; readonly requestId?: string; readonly cfRay?: string; constructor(message: string, context?: RetryErrorContext); } declare function getRetryErrorContext(error: unknown): RetryErrorContext; declare function hasTransientStatusMention(message: string): boolean; declare function isRetryableError(error: unknown): boolean; declare function withRetry(fn: () => Promise, options?: RetryOptions): Promise; type TokenEstimator = (text: string, model: string) => number; type TokenAccountingSource = "exact" | "provider-reported" | "estimated"; interface TokenAccountingResult { tokens: number; source: TokenAccountingSource; adapterId: string; } interface TokenAccountingAdapter { readonly id: string; readonly source: Exclude; countText(text: string, model: string): number; countImage?(input: { model: string; detail?: "auto" | "low" | "high"; }): number; safetyMarginRatio?(model: string): number; } declare const estimateTokensForModel: TokenEstimator; declare const conservativeTokenAccountingAdapter: TokenAccountingAdapter; declare function accountTextTokens(text: string, model: string, adapter?: TokenAccountingAdapter): TokenAccountingResult; declare function estimateTokens(text: string): number; declare function truncateToTokens(text: string, maxTokens: number): string; declare function fitsInBudget(text: string, budget: number): boolean; declare function remainingBudget(used: number, total: number): number; declare function calculateCost(model: string, inputTokens: number, outputTokens: number): number; declare function formatCost(cost: number): string; declare function copyTextToClipboard(text: string): void; declare function isBenchmarkMode(): boolean; declare function isBenchmarkLeakPath(filePath: string): boolean; declare function filterBenchmarkLeakPaths(paths: string[]): string[]; declare function benchmarkLeakError(target: string): string; declare function commandMentionsBenchmarkLeak(command: string): boolean; declare function getBenchmarkReferenceOverwriteHint(command: string): string | null; declare const WEB_CONTEXT_TOOL_RESULT_SCHEMA: "xeno.web-context.tool-result.v1"; interface WebContextEvidenceProjection { evidenceId: string; requestId: string; sourceUrl: string; finalUrl?: string; citations: Array<{ url: string; title?: string; artifactId?: string; }>; } interface WebContextToolResult { schemaVersion: typeof WEB_CONTEXT_TOOL_RESULT_SCHEMA; operation: "search" | "fetch"; requestId: string; evidence: WebContextEvidenceProjection; job?: { jobId: string; state: string; }; artifact?: { artifactId: string; mediaType: string; bytes: number; }; jobProgress?: WebJobProgress; } interface ImageUrlBlock { type: "image_url"; image_url: { url: string; detail?: "auto" | "low" | "high"; }; } interface ResourceContentBlock { type: "resource"; uri?: string; mimeType?: string; text?: string; data?: string; } type ToolAssistantContentBlock = TextBlock | ImageUrlBlock | ResourceContentBlock; type ToolResultContent = string | ToolAssistantContentBlock[]; type ToolOperationState = "registered" | "starting" | "running_foreground" | "running_background" | "waiting_for_input" | "stalled" | "verifying" | "completed" | "failed" | "timed_out" | "cancelled" | "orphaned"; type ToolCompletionPolicy = "await" | "observe" | "detach"; interface ExpectedOutputContract { path: string; kind?: "file" | "directory"; nonEmpty?: boolean; } interface ToolEvidence { id: string; kind: "artifact" | "process" | "verification"; status: "pending" | "verified" | "failed"; path?: string; observedAt: string; operationId: string; detail?: Record; } interface ToolOperationSnapshot { schemaVersion: 1; operationId: string; turnId: string; generation: number; toolCallId: string; toolName: string; ownerSessionId?: string; state: ToolOperationState; terminal: boolean; presentation: "foreground" | "background"; completionPolicy: ToolCompletionPolicy; promotable: boolean; processId?: string; taskId?: string; displayName?: string; pid?: number; commandFingerprint?: string; outputPath?: string; startedAt: string; lastActivityAt: string; deadlineAt?: string; elapsedMs: number; idleMs: number; outputBytes: number; nextOffset: number; exitCode?: number | null; completionReason?: string; suggestedNextAction?: string; expectedOutputs?: ExpectedOutputContract[]; evidence?: ToolEvidence[]; } interface ToolResult { success: boolean; output: string; error?: string; errorCode?: string; errorDetails?: Record; assistantContent?: ToolAssistantContentBlock[]; assistantOnlyContent?: ToolAssistantContentBlock[]; operation?: ToolOperationSnapshot; evidence?: ToolEvidence[]; webContext?: WebContextToolResult; retryable?: boolean; } interface TextBlock { type: "text"; text: string; } interface ToolResultBlock { type: "tool_result"; tool_use_id: string; content: string; assistant_content?: ToolAssistantContentBlock[]; assistant_only_content?: ToolAssistantContentBlock[]; is_error?: boolean; operation?: ToolOperationSnapshot; evidence?: ToolEvidence[]; web_context?: WebContextToolResult; retryable?: boolean; } declare function toolAssistantContentToText(blocks: ToolAssistantContentBlock[]): string; declare function toolResultContentToText(content: ToolResultContent): string; declare function buildToolResultText(result: ToolResult): string; declare function getToolResultTransportContent(block: { content: ToolResultContent; assistant_content?: ToolAssistantContentBlock[]; assistant_only_content?: ToolAssistantContentBlock[]; operation?: ToolResult["operation"]; evidence?: ToolResult["evidence"]; retryable?: boolean; }): ToolResultContent; declare function hasNonTextToolResultContent(content: ToolResultContent): boolean; declare function toTransportAssistantBlocks(content: ToolResultContent): ToolAssistantContentBlock[]; declare function buildToolResultBlock(toolUseId: string, result: ToolResult): ToolResultBlock; interface XenoAsciiControlCharacterPolicy { allowTab?: boolean; allowLineBreaks?: boolean; } declare function hasDisallowedAsciiControlCharacter(value: string, policy?: XenoAsciiControlCharacterPolicy): boolean; export { ApiTransientError, HOME_DIR, IS_LINUX, IS_MAC, IS_WINDOWS, type LineEnding, LogLevel, OS_VERSION, PLATFORM, type ParsedDocument, type RetryErrorContext, type RetryOptions, type TextEncoding, type TextFileContents, type TokenAccountingAdapter, type TokenAccountingResult, type TokenAccountingSource, type TokenEstimator, type XenoAsciiControlCharacterPolicy, accountTextTokens, appendDurableLine, appendLine, benchmarkLeakError, buildToolResultBlock, buildToolResultText, calculateCost, commandMentionsBenchmarkLeak, conservativeTokenAccountingAdapter, copyTextToClipboard, createSafeRegex, debug, decodeTextBuffer, deleteDir, deleteFile, detectLineEnding, detectPreferredLineEnding, detectTextEncoding, encodeTextBuffer, ensureDir, error, estimateTokens, estimateTokensForModel, existsSync, filterBenchmarkLeakPaths, findSimilarFile, fitsInBudget, formatCost, getAgentHome, getBenchmarkReferenceOverwriteHint, getBoolean, getConfigDir, getLogLevel, getNumber, getProjectConfigDir, getRetryErrorContext, getShellName, getString, getToolResultTransportContent, hasDir, hasDisallowedAsciiControlCharacter, hasFile, hasFrontmatter, hasNonTextToolResultContent, hasTransientStatusMention, info, isBenchmarkLeakPath, isBenchmarkMode, isGitRepo, isPathSafe, isRetryableError, listDirs, listFiles, normalizeLineEndings, parseDocument, parseJsonLines, readFileSafe, readIfExists, readTextFile, remainingBudget, safeJsonParse, safeJsonStringify, safeRegexTest, safeResolvePath, setLogLevel, stringifyDocument, toTransportAssistantBlocks, toolAssistantContentToText, toolResultContentToText, truncateToTokens, validateRegexPattern, validateRequired, warn, withRetry, writeAtomic, writeTextFile };