girb 0.1.1 → 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 +13 -0
- data/README.md +47 -56
- data/README_ja.md +47 -56
- 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,18 @@
|
|
|
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
|
+
|
|
3
16
|
## [0.1.1] - 2026-02-03
|
|
4
17
|
|
|
5
18
|
### Changed
|
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,84 +32,76 @@ Then run:
|
|
|
29
32
|
bundle install
|
|
30
33
|
```
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
gem install girb girb-ruby_llm
|
|
36
|
-
```
|
|
35
|
+
Create a `.girbrc` file in your project root:
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
```ruby
|
|
38
|
+
# .girbrc
|
|
39
|
+
require 'girb-ruby_llm'
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
Girb.configure do |c|
|
|
42
|
+
c.provider = Girb::Providers::RubyLlm.new(model: 'gemini-2.5-flash')
|
|
43
|
+
end
|
|
42
44
|
```
|
|
43
45
|
|
|
44
|
-
|
|
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
|
|
46
|
+
Now `rails console` will automatically load girb!
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
## Setup
|
|
54
|
-
|
|
55
|
-
### Using girb-ruby_llm (Recommended)
|
|
48
|
+
### For Non-Rails Projects
|
|
56
49
|
|
|
57
|
-
|
|
50
|
+
Install globally:
|
|
58
51
|
|
|
59
52
|
```bash
|
|
60
53
|
gem install girb girb-ruby_llm
|
|
61
54
|
```
|
|
62
55
|
|
|
63
|
-
|
|
56
|
+
Create a `.girbrc` file in your project directory:
|
|
64
57
|
|
|
65
58
|
```ruby
|
|
59
|
+
# .girbrc
|
|
66
60
|
require 'girb-ruby_llm'
|
|
67
61
|
|
|
68
|
-
RubyLLM.configure do |config|
|
|
69
|
-
config.gemini_api_key = 'your-api-key'
|
|
70
|
-
end
|
|
71
|
-
|
|
72
62
|
Girb.configure do |c|
|
|
73
63
|
c.provider = Girb::Providers::RubyLlm.new(model: 'gemini-2.5-flash')
|
|
74
64
|
end
|
|
75
65
|
```
|
|
76
66
|
|
|
77
|
-
|
|
67
|
+
Then use `girb` command instead of `irb`.
|
|
78
68
|
|
|
79
|
-
|
|
69
|
+
## How .girbrc Works
|
|
80
70
|
|
|
81
|
-
|
|
82
|
-
gem install girb girb-gemini
|
|
83
|
-
```
|
|
71
|
+
girb searches for `.girbrc` in the following order:
|
|
84
72
|
|
|
85
|
-
|
|
73
|
+
1. Current directory, then parent directories (up to root)
|
|
74
|
+
2. `~/.girbrc` as fallback
|
|
86
75
|
|
|
87
|
-
|
|
88
|
-
require 'girb-gemini'
|
|
76
|
+
This allows you to:
|
|
89
77
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
|
81
|
+
|
|
82
|
+
## Providers
|
|
83
|
+
|
|
84
|
+
Currently available providers:
|
|
85
|
+
|
|
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
|
|
88
|
+
|
|
89
|
+
You can also [create your own provider](#custom-providers).
|
|
97
90
|
|
|
98
91
|
## Usage
|
|
99
92
|
|
|
100
|
-
###
|
|
93
|
+
### For Rails Projects
|
|
101
94
|
|
|
102
95
|
```bash
|
|
103
|
-
|
|
96
|
+
rails console
|
|
104
97
|
```
|
|
105
98
|
|
|
106
|
-
|
|
99
|
+
girb is automatically loaded via Railtie.
|
|
107
100
|
|
|
108
|
-
|
|
109
|
-
|
|
101
|
+
### For Non-Rails Projects
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
girb
|
|
110
105
|
```
|
|
111
106
|
|
|
112
107
|
### Debug with binding.girb
|
|
@@ -139,7 +134,7 @@ irb(main):001> qq "How do I use this method?"
|
|
|
139
134
|
|
|
140
135
|
## Configuration Options
|
|
141
136
|
|
|
142
|
-
Add to your
|
|
137
|
+
Add to your `.girbrc`:
|
|
143
138
|
|
|
144
139
|
```ruby
|
|
145
140
|
require 'girb-ruby_llm'
|
|
@@ -165,10 +160,12 @@ girb --help # Show help
|
|
|
165
160
|
|
|
166
161
|
### Environment Variables
|
|
167
162
|
|
|
163
|
+
For `girb` command, you can also configure via environment variables (used when no `.girbrc` is found):
|
|
164
|
+
|
|
168
165
|
| Variable | Description |
|
|
169
166
|
|----------|-------------|
|
|
170
|
-
| `GIRB_PROVIDER` |
|
|
171
|
-
| `GIRB_MODEL` | Model to use (e.g., `gemini-2.5-flash`, `gpt-4o`)
|
|
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`) |
|
|
172
169
|
| `GIRB_DEBUG` | Set to `1` to enable debug output |
|
|
173
170
|
|
|
174
171
|
## Available Tools
|
|
@@ -220,12 +217,6 @@ Girb.configure do |c|
|
|
|
220
217
|
end
|
|
221
218
|
```
|
|
222
219
|
|
|
223
|
-
Then run with:
|
|
224
|
-
|
|
225
|
-
```bash
|
|
226
|
-
GIRB_PROVIDER=my_provider girb
|
|
227
|
-
```
|
|
228
|
-
|
|
229
220
|
## Examples
|
|
230
221
|
|
|
231
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,84 +30,76 @@ gem 'girb-ruby_llm' # または girb-gemini
|
|
|
27
30
|
bundle install
|
|
28
31
|
```
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
gem install girb girb-ruby_llm
|
|
34
|
-
```
|
|
33
|
+
プロジェクトルートに `.girbrc` ファイルを作成:
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
```ruby
|
|
36
|
+
# .girbrc
|
|
37
|
+
require 'girb-ruby_llm'
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
Girb.configure do |c|
|
|
40
|
+
c.provider = Girb::Providers::RubyLlm.new(model: 'gemini-2.5-flash')
|
|
41
|
+
end
|
|
40
42
|
```
|
|
41
43
|
|
|
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
|
|
44
|
+
これで `rails console` が自動的にgirbを読み込みます!
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
## セットアップ
|
|
52
|
-
|
|
53
|
-
### girb-ruby_llmを使用する場合(推奨)
|
|
46
|
+
### 非Railsプロジェクトの場合
|
|
54
47
|
|
|
55
|
-
|
|
48
|
+
グローバルにインストール:
|
|
56
49
|
|
|
57
50
|
```bash
|
|
58
51
|
gem install girb girb-ruby_llm
|
|
59
52
|
```
|
|
60
53
|
|
|
61
|
-
|
|
54
|
+
プロジェクトディレクトリに `.girbrc` ファイルを作成:
|
|
62
55
|
|
|
63
56
|
```ruby
|
|
57
|
+
# .girbrc
|
|
64
58
|
require 'girb-ruby_llm'
|
|
65
59
|
|
|
66
|
-
RubyLLM.configure do |config|
|
|
67
|
-
config.gemini_api_key = 'your-api-key'
|
|
68
|
-
end
|
|
69
|
-
|
|
70
60
|
Girb.configure do |c|
|
|
71
61
|
c.provider = Girb::Providers::RubyLlm.new(model: 'gemini-2.5-flash')
|
|
72
62
|
end
|
|
73
63
|
```
|
|
74
64
|
|
|
75
|
-
|
|
65
|
+
`irb` の代わりに `girb` コマンドを使用します。
|
|
76
66
|
|
|
77
|
-
|
|
67
|
+
## .girbrc の仕組み
|
|
78
68
|
|
|
79
|
-
|
|
80
|
-
gem install girb girb-gemini
|
|
81
|
-
```
|
|
69
|
+
girbは以下の順序で `.girbrc` を探します:
|
|
82
70
|
|
|
83
|
-
|
|
71
|
+
1. カレントディレクトリから親ディレクトリを遡って探索(ルートまで)
|
|
72
|
+
2. `~/.girbrc` にフォールバック
|
|
84
73
|
|
|
85
|
-
|
|
86
|
-
require 'girb-gemini'
|
|
74
|
+
これにより:
|
|
87
75
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
76
|
+
- **プロジェクト固有の設定**: プロジェクトルートに `.girbrc` を配置
|
|
77
|
+
- **共有設定**: 親ディレクトリに `.girbrc` を配置(例: `~/work/.girbrc` で仕事用プロジェクト全体に適用)
|
|
78
|
+
- **グローバルデフォルト**: ホームディレクトリに `.girbrc` を配置
|
|
79
|
+
|
|
80
|
+
## プロバイダー
|
|
81
|
+
|
|
82
|
+
現在利用可能なプロバイダー:
|
|
83
|
+
|
|
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
|
|
86
|
+
|
|
87
|
+
[独自プロバイダーの作成](#カスタムプロバイダー)も可能です。
|
|
95
88
|
|
|
96
89
|
## 使い方
|
|
97
90
|
|
|
98
|
-
###
|
|
91
|
+
### Railsプロジェクトの場合
|
|
99
92
|
|
|
100
93
|
```bash
|
|
101
|
-
|
|
94
|
+
rails console
|
|
102
95
|
```
|
|
103
96
|
|
|
104
|
-
|
|
97
|
+
Railtieにより自動的にgirbが読み込まれます。
|
|
105
98
|
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
### 非Railsプロジェクトの場合
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
girb
|
|
108
103
|
```
|
|
109
104
|
|
|
110
105
|
### binding.girbでデバッグ
|
|
@@ -137,7 +132,7 @@ irb(main):001> qq "このメソッドの使い方を教えて"
|
|
|
137
132
|
|
|
138
133
|
## 設定オプション
|
|
139
134
|
|
|
140
|
-
|
|
135
|
+
`.girbrc` に追加:
|
|
141
136
|
|
|
142
137
|
```ruby
|
|
143
138
|
require 'girb-ruby_llm'
|
|
@@ -163,10 +158,12 @@ girb --help # ヘルプを表示
|
|
|
163
158
|
|
|
164
159
|
### 環境変数
|
|
165
160
|
|
|
161
|
+
`girb` コマンドでは、`.girbrc` が見つからない場合に環境変数で設定することもできます:
|
|
162
|
+
|
|
166
163
|
| 変数 | 説明 |
|
|
167
164
|
|------|------|
|
|
168
|
-
| `GIRB_PROVIDER` |
|
|
169
|
-
| `GIRB_MODEL` | 使用するモデル(例: `gemini-2.5-flash`、`gpt-4o
|
|
165
|
+
| `GIRB_PROVIDER` | 読み込むプロバイダーgem(例: `girb-ruby_llm`、`girb-gemini`) |
|
|
166
|
+
| `GIRB_MODEL` | 使用するモデル(例: `gemini-2.5-flash`、`gpt-4o`) |
|
|
170
167
|
| `GIRB_DEBUG` | `1`に設定するとデバッグ出力を有効化 |
|
|
171
168
|
|
|
172
169
|
## AIが使用できるツール
|
|
@@ -218,12 +215,6 @@ Girb.configure do |c|
|
|
|
218
215
|
end
|
|
219
216
|
```
|
|
220
217
|
|
|
221
|
-
実行:
|
|
222
|
-
|
|
223
|
-
```bash
|
|
224
|
-
GIRB_PROVIDER=my_provider girb
|
|
225
|
-
```
|
|
226
|
-
|
|
227
218
|
## 使用例
|
|
228
219
|
|
|
229
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
|