easyai 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ee34c42f56cf088f27d3cc18a895d6117a855a9fdf309d37fc40c4486e50a417
4
+ data.tar.gz: e1b40e6f017f435dae47ab4f9a3eddf27350c9707afa1b885eb9523cf0880b8b
5
+ SHA512:
6
+ metadata.gz: ff21c89a1df4b50e5d539083d65189439e45f9ad027588dacb8d160d90c83ec8bbbdffc0d0dd72b36a9f231a67711a3755ea37ecde0f8d0556960625a2cbff0d
7
+ data.tar.gz: efb410b066000120b690e1742bf67799912d7f1c3934447426fe71bf7756e5b794610818f77197f3d430371485e3b89170da3d84bbe95aacea07a172be1b8df6
data/CLAUDE.md ADDED
@@ -0,0 +1,107 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ **重要说明:此项目的所有回答和交流都应该使用中文。**
6
+
7
+ ## 项目概述
8
+
9
+ EasyAI 是一个 Ruby CLI 工具,作为 AI 命令行工具(Claude、Gemini、GPT)的包装器。它提供环境隔离和配置管理功能,允许用户使用预配置的 API 令牌和代理设置运行 AI 工具,而不会影响系统环境变量。
10
+
11
+ ## 架构设计
12
+
13
+ 代码库采用基于 CLAide 的模块化架构:
14
+
15
+ - **主命令 (`lib/easyai.rb`)**:抽象基础命令,处理全局选项(`--setup`、`--config`)和配置管理
16
+ - **子命令 (`lib/easyai/*.rb`)**:每个 AI 工具(claude、gemini、gpt)都有自己的命令类,继承自主命令
17
+ - **环境隔离**:使用 Ruby 的 `exec()` 替换当前进程为目标 AI 工具,在注入环境变量的同时保持交互性
18
+ - **跨平台支持**:处理 Unix(`which`)和 Windows(`where`)之间的命令检测差异
19
+
20
+ ## 关键命令
21
+
22
+ ### 开发和测试
23
+ ```bash
24
+ # 本地开发测试
25
+ ./test_local.sh # 本地构建和安装 gem
26
+ ruby bin/easyai --help # 开发期间测试
27
+
28
+ # 发布流程
29
+ ./release_remote.sh # 完整发布:git 操作、gem 构建和发布到 RubyGems
30
+
31
+ # 手动 gem 操作
32
+ gem build easyai.gemspec # 构建 gem 包
33
+ gem install easyai-x.x.x.gem # 安装特定版本
34
+ ```
35
+
36
+ ### 配置管理
37
+ ```bash
38
+ # 交互式设置 API 令牌
39
+ easyai --setup
40
+
41
+ # 显示配置文件位置
42
+ easyai --config
43
+
44
+ # 配置文件:~/.easyai/config.yml
45
+ ```
46
+
47
+ ## 核心实现细节
48
+
49
+ ### 环境变量注入
50
+ 每个子命令在调用 `exec()` 前合并环境变量:
51
+ - Claude: `ANTHROPIC_API_KEY`, `CLAUDE_CODE_OAUTH_TOKEN`
52
+ - Gemini: `GOOGLE_API_KEY`, `GEMINI_API_KEY`
53
+ - OpenAI: `OPENAI_API_KEY`
54
+ - 代理: `HTTP_PROXY`, `HTTPS_PROXY`, `http_proxy`, `https_proxy`
55
+
56
+ ### 命令验证
57
+ 每个子命令使用平台特定检测验证目标 CLI 工具是否已安装:
58
+ - Unix/Linux/macOS: `which <command> > /dev/null 2>&1`
59
+ - Windows: `where <command> >nul 2>&1`
60
+
61
+ ### 进程替换策略
62
+ 使用 `exec(env, command, *args)` 而非 `system()` 来:
63
+ - 完全替换当前进程(无子进程)
64
+ - 保留 stdin/stdout/stderr 用于交互式工具
65
+ - 透明处理 Ctrl+C 和其他信号
66
+ - 保持与直接运行工具相同的用户体验
67
+
68
+ ## 版本管理
69
+
70
+ 版本在 `lib/easyai/version.rb` 中定义,自动被以下文件引用:
71
+ - `easyai.gemspec` 通过 `require_relative`
72
+ - 发布脚本通过正则解析
73
+ - 主命令通过 `self.version = VERSION`
74
+
75
+ 只需更新 `lib/easyai/version.rb` 中的版本 - 其他引用是自动的。
76
+
77
+ ## 开发注意事项
78
+
79
+ 1. **使用中文**:所有代码注释、提交信息、文档和交流都应使用中文
80
+ 2. **用户界面中文化**:所有命令行帮助信息、提示信息、错误信息都必须使用中文
81
+ 3. **测试流程**:使用 `./test_local.sh` 进行本地测试,确保功能正常后再发布
82
+ 4. **跨平台兼容性**:添加新功能时要考虑 Windows、Linux、macOS 的兼容性
83
+ 5. **环境隔离**:确保不影响用户的系统环境变量,所有配置都应在子进程中生效
84
+
85
+ ## 中文化要求
86
+
87
+ ### 代码界面中文化
88
+ - **命令描述**:所有 `self.summary` 和 `self.description` 必须使用中文
89
+ - **选项说明**:`self.options` 中的描述文字必须为中文
90
+ - **错误信息**:`help!` 和错误提示必须使用中文
91
+ - **交互提示**:用户输入提示(如 `print` 语句)必须使用中文
92
+ - **状态信息**:运行时的状态输出必须使用中文
93
+
94
+ ### 文档中文化
95
+ - **README.md**:必须完全使用中文编写,包括所有章节标题、描述文字、使用示例
96
+ - **代码注释**:所有代码注释必须使用中文
97
+ - **提交信息**:Git 提交信息必须使用中文描述
98
+ - **变更日志**:如有 CHANGELOG 文件,必须使用中文记录
99
+ - **API 文档**:如有生成的 API 文档,描述内容应为中文
100
+
101
+ ### 中文化检查清单
102
+ 在添加新功能或修改现有功能时,确保:
103
+ - [ ] 所有用户可见的文本都是中文
104
+ - [ ] README.md 的新内容使用中文
105
+ - [ ] 新的错误信息使用中文
106
+ - [ ] 代码注释使用中文
107
+ - [ ] 提交信息使用中文
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # EasyAI
2
+
3
+ 一个简化运行 AI 工具的 CLI 包装器,支持 Claude、Gemini 和 GPT,提供环境配置管理功能。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ gem build easyai.gemspec
9
+ gem install easyai-1.0.2.gem
10
+ ```
11
+
12
+ ## 设置
13
+
14
+ 首先配置你的 API 令牌:
15
+
16
+ ```bash
17
+ easyai --setup
18
+ ```
19
+
20
+ 系统会提示你输入:
21
+ - Claude API 令牌
22
+ - Gemini API 令牌
23
+ - OpenAI API 令牌
24
+ - HTTP 代理(可选)
25
+
26
+ 配置会保存到 `~/.easyai/config.yml`
27
+
28
+ ## 使用方法
29
+
30
+ ### Claude
31
+ ```bash
32
+ # 交互模式
33
+ easyai claude
34
+
35
+ # 单次查询
36
+ easyai claude --print "解释这段代码"
37
+
38
+ # 继续对话
39
+ easyai claude --continue
40
+
41
+ # 选择模型
42
+ easyai claude --model sonnet "分析性能"
43
+ ```
44
+
45
+ ### Gemini
46
+ ```bash
47
+ # 交互模式
48
+ easyai gemini
49
+
50
+ # 调试模式
51
+ easyai gemini --debug "优化这个函数"
52
+
53
+ # YOLO 模式
54
+ easyai gemini --yolo
55
+ ```
56
+
57
+ ### GPT
58
+ ```bash
59
+ # 交互模式
60
+ easyai gpt
61
+
62
+ # 单次查询
63
+ easyai gpt "写一个函数"
64
+ ```
65
+
66
+ ## 特性
67
+
68
+ - ✅ 环境变量隔离(不影响系统环境)
69
+ - ✅ HTTP/HTTPS 代理支持
70
+ - ✅ 多 AI 工具支持
71
+ - ✅ 基于 CLAide 的专业 CLI 结构
72
+ - ✅ 完整的参数透传
73
+ - ✅ 交互式配置设置
74
+ - ✅ 跨平台支持(Windows、Linux、macOS)
75
+
76
+ ## 系统要求
77
+
78
+ - Ruby >= 2.7.0
79
+ - 已安装的 AI CLI 工具:
80
+ - Claude: `npm install -g @anthropic-ai/claude-code`
81
+ - Gemini: `npm install -g @google/gemini-cli`
82
+ - OpenAI: `pip install openai`
83
+
84
+ ## 开发
85
+
86
+ ### 本地测试
87
+ ```bash
88
+ ./test_local.sh # 构建并本地安装 gem
89
+ ```
90
+
91
+ ### 发布
92
+ ```bash
93
+ ./release_remote.sh # 完整发布流程
94
+ ```
data/bin/easyai ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ lib_path = File.expand_path('../../lib', __FILE__)
6
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
7
+
8
+ require 'easyai'
9
+
10
+ EasyAI::Command.run
data/easyai.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/easyai/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'easyai'
5
+ spec.version = EasyAI::VERSION
6
+ spec.authors = ['Wade']
7
+ spec.email = ['wade@example.com']
8
+
9
+ spec.summary = 'Easy AI CLI tool wrapper'
10
+ spec.description = 'A CLI tool that simplifies running AI tools like Claude, Gemini, and GPT with environment configuration'
11
+ spec.homepage = 'https://github.com/wade/easyai'
12
+ spec.license = 'MIT'
13
+
14
+ spec.required_ruby_version = '>= 2.7.0'
15
+
16
+ spec.files = Dir['lib/**/*', 'bin/*', '*.md', '*.gemspec']
17
+ spec.bindir = 'bin'
18
+ spec.executables = ['easyai']
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'claide', '~> 1.0'
22
+ spec.add_dependency 'colored2', '~> 3.1'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 2.0'
25
+ spec.add_development_dependency 'rake', '~> 13.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
@@ -0,0 +1,61 @@
1
+ module EasyAI
2
+ class Claude < Command
3
+ self.command = 'claude'
4
+ self.summary = '使用配置的环境运行 Claude CLI'
5
+ self.description = <<-DESC
6
+ 使用预配置的 API 令牌和代理设置运行 Claude CLI 工具。
7
+ 所有参数都会传递给 claude 命令。
8
+ DESC
9
+
10
+ def initialize(argv)
11
+ @claude_args = argv.remainder!
12
+ super
13
+ end
14
+
15
+ def validate!
16
+ super
17
+ help! '未找到 Claude CLI。请安装:npm install -g @anthropic-ai/claude-code' unless claude_available?
18
+ end
19
+
20
+ def run
21
+ config = load_config
22
+
23
+ env = ENV.to_h.merge({
24
+ 'ANTHROPIC_API_KEY' => config['claude_token'] || config['anthropic_api_key'],
25
+ 'CLAUDE_CODE_OAUTH_TOKEN' => config['claude_token'] || config['anthropic_api_key']
26
+ })
27
+
28
+ # Add proxy settings if configured
29
+ if config['http_proxy']
30
+ env['HTTP_PROXY'] = config['http_proxy']
31
+ env['HTTPS_PROXY'] = config['http_proxy']
32
+ env['http_proxy'] = config['http_proxy']
33
+ env['https_proxy'] = config['http_proxy']
34
+ end
35
+
36
+ puts "正在运行: claude #{@claude_args.join(' ')}".blue if verbose?
37
+ exec(env, 'claude', *@claude_args)
38
+ end
39
+
40
+ private
41
+
42
+ def claude_available?
43
+ # 跨平台命令检测
44
+ if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
45
+ system('where claude >nul 2>&1')
46
+ else
47
+ system('which claude > /dev/null 2>&1')
48
+ end
49
+ end
50
+
51
+ def load_config
52
+ config_path = File.expand_path('~/.easyai/config.yml')
53
+ return {} unless File.exist?(config_path)
54
+
55
+ YAML.load_file(config_path) || {}
56
+ rescue => e
57
+ puts "加载配置出错: #{e.message}".red
58
+ {}
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,61 @@
1
+ module EasyAI
2
+ class Gemini < Command
3
+ self.command = 'gemini'
4
+ self.summary = '使用配置的环境运行 Gemini CLI'
5
+ self.description = <<-DESC
6
+ 使用预配置的 API 令牌和代理设置运行 Gemini CLI 工具。
7
+ 所有参数都会传递给 gemini 命令。
8
+ DESC
9
+
10
+ def initialize(argv)
11
+ @gemini_args = argv.remainder!
12
+ super
13
+ end
14
+
15
+ def validate!
16
+ super
17
+ help! '未找到 Gemini CLI。请安装:npm install -g @google/gemini-cli' unless gemini_available?
18
+ end
19
+
20
+ def run
21
+ config = load_config
22
+
23
+ env = ENV.to_h.merge({
24
+ 'GOOGLE_API_KEY' => config['gemini_token'] || config['google_api_key'],
25
+ 'GEMINI_API_KEY' => config['gemini_token'] || config['google_api_key']
26
+ })
27
+
28
+ # Add proxy settings if configured
29
+ if config['http_proxy']
30
+ env['HTTP_PROXY'] = config['http_proxy']
31
+ env['HTTPS_PROXY'] = config['http_proxy']
32
+ env['http_proxy'] = config['http_proxy']
33
+ env['https_proxy'] = config['http_proxy']
34
+ end
35
+
36
+ puts "正在运行: gemini #{@gemini_args.join(' ')}".blue if verbose?
37
+ exec(env, 'gemini', *@gemini_args)
38
+ end
39
+
40
+ private
41
+
42
+ def gemini_available?
43
+ # 跨平台命令检测
44
+ if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
45
+ system('where gemini >nul 2>&1')
46
+ else
47
+ system('which gemini > /dev/null 2>&1')
48
+ end
49
+ end
50
+
51
+ def load_config
52
+ config_path = File.expand_path('~/.easyai/config.yml')
53
+ return {} unless File.exist?(config_path)
54
+
55
+ YAML.load_file(config_path) || {}
56
+ rescue => e
57
+ puts "加载配置出错: #{e.message}".red
58
+ {}
59
+ end
60
+ end
61
+ end
data/lib/easyai/gpt.rb ADDED
@@ -0,0 +1,60 @@
1
+ module EasyAI
2
+ class GPT < Command
3
+ self.command = 'gpt'
4
+ self.summary = '使用配置的环境运行 OpenAI CLI'
5
+ self.description = <<-DESC
6
+ 使用预配置的 API 令牌和代理设置运行 OpenAI CLI 工具。
7
+ 所有参数都会传递给 openai 命令。
8
+ DESC
9
+
10
+ def initialize(argv)
11
+ @gpt_args = argv.remainder!
12
+ super
13
+ end
14
+
15
+ def validate!
16
+ super
17
+ help! '未找到 OpenAI CLI。请安装:pip install openai' unless gpt_available?
18
+ end
19
+
20
+ def run
21
+ config = load_config
22
+
23
+ env = ENV.to_h.merge({
24
+ 'OPENAI_API_KEY' => config['openai_token'] || config['openai_api_key']
25
+ })
26
+
27
+ # Add proxy settings if configured
28
+ if config['http_proxy']
29
+ env['HTTP_PROXY'] = config['http_proxy']
30
+ env['HTTPS_PROXY'] = config['http_proxy']
31
+ env['http_proxy'] = config['http_proxy']
32
+ env['https_proxy'] = config['http_proxy']
33
+ end
34
+
35
+ puts "正在运行: openai #{@gpt_args.join(' ')}".blue if verbose?
36
+ exec(env, 'openai', *@gpt_args)
37
+ end
38
+
39
+ private
40
+
41
+ def gpt_available?
42
+ # 跨平台命令检测
43
+ if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
44
+ system('where openai >nul 2>&1')
45
+ else
46
+ system('which openai > /dev/null 2>&1')
47
+ end
48
+ end
49
+
50
+ def load_config
51
+ config_path = File.expand_path('~/.easyai/config.yml')
52
+ return {} unless File.exist?(config_path)
53
+
54
+ YAML.load_file(config_path) || {}
55
+ rescue => e
56
+ puts "加载配置出错: #{e.message}".red
57
+ {}
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module EasyAI
2
+ VERSION = '1.0.2'
3
+ end
data/lib/easyai.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'claide'
2
+ require 'yaml'
3
+ require 'fileutils'
4
+ require 'colored2'
5
+ require 'easyai/version'
6
+
7
+ module EasyAI
8
+
9
+ class Command < CLAide::Command
10
+ self.abstract_command = true
11
+ self.command = 'easyai'
12
+ self.version = VERSION
13
+ self.description = '简化 AI 命令行工具的 CLI 包装器,支持 Claude、Gemini 和 GPT'
14
+
15
+ def self.options
16
+ [
17
+ ['--config', '显示配置文件路径'],
18
+ ['--setup', '交互式设置配置']
19
+ ].concat(super)
20
+ end
21
+
22
+ def initialize(argv)
23
+ @config_flag = argv.flag?('config')
24
+ @setup_flag = argv.flag?('setup')
25
+ super
26
+ end
27
+
28
+ def run
29
+ if @config_flag
30
+ puts config_file_path
31
+ return
32
+ end
33
+
34
+ if @setup_flag
35
+ setup_config
36
+ return
37
+ end
38
+
39
+ super
40
+ end
41
+
42
+ private
43
+
44
+ def config_file_path
45
+ @config_file_path ||= File.expand_path('~/.easyai/config.yml')
46
+ end
47
+
48
+ def setup_config
49
+ puts "正在设置 EasyAI 配置...".green
50
+ FileUtils.mkdir_p(File.dirname(config_file_path))
51
+
52
+ config = {}
53
+
54
+ print "Claude API 令牌 (ANTHROPIC_API_KEY): "
55
+ config['claude_token'] = STDIN.gets.chomp
56
+
57
+ print "Gemini API 令牌 (GOOGLE_API_KEY): "
58
+ config['gemini_token'] = STDIN.gets.chomp
59
+
60
+ print "OpenAI API 令牌 (OPENAI_API_KEY): "
61
+ config['openai_token'] = STDIN.gets.chomp
62
+
63
+ print "HTTP 代理 (可选): "
64
+ proxy = STDIN.gets.chomp
65
+ config['http_proxy'] = proxy unless proxy.empty?
66
+
67
+ File.write(config_file_path, config.to_yaml)
68
+ puts "配置已保存到 #{config_file_path}".green
69
+ end
70
+ end
71
+ end
72
+
73
+ require 'easyai/claude'
74
+ require 'easyai/gemini'
75
+ require 'easyai/gpt'
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easyai
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Wade
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: claide
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: colored2
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.1'
40
+ - !ruby/object:Gem::Dependency
41
+ name: bundler
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rake
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '13.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '13.0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rspec
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ description: A CLI tool that simplifies running AI tools like Claude, Gemini, and
83
+ GPT with environment configuration
84
+ email:
85
+ - wade@example.com
86
+ executables:
87
+ - easyai
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - CLAUDE.md
92
+ - README.md
93
+ - bin/easyai
94
+ - easyai.gemspec
95
+ - lib/easyai.rb
96
+ - lib/easyai/claude.rb
97
+ - lib/easyai/gemini.rb
98
+ - lib/easyai/gpt.rb
99
+ - lib/easyai/version.rb
100
+ homepage: https://github.com/wade/easyai
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 2.7.0
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.6.9
119
+ specification_version: 4
120
+ summary: Easy AI CLI tool wrapper
121
+ test_files: []