/** * Claude Session * * High-level wrapper for interactive Claude Code sessions with mid-execution messaging. * * @module agents/claude/session */ import type { ClaudeCodeConfig } from './types/config.js'; import type { ManagedProcess } from '../../process/types.js'; import type { OutputChunk, NormalizedEntry } from '../types/agent-executor.js'; /** * Session state */ export type SessionState = 'idle' | 'running' | 'interrupted' | 'closed'; /** * Claude Session * * Provides a high-level API for interactive Claude Code sessions that support * mid-execution messaging. This wrapper simplifies the common pattern of: * 1. Starting a task * 2. Sending additional messages during execution * 3. Interrupting if needed * 4. Cleaning up * * @example Basic usage * ```typescript * const session = new ClaudeSession({ * workDir: '/path/to/project', * print: true, * outputFormat: 'stream-json', * }); * * // Start a task * await session.start('Build a login feature'); * * // Send additional guidance mid-execution * await session.sendMessage('Also add password validation'); * await session.sendMessage('Use bcrypt for hashing'); * * // Clean up when done * await session.close(); * ``` * * @example With output handling * ```typescript * const session = new ClaudeSession(config); * await session.start('Refactor the auth module'); * * // Get normalized output stream * const outputStream = session.getOutputChunks(); * if (outputStream) { * for await (const entry of session.normalizeOutput(outputStream)) { * console.log(entry.type.kind, entry.content); * } * } * ``` */ export declare class ClaudeSession { private readonly executor; private readonly config; private process; private state; /** * Create a new Claude session * * @param config - Claude Code configuration */ constructor(config: ClaudeCodeConfig); /** * Get current session state * * @returns Current session state */ getState(): SessionState; /** * Check if session is running * * @returns True if session is in running state */ isRunning(): boolean; /** * Start a new session with an initial prompt * * @param prompt - Initial prompt to send to Claude * @param workDir - Working directory (defaults to config.workDir) * @throws Error if session is already started * * @example * ```typescript * const session = new ClaudeSession(config); * await session.start('Add a new API endpoint for user profiles'); * ``` */ start(prompt: string, workDir?: string): Promise; /** * Send an additional message to the running session * * Use this to provide mid-execution guidance, additional context, * or corrections while Claude is working on the task. * * @param message - Message content to send * @throws Error if session is not running * * @example * ```typescript * await session.start('Build a user dashboard'); * * // Provide additional guidance during execution * await session.sendMessage('Use Chart.js for the graphs'); * await session.sendMessage('Add dark mode support'); * ``` */ sendMessage(message: string): Promise; /** * Interrupt the current operation * * Sends an interrupt signal to Claude. Claude handles this gracefully, * typically finishing the current tool operation before stopping. * * @throws Error if session is not running * * @example * ```typescript * // User wants to stop the current task * await session.interrupt(); * ``` */ interrupt(): Promise; /** * Get the underlying managed process * * Use this for advanced operations not covered by the session API. * * @returns The managed process or null if not started */ getProcess(): ManagedProcess | null; /** * Get output chunks from the process * * Creates an async iterable of raw output chunks from the process streams. * Use with `normalizeOutput()` to get structured entries. * * @returns Async iterable of output chunks, or null if not running */ getOutputChunks(): AsyncIterable | null; /** * Normalize output chunks to structured entries * * Converts raw output chunks into normalized entries that can be * rendered consistently. * * @param outputStream - Raw output chunks from getOutputChunks() * @returns Async iterable of normalized entries */ normalizeOutput(outputStream: AsyncIterable): AsyncIterable; /** * Close the session * * Interrupts any running task and cleans up resources. * The session cannot be reused after closing. * * @example * ```typescript * try { * await session.start('Build feature'); * // ... work with session ... * } finally { * await session.close(); * } * ``` */ close(): Promise; /** * Create an execution task from prompt and workDir */ private createTask; } //# sourceMappingURL=session.d.ts.map