utils 0.70.0 → 0.71.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ceaf5765e54421ff1940fb7f39c2e46a40ae1f3886b31490da70780e810cdf6
4
- data.tar.gz: 3b1df5558bb1a352778b8c747a4a1085951a16e4dc33050a2d14ce5353402ad6
3
+ metadata.gz: fb43a2fb980621c39c8dd83850e3b7752d3b8b2697d169d155ee2d541e9d4649
4
+ data.tar.gz: b804d7973f33d5ce1a8904d96d9b11b7e1560f73fd18facd6e0d1011de95b8a8
5
5
  SHA512:
6
- metadata.gz: a1318e0a95615867bdaff12d8a5fd88e9e8329ab997585a804e7e8f160b7ff303d33101b9f43b055ec6bbc30c93ba9c915f9e5c3c29f4d45c876377b7269225c
7
- data.tar.gz: 6f064a83362f4e5053fb3dbb37ab1331b00865707139cc880e08f2230fac2c95bb16184814e707c8f88f87a08aa3f13b3d432cac6e706443c4feeb12a51f5c59
6
+ metadata.gz: 6214647c846b302c6ae3a02f4c58dd1520a58e5d61f6f7b9a5060d90d16c8663eae861ae866c43f5e70c01e3794a8376efccdd942e282efeaa3e130ee83d418b
7
+ data.tar.gz: 1a1e7c14221af1f4a72d0c94fa81915fd512378e62bd8981299e4ab697fb5a664c293387a96d368322ca75da30ac3f437dfb215c7a3bd45496100ae7f41ce602
data/Rakefile CHANGED
@@ -31,6 +31,7 @@ GemHadar do
31
31
  dependency 'ollama-ruby', '~> 1.5.0'
32
32
  dependency 'kramdown-ansi', '~> 0.0.1'
33
33
  dependency 'figlet', '~> 1.0'
34
+ dependency 'context_spook', '~> 0.2'
34
35
  dependency 'simplecov'
35
36
  dependency 'debug'
36
37
  development_dependency 'test-unit'
data/bin/code_comment CHANGED
@@ -32,6 +32,7 @@
32
32
  require 'ollama'
33
33
  include Ollama
34
34
  require 'utils'
35
+ require 'context_spook'
35
36
 
