/** * Claude CLI Subprocess Wrapper - ToS-Compliant Alternative to Pi Agent * * WHY THIS EXISTS: * - Current Pi Agent uses OAuth token directly via API (ToS violation, ban risk) * - Claude CLI is official Anthropic tool (ToS compliant) * - Keeps $200/month subscription benefits vs $1000+/month API costs * * ARCHITECTURE: * - Spawns `claude` CLI as subprocess * - Communicates via stdin (prompts) / stdout (JSON responses) * - Uses --output-format json for structured data * - Session continuity via --session-id flag * * TRADEOFFS: * + ✅ ToS compliant (official Claude tool) * + ✅ Keeps subscription pricing * + ✅ Real usage tracking (cost, tokens) * - ⚠️ More complex than direct API * - ⚠️ Requires claude CLI installed * - ⚠️ Tool integration via MCP (future work) */ import type { PromptCallbacks, ToolUseBlock } from './types.js'; export interface ClaudeCLIWrapperOptions { model?: string; /** * Effort level for Claude 4.6 adaptive thinking * Applies to claude-opus-4-6 and claude-sonnet-4-6 * 'max' is only available on Opus 4.6 */ effort?: 'low' | 'medium' | 'high' | 'max'; sessionId?: string; systemPrompt?: string; mcpConfigPath?: string; /** * Skip permission prompts for tool execution * * @warning SECURITY RISK: Bypasses all permission checks. * Only enable in trusted environments where agent actions are pre-approved. */ dangerouslySkipPermissions?: boolean; /** If true, use GatewayToolExecutor instead of MCP (default: false) */ useGatewayTools?: boolean; /** Request timeout in ms (default: 120000). Increase for complex/long tasks. */ requestTimeout?: number; /** Override built-in tool set (--tools CLI flag). Use "" to disable all tools. */ tools?: string; /** Override plugin directory (--plugin-dir CLI flag). Use empty dir to disable plugins. */ pluginDir?: string; /** Structurally disallowed tools (--disallowedTools CLI flag) */ disallowedTools?: string[]; /** Structurally allowed tools (--allowedTools CLI flag) */ allowedTools?: string[]; } export type { PromptCallbacks, ToolUseBlock } from './types.js'; export interface PromptResult { response: string; usage: { input_tokens: number; output_tokens: number; cache_creation_input_tokens?: number; cache_read_input_tokens?: number; }; session_id: string; cost_usd?: number; /** Tool use blocks if Claude requested tools */ toolUseBlocks?: ToolUseBlock[]; /** True if Claude requested tool use */ hasToolUse?: boolean; } /** * ClaudeCLIWrapper - Wraps Claude CLI for programmatic use * * Usage: * const wrapper = new ClaudeCLIWrapper({ sessionId: 'my-session' }); * const result = await wrapper.prompt('Hello, Claude!', { * onDelta: (text) => console.log('Delta:', text) * }); * * Key Features: * - Session continuity (multi-turn conversations) * - Real-time streaming (--output-format json streams) * - Usage tracking (tokens, cost) * - ToS compliant (official CLI) * * IMPORTANT: * - Requires `claude` CLI in PATH * - Uses subscription credentials from ~/.claude/.credentials.json * - Tools not yet supported (future: via MCP) */ export declare class ClaudeCLIWrapper { private sessionId; private options; private turnCount; constructor(options?: ClaudeCLIWrapperOptions); /** * Send a prompt to Claude CLI * * Workflow: * 1. Spawn `claude -p "" --output-format json` * 2. Parse JSON output (type: result | error | delta) * 3. Aggregate deltas for streaming * 4. Return final result with usage stats * * @param content - Prompt text (images not yet supported) * @param callbacks - Streaming callbacks * @param options - Optional per-request overrides (model, etc.) * @returns PromptResult with response and usage */ prompt(content: string, callbacks?: PromptCallbacks, options?: { model?: string; resumeSession?: boolean; }): Promise; /** * Get current session ID */ getSessionId(): string; /** * Create a new session (resets conversation history) */ resetSession(): void; /** * Set session ID (for channel-specific conversations) */ setSessionId(sessionId: string): void; /** * Set system prompt (updates options for next prompt) */ setSystemPrompt(prompt: string): void; /** * Get current options (for debugging) */ getOptions(): ClaudeCLIWrapperOptions; } /** * Usage Example: * * const wrapper = new ClaudeCLIWrapper({ sessionId: 'discord-channel-123' }); * * // First message * const result1 = await wrapper.prompt('Hello, what is 2+2?', { * onDelta: (text) => console.log('Streaming:', text) * }); * * console.log(result1.response); // "4" * console.log(result1.usage.input_tokens); // 3 * console.log(result1.cost_usd); // 0.045 * * // Follow-up (same session) * const result2 = await wrapper.prompt('What about 3+3?'); * console.log(result2.response); // "6" * * // Cost Tracking Example: * let totalCost = 0; * const result = await wrapper.prompt('...'); * totalCost += result.cost_usd || 0; * console.log(`Total spent: $${totalCost.toFixed(4)}`); */ //# sourceMappingURL=claude-cli-wrapper.d.ts.map