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 +4 -4
- data/Rakefile +1 -0
- data/bin/code_comment +29 -12
- data/lib/utils/version.rb +1 -1
- data/utils.gemspec +3 -2
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb43a2fb980621c39c8dd83850e3b7752d3b8b2697d169d155ee2d541e9d4649
|
4
|
+
data.tar.gz: b804d7973f33d5ce1a8904d96d9b11b7e1560f73fd18facd6e0d1011de95b8a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6214647c846b302c6ae3a02f4c58dd1520a58e5d61f6f7b9a5060d90d16c8663eae861ae866c43f5e70c01e3794a8376efccdd942e282efeaa3e130ee83d418b
|
7
|
+
data.tar.gz: 1a1e7c14221af1f4a72d0c94fa81915fd512378e62bd8981299e4ab697fb5a664c293387a96d368322ca75da30ac3f437dfb215c7a3bd45496100ae7f41ce602
|
data/Rakefile
CHANGED
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,
|
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
|
-
%{
|
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:,
|
122
|
+
construct_type:, construct:, context:,
|
122
123
|
}
|
123
124
|
end
|
124
125
|
|
125
|
-
def build_class_module_prompt(construct_type, construct,
|
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
|
-
%{
|
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:,
|
158
|
+
construct_type:, construct:, context:,
|
158
159
|
}
|
159
160
|
end
|
160
161
|
|
161
|
-
def build_prompt(construct_type, construct,
|
162
|
+
def build_prompt(construct_type, construct, context)
|
162
163
|
case construct_type
|
163
164
|
when :method
|
164
|
-
build_method_prompt(construct_type, construct,
|
165
|
+
build_method_prompt(construct_type, construct, context)
|
165
166
|
when :class, :module
|
166
|
-
build_class_module_prompt(construct_type, construct,
|
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
|
-
|
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,
|
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
data/utils.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: utils 0.
|
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.
|
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.
|
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
|