36
37
  META_METHOD = /(
37
38
  (class_)? # Optional "class_" prefix
@@ -79,11 +80,11 @@ def fetch_construct(filename_linenumber)
79
80
  return result, :method
80
81
  end
81
82
 
82
- def build_method_prompt(construct_type, construct, file_contents)
83
+ def build_method_prompt(construct_type, construct, context)
83
84
  default_prompt = <<~EOT
84
85
  Look at this code to document it:
85
86
 
86
- %{file_contents}
87
+ %{context}
87
88
 
88
89
  Here's an example for how you should document a %{construct_type}.
89
90
 
@@ -118,15 +119,15 @@ def build_method_prompt(construct_type, construct, file_contents)
118
119
  5. Start each line of your comment with a single # character.
119
120
  EOT
120
121
  $config.read('method-prompt.txt', default: default_prompt) % {
121
- construct_type:, construct:, file_contents:,
122
+ construct_type:, construct:, context:,
122
123
  }
123
124
  end
124
125
 
125
- def build_class_module_prompt(construct_type, construct, file_contents)
126
+ def build_class_module_prompt(construct_type, construct, context)
126
127
  default_prompt = <<~EOT
127
128
  Look at this code to document it:
128
129
 
129
- %{file_contents}
130
+ %{context}
130
131
 
131
132
  Here's an example for how you should document a %{construct_type}.
132
133
 
@@ -154,16 +155,16 @@ def build_class_module_prompt(construct_type, construct, file_contents)
154
155
  5. Start each line of your comment with a single # character.
155
156
  EOT
156
157
  $config.read('class-module-prompt.txt', default: default_prompt) % {
157
- construct_type:, construct:, file_contents:,
158
+ construct_type:, construct:, context:,
158
159
  }
159
160
  end
160
161
 
161
- def build_prompt(construct_type, construct, file_contents)
162
+ def build_prompt(construct_type, construct, context)
162
163
  case construct_type
163
164
  when :method
164
- build_method_prompt(construct_type, construct, file_contents)
165
+ build_method_prompt(construct_type, construct, context)
165
166
  when :class, :module
166
- build_class_module_prompt(construct_type, construct, file_contents)
167
+ build_class_module_prompt(construct_type, construct, context)
167
168
  else
168
169
  fail "unknown construct_type #{construct_type.inspect}"
169
170
  end
@@ -171,12 +172,28 @@ end
171
172
 
172
173
  filename_linenumber = ARGV.shift or fail "require file_name as second argument"
173
174
  $config = Utils::ConfigDir.new('code_comment', env_var: 'XDG_CONFIG_HOME')
174
- files = Dir['{lib,spec,test}/**/*.rb']
175
175
  base_url = ENV['OLLAMA_URL'] || 'http://%s' % ENV.fetch('OLLAMA_HOST')
176
176
  model = ENV.fetch('OLLAMA_MODEL', 'llama3.1')
177
177
  construct, construct_type = fetch_construct(filename_linenumber)
178
178
  construct_indent = construct[/\A( *)/, 1].size
179
- file_contents = files.map { _1 + ":\n" + File.read(_1) } * ?\n
179
+ context = if File.exist?(filename = 'contexts/code_comment.rb')
180
+ ContextSpook.generate_context(filename)
181
+ else
182
+ ContextSpook.generate_context do
183
+ context do
184
+ file "README.md", tags: %w[ documentation ]
185
+
186
+ # Auto-discover files using globs
187
+ %w[ lib spec test ].each do |dir|
188
+ namespace dir do
189
+ Dir["#{dir}/**/*.rb"].each do |filename|
190
+ file filename, tags: %w[ ruby ]
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end.to_json
180
197
  #call_sites = %x(cscope -L -3 "#{method_name}" $(find . -name '*.rb') | awk '{ print $1 ":" $3 }').lines.map(&:chomp).uniq
181
198
  #methods = call_sites.map { fetch_method(_1) } * ?\n
182
199
 
@@ -201,7 +218,7 @@ default_system = <<~EOT
201
218
  EOT
202
219
  system = $config.read('system.txt', default: default_system)
203
220
 
204
- prompt = build_prompt(construct_type, construct, file_contents)
221
+ prompt = build_prompt(construct_type, construct, context)
205
222
 
206
223
  default_options = JSON(
207
224
  #repeat_penalty: 1.8,
data/lib/utils/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Utils
2
2
  # Utils version
3
- VERSION = '0.70.0'
3
+ VERSION = '0.71.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/utils.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: utils 0.70.0 ruby lib
2
+ # stub: utils 0.71.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "utils".freeze
6
- s.version = "0.70.0".freeze
6
+ s.version = "0.71.0".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
37
37
  s.add_runtime_dependency(%q<ollama-ruby>.freeze, ["~> 1.5.0".freeze])
38
38
  s.add_runtime_dependency(%q<kramdown-ansi>.freeze, ["~> 0.0.1".freeze])
39
39
  s.add_runtime_dependency(%q<figlet>.freeze, ["~> 1.0".freeze])
40
+ s.add_runtime_dependency(%q<context_spook>.freeze, ["~> 0.2".freeze])
40
41
  s.add_runtime_dependency(%q<simplecov>.freeze, [">= 0".freeze])
41
42
  s.add_runtime_dependency(%q<debug>.freeze, [">= 0".freeze])
42
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.70.0
4
+ version: 0.71.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -205,6 +205,20 @@ dependencies:
205
205
  - - "~>"
206
206
  - !ruby/object:Gem::Version
207
207
  version: '1.0'
208
+ - !ruby/object:Gem::Dependency
209
+ name: context_spook
210
+ requirement: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - "~>"
213
+ - !ruby/object:Gem::Version
214
+ version: '0.2'
215
+ type: :runtime
216
+ prerelease: false
217
+ version_requirements: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - "~>"
220
+ - !ruby/object:Gem::Version
221
+ version: '0.2'
208
222
  - !ruby/object:Gem::Dependency
209
223
  name: simplecov
210
224
  requirement: !ruby/object:Gem::Requirement