girb 0.1.0 → 0.1.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 +4 -4
- data/CHANGELOG.md +26 -0
- data/README.md +53 -44
- data/README_ja.md +53 -44
- data/exe/girb +16 -9
- data/lib/girb/ai_client.rb +2 -1
- data/lib/girb/girbrc_loader.rb +46 -0
- data/lib/girb/providers/base.rb +2 -1
- data/lib/girb/railtie.rb +11 -0
- data/lib/girb/tools/environment_tools.rb +31 -0
- data/lib/girb/tools/rails_tools.rb +58 -0
- data/lib/girb/tools.rb +5 -3
- data/lib/girb/version.rb +1 -1
- data/lib/girb.rb +4 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 69a7d9cee0ae606d21d75c1fc94c1aef3665c8e38e4f704c9e8f899d7e70b943
|
|
4
|
+
data.tar.gz: 898823b1d088a67f8adb5e93705bb547d623eb0564d1831fe39cfa98757e233e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 93e107025ea0480db5b0403531a3af424836dfbef23a7f7f174e8c89036b1b3d140571ba0334a3c2f1ff7fda89ab91df2c5478f18f945474fd1ca836eb3ae5c3
|
|
7
|
+
data.tar.gz: bd5097cc780074724642e3c2932d23178eea0140e6bdd9460489abb97a0ac3f567577d1ecd6153d29ef896ed6803ed9c1988995d64ffd47db3c08dac702f6b21
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.2] - 2026-02-03
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `.girbrc` configuration file support with directory traversal
|
|
8
|
+
- Railtie for automatic Rails console integration
|
|
9
|
+
- GirbrcLoader utility for finding and loading `.girbrc` files
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Recommend `.girbrc` configuration instead of `~/.irbrc`
|
|
14
|
+
- `girb` command now loads `.girbrc` before falling back to environment variables
|
|
15
|
+
|
|
16
|
+
## [0.1.1] - 2026-02-03
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- GIRB_PROVIDER environment variable is now required for `girb` command
|
|
21
|
+
- Recommend ~/.irbrc configuration instead of environment variables
|
|
22
|
+
- Remove legacy configuration (gemini_api_key, model accessors)
|
|
23
|
+
- Remove built-in provider auto-detection
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- GIRB_MODEL environment variable support
|
|
28
|
+
|
|
3
29
|
## [0.1.0] - 2025-02-02
|
|
4
30
|
|
|
5
31
|
### Added
|
data/README.md
CHANGED
|
@@ -16,11 +16,14 @@ An AI assistant embedded in your IRB session. It understands your runtime contex
|
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
19
|
+
### For Rails Projects
|
|
20
|
+
|
|
19
21
|
Add to your Gemfile:
|
|
20
22
|
|
|
21
23
|
```ruby
|
|
22
|
-
|
|
23
|
-
gem 'girb-ruby_llm' # or girb-gemini
|
|
24
|
+
group :development do
|
|
25
|
+
gem 'girb-ruby_llm' # or girb-gemini
|
|
26
|
+
end
|
|
24
27
|
```
|
|
25
28
|
|
|
26
29
|
Then run:
|
|
@@ -29,67 +32,76 @@ Then run:
|
|
|
29
32
|
bundle install
|
|
30
33
|
```
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
Create a `.girbrc` file in your project root:
|
|
33
36
|
|
|
34
|
-
```
|
|
35
|
-
|
|
37
|
+
```ruby
|
|
38
|
+
# .girbrc
|
|
39
|
+
require 'girb-ruby_llm'
|
|
40
|
+
|
|
41
|
+
Girb.configure do |c|
|
|
42
|
+
c.provider = Girb::Providers::RubyLlm.new(model: 'gemini-2.5-flash')
|
|
43
|
+
end
|
|
36
44
|
```
|
|
37
45
|
|
|
38
|
-
|
|
46
|
+
Now `rails console` will automatically load girb!
|
|
47
|
+
|
|
48
|
+
### For Non-Rails Projects
|
|
49
|
+
|
|
50
|
+
Install globally:
|
|
39
51
|
|
|
40
52
|
```bash
|
|
41
|
-
|
|
53
|
+
gem install girb girb-ruby_llm
|
|
42
54
|
```
|
|
43
55
|
|
|
44
|
-
|
|
56
|
+
Create a `.girbrc` file in your project directory:
|
|
45
57
|
|
|
46
|
-
|
|
58
|
+
```ruby
|
|
59
|
+
# .girbrc
|
|
60
|
+
require 'girb-ruby_llm'
|
|
47
61
|
|
|
48
|
-
|
|
49
|
-
|
|
62
|
+
Girb.configure do |c|
|
|
63
|
+
c.provider = Girb::Providers::RubyLlm.new(model: 'gemini-2.5-flash')
|
|
64
|
+
end
|
|
65
|
+
```
|
|
50
66
|
|
|
51
|
-
|
|
67
|
+
Then use `girb` command instead of `irb`.
|
|
52
68
|
|
|
53
|
-
##
|
|
69
|
+
## How .girbrc Works
|
|
54
70
|
|
|
55
|
-
|
|
71
|
+
girb searches for `.girbrc` in the following order:
|
|
56
72
|
|
|
57
|
-
|
|
73
|
+
1. Current directory, then parent directories (up to root)
|
|
74
|
+
2. `~/.girbrc` as fallback
|
|
58
75
|
|
|
59
|
-
|
|
60
|
-
# Install
|
|
61
|
-
gem install girb girb-ruby_llm
|
|
76
|
+
This allows you to:
|
|
62
77
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
```
|
|
78
|
+
- **Project-specific settings**: Place `.girbrc` in your project root
|
|
79
|
+
- **Shared settings**: Place `.girbrc` in a parent directory (e.g., `~/work/.girbrc` for all work projects)
|
|
80
|
+
- **Global default**: Place `.girbrc` in your home directory
|
|
67
81
|
|
|
68
|
-
|
|
82
|
+
## Providers
|
|
69
83
|
|
|
70
|
-
|
|
84
|
+
Currently available providers:
|
|
71
85
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
gem install girb girb-gemini
|
|
86
|
+
- [girb-ruby_llm](https://github.com/rira100000000/girb-ruby_llm) - Multiple providers via RubyLLM (OpenAI, Anthropic, Gemini, Ollama, etc.)
|
|
87
|
+
- [girb-gemini](https://github.com/rira100000000/girb-gemini) - Google Gemini
|
|
75
88
|
|
|
76
|
-
|
|
77
|
-
export GIRB_PROVIDER=girb-gemini
|
|
78
|
-
export GEMINI_API_KEY=your-api-key
|
|
79
|
-
```
|
|
89
|
+
You can also [create your own provider](#custom-providers).
|
|
80
90
|
|
|
81
91
|
## Usage
|
|
82
92
|
|
|
83
|
-
###
|
|
93
|
+
### For Rails Projects
|
|
84
94
|
|
|
85
95
|
```bash
|
|
86
|
-
|
|
96
|
+
rails console
|
|
87
97
|
```
|
|
88
98
|
|
|
89
|
-
|
|
99
|
+
girb is automatically loaded via Railtie.
|
|
90
100
|
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
### For Non-Rails Projects
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
girb
|
|
93
105
|
```
|
|
94
106
|
|
|
95
107
|
### Debug with binding.girb
|
|
@@ -122,7 +134,7 @@ irb(main):001> qq "How do I use this method?"
|
|
|
122
134
|
|
|
123
135
|
## Configuration Options
|
|
124
136
|
|
|
125
|
-
Add to your
|
|
137
|
+
Add to your `.girbrc`:
|
|
126
138
|
|
|
127
139
|
```ruby
|
|
128
140
|
require 'girb-ruby_llm'
|
|
@@ -148,9 +160,12 @@ girb --help # Show help
|
|
|
148
160
|
|
|
149
161
|
### Environment Variables
|
|
150
162
|
|
|
163
|
+
For `girb` command, you can also configure via environment variables (used when no `.girbrc` is found):
|
|
164
|
+
|
|
151
165
|
| Variable | Description |
|
|
152
166
|
|----------|-------------|
|
|
153
|
-
| `GIRB_PROVIDER` |
|
|
167
|
+
| `GIRB_PROVIDER` | Provider gem to load (e.g., `girb-ruby_llm`, `girb-gemini`) |
|
|
168
|
+
| `GIRB_MODEL` | Model to use (e.g., `gemini-2.5-flash`, `gpt-4o`) |
|
|
154
169
|
| `GIRB_DEBUG` | Set to `1` to enable debug output |
|
|
155
170
|
|
|
156
171
|
## Available Tools
|
|
@@ -202,12 +217,6 @@ Girb.configure do |c|
|
|
|
202
217
|
end
|
|
203
218
|
```
|
|
204
219
|
|
|
205
|
-
Then run with:
|
|
206
|
-
|
|
207
|
-
```bash
|
|
208
|
-
GIRB_PROVIDER=my_provider girb
|
|
209
|
-
```
|
|
210
|
-
|
|
211
220
|
## Examples
|
|
212
221
|
|
|
213
222
|
### Debugging Assistance
|
data/README_ja.md
CHANGED
|
@@ -14,11 +14,14 @@ IRBセッションに組み込まれたAIアシスタント。実行中のコン
|
|
|
14
14
|
|
|
15
15
|
## インストール
|
|
16
16
|
|
|
17
|
+
### Railsプロジェクトの場合
|
|
18
|
+
|
|
17
19
|
Gemfileに追加:
|
|
18
20
|
|
|
19
21
|
```ruby
|
|
20
|
-
|
|
21
|
-
gem 'girb-ruby_llm' # または girb-gemini
|
|
22
|
+
group :development do
|
|
23
|
+
gem 'girb-ruby_llm' # または girb-gemini
|
|
24
|
+
end
|
|
22
25
|
```
|
|
23
26
|
|
|
24
27
|
そして実行:
|
|
@@ -27,67 +30,76 @@ gem 'girb-ruby_llm' # または girb-gemini
|
|
|
27
30
|
bundle install
|
|
28
31
|
```
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
プロジェクトルートに `.girbrc` ファイルを作成:
|
|
31
34
|
|
|
32
|
-
```
|
|
33
|
-
|
|
35
|
+
```ruby
|
|
36
|
+
# .girbrc
|
|
37
|
+
require 'girb-ruby_llm'
|
|
38
|
+
|
|
39
|
+
Girb.configure do |c|
|
|
40
|
+
c.provider = Girb::Providers::RubyLlm.new(model: 'gemini-2.5-flash')
|
|
41
|
+
end
|
|
34
42
|
```
|
|
35
43
|
|
|
36
|
-
|
|
44
|
+
これで `rails console` が自動的にgirbを読み込みます!
|
|
45
|
+
|
|
46
|
+
### 非Railsプロジェクトの場合
|
|
47
|
+
|
|
48
|
+
グローバルにインストール:
|
|
37
49
|
|
|
38
50
|
```bash
|
|
39
|
-
|
|
51
|
+
gem install girb girb-ruby_llm
|
|
40
52
|
```
|
|
41
53
|
|
|
42
|
-
|
|
54
|
+
プロジェクトディレクトリに `.girbrc` ファイルを作成:
|
|
43
55
|
|
|
44
|
-
|
|
56
|
+
```ruby
|
|
57
|
+
# .girbrc
|
|
58
|
+
require 'girb-ruby_llm'
|
|
45
59
|
|
|
46
|
-
|
|
47
|
-
|
|
60
|
+
Girb.configure do |c|
|
|
61
|
+
c.provider = Girb::Providers::RubyLlm.new(model: 'gemini-2.5-flash')
|
|
62
|
+
end
|
|
63
|
+
```
|
|
48
64
|
|
|
49
|
-
|
|
65
|
+
`irb` の代わりに `girb` コマンドを使用します。
|
|
50
66
|
|
|
51
|
-
##
|
|
67
|
+
## .girbrc の仕組み
|
|
52
68
|
|
|
53
|
-
|
|
69
|
+
girbは以下の順序で `.girbrc` を探します:
|
|
54
70
|
|
|
55
|
-
|
|
71
|
+
1. カレントディレクトリから親ディレクトリを遡って探索(ルートまで)
|
|
72
|
+
2. `~/.girbrc` にフォールバック
|
|
56
73
|
|
|
57
|
-
|
|
58
|
-
# インストール
|
|
59
|
-
gem install girb girb-ruby_llm
|
|
74
|
+
これにより:
|
|
60
75
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
```
|
|
76
|
+
- **プロジェクト固有の設定**: プロジェクトルートに `.girbrc` を配置
|
|
77
|
+
- **共有設定**: 親ディレクトリに `.girbrc` を配置(例: `~/work/.girbrc` で仕事用プロジェクト全体に適用)
|
|
78
|
+
- **グローバルデフォルト**: ホームディレクトリに `.girbrc` を配置
|
|
65
79
|
|
|
66
|
-
|
|
80
|
+
## プロバイダー
|
|
67
81
|
|
|
68
|
-
|
|
82
|
+
現在利用可能なプロバイダー:
|
|
69
83
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
gem install girb girb-gemini
|
|
84
|
+
- [girb-ruby_llm](https://github.com/rira100000000/girb-ruby_llm) - RubyLLM経由で複数プロバイダー対応(OpenAI、Anthropic、Gemini、Ollama等)
|
|
85
|
+
- [girb-gemini](https://github.com/rira100000000/girb-gemini) - Google Gemini
|
|
73
86
|
|
|
74
|
-
|
|
75
|
-
export GIRB_PROVIDER=girb-gemini
|
|
76
|
-
export GEMINI_API_KEY=your-api-key
|
|
77
|
-
```
|
|
87
|
+
[独自プロバイダーの作成](#カスタムプロバイダー)も可能です。
|
|
78
88
|
|
|
79
89
|
## 使い方
|
|
80
90
|
|
|
81
|
-
###
|
|
91
|
+
### Railsプロジェクトの場合
|
|
82
92
|
|
|
83
93
|
```bash
|
|
84
|
-
|
|
94
|
+
rails console
|
|
85
95
|
```
|
|
86
96
|
|
|
87
|
-
|
|
97
|
+
Railtieにより自動的にgirbが読み込まれます。
|
|
88
98
|
|
|
89
|
-
|
|
90
|
-
|
|
99
|
+
### 非Railsプロジェクトの場合
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
girb
|
|
91
103
|
```
|
|
92
104
|
|
|
93
105
|
### binding.girbでデバッグ
|
|
@@ -120,7 +132,7 @@ irb(main):001> qq "このメソッドの使い方を教えて"
|
|
|
120
132
|
|
|
121
133
|
## 設定オプション
|
|
122
134
|
|
|
123
|
-
|
|
135
|
+
`.girbrc` に追加:
|
|
124
136
|
|
|
125
137
|
```ruby
|
|
126
138
|
require 'girb-ruby_llm'
|
|
@@ -146,9 +158,12 @@ girb --help # ヘルプを表示
|
|
|
146
158
|
|
|
147
159
|
### 環境変数
|
|
148
160
|
|
|
161
|
+
`girb` コマンドでは、`.girbrc` が見つからない場合に環境変数で設定することもできます:
|
|
162
|
+
|
|
149
163
|
| 変数 | 説明 |
|
|
150
164
|
|------|------|
|
|
151
|
-
| `GIRB_PROVIDER` |
|
|
165
|
+
| `GIRB_PROVIDER` | 読み込むプロバイダーgem(例: `girb-ruby_llm`、`girb-gemini`) |
|
|
166
|
+
| `GIRB_MODEL` | 使用するモデル(例: `gemini-2.5-flash`、`gpt-4o`) |
|
|
152
167
|
| `GIRB_DEBUG` | `1`に設定するとデバッグ出力を有効化 |
|
|
153
168
|
|
|
154
169
|
## AIが使用できるツール
|
|
@@ -200,12 +215,6 @@ Girb.configure do |c|
|
|
|
200
215
|
end
|
|
201
216
|
```
|
|
202
217
|
|
|
203
|
-
実行:
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
GIRB_PROVIDER=my_provider girb
|
|
207
|
-
```
|
|
208
|
-
|
|
209
218
|
## 使用例
|
|
210
219
|
|
|
211
220
|
### デバッグ支援
|
data/exe/girb
CHANGED
|
@@ -21,18 +21,25 @@ ENV["GIRB_DEBUG"] = "1" if options[:debug]
|
|
|
21
21
|
|
|
22
22
|
require "irb"
|
|
23
23
|
|
|
24
|
-
# Load girb
|
|
24
|
+
# Load girb
|
|
25
25
|
require "girb"
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
# Load .girbrc (searches from current directory up to root, then ~/.girbrc)
|
|
28
|
+
girbrc_loaded = Girb::GirbrcLoader.load_girbrc
|
|
29
|
+
|
|
30
|
+
# If no .girbrc found, try environment variable based configuration
|
|
31
|
+
unless girbrc_loaded
|
|
32
|
+
if ENV["GIRB_PROVIDER"]
|
|
33
|
+
begin
|
|
34
|
+
require ENV["GIRB_PROVIDER"]
|
|
35
|
+
rescue LoadError
|
|
36
|
+
warn "[girb] Failed to load provider: #{ENV["GIRB_PROVIDER"]}"
|
|
37
|
+
end
|
|
38
|
+
else
|
|
39
|
+
warn "[girb] No .girbrc found and GIRB_PROVIDER not set."
|
|
40
|
+
warn "[girb] Create a .girbrc file or set GIRB_PROVIDER environment variable."
|
|
41
|
+
warn "[girb] Example: GIRB_PROVIDER=girb-ruby_llm girb"
|
|
32
42
|
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
43
|
end
|
|
37
44
|
|
|
38
45
|
IRB.start
|
data/lib/girb/ai_client.rb
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "pathname"
|
|
4
|
+
|
|
5
|
+
module Girb
|
|
6
|
+
module GirbrcLoader
|
|
7
|
+
class << self
|
|
8
|
+
# Find .girbrc by traversing from start_dir up to root,
|
|
9
|
+
# then fall back to ~/.girbrc
|
|
10
|
+
def find_girbrc(start_dir = Dir.pwd)
|
|
11
|
+
dir = Pathname.new(start_dir).expand_path
|
|
12
|
+
|
|
13
|
+
# Traverse up to find .girbrc
|
|
14
|
+
while dir != dir.parent
|
|
15
|
+
candidate = dir.join(".girbrc")
|
|
16
|
+
return candidate if candidate.exist?
|
|
17
|
+
dir = dir.parent
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Check root directory
|
|
21
|
+
root_candidate = dir.join(".girbrc")
|
|
22
|
+
return root_candidate if root_candidate.exist?
|
|
23
|
+
|
|
24
|
+
# Fall back to ~/.girbrc
|
|
25
|
+
home_girbrc = Pathname.new(File.expand_path("~/.girbrc"))
|
|
26
|
+
home_girbrc.exist? ? home_girbrc : nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Load .girbrc if found
|
|
30
|
+
def load_girbrc(start_dir = Dir.pwd)
|
|
31
|
+
girbrc = find_girbrc(start_dir)
|
|
32
|
+
return false unless girbrc
|
|
33
|
+
|
|
34
|
+
if Girb.configuration&.debug
|
|
35
|
+
warn "[girb] Loading #{girbrc}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
load girbrc.to_s
|
|
39
|
+
true
|
|
40
|
+
rescue SyntaxError, LoadError, StandardError => e
|
|
41
|
+
warn "[girb] Error loading #{girbrc}: #{e.message}"
|
|
42
|
+
false
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/lib/girb/providers/base.rb
CHANGED
|
@@ -24,8 +24,9 @@ module Girb
|
|
|
24
24
|
# Each message has :role (:user, :assistant, :tool_call, :tool_result) and :content
|
|
25
25
|
# @param system_prompt [String] System prompt
|
|
26
26
|
# @param tools [Array<Hash>] Tool definitions in normalized format
|
|
27
|
+
# @param binding [Binding] Optional binding for tool execution (used by some providers)
|
|
27
28
|
# @return [Response] Response object with text and/or function_calls
|
|
28
|
-
def chat(messages:, system_prompt:, tools:)
|
|
29
|
+
def chat(messages:, system_prompt:, tools:, binding: nil)
|
|
29
30
|
raise NotImplementedError, "#{self.class}#chat must be implemented"
|
|
30
31
|
end
|
|
31
32
|
|
data/lib/girb/railtie.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module Girb
|
|
6
|
+
module Tools
|
|
7
|
+
# General tool for getting current directory - always available
|
|
8
|
+
class GetCurrentDirectory < Base
|
|
9
|
+
class << self
|
|
10
|
+
def description
|
|
11
|
+
"Get the current working directory (pwd). Use this when user asks about current directory or project location."
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def parameters
|
|
15
|
+
{
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {},
|
|
18
|
+
required: []
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def execute(binding)
|
|
24
|
+
{
|
|
25
|
+
current_directory: Dir.pwd,
|
|
26
|
+
home_directory: Dir.home
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -4,6 +4,64 @@ require_relative "base"
|
|
|
4
4
|
|
|
5
5
|
module Girb
|
|
6
6
|
module Tools
|
|
7
|
+
class RailsProjectInfo < Base
|
|
8
|
+
class << self
|
|
9
|
+
def available?
|
|
10
|
+
defined?(Rails)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def description
|
|
14
|
+
"Get Rails project information: current directory (Rails.root), environment, Ruby/Rails versions, database config, and list of all defined models. Use this to find project path or list models."
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def parameters
|
|
18
|
+
{
|
|
19
|
+
type: "object",
|
|
20
|
+
properties: {},
|
|
21
|
+
required: []
|
|
22
|
+
}
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def execute(binding)
|
|
27
|
+
info = {
|
|
28
|
+
root: Rails.root.to_s,
|
|
29
|
+
environment: Rails.env,
|
|
30
|
+
ruby_version: RUBY_VERSION
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Rails version
|
|
34
|
+
info[:rails_version] = Rails.version if Rails.respond_to?(:version)
|
|
35
|
+
|
|
36
|
+
# Database info
|
|
37
|
+
if defined?(ActiveRecord::Base)
|
|
38
|
+
begin
|
|
39
|
+
config = ActiveRecord::Base.connection_db_config
|
|
40
|
+
info[:database] = {
|
|
41
|
+
adapter: config.adapter,
|
|
42
|
+
database: config.database
|
|
43
|
+
}
|
|
44
|
+
rescue StandardError
|
|
45
|
+
# DB not connected
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Defined models
|
|
50
|
+
if defined?(ActiveRecord::Base)
|
|
51
|
+
begin
|
|
52
|
+
Rails.application.eager_load! unless Rails.application.config.eager_load
|
|
53
|
+
info[:models] = ActiveRecord::Base.descendants.map(&:name).sort
|
|
54
|
+
rescue StandardError
|
|
55
|
+
# Unable to load models
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
info
|
|
60
|
+
rescue StandardError => e
|
|
61
|
+
{ error: "#{e.class}: #{e.message}" }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
7
65
|
class RailsModelInfo < Base
|
|
8
66
|
class << self
|
|
9
67
|
def available?
|
data/lib/girb/tools.rb
CHANGED
|
@@ -8,19 +8,21 @@ require_relative "tools/evaluate_code"
|
|
|
8
8
|
require_relative "tools/read_file"
|
|
9
9
|
require_relative "tools/find_file"
|
|
10
10
|
require_relative "tools/session_history_tool"
|
|
11
|
+
require_relative "tools/environment_tools"
|
|
11
12
|
|
|
12
13
|
module Girb
|
|
13
14
|
module Tools
|
|
14
|
-
CORE_TOOLS = [InspectObject, GetSource, ListMethods, EvaluateCode, ReadFile, FindFile, SessionHistoryTool].freeze
|
|
15
|
+
CORE_TOOLS = [InspectObject, GetSource, ListMethods, EvaluateCode, ReadFile, FindFile, SessionHistoryTool, GetCurrentDirectory].freeze
|
|
15
16
|
|
|
16
17
|
class << self
|
|
17
18
|
def available_tools
|
|
18
19
|
tools = CORE_TOOLS.dup
|
|
19
20
|
|
|
20
21
|
# Rails tools are loaded conditionally
|
|
21
|
-
if defined?(
|
|
22
|
+
if defined?(Rails)
|
|
22
23
|
require_relative "tools/rails_tools"
|
|
23
|
-
tools <<
|
|
24
|
+
tools << RailsProjectInfo
|
|
25
|
+
tools << RailsModelInfo if defined?(ActiveRecord::Base)
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
tools.select { |t| !t.respond_to?(:available?) || t.available? }
|
data/lib/girb/version.rb
CHANGED
data/lib/girb.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "girb/version"
|
|
4
4
|
require_relative "girb/configuration"
|
|
5
|
+
require_relative "girb/girbrc_loader"
|
|
5
6
|
require_relative "girb/providers/base"
|
|
6
7
|
require_relative "girb/exception_capture"
|
|
7
8
|
require_relative "girb/context_builder"
|
|
@@ -37,6 +38,9 @@ if defined?(IRB)
|
|
|
37
38
|
Girb.setup!
|
|
38
39
|
end
|
|
39
40
|
|
|
41
|
+
# Rails がロードされていたら Railtie を組み込む
|
|
42
|
+
require_relative "girb/railtie" if defined?(Rails::Railtie)
|
|
43
|
+
|
|
40
44
|
# binding.girb サポート
|
|
41
45
|
class Binding
|
|
42
46
|
def girb
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: girb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- rira100000000
|
|
@@ -88,12 +88,15 @@ files:
|
|
|
88
88
|
- lib/girb/context_builder.rb
|
|
89
89
|
- lib/girb/conversation_history.rb
|
|
90
90
|
- lib/girb/exception_capture.rb
|
|
91
|
+
- lib/girb/girbrc_loader.rb
|
|
91
92
|
- lib/girb/irb_integration.rb
|
|
92
93
|
- lib/girb/prompt_builder.rb
|
|
93
94
|
- lib/girb/providers/base.rb
|
|
95
|
+
- lib/girb/railtie.rb
|
|
94
96
|
- lib/girb/session_history.rb
|
|
95
97
|
- lib/girb/tools.rb
|
|
96
98
|
- lib/girb/tools/base.rb
|
|
99
|
+
- lib/girb/tools/environment_tools.rb
|
|
97
100
|
- lib/girb/tools/evaluate_code.rb
|
|
98
101
|
- lib/girb/tools/find_file.rb
|
|
99
102
|
- lib/girb/tools/get_source.rb
|