girb 0.1.0
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 +7 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +15 -0
- data/LICENSE +21 -0
- data/README.md +253 -0
- data/README_ja.md +251 -0
- data/Rakefile +8 -0
- data/exe/girb +38 -0
- data/lib/girb/ai_client.rb +157 -0
- data/lib/girb/configuration.rb +39 -0
- data/lib/girb/context_builder.rb +134 -0
- data/lib/girb/conversation_history.rb +132 -0
- data/lib/girb/exception_capture.rb +54 -0
- data/lib/girb/irb_integration.rb +87 -0
- data/lib/girb/prompt_builder.rb +173 -0
- data/lib/girb/providers/base.rb +65 -0
- data/lib/girb/session_history.rb +197 -0
- data/lib/girb/tools/base.rb +61 -0
- data/lib/girb/tools/evaluate_code.rb +43 -0
- data/lib/girb/tools/find_file.rb +93 -0
- data/lib/girb/tools/get_source.rb +145 -0
- data/lib/girb/tools/inspect_object.rb +54 -0
- data/lib/girb/tools/list_methods.rb +66 -0
- data/lib/girb/tools/rails_tools.rb +141 -0
- data/lib/girb/tools/read_file.rb +124 -0
- data/lib/girb/tools/session_history_tool.rb +183 -0
- data/lib/girb/tools.rb +38 -0
- data/lib/girb/version.rb +5 -0
- data/lib/girb.rb +53 -0
- data/lib/irb/command/qq.rb +55 -0
- metadata +131 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 16db97a82963a642f3816a1083664d3434e94a8bbe6c589ef21cc2da21d0ba46
|
|
4
|
+
data.tar.gz: f1bb07ca19f8c2af6d11cb0ba37738e9948a0bc0f286e38494a00bc7113ce482
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ae327ef4bd1ac6d9cdfdf18a2135707ab6959a9af1390737a2e02bc4fc05dd586469d4196d94136b37d140c405dae379d2d987dd30dfb70253aa507637864cd7
|
|
7
|
+
data.tar.gz: ab3de747ee65f5d5d77e72203261f0a2c110e6c3d5fa5b39a299aded75f38d64e6de91ce1ce854a3044556c57b8d28933663afca13ce5159b8006f4f38fea427
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - 2025-02-02
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Initial release
|
|
8
|
+
- AI-powered IRB assistant with `qq` command
|
|
9
|
+
- Provider-agnostic architecture supporting multiple LLM backends
|
|
10
|
+
- Tools: evaluate_code, read_file, find_file, get_source, inspect_object, list_methods
|
|
11
|
+
- Rails integration with model inspection tools
|
|
12
|
+
- Session history support
|
|
13
|
+
- Exception capture and context building
|
|
14
|
+
- Custom prompt configuration
|
|
15
|
+
- Debug mode
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Rira
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# girb (Generative IRB)
|
|
2
|
+
|
|
3
|
+
An AI assistant embedded in your IRB session. It understands your runtime context and helps with debugging and development.
|
|
4
|
+
|
|
5
|
+
[日本語版 README](README_ja.md)
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Context Awareness**: Automatically understands local variables, instance variables, and self object
|
|
10
|
+
- **Exception Capture**: Automatically captures recent exceptions - just ask "why did this fail?" after an error
|
|
11
|
+
- **Session History Understanding**: Tracks IRB input history and understands conversation flow
|
|
12
|
+
- **Tool Execution**: AI autonomously executes code, inspects objects, and retrieves source code
|
|
13
|
+
- **Multi-language Support**: Detects user's language and responds in the same language
|
|
14
|
+
- **Customizable**: Add custom prompts for project-specific instructions
|
|
15
|
+
- **Provider Agnostic**: Use any LLM provider or implement your own
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Add to your Gemfile:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
gem 'girb'
|
|
23
|
+
gem 'girb-ruby_llm' # or girb-gemini
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Then run:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
bundle install
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or install directly:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
gem install girb girb-ruby_llm
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Set the provider via environment variable:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
export GIRB_PROVIDER=girb-ruby_llm
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Providers
|
|
45
|
+
|
|
46
|
+
Currently available providers:
|
|
47
|
+
|
|
48
|
+
- [girb-ruby_llm](https://github.com/rira100000000/girb-ruby_llm) - Multiple providers via RubyLLM (OpenAI, Anthropic, Gemini, Ollama, etc.)
|
|
49
|
+
- [girb-gemini](https://github.com/rira100000000/girb-gemini) - Google Gemini
|
|
50
|
+
|
|
51
|
+
You can also [create your own provider](#custom-providers).
|
|
52
|
+
|
|
53
|
+
## Setup
|
|
54
|
+
|
|
55
|
+
### Using girb-ruby_llm (Recommended)
|
|
56
|
+
|
|
57
|
+
girb-ruby_llm supports multiple LLM providers through RubyLLM.
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Install
|
|
61
|
+
gem install girb girb-ruby_llm
|
|
62
|
+
|
|
63
|
+
# Set provider and API key
|
|
64
|
+
export GIRB_PROVIDER=girb-ruby_llm
|
|
65
|
+
export GEMINI_API_KEY=your-api-key # or OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
See [girb-ruby_llm README](https://github.com/rira100000000/girb-ruby_llm) for detailed configuration.
|
|
69
|
+
|
|
70
|
+
### Using girb-gemini
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Install
|
|
74
|
+
gem install girb girb-gemini
|
|
75
|
+
|
|
76
|
+
# Set provider and API key
|
|
77
|
+
export GIRB_PROVIDER=girb-gemini
|
|
78
|
+
export GEMINI_API_KEY=your-api-key
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Usage
|
|
82
|
+
|
|
83
|
+
### Quick Start
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
girb
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Or add to your `~/.irbrc` for automatic loading with regular `irb`:
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
require 'girb-ruby_llm' # or 'girb-gemini'
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Debug with binding.girb
|
|
96
|
+
|
|
97
|
+
Insert `binding.girb` in your code:
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
def problematic_method
|
|
101
|
+
result = some_calculation
|
|
102
|
+
binding.girb # AI-powered IRB starts here
|
|
103
|
+
result
|
|
104
|
+
end
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### How to Ask AI
|
|
108
|
+
|
|
109
|
+
#### Method 1: Ctrl+Space
|
|
110
|
+
|
|
111
|
+
Press `Ctrl+Space` after typing to send your input as a question to AI.
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
irb(main):001> What's causing this error?[Ctrl+Space]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### Method 2: qq command
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
irb(main):001> qq "How do I use this method?"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Configuration Options
|
|
124
|
+
|
|
125
|
+
Add to your `~/.irbrc`:
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
require 'girb-ruby_llm'
|
|
129
|
+
|
|
130
|
+
Girb.configure do |c|
|
|
131
|
+
# Debug output (default: false)
|
|
132
|
+
c.debug = true
|
|
133
|
+
|
|
134
|
+
# Custom prompt (optional)
|
|
135
|
+
c.custom_prompt = <<~PROMPT
|
|
136
|
+
This is a production environment. Always confirm before destructive operations.
|
|
137
|
+
PROMPT
|
|
138
|
+
end
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Command Line Options
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
girb --debug # Enable debug output
|
|
145
|
+
girb -d # Same as above
|
|
146
|
+
girb --help # Show help
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Environment Variables
|
|
150
|
+
|
|
151
|
+
| Variable | Description |
|
|
152
|
+
|----------|-------------|
|
|
153
|
+
| `GIRB_PROVIDER` | **Required.** Provider gem to load (e.g., `girb-ruby_llm`, `girb-gemini`) |
|
|
154
|
+
| `GIRB_DEBUG` | Set to `1` to enable debug output |
|
|
155
|
+
|
|
156
|
+
## Available Tools
|
|
157
|
+
|
|
158
|
+
| Tool | Description |
|
|
159
|
+
|------|-------------|
|
|
160
|
+
| `evaluate_code` | Execute Ruby code in IRB context |
|
|
161
|
+
| `inspect_object` | Inspect object details |
|
|
162
|
+
| `get_source` | Get source code of methods or classes |
|
|
163
|
+
| `list_methods` | List methods of an object |
|
|
164
|
+
| `find_file` | Search for files in the project |
|
|
165
|
+
| `read_file` | Read file contents |
|
|
166
|
+
| `session_history` | Get IRB session history |
|
|
167
|
+
|
|
168
|
+
### Additional Tools in Rails Environment
|
|
169
|
+
|
|
170
|
+
| Tool | Description |
|
|
171
|
+
|------|-------------|
|
|
172
|
+
| `query_model` | Execute queries on ActiveRecord models |
|
|
173
|
+
| `model_info` | Get model schema information |
|
|
174
|
+
|
|
175
|
+
## Custom Providers
|
|
176
|
+
|
|
177
|
+
Implement your own LLM provider:
|
|
178
|
+
|
|
179
|
+
```ruby
|
|
180
|
+
class MyProvider < Girb::Providers::Base
|
|
181
|
+
def initialize(api_key:)
|
|
182
|
+
@api_key = api_key
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def chat(messages:, system_prompt:, tools:)
|
|
186
|
+
# messages: Array of { role: :user/:assistant/:tool_call/:tool_result, content: "..." }
|
|
187
|
+
# tools: Array of { name: "...", description: "...", parameters: {...} }
|
|
188
|
+
|
|
189
|
+
# Call your LLM API here
|
|
190
|
+
response = call_my_llm(messages, system_prompt, tools)
|
|
191
|
+
|
|
192
|
+
# Return a Response object
|
|
193
|
+
Girb::Providers::Base::Response.new(
|
|
194
|
+
text: response.text,
|
|
195
|
+
function_calls: response.tool_calls&.map { |tc| { name: tc.name, args: tc.args } }
|
|
196
|
+
)
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
Girb.configure do |c|
|
|
201
|
+
c.provider = MyProvider.new(api_key: ENV['MY_API_KEY'])
|
|
202
|
+
end
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Then run with:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
GIRB_PROVIDER=my_provider girb
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Examples
|
|
212
|
+
|
|
213
|
+
### Debugging Assistance
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
irb(main):001> user = User.find(1)
|
|
217
|
+
irb(main):002> user.update(name: "test")
|
|
218
|
+
=> false
|
|
219
|
+
irb(main):003> Why did the update fail?[Ctrl+Space]
|
|
220
|
+
Checking `user.errors.full_messages` shows validation errors:
|
|
221
|
+
- "Email can't be blank"
|
|
222
|
+
The email might be getting cleared when updating the name.
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Code Understanding
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
irb(main):001> Where is the User model defined in this project?[Ctrl+Space]
|
|
229
|
+
It's defined in app/models/user.rb.
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Pattern Recognition
|
|
233
|
+
|
|
234
|
+
```
|
|
235
|
+
irb(main):001> a = 1
|
|
236
|
+
irb(main):002> b = 2
|
|
237
|
+
irb(main):003> What would z be if I continue with c = 3 and beyond?[Ctrl+Space]
|
|
238
|
+
Following the pattern a=1, b=2, c=3..., z would be 26.
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Requirements
|
|
242
|
+
|
|
243
|
+
- Ruby 3.2.0 or higher
|
|
244
|
+
- IRB 1.6.0 or higher
|
|
245
|
+
- An LLM provider gem (girb-ruby_llm or girb-gemini)
|
|
246
|
+
|
|
247
|
+
## License
|
|
248
|
+
|
|
249
|
+
MIT License
|
|
250
|
+
|
|
251
|
+
## Contributing
|
|
252
|
+
|
|
253
|
+
Bug reports and feature requests are welcome at [GitHub Issues](https://github.com/rira100000000/girb/issues).
|
data/README_ja.md
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# girb (Generative IRB)
|
|
2
|
+
|
|
3
|
+
IRBセッションに組み込まれたAIアシスタント。実行中のコンテキストを理解し、デバッグや開発を支援します。
|
|
4
|
+
|
|
5
|
+
## 特徴
|
|
6
|
+
|
|
7
|
+
- **コンテキスト認識**: ローカル変数、インスタンス変数、selfオブジェクトなどを自動的に把握
|
|
8
|
+
- **例外キャプチャ**: 直前の例外を自動キャプチャ - エラー後に「なぜ失敗した?」と聞くだけでOK
|
|
9
|
+
- **セッション履歴の理解**: IRBでの入力履歴を追跡し、会話の流れを理解
|
|
10
|
+
- **ツール実行**: コードの実行、オブジェクトの検査、ソースコードの取得などをAIが自律的に実行
|
|
11
|
+
- **多言語対応**: ユーザーの言語を検出し、同じ言語で応答
|
|
12
|
+
- **カスタマイズ可能**: 独自のプロンプトを追加して、プロジェクト固有の指示を設定可能
|
|
13
|
+
- **プロバイダー非依存**: 任意のLLMプロバイダーを使用、または独自実装が可能
|
|
14
|
+
|
|
15
|
+
## インストール
|
|
16
|
+
|
|
17
|
+
Gemfileに追加:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
gem 'girb'
|
|
21
|
+
gem 'girb-ruby_llm' # または girb-gemini
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
そして実行:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
bundle install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
または直接インストール:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
gem install girb girb-ruby_llm
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
環境変数でプロバイダーを設定:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
export GIRB_PROVIDER=girb-ruby_llm
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## プロバイダー
|
|
43
|
+
|
|
44
|
+
現在利用可能なプロバイダー:
|
|
45
|
+
|
|
46
|
+
- [girb-ruby_llm](https://github.com/rira100000000/girb-ruby_llm) - RubyLLM経由で複数プロバイダー対応(OpenAI、Anthropic、Gemini、Ollama等)
|
|
47
|
+
- [girb-gemini](https://github.com/rira100000000/girb-gemini) - Google Gemini
|
|
48
|
+
|
|
49
|
+
[独自プロバイダーの作成](#カスタムプロバイダー)も可能です。
|
|
50
|
+
|
|
51
|
+
## セットアップ
|
|
52
|
+
|
|
53
|
+
### girb-ruby_llmを使用する場合(推奨)
|
|
54
|
+
|
|
55
|
+
girb-ruby_llmはRubyLLMを通じて複数のLLMプロバイダーをサポートしています。
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# インストール
|
|
59
|
+
gem install girb girb-ruby_llm
|
|
60
|
+
|
|
61
|
+
# プロバイダーとAPIキーを設定
|
|
62
|
+
export GIRB_PROVIDER=girb-ruby_llm
|
|
63
|
+
export GEMINI_API_KEY=your-api-key # または OPENAI_API_KEY、ANTHROPIC_API_KEY 等
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
詳細な設定については [girb-ruby_llm README](https://github.com/rira100000000/girb-ruby_llm) を参照してください。
|
|
67
|
+
|
|
68
|
+
### girb-geminiを使用する場合
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# インストール
|
|
72
|
+
gem install girb girb-gemini
|
|
73
|
+
|
|
74
|
+
# プロバイダーとAPIキーを設定
|
|
75
|
+
export GIRB_PROVIDER=girb-gemini
|
|
76
|
+
export GEMINI_API_KEY=your-api-key
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## 使い方
|
|
80
|
+
|
|
81
|
+
### 起動方法
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
girb
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
または `~/.irbrc` に以下を追加すると、通常の `irb` コマンドでも使えます:
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
require 'girb-ruby_llm' # または 'girb-gemini'
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### binding.girbでデバッグ
|
|
94
|
+
|
|
95
|
+
コード内に `binding.girb` を挿入:
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
def problematic_method
|
|
99
|
+
result = some_calculation
|
|
100
|
+
binding.girb # ここでAI付きIRBが起動
|
|
101
|
+
result
|
|
102
|
+
end
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### AIへの質問方法
|
|
106
|
+
|
|
107
|
+
#### 方法1: Ctrl+Space
|
|
108
|
+
|
|
109
|
+
入力後に `Ctrl+Space` を押すと、その入力がAIへの質問として送信されます。
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
irb(main):001> このエラーの原因は?[Ctrl+Space]
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### 方法2: qqコマンド
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
irb(main):001> qq "このメソッドの使い方を教えて"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 設定オプション
|
|
122
|
+
|
|
123
|
+
`~/.irbrc` に追加:
|
|
124
|
+
|
|
125
|
+
```ruby
|
|
126
|
+
require 'girb-ruby_llm'
|
|
127
|
+
|
|
128
|
+
Girb.configure do |c|
|
|
129
|
+
# デバッグ出力(デフォルト: false)
|
|
130
|
+
c.debug = true
|
|
131
|
+
|
|
132
|
+
# カスタムプロンプト(オプション)
|
|
133
|
+
c.custom_prompt = <<~PROMPT
|
|
134
|
+
本番環境です。破壊的操作の前に必ず確認してください。
|
|
135
|
+
PROMPT
|
|
136
|
+
end
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### コマンドラインオプション
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
girb --debug # デバッグ出力を有効化
|
|
143
|
+
girb -d # 同上
|
|
144
|
+
girb --help # ヘルプを表示
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 環境変数
|
|
148
|
+
|
|
149
|
+
| 変数 | 説明 |
|
|
150
|
+
|------|------|
|
|
151
|
+
| `GIRB_PROVIDER` | **必須。** 読み込むプロバイダーgem(例: `girb-ruby_llm`、`girb-gemini`) |
|
|
152
|
+
| `GIRB_DEBUG` | `1`に設定するとデバッグ出力を有効化 |
|
|
153
|
+
|
|
154
|
+
## AIが使用できるツール
|
|
155
|
+
|
|
156
|
+
| ツール | 説明 |
|
|
157
|
+
|--------|------|
|
|
158
|
+
| `evaluate_code` | IRBのコンテキストでRubyコードを実行 |
|
|
159
|
+
| `inspect_object` | オブジェクトの詳細を検査 |
|
|
160
|
+
| `get_source` | メソッドやクラスのソースコードを取得 |
|
|
161
|
+
| `list_methods` | オブジェクトのメソッド一覧を取得 |
|
|
162
|
+
| `find_file` | プロジェクト内のファイルを検索 |
|
|
163
|
+
| `read_file` | ファイルの内容を読み取り |
|
|
164
|
+
| `session_history` | IRBセッションの履歴を取得 |
|
|
165
|
+
|
|
166
|
+
### Rails環境での追加ツール
|
|
167
|
+
|
|
168
|
+
| ツール | 説明 |
|
|
169
|
+
|--------|------|
|
|
170
|
+
| `query_model` | ActiveRecordモデルへのクエリ実行 |
|
|
171
|
+
| `model_info` | モデルのスキーマ情報を取得 |
|
|
172
|
+
|
|
173
|
+
## カスタムプロバイダー
|
|
174
|
+
|
|
175
|
+
独自のLLMプロバイダーを実装:
|
|
176
|
+
|
|
177
|
+
```ruby
|
|
178
|
+
class MyProvider < Girb::Providers::Base
|
|
179
|
+
def initialize(api_key:)
|
|
180
|
+
@api_key = api_key
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def chat(messages:, system_prompt:, tools:)
|
|
184
|
+
# messages: { role: :user/:assistant/:tool_call/:tool_result, content: "..." } の配列
|
|
185
|
+
# tools: { name: "...", description: "...", parameters: {...} } の配列
|
|
186
|
+
|
|
187
|
+
# LLM APIを呼び出す
|
|
188
|
+
response = call_my_llm(messages, system_prompt, tools)
|
|
189
|
+
|
|
190
|
+
# Responseオブジェクトを返す
|
|
191
|
+
Girb::Providers::Base::Response.new(
|
|
192
|
+
text: response.text,
|
|
193
|
+
function_calls: response.tool_calls&.map { |tc| { name: tc.name, args: tc.args } }
|
|
194
|
+
)
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
Girb.configure do |c|
|
|
199
|
+
c.provider = MyProvider.new(api_key: ENV['MY_API_KEY'])
|
|
200
|
+
end
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
実行:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
GIRB_PROVIDER=my_provider girb
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## 使用例
|
|
210
|
+
|
|
211
|
+
### デバッグ支援
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
irb(main):001> user = User.find(1)
|
|
215
|
+
irb(main):002> user.update(name: "test")
|
|
216
|
+
=> false
|
|
217
|
+
irb(main):003> なぜ更新に失敗したの?[Ctrl+Space]
|
|
218
|
+
`user.errors.full_messages` を確認したところ、バリデーションエラーが発生しています:
|
|
219
|
+
- "Email can't be blank"
|
|
220
|
+
nameの更新時にemailが空になっている可能性があります。
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### コードの理解
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
irb(main):001> このプロジェクトでUserモデルはどこで定義されてる?[Ctrl+Space]
|
|
227
|
+
app/models/user.rb で定義されています。
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### パターン認識
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
irb(main):001> a = 1
|
|
234
|
+
irb(main):002> b = 2
|
|
235
|
+
irb(main):003> c = 3以降も続けるとzはいくつ?[Ctrl+Space]
|
|
236
|
+
パターン a=1, b=2, c=3... を続けると、z=26 になります。
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## 動作要件
|
|
240
|
+
|
|
241
|
+
- Ruby 3.2.0以上
|
|
242
|
+
- IRB 1.6.0以上
|
|
243
|
+
- LLMプロバイダーgem(girb-ruby_llm または girb-gemini)
|
|
244
|
+
|
|
245
|
+
## ライセンス
|
|
246
|
+
|
|
247
|
+
MIT License
|
|
248
|
+
|
|
249
|
+
## 貢献
|
|
250
|
+
|
|
251
|
+
バグ報告や機能リクエストは [GitHub Issues](https://github.com/rira100000000/girb/issues) へお願いします。
|
data/Rakefile
ADDED
data/exe/girb
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "optparse"
|
|
5
|
+
|
|
6
|
+
options = {}
|
|
7
|
+
OptionParser.new do |opts|
|
|
8
|
+
opts.banner = "Usage: girb [options]"
|
|
9
|
+
|
|
10
|
+
opts.on("-d", "--debug", "Enable debug output") do
|
|
11
|
+
options[:debug] = true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
opts.on("-h", "--help", "Show this help") do
|
|
15
|
+
puts opts
|
|
16
|
+
exit
|
|
17
|
+
end
|
|
18
|
+
end.parse!
|
|
19
|
+
|
|
20
|
+
ENV["GIRB_DEBUG"] = "1" if options[:debug]
|
|
21
|
+
|
|
22
|
+
require "irb"
|
|
23
|
+
|
|
24
|
+
# Load girb and provider
|
|
25
|
+
require "girb"
|
|
26
|
+
|
|
27
|
+
if ENV["GIRB_PROVIDER"]
|
|
28
|
+
begin
|
|
29
|
+
require ENV["GIRB_PROVIDER"]
|
|
30
|
+
rescue LoadError
|
|
31
|
+
warn "[girb] Failed to load provider: #{ENV["GIRB_PROVIDER"]}"
|
|
32
|
+
end
|
|
33
|
+
else
|
|
34
|
+
warn "[girb] No provider specified. Set GIRB_PROVIDER environment variable."
|
|
35
|
+
warn "[girb] Example: GIRB_PROVIDER=girb-ruby_llm girb"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
IRB.start
|