UNPKG

zcf

Version:

Zero-Config Code Flow - One-click configuration tool for Code Cli

322 lines (311 loc) 14.1 kB
declare const CLAUDE_DIR: string; declare const SETTINGS_FILE: string; declare const CLAUDE_MD_FILE: string; declare const ClAUDE_CONFIG_FILE: string; declare const CLAUDE_VSC_CONFIG_FILE: string; declare const CODEX_DIR: string; declare const CODEX_CONFIG_FILE: string; declare const CODEX_AUTH_FILE: string; declare const CODEX_AGENTS_FILE: string; declare const CODEX_PROMPTS_DIR: string; declare const ZCF_CONFIG_DIR: string; declare const ZCF_CONFIG_FILE: string; declare const LEGACY_ZCF_CONFIG_FILES: string[]; declare const CODE_TOOL_TYPES: readonly ["claude-code", "codex"]; type CodeToolType = (typeof CODE_TOOL_TYPES)[number]; declare const DEFAULT_CODE_TOOL_TYPE: CodeToolType; declare const CODE_TOOL_BANNERS: Record<CodeToolType, string>; declare const CODE_TOOL_ALIASES: Record<string, CodeToolType>; declare function isCodeToolType(value: any): value is CodeToolType; declare const API_DEFAULT_URL = "https://api.anthropic.com"; declare const API_ENV_KEY = "ANTHROPIC_API_KEY"; declare function resolveCodeToolType(value: unknown): CodeToolType; declare const SUPPORTED_LANGS: readonly ["zh-CN", "en"]; type SupportedLang = (typeof SUPPORTED_LANGS)[number]; declare const LANG_LABELS: { readonly 'zh-CN': "简体中文"; readonly en: "English"; }; declare const AI_OUTPUT_LANGUAGES: { readonly 'zh-CN': { readonly directive: "Always respond in Chinese-simplified"; }; readonly en: { readonly directive: "Always respond in English"; }; readonly custom: { readonly directive: ""; }; }; type AiOutputLanguage = keyof typeof AI_OUTPUT_LANGUAGES; declare function getAiOutputLanguageLabel(lang: AiOutputLanguage): string; interface InitOptions { configLang?: SupportedLang; aiOutputLang?: AiOutputLanguage | string; force?: boolean; skipBanner?: boolean; skipPrompt?: boolean; codeType?: CodeToolType | string; configAction?: 'new' | 'backup' | 'merge' | 'docs-only' | 'skip'; apiType?: 'auth_token' | 'api_key' | 'ccr_proxy' | 'skip'; apiKey?: string; apiUrl?: string; apiModel?: string; apiHaikuModel?: string; apiSonnetModel?: string; apiOpusModel?: string; provider?: string; mcpServices?: string[] | string | boolean; workflows?: string[] | string | boolean; outputStyles?: string[] | string | boolean; defaultOutputStyle?: string; allLang?: string; installCometixLine?: string | boolean; apiConfigs?: string; apiConfigsFile?: string; } declare function init(options?: InitOptions): Promise<void>; declare function getPlatform(): 'windows' | 'macos' | 'linux'; declare function commandExists(command: string): Promise<boolean>; /** * Get recommended install methods for a code tool based on current platform * Returns methods in priority order (most recommended first) */ type CodeType = 'claude-code' | 'codex'; type InstallMethod$1 = 'npm' | 'homebrew' | 'curl' | 'powershell' | 'cmd' | 'npm-global' | 'native'; interface McpService { id: string; name: string; description: string; requiresApiKey: boolean; apiKeyPrompt?: string; apiKeyPlaceholder?: string; apiKeyEnvVar?: string; config: McpServerConfig; } interface McpServerConfig { type: 'stdio' | 'sse'; command?: string; args?: string[]; url?: string; env?: Record<string, string>; startup_timeout_ms?: number; } interface ClaudeConfiguration { mcpServers: Record<string, McpServerConfig>; hasCompletedOnboarding?: boolean; customApiKeyResponses?: { approved: string[]; rejected: string[]; }; env?: Record<string, string>; primaryApiKey?: string; installMethod?: InstallMethod$1; } declare function getMcpConfigPath(): string; declare function readMcpConfig(): ClaudeConfiguration | null; declare function writeMcpConfig(config: ClaudeConfiguration): void; declare function backupMcpConfig(): string | null; declare function mergeMcpServers(existing: ClaudeConfiguration | null, newServers: Record<string, McpServerConfig>): ClaudeConfiguration; declare function buildMcpServerConfig(baseConfig: McpServerConfig, apiKey?: string, placeholder?: string, envVarName?: string): McpServerConfig; declare function fixWindowsMcpConfig(config: ClaudeConfiguration): ClaudeConfiguration; declare function addCompletedOnboarding(): void; /** * Ensures that an API key is in the approved list and not in the rejected list * @param config - Claude configuration object * @param apiKey - The API key to manage * @returns Updated configuration with API key properly approved */ declare function ensureApiKeyApproved(config: ClaudeConfiguration, apiKey: string): ClaudeConfiguration; /** * Removes an API key from the rejected list * @param config - Claude configuration object * @param apiKey - The API key to remove from rejected list * @returns Updated configuration with API key removed from rejected list */ declare function removeApiKeyFromRejected(config: ClaudeConfiguration, apiKey: string): ClaudeConfiguration; /** * Manages API key approval status by reading config, updating it, and writing it back * @param apiKey - The API key to ensure is approved (e.g., 'sk-zcf-x-ccr') */ declare function manageApiKeyApproval(apiKey: string): void; /** * Sets the primaryApiKey field in ~/.claude/config.json (VSCode extension config) * This is required for Claude Code 2.0 to properly recognize third-party API configurations * and prevent redirecting to official login page */ declare function setPrimaryApiKey(): void; /** * API configuration for Claude Code */ interface ApiConfig { url: string; key: string; authType?: 'auth_token' | 'api_key'; } /** * Installation method types for code tools */ type InstallMethod = 'npm' | 'homebrew' | 'curl' | 'powershell' | 'cmd'; declare function ensureClaudeDir(): void; declare function backupExistingConfig(): string | null; declare function copyConfigFiles(onlyMd?: boolean): void; declare function configureApi(apiConfig: ApiConfig | null): ApiConfig | null; declare function mergeConfigs(sourceFile: string, targetFile: string): void; /** * Update custom model configuration using environment variables * @param primaryModel - Primary model name for general tasks * @param haikuModel - Default Haiku model (optional) * @param sonnetModel - Default Sonnet model (optional) * @param opusModel - Default Opus model (optional) */ declare function updateCustomModel(primaryModel?: string, haikuModel?: string, sonnetModel?: string, opusModel?: string): void; /** * Update the default model configuration in settings.json * @param model - The model type to set: opus, sonnet, sonnet[1m], default, or custom * Note: 'custom' model type is handled differently - it should use environment variables instead */ declare function updateDefaultModel(model: 'opus' | 'sonnet' | 'sonnet[1m]' | 'default' | 'custom'): void; /** * Merge settings.json intelligently * Preserves user's environment variables and custom configurations */ declare function mergeSettingsFile(templatePath: string, targetPath: string): void; /** * Get existing model configuration from settings.json */ declare function getExistingModelConfig(): 'opus' | 'sonnet' | 'sonnet[1m]' | 'default' | 'custom' | null; /** * Get existing API configuration from settings.json */ declare function getExistingApiConfig(): ApiConfig | null; declare function applyAiLanguageDirective(aiOutputLang: AiOutputLanguage | string): void; /** * Switch to official login mode - remove all third-party API configurations * Removes: ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY from settings.json * Removes: primaryApiKey from ~/.claude/config.json */ declare function switchToOfficialLogin(): boolean; /** * Prompt user for API configuration action when existing config is found * Returns the user's choice for how to handle existing configuration */ declare function promptApiConfigurationAction(): Promise<'modify-partial' | 'modify-all' | 'keep-existing' | null>; declare function isClaudeCodeInstalled(): Promise<boolean>; /** * Install Claude Code with method selection support * @param skipMethodSelection - If true, use default npm installation */ declare function installClaudeCode(skipMethodSelection?: boolean): Promise<void>; /** * Check if Codex is installed */ declare function isCodexInstalled(): Promise<boolean>; /** * Install Codex with method selection support * @param skipMethodSelection - If true, use default npm installation */ declare function installCodex(skipMethodSelection?: boolean): Promise<void>; /** * Check if local Claude Code installation exists */ declare function isLocalClaudeCodeInstalled(): Promise<boolean>; /** * Get installation status for both global and local Claude Code */ interface InstallationStatus { hasGlobal: boolean; hasLocal: boolean; localPath: string; } declare function getInstallationStatus(): Promise<InstallationStatus>; /** * Remove local Claude Code installation */ declare function removeLocalClaudeCode(): Promise<void>; /** * Uninstall code tool based on install method * @param codeType - Type of code tool to uninstall * @returns true if uninstalled successfully */ declare function uninstallCodeTool(codeType: CodeType): Promise<boolean>; /** * Set installMethod in both ~/.claude.json and zcf-config * This ensures Claude Code knows it was installed via npm for proper auto-updates */ declare function setInstallMethod(method: InstallMethod, codeType?: CodeType): Promise<void>; /** * Detect installed version of a code tool * Returns version string or null if not installed */ declare function detectInstalledVersion(codeType: CodeType): Promise<string | null>; /** * Select installation method interactively */ declare function selectInstallMethod(codeType: CodeType, excludeMethods?: InstallMethod[]): Promise<InstallMethod | null>; /** * Execute installation using specified method */ declare function executeInstallMethod(method: InstallMethod, codeType: CodeType): Promise<boolean>; /** * Handle installation failure with retry options */ declare function handleInstallFailure(codeType: CodeType, failedMethods: InstallMethod[]): Promise<boolean>; /** * Installation verification result */ interface VerificationResult { success: boolean; commandPath: string | null; version: string | null; needsSymlink: boolean; symlinkCreated: boolean; error?: string; } /** * Verify installation by checking command availability and version * If command is not in PATH but found in Homebrew paths, attempt to create symlink */ declare function verifyInstallation(codeType: CodeType): Promise<VerificationResult>; /** * Symlink creation result */ interface SymlinkResult { success: boolean; symlinkPath: string | null; error?: string; } /** * Create symlink in Homebrew bin directory for commands installed via npm * This handles the case where npm global packages are installed to * /opt/homebrew/Cellar/node/{version}/bin/ but that path is not in the user's PATH */ declare function createHomebrewSymlink(command: string, sourcePath: string): Promise<SymlinkResult>; /** * Display verification result to user with appropriate messages */ declare function displayVerificationResult(result: VerificationResult, codeType: CodeType): void; /** * Clean up and deduplicate permissions array * Removes invalid and redundant permissions based on template */ /** * Clean up permissions array by removing invalid and redundant entries * @param templatePermissions - Permissions from template (source of truth) * @param userPermissions - User's existing permissions * @returns Cleaned permissions array */ declare function cleanupPermissions(templatePermissions: string[], userPermissions: string[]): string[]; /** * Merge and clean permissions arrays * Combines template and user permissions while removing invalid/redundant entries * @param templatePermissions - Permissions from template * @param userPermissions - User's existing permissions * @returns Merged and cleaned permissions array */ declare function mergeAndCleanPermissions(templatePermissions: string[] | undefined, userPermissions: string[] | undefined): string[]; declare function importRecommendedEnv(): Promise<void>; declare function importRecommendedPermissions(): Promise<void>; declare function openSettingsJson(): Promise<void>; export { AI_OUTPUT_LANGUAGES, API_DEFAULT_URL, API_ENV_KEY, CLAUDE_DIR, CLAUDE_MD_FILE, CLAUDE_VSC_CONFIG_FILE, CODEX_AGENTS_FILE, CODEX_AUTH_FILE, CODEX_CONFIG_FILE, CODEX_DIR, CODEX_PROMPTS_DIR, CODE_TOOL_ALIASES, CODE_TOOL_BANNERS, CODE_TOOL_TYPES, ClAUDE_CONFIG_FILE, DEFAULT_CODE_TOOL_TYPE, LANG_LABELS, LEGACY_ZCF_CONFIG_FILES, SETTINGS_FILE, SUPPORTED_LANGS, ZCF_CONFIG_DIR, ZCF_CONFIG_FILE, addCompletedOnboarding, applyAiLanguageDirective, backupExistingConfig, backupMcpConfig, buildMcpServerConfig, cleanupPermissions, commandExists, configureApi, copyConfigFiles, createHomebrewSymlink, detectInstalledVersion, displayVerificationResult, ensureApiKeyApproved, ensureClaudeDir, executeInstallMethod, fixWindowsMcpConfig, getAiOutputLanguageLabel, getExistingApiConfig, getExistingModelConfig, getInstallationStatus, getMcpConfigPath, getPlatform, handleInstallFailure, importRecommendedEnv, importRecommendedPermissions, init, installClaudeCode, installCodex, isClaudeCodeInstalled, isCodeToolType, isCodexInstalled, isLocalClaudeCodeInstalled, manageApiKeyApproval, mergeAndCleanPermissions, mergeConfigs, mergeMcpServers, mergeSettingsFile, openSettingsJson, promptApiConfigurationAction, readMcpConfig, removeApiKeyFromRejected, removeLocalClaudeCode, resolveCodeToolType, selectInstallMethod, setInstallMethod, setPrimaryApiKey, switchToOfficialLogin, uninstallCodeTool, updateCustomModel, updateDefaultModel, verifyInstallation, writeMcpConfig }; export type { AiOutputLanguage, ApiConfig, ClaudeConfiguration, CodeToolType, InstallationStatus, McpServerConfig, McpService, SupportedLang, VerificationResult };