/** * Agent chat API layer and prompt building. * * Exported: * loadProjectRules() — loads .codeep/rules.md or CODEEP.md * formatChatHistoryForAgent() — trims history to fit context window * getAgentSystemPrompt() — builds system prompt for native-tool mode * getFallbackSystemPrompt() — builds system prompt for text-tool mode * agentChat() — native tool-calling API call * agentChatFallback() — text-based tool format fallback * AgentChatResponse — response type (re-export from agentStream) * TimeoutError — distinguishes timeout from user abort */ import { ProjectContext } from './project'; import { Message } from '../config/index'; import { AdditionalToolDef } from './tools'; import type { AgentChatResponse } from './agentStream'; export type { AgentChatResponse }; /** Per-run overrides used by structured custom bots. They never mutate config. */ export interface AgentChatRuntime { providerId?: string; model?: string; protocol?: 'openai' | 'anthropic'; allowedToolNames?: string[]; } /** * Custom error class for timeout */ export declare class TimeoutError extends Error { constructor(message?: string); } /** * Load project rules from .codeep/rules.md or CODEEP.md */ export declare function loadProjectRules(projectRoot: string): string; /** * Load agent progress log from .codeep/progress.md * Injected into system prompt so agent knows what was previously done. */ export declare function loadProgressLog(projectRoot: string): string; /** * Write agent progress log to .codeep/progress.md * Called after each agent run so the next session has context. */ export declare function writeProgressLog(projectRoot: string, prompt: string, result: { success: boolean; iterations: number; actions: Array<{ type: string; target: string; }>; finalResponse: string; }, projectName?: string): void; /** * Format chat session history for inclusion in agent system prompt. * Keeps the most recent messages within a character budget. */ export declare function formatChatHistoryForAgent(history?: Array<{ role: 'user' | 'assistant'; content: string; }>, maxChars?: number): string; /** * Summarize the OVERFLOW that `formatChatHistoryForAgent` drops. When prior * history exceeds `maxChars`, that function keeps only the most recent messages * and silently discards the older ones — losing early decisions/constraints on * long sessions. This condenses those dropped messages into a short recap that * the caller prepends *before* the recent verbatim history. * * Returns '' when: opted out (`autoSummarizeHistory === false`), nothing * overflows, or the summarization call fails (graceful fallback — the recent * history still goes in, we just don't add a recap). */ export declare function summarizeEarlierHistory(history?: Array<{ role: 'user' | 'assistant'; content: string; }>, maxChars?: number): Promise; export declare function getAgentSystemPrompt(projectContext: ProjectContext, runtime?: AgentChatRuntime): string; export declare function getFallbackSystemPrompt(projectContext: ProjectContext, additionalTools?: AdditionalToolDef[], runtime?: AgentChatRuntime): string; /** * Make a chat API call for agent mode with native tool support. * Falls back to agentChatFallback() if provider doesn't support tools. */ export declare function agentChat(messages: Message[], systemPrompt: string, onChunk?: (chunk: string) => void, abortSignal?: AbortSignal, dynamicTimeout?: number, /** * Extra tool definitions appended to the catalog (currently used to * surface MCP-registered tools as first-class entries the model can * invoke). Optional — built-in tools work the same whether this is * omitted or an empty array. */ additionalTools?: AdditionalToolDef[], runtime?: AgentChatRuntime): Promise; /** * Fallback chat without native tools (text-based tool format) */ export declare function agentChatFallback(messages: Message[], systemPrompt: string, onChunk?: (chunk: string) => void, abortSignal?: AbortSignal, dynamicTimeout?: number, additionalTools?: AdditionalToolDef[], runtime?: AgentChatRuntime): Promise;