diff --git a/eslint.config.js b/eslint.config.js index 7f681e3..3e2d1d5 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,82 +1,67 @@ import js from '@eslint/js'; -import typescript from '@typescript-eslint/eslint-plugin'; -import typescriptParser from '@typescript-eslint/parser'; +import tseslint from 'typescript-eslint'; import prettierConfig from 'eslint-config-prettier'; -import prettierPlugin from 'eslint-plugin-prettier'; -export default [ - // 基础 JavaScript 推荐配置 +export default tseslint.config( + // 基础推荐配置 js.configs.recommended, + ...tseslint.configs.recommended, - // TypeScript 文件配置 + // Prettier 集成 + prettierConfig, + + // 源代码配置 { - files: ['**/*.{ts,tsx}'], + files: ['src/**/*.{ts,tsx}'], languageOptions: { - parser: typescriptParser, parserOptions: { - ecmaVersion: 'latest', - sourceType: 'module', - project: ['./tsconfig.json', './tsconfig.test.json'], - tsconfigRootDir: process.cwd(), + project: './tsconfig.json', + tsconfigRootDir: import.meta.dirname, }, }, - plugins: { - '@typescript-eslint': typescript, - prettier: prettierPlugin, - }, rules: { - // TypeScript 推荐规则 - ...typescript.configs['recommended'].rules, - ...typescript.configs['recommended-requiring-type-checking'].rules, - - // 自定义规则 - '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], - '@typescript-eslint/no-explicit-any': 'warn', - '@typescript-eslint/prefer-const': 'error', - '@typescript-eslint/no-non-null-assertion': 'warn', - '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/no-empty-function': 'off', - '@typescript-eslint/no-floating-promises': 'error', - '@typescript-eslint/await-thenable': 'error', - '@typescript-eslint/no-misused-promises': 'error', - - // 代码质量规则 - 'no-console': 'warn', - 'prefer-const': 'error', - 'no-var': 'error', - 'object-shorthand': 'error', - 'prefer-template': 'error', - - // Prettier 规则 - 'prettier/prettier': 'error', + '@typescript-eslint/no-unused-vars': [ + 'error', + { + argsIgnorePattern: '^_', + varsIgnorePattern: '^_' + } + ], + 'no-console': 'off', // CLI 工具需要 console }, }, - // 测试文件特殊配置 + // 测试文件配置 { - files: ['**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'], + files: ['tests/**/*.{ts,tsx}', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}'], + languageOptions: { + parserOptions: { + project: './tsconfig.test.json', + tsconfigRootDir: import.meta.dirname, + }, + }, rules: { '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-unused-vars': [ + 'error', + { + argsIgnorePattern: '^_', + varsIgnorePattern: '^_' + } + ], 'no-console': 'off', }, }, - // 忽略文件 + // 忽略配置 { ignores: [ - 'node_modules/', 'dist/', 'coverage/', + 'node_modules/', '*.js', - '*.mjs', - '*.cjs', - 'bin/', - 'scripts/', - 'lib/', + '*.mjs', + '*.cjs' ], - }, - - // Prettier 配置(必须放在最后) - prettierConfig, -]; \ No newline at end of file + } +); \ No newline at end of file diff --git a/package.json b/package.json index 10ddf44..b76b69b 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "format": "prettier --write \"src/**/*.{ts,tsx,json,md}\" \"tests/**/*.{ts,tsx,json}\"", "format:check": "prettier --check \"src/**/*.{ts,tsx,json,md}\" \"tests/**/*.{ts,tsx,json}\"", "clean": "rimraf dist coverage", - "prepublishOnly": "pnpm run clean && pnpm run build && pnpm run test", "prepare": "husky" }, @@ -43,7 +42,14 @@ "pnpm": ">=9.0.0" }, "packageManager": "pnpm@9.15.0", - "keywords": ["claude", "claude code", "cli", "wrapper", "anthropic", "typescript"], + "keywords": [ + "claude", + "claude code", + "cli", + "wrapper", + "anthropic", + "typescript" + ], "author": "Milly Lee", "license": "MIT", "devDependencies": { @@ -54,12 +60,12 @@ "@vitest/ui": "^3.2.4", "eslint": "^9.18.0", "eslint-config-prettier": "^9.1.0", - "eslint-plugin-prettier": "^5.2.1", "husky": "^9.1.7", "lint-staged": "^15.3.0", "prettier": "^3.4.2", "rimraf": "^6.0.1", "typescript": "^5.7.2", + "typescript-eslint": "^8.38.0", "vite": "^7.0.5", "vitest": "^3.2.4" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a28aa39..4788952 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,9 +29,6 @@ importers: eslint-config-prettier: specifier: ^9.1.0 version: 9.1.2(eslint@9.32.0) - eslint-plugin-prettier: - specifier: ^5.2.1 - version: 5.5.3(eslint-config-prettier@9.1.2(eslint@9.32.0))(eslint@9.32.0)(prettier@3.6.2) husky: specifier: ^9.1.7 version: 9.1.7 @@ -47,6 +44,9 @@ importers: typescript: specifier: ^5.7.2 version: 5.8.3 + typescript-eslint: + specifier: ^8.38.0 + version: 8.38.0(eslint@9.32.0)(typescript@5.8.3) vite: specifier: ^7.0.5 version: 7.0.6(@types/node@18.19.120)(yaml@2.8.0) @@ -340,10 +340,6 @@ packages: resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} - '@pkgr/core@0.2.9': - resolution: {integrity: sha512-QNqXyfVS2wm9hweSYD2O7F0G06uurj9kZ96TRQE5Y9hU7+tgdZwIkbAKc5Ocy1HxEY2kuDQa6cQ1WRs/O5LFKA==} - engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} - '@polka/url@1.0.0-next.29': resolution: {integrity: sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww==} @@ -734,20 +730,6 @@ packages: peerDependencies: eslint: '>=7.0.0' - eslint-plugin-prettier@5.5.3: - resolution: {integrity: sha512-NAdMYww51ehKfDyDhv59/eIItUVzU0Io9H2E8nHNGKEeeqlnci+1gCvrHib6EmZdf6GxF+LCV5K7UC65Ezvw7w==} - engines: {node: ^14.18.0 || >=16.0.0} - peerDependencies: - '@types/eslint': '>=8.0.0' - eslint: '>=8.0.0' - eslint-config-prettier: '>= 7.0.0 <10.0.0 || >=10.1.0' - prettier: '>=3.0.0' - peerDependenciesMeta: - '@types/eslint': - optional: true - eslint-config-prettier: - optional: true - eslint-scope@8.4.0: resolution: {integrity: sha512-sNXOfKCn74rt8RICKMvJS7XKV/Xk9kA7DyJr8mJik3S7Cwgy3qlkkmyS2uQB3jiJg6VNdZd/pDBJu0nvG2NlTg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -807,9 +789,6 @@ packages: fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} - fast-diff@1.3.0: - resolution: {integrity: sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==} - fast-glob@3.3.3: resolution: {integrity: sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==} engines: {node: '>=8.6.0'} @@ -1178,10 +1157,6 @@ packages: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} - prettier-linter-helpers@1.0.0: - resolution: {integrity: sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==} - engines: {node: '>=6.0.0'} - prettier@3.6.2: resolution: {integrity: sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==} engines: {node: '>=14'} @@ -1303,10 +1278,6 @@ packages: resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==} engines: {node: '>=8'} - synckit@0.11.11: - resolution: {integrity: sha512-MeQTA1r0litLUf0Rp/iisCaL8761lKAZHaimlbGK4j0HysC4PLfqygQj9srcs0m2RdtDYnF8UuYyKpbjHYp7Jw==} - engines: {node: ^14.18.0 || >=16.0.0} - test-exclude@7.0.1: resolution: {integrity: sha512-pFYqmTw68LXVjeWJMST4+borgQP2AyMNbg1BpZh9LbyhUeNkeaPF9gzfPGUAnSMV3qPYdWUwDIjjCLiSDOl7vg==} engines: {node: '>=18'} @@ -1351,6 +1322,13 @@ packages: resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} engines: {node: '>= 0.8.0'} + typescript-eslint@8.38.0: + resolution: {integrity: sha512-FsZlrYK6bPDGoLeZRuvx2v6qrM03I0U0SnfCLPs/XCCPCFD80xU9Pg09H/K+XFa68uJuZo7l/Xhs+eDRg2l3hg==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 + typescript: '>=4.8.4 <5.9.0' + typescript@5.8.3: resolution: {integrity: sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==} engines: {node: '>=14.17'} @@ -1673,8 +1651,6 @@ snapshots: '@pkgjs/parseargs@0.11.0': optional: true - '@pkgr/core@0.2.9': {} - '@polka/url@1.0.0-next.29': {} '@rollup/rollup-android-arm-eabi@4.45.1': @@ -2071,15 +2047,6 @@ snapshots: dependencies: eslint: 9.32.0 - eslint-plugin-prettier@5.5.3(eslint-config-prettier@9.1.2(eslint@9.32.0))(eslint@9.32.0)(prettier@3.6.2): - dependencies: - eslint: 9.32.0 - prettier: 3.6.2 - prettier-linter-helpers: 1.0.0 - synckit: 0.11.11 - optionalDependencies: - eslint-config-prettier: 9.1.2(eslint@9.32.0) - eslint-scope@8.4.0: dependencies: esrecurse: 4.3.0 @@ -2169,8 +2136,6 @@ snapshots: fast-deep-equal@3.1.3: {} - fast-diff@1.3.0: {} - fast-glob@3.3.3: dependencies: '@nodelib/fs.stat': 2.0.5 @@ -2512,10 +2477,6 @@ snapshots: prelude-ls@1.2.1: {} - prettier-linter-helpers@1.0.0: - dependencies: - fast-diff: 1.3.0 - prettier@3.6.2: {} punycode@2.3.1: {} @@ -2642,10 +2603,6 @@ snapshots: dependencies: has-flag: 4.0.0 - synckit@0.11.11: - dependencies: - '@pkgr/core': 0.2.9 - test-exclude@7.0.1: dependencies: '@istanbuljs/schema': 0.1.3 @@ -2681,6 +2638,17 @@ snapshots: dependencies: prelude-ls: 1.2.1 + typescript-eslint@8.38.0(eslint@9.32.0)(typescript@5.8.3): + dependencies: + '@typescript-eslint/eslint-plugin': 8.38.0(@typescript-eslint/parser@8.38.0(eslint@9.32.0)(typescript@5.8.3))(eslint@9.32.0)(typescript@5.8.3) + '@typescript-eslint/parser': 8.38.0(eslint@9.32.0)(typescript@5.8.3) + '@typescript-eslint/typescript-estree': 8.38.0(typescript@5.8.3) + '@typescript-eslint/utils': 8.38.0(eslint@9.32.0)(typescript@5.8.3) + eslint: 9.32.0 + typescript: 5.8.3 + transitivePeerDependencies: + - supports-color + typescript@5.8.3: {} undici-types@5.26.5: {} diff --git a/src/cli/commands.ts b/src/cli/commands.ts index 203a335..9419e68 100644 --- a/src/cli/commands.ts +++ b/src/cli/commands.ts @@ -13,7 +13,7 @@ declare const __PKG_DESCRIPTION__: string; */ export function parseArgs(args: string[]): CLIOptions { const options: CLIOptions = {}; - + for (const arg of args) { switch (arg) { case '--help': @@ -38,7 +38,7 @@ export function parseArgs(args: string[]): CLIOptions { break; } } - + return options; } @@ -85,13 +85,12 @@ Examples: /** * Handle configuration-related commands */ -export function handleConfigCommands( - options: CLIOptions, - configManager: ConfigManager -): boolean { +export function handleConfigCommands(options: CLIOptions, configManager: ConfigManager): boolean { if (options.next) { const newConfig = configManager.switchToNext(); - console.log(`✅ Switched to config: ${newConfig.name} - ${newConfig.description || 'No description'}`); + console.log( + `✅ Switched to config: ${newConfig.name} - ${newConfig.description || 'No description'}` + ); console.log(` Base URL: ${newConfig.baseUrl || '(not set)'}`); console.log(` Token: ${newConfig.authToken ? 'set' : 'not set'}`); return true; @@ -106,7 +105,9 @@ export function handleConfigCommands( configs.forEach((cfg, idx) => { const currentConfig = configManager.getCurrentConfig(); const current = cfg === currentConfig ? ' (current)' : ''; - console.log(` [${idx}] ${cfg.name}${cfg.description ? ` - ${cfg.description}` : ''}${current}`); + console.log( + ` [${idx}] ${cfg.name}${cfg.description ? ` - ${cfg.description}` : ''}${current}` + ); }); } return true; @@ -183,7 +184,9 @@ export function setupEnvironment(config: ConfigItem): EnvironmentVariables { */ export function showCurrentConfig(config: ConfigItem): void { if (config.name !== 'default' || config.baseUrl || config.authToken) { - console.log(`🔧 Current config: ${config.name}${config.description ? ` - ${config.description}` : ''}`); + console.log( + `🔧 Current config: ${config.name}${config.description ? ` - ${config.description}` : ''}` + ); } } @@ -214,7 +217,7 @@ export async function handleCLI(args: string[]): Promise { // Show current configuration info (only in non-silent mode) const currentConfig = configManager.getCurrentConfig(); showCurrentConfig(currentConfig); - + // Set environment variables and run Claude Code const env = setupEnvironment(currentConfig); runClaudeCode(args, env); @@ -224,7 +227,9 @@ export async function handleCLI(args: string[]): Promise { } else { console.error('❌ Error:', String(error)); } - console.error('🔧 If the problem persists, please check your network connection or contact support.'); + console.error( + '🔧 If the problem persists, please check your network connection or contact support.' + ); process.exit(1); } -} \ No newline at end of file +} diff --git a/src/cli/index.ts b/src/cli/index.ts index 6cae775..23cdb67 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -10,7 +10,7 @@ import { checkClaudeCode, installClaudeCode } from '../utils/claude'; async function ensureClaudeCode(): Promise { try { const hasClaudeCode = await checkClaudeCode(); - + if (hasClaudeCode) { // Claude Code is already available, proceed silently return; @@ -19,15 +19,15 @@ async function ensureClaudeCode(): Promise { // Claude Code not found, attempt automatic installation console.log('🔍 First time use detected, checking Claude Code installation...'); console.log('📦 Claude Code not found, installing automatically...'); - + try { await installClaudeCode(); - + // Verify installation was successful const isInstalled = await checkClaudeCode(); if (isInstalled) { console.log('✅ Claude Code installed successfully!'); - console.log('🎉 You\'re ready to use auo!'); + console.log("🎉 You're ready to use auo!"); } else { console.warn('⚠️ Claude Code installation may have issues'); console.log('💡 Manual installation: npm install -g @anthropic-ai/claude-code'); @@ -49,7 +49,7 @@ async function ensureClaudeCode(): Promise { if (checkError instanceof Error) { console.log(` Error: ${checkError.message}`); } - console.log('💡 This won\'t prevent auo from running, installation will be retried if needed'); + console.log("💡 This won't prevent auo from running, installation will be retried if needed"); } } @@ -73,7 +73,7 @@ export async function main(): Promise { try { // Lazy initialization - check Claude Code only when CLI is used await ensureClaudeCode(); - + await handleCLI(args); } catch (error) { if (error instanceof Error) { @@ -88,11 +88,15 @@ export async function main(): Promise { // If this file is run directly, execute main function // Support both CommonJS and ESM environments const isMainModule = typeof require !== 'undefined' && require.main === module; -const isESMMain = typeof import.meta !== 'undefined' && import.meta.url && process.argv[1] && import.meta.url.includes(process.argv[1]); +const isESMMain = + typeof import.meta !== 'undefined' && + import.meta.url && + process.argv[1] && + import.meta.url.includes(process.argv[1]); if (isMainModule || isESMMain) { main().catch((error) => { console.error('❌ Startup failed:', error); process.exit(1); }); -} \ No newline at end of file +} diff --git a/src/config/index.ts b/src/config/index.ts index a03a438..43ce022 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -3,4 +3,4 @@ export * from './types'; export * from './manager'; // Export a default instance for convenience -export { ConfigManager as default } from './manager'; \ No newline at end of file +export { ConfigManager as default } from './manager'; diff --git a/src/config/manager.ts b/src/config/manager.ts index d78d541..aca5d2f 100644 --- a/src/config/manager.ts +++ b/src/config/manager.ts @@ -1,12 +1,7 @@ import fs from 'fs'; import path from 'path'; import os from 'os'; -import type { - ConfigItem, - ConfigFile, - ConfigManagerOptions, - AddConfigParams, -} from './types'; +import type { ConfigItem, ConfigFile, ConfigManagerOptions, AddConfigParams } from './types'; /** * Configuration manager class @@ -18,10 +13,7 @@ export class ConfigManager { constructor(options: ConfigManagerOptions = {}) { this.configDir = options.configDir || path.join(os.homedir(), '.auo'); - this.configFile = path.join( - this.configDir, - options.configFileName || 'config.json' - ); + this.configFile = path.join(this.configDir, options.configFileName || 'config.json'); this.ensureConfigDir(); } @@ -59,25 +51,27 @@ export class ConfigManager { if (fs.existsSync(this.configFile)) { const data = fs.readFileSync(this.configFile, 'utf8'); const config = JSON.parse(data) as ConfigFile; - + // Validate configuration file format if (!config.providers || !Array.isArray(config.providers)) { throw new Error('Invalid config format'); } - + // Ensure currentIndex is valid - if (typeof config.currentIndex !== 'number' || - config.currentIndex < 0 || - config.currentIndex >= config.providers.length) { + if ( + typeof config.currentIndex !== 'number' || + config.currentIndex < 0 || + config.currentIndex >= config.providers.length + ) { config.currentIndex = 0; } - + return config; } } catch (error) { console.warn('⚠️ Failed to read configuration file, using default config:', error); } - + return this.getDefaultConfig(); } @@ -148,7 +142,7 @@ export class ConfigManager { */ switchToIndex(index: number): ConfigItem | null { const config = this.loadConfig(); - + if (index < 0 || index >= config.providers.length) { return null; } @@ -173,7 +167,7 @@ export class ConfigManager { const baseUrl = cfg.baseUrl || '(not set)'; const authToken = cfg.authToken ? '✅' : '❌'; const description = cfg.description ? ` - ${cfg.description}` : ''; - + console.log(`${marker} [${index}] ${cfg.name}${description}`); console.log(` Base URL: ${baseUrl}`); console.log(` Auth Token: ${authToken}`); @@ -289,13 +283,14 @@ export class ConfigManager { console.error(`❌ Configuration "${name}" does not exist`); return false; } - + // Merge updates, keeping existing values as defaults - config.providers[index] = { + config.providers[index] = { name: updates.name || existingConfig.name, baseUrl: updates.baseUrl !== undefined ? updates.baseUrl : existingConfig.baseUrl, authToken: updates.authToken !== undefined ? updates.authToken : existingConfig.authToken, - description: updates.description !== undefined ? updates.description : existingConfig.description, + description: + updates.description !== undefined ? updates.description : existingConfig.description, }; this.saveConfig(config); @@ -313,7 +308,7 @@ export class ConfigManager { resetConfig(): void { const defaultConfig = this.getDefaultConfig(); this.saveConfig(defaultConfig); - + console.log('✅ Configuration reset to default values'); } @@ -340,4 +335,4 @@ export class ConfigManager { const config = this.loadConfig(); return [...config.providers]; } -} \ No newline at end of file +} diff --git a/src/config/types.ts b/src/config/types.ts index c91cb83..9c5dece 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -44,4 +44,4 @@ export interface AddConfigParams { authToken: string; /** Configuration description */ description?: string; -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 513b1fd..62aa6b4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,4 +5,4 @@ export * from './cli'; export * from './types'; // Re-export main CLI function for bin script -export { main } from './cli'; \ No newline at end of file +export { main } from './cli'; diff --git a/src/types/index.ts b/src/types/index.ts index 0d4b5c4..6920bc1 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -66,4 +66,4 @@ export interface CommandResult { stderr?: string; /** Whether successful */ success: boolean; -} \ No newline at end of file +} diff --git a/src/utils/claude.ts b/src/utils/claude.ts index c38aad5..cd0e0c9 100644 --- a/src/utils/claude.ts +++ b/src/utils/claude.ts @@ -50,16 +50,12 @@ export async function checkClaudeCode(): Promise { */ export async function installClaudeCode(): Promise { console.log('🔄 Installing Claude Code, please wait...'); - + return new Promise((resolve, reject) => { - const install: ChildProcess = spawn( - 'npm', - ['install', '-g', '@anthropic-ai/claude-code'], - { - stdio: 'inherit', - shell: true, - } - ); + const install: ChildProcess = spawn('npm', ['install', '-g', '@anthropic-ai/claude-code'], { + stdio: 'inherit', + shell: true, + }); install.on('close', (code: number | null) => { if (code === 0) { @@ -83,7 +79,7 @@ export async function installClaudeCode(): Promise { */ export function runClaudeCode(args: string[], env: NodeJS.ProcessEnv = {}): void { const mergedEnv = { ...process.env, ...env }; - + const claude: ChildProcess = spawn('claude', args, { stdio: 'inherit', shell: true, @@ -99,4 +95,4 @@ export function runClaudeCode(args: string[], env: NodeJS.ProcessEnv = {}): void console.error('🔧 Please try reinstalling: npm install -g auo'); process.exit(1); }); -} \ No newline at end of file +} diff --git a/src/utils/index.ts b/src/utils/index.ts index 4b2fc40..1d23e72 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,3 +1,3 @@ // Utilities module entry point export * from './claude'; -export * from './system'; \ No newline at end of file +export * from './system'; diff --git a/src/utils/system.ts b/src/utils/system.ts index 854a5c1..2623da3 100644 --- a/src/utils/system.ts +++ b/src/utils/system.ts @@ -81,4 +81,4 @@ export function runCommand( }, options.timeout); } }); -} \ No newline at end of file +} diff --git a/tests/cli/commands.test.ts b/tests/cli/commands.test.ts index 57c770c..261077a 100644 --- a/tests/cli/commands.test.ts +++ b/tests/cli/commands.test.ts @@ -6,7 +6,7 @@ describe('CLI Command Parsing', () => { it('should correctly parse help parameters', () => { const result = parseArgs(['--help']); expect(result.help).toBe(true); - + const result2 = parseArgs(['-h']); expect(result2.help).toBe(true); }); @@ -14,7 +14,7 @@ describe('CLI Command Parsing', () => { it('should correctly parse version parameters', () => { const result = parseArgs(['--version']); expect(result.version).toBe(true); - + const result2 = parseArgs(['-v']); expect(result2.version).toBe(true); }); @@ -55,13 +55,13 @@ describe('CLI Commands', () => { describe('showHelp', () => { it('should display help information', () => { const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); - + showHelp(); - + expect(consoleSpy).toHaveBeenCalled(); expect(consoleSpy.mock.calls[0][0]).toContain('auo'); expect(consoleSpy.mock.calls[0][0]).toContain('Usage'); - + consoleSpy.mockRestore(); }); }); @@ -123,4 +123,4 @@ describe('CLI Commands', () => { expect(env.ANTHROPIC_AUTH_TOKEN).toBeUndefined(); }); }); -}); \ No newline at end of file +}); diff --git a/tests/config/manager.test.ts b/tests/config/manager.test.ts index 733a277..cba4689 100644 --- a/tests/config/manager.test.ts +++ b/tests/config/manager.test.ts @@ -3,7 +3,7 @@ import fs from 'fs'; import path from 'path'; import os from 'os'; import { ConfigManager } from '../../src/config/manager'; -import type { ConfigItem } from '../../src/types'; +import type { ConfigItem as _ConfigItem } from '../../src/types'; describe('ConfigManager', () => { let configManager: ConfigManager; @@ -31,7 +31,7 @@ describe('ConfigManager', () => { it('should use custom configuration options', () => { const customDir = path.join(os.tmpdir(), `auo-custom-${Date.now()}`); - const customManager = new ConfigManager({ + const _customManager = new ConfigManager({ configDir: customDir, configFileName: 'custom-config.json', }); @@ -86,10 +86,8 @@ describe('ConfigManager', () => { // Write config with invalid currentIndex const configPath = path.join(tempDir, 'config.json'); const invalidConfig = { - providers: [ - { name: 'test', baseUrl: '', authToken: 'token', description: 'test' } - ], - currentIndex: 999 // Invalid index + providers: [{ name: 'test', baseUrl: '', authToken: 'token', description: 'test' }], + currentIndex: 999, // Invalid index }; fs.writeFileSync(configPath, JSON.stringify(invalidConfig)); @@ -119,7 +117,7 @@ describe('ConfigManager', () => { // Create a read-only directory to simulate save failure const readOnlyDir = path.join(os.tmpdir(), `auo-readonly-${Date.now()}`); fs.mkdirSync(readOnlyDir); - + try { // On Windows, we simulate write failure const spy = vi.spyOn(fs, 'writeFileSync').mockImplementation(() => { @@ -129,13 +127,13 @@ describe('ConfigManager', () => { const manager = new ConfigManager({ configDir: readOnlyDir, }); - + const result = manager.addConfig({ name: 'test', baseUrl: 'https://api.test.com', authToken: 'test-token', }); - + expect(result).toBe(false); spy.mockRestore(); } finally { @@ -200,10 +198,10 @@ describe('ConfigManager', () => { }); expect(result).toBe(true); - + const allConfigs = configManager.getAllConfigs(); expect(allConfigs).toHaveLength(2); // default + new - expect(allConfigs.find(c => c.name === 'test-provider')).toBeDefined(); + expect(allConfigs.find((c) => c.name === 'test-provider')).toBeDefined(); }); it('should reject duplicate configuration names', () => { @@ -222,9 +220,9 @@ describe('ConfigManager', () => { }); expect(result).toBe(false); - + const allConfigs = configManager.getAllConfigs(); - expect(allConfigs.filter(c => c.name === 'duplicate')).toHaveLength(1); + expect(allConfigs.filter((c) => c.name === 'duplicate')).toHaveLength(1); }); }); @@ -242,7 +240,7 @@ describe('ConfigManager', () => { expect(result).toBe(true); const allConfigs = configManager.getAllConfigs(); - expect(allConfigs.find(c => c.name === 'to-delete')).toBeUndefined(); + expect(allConfigs.find((c) => c.name === 'to-delete')).toBeUndefined(); }); it('should adjust currentIndex when deleting current configuration', () => { @@ -267,4 +265,4 @@ describe('ConfigManager', () => { expect(currentConfig.name).toBe('default'); }); }); -}); \ No newline at end of file +}); diff --git a/tests/utils/claude.test.ts b/tests/utils/claude.test.ts index bd5221e..700ba6d 100644 --- a/tests/utils/claude.test.ts +++ b/tests/utils/claude.test.ts @@ -16,4 +16,4 @@ describe('Claude Utils', () => { expect(installClaudeCode).toBeDefined(); }); }); -}); \ No newline at end of file +}); diff --git a/tests/utils/system.test.ts b/tests/utils/system.test.ts index 367ccb0..0ccca9c 100644 --- a/tests/utils/system.test.ts +++ b/tests/utils/system.test.ts @@ -5,4 +5,4 @@ describe('SystemUtils', () => { it('should be defined', () => { expect(SystemUtils).toBeDefined(); }); -}); \ No newline at end of file +});