utils 0.102.0 → 0.103.1

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: abb775b7e56e5891b294675b3f3edf11b4b231d081f02ffedb1d6e15a04cbf37
4
- data.tar.gz: d0b00a06adc95b98988966e38334d6bc05b5fab2bd1b1a69fa2367527c26bd59
3
+ metadata.gz: 6024db955c83cb231efefeb42680de18cd5e716ffc865cf4407d3b3fd792d28d
4
+ data.tar.gz: f6b8e243b0c317f61cc51bcec7a1cf4784803bf564c7b0f81d950bddceabb4ae
5
5
  SHA512:
6
- metadata.gz: 8713a67e435fb0bae1990c1fa82d41a5f910499a36bcc44a3df042c2c67db09c2e6e4be62808a282bf6d60f7d946f3d29a04be9470ff5292697061f49e1d751c
7
- data.tar.gz: 672ae5366010f42aed89462c083c1681f054a9f4e3d34a061272cfb965e9d1d398fa34ddd4596b560321f398aa1bf340d032d234cc2b754893498cd120ae8e24
6
+ metadata.gz: ec95926bf9da05c820494b467a97cf2ea2267bec0d31088f9d34420d433618a36e2f12130ebec5293b290c10387f2e8c80424c3d882a2df2fb90506ca5f598ec
7
+ data.tar.gz: 957e89193b73ff2ac6cb60dda02b8345a980e71eaae9240bcb5eb512f57b4e3e1cebc2ffdb1a5be4b3b6975cacc159012e06bdaf5e00988a915bdfdd869f9eef
data/bin/changes CHANGED
@@ -76,6 +76,33 @@ def find_highest_version_tag(filename)
76
76
  end
77
77
  end
78
78
 
79
+ # Normalizes a version tag to ensure it carries a `v` prefix.
80
+ #
81
+ # If the tag matches a bare semver pattern (e.g. `1.2.3`), a `v` is
82
+ # prepended. Tags that already carry the prefix (e.g. `v1.2.3`) or
83
+ # that don't look like a version (e.g. `HEAD`) are returned as-is.
84
+ #
85
+ # @param tag [Object] the version tag to normalize
86
+ #
87
+ # @return [String] the tag with a guaranteed `v` prefix for bare versions
88
+ def version_tag(tag)
89
+ tag.to_s.sub(/\Av?(\d+\.\d+\.\d+)\z/, 'v\1')
90
+ end
91
+
92
+ # The options method retrieves and parses model configuration options from the
93
+ # OLLAMA_MODEL_OPTIONS environment variable.
94
+ #
95
+ # This method fetches the OLLAMA_MODEL_OPTIONS environment variable, which is
96
+ # expected to contain a JSON-encoded hash of configuration parameters. If the
97
+ # variable is not set, it defaults to an empty hash. The JSON string is then
98
+ # parsed into a Ruby hash and converted into an Options object using the
99
+ # Options.from_hash class method.
100
+ #
101
+ # @return [ Options ] an Options object representing the parsed configuration parameters
102
+ def options
103
+ Options.from_hash(JSON.parse(ENV.fetch('OLLAMA_MODEL_OPTIONS', '{}')))
104
+ end
105
+
79
106
  # Generates a formatted changelog entry by processing Git logs and utilizing an
80
107
  # LLM.
81
108
  #
@@ -89,23 +116,37 @@ end
89
116
  # in the resulting header; defaults to `range_to`
90
117
  #
91
118
  # @return [String] a formatted Markdown changelog entry including date and summary
92
- def compute_change(range_from, range_to, future_tag: range_to, patch: false)
93
- range_from = range_from.to_s.sub(/\Av?/, ?v)
119
+ def compute_change(range_from, range_to, future_tag: range_to, patch: false, context_length: 4096)
120
+ range_from = version_tag(range_from)
94
121
  if range_to.to_s == 'HEAD'
95
122
  range = "#{range_from}..HEAD"
96
123
  else
97
- range_to = range_to.to_s.sub(/\Av?/, ?v)
124
+ range_to = version_tag(range_to)
98
125
  range = "#{range_from}..#{range_to}"
99
126
  end
100
127
 
128
+ max_log = (context_length * 0.8 * 4).to_i
129
+
101
130
  log = x("git log #{'-p ' if patch}#{range}")
131
+ log = log.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: '')
132
+
133
+ if log.size > max_log
134
+ if patch
135
+ warn "Diff too large for #{range} (#{log.size} > #{max_log}), retrying without -p."
136
+ log = x("git log #{range}")
137
+ log = log.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: '')
138
+ end
139
+ if log.size > max_log
140
+ log = log[0, max_log] + "\n\n[log truncated]"
141
+ end
142
+ end
102
143
 
103
144
  date = x("git log -n1 --pretty='format:%cd' --date=short #{range_to}")
104
145
 
105
146
  if log.strip.empty?
106
147
  return <<~EOT
107
148
 
108
- ## #{date} #{future_tag}
149
+ ## #{date} #{version_tag(future_tag)}
109
150
  EOT
110
151
  end
111
152
 
@@ -123,13 +164,12 @@ def compute_change(range_from, range_to, future_tag: range_to, patch: false)
123
164
  end
124
165
 
125
166
  ollama = Client.configure_with(client_config)
126
- options = Options.from_hash(JSON.parse(ENV.fetch('OLLAMA_MODEL_OPTIONS', '{}')))
127
167
  changes = ollama.generate(model:, system:, prompt:, options:, stream: false, think: false)
128
168
  changes = changes.response.gsub(/\t/, ' ')
129
169
 
130
170
  return <<~EOT
131
171
 
132
- ## #{date} #{future_tag}
172
+ ## #{date} #{version_tag(future_tag)}
133
173
 
134
174
  #{changes}
135
175
  EOT
@@ -137,7 +177,8 @@ end
137
177
 
138
178
  x("git fetch --tags")
139
179
 
140
- opts = go('pr:')
180
+ opts = go('pr:m:', defaults: { ?m => options.num_ctx })
181
+ context_length = opts[?m].to_i.nonzero? || 4_096
141
182
 
142
183
  case command = ARGV.shift
143
184
  when 'pending'
@@ -145,7 +186,7 @@ when 'pending'
145
186
  _1.sub(/\Av/, '').version
146
187
  }.max
147
188
  if last_version
148
- puts compute_change(last_version, :HEAD, future_tag: opts[?r], patch: opts[?p])
189
+ puts compute_change(last_version, :HEAD, future_tag: opts[?r], patch: opts[?p], context_length:)
149
190
  else
150
191
  fail 'need at least one version tag to work'
151
192
  end
@@ -154,7 +195,7 @@ when 'current'
154
195
  _1.sub(/\Av/, '').version
155
196
  }.sort.last(2)
156
197
  if version1 and version2
157
- puts compute_change(version1, version2, patch: opts[?p])
198
+ puts compute_change(version1, version2, patch: opts[?p], context_length:)
158
199
  else
159
200
  fail 'need at least two version tags to work'
160
201
  end
@@ -162,7 +203,7 @@ when 'range'
162
203
  range = ARGV.shift
163
204
  if range =~ /\A(.+)\.\.(.+)\z/
164
205
  range_from, range_to = $1, $2
165
- puts compute_change(range_from, range_to, patch: opts[?p])
206
+ puts compute_change(range_from, range_to, patch: opts[?p], context_length:)
166
207
  else
167
208
  fail "need range of the form v1.2.3..v1.2.4"
168
209
  end
@@ -179,8 +220,9 @@ when 'full', 'add'
179
220
 
180
221
  * Start
181
222
  EOT
182
- tags.each_cons(2) do |range_from, range_to|
183
- ary << compute_change(range_from, range_to, patch: opts[?p])
223
+ tags.each_cons(2).with_infobar(label: 'Change', output: STDERR, show: STDERR.tty?) do |range_from, range_to|
224
+ ary << compute_change(range_from, range_to, patch: opts[?p], context_length:)
225
+ +infobar
184
226
  end
185
227
  ary.reverse!
186
228
  ary.unshift <<~EOT
@@ -192,8 +234,9 @@ when 'full', 'add'
192
234
  start_tag = find_highest_version_tag(filename)
193
235
  tags = tags.drop_while { |t| t < start_tag }
194
236
  ary = []
195
- tags.each_cons(2) do |range_from, range_to|
196
- ary << compute_change(range_from, range_to, patch: opts[?p])
237
+ tags.each_cons(2).with_infobar(label: 'Change', output: STDERR, show: STDERR.tty?) do |range_from, range_to|
238
+ ary << compute_change(range_from, range_to, patch: opts[?p], context_length:)
239
+ +infobar
197
240
  end
198
241
  ary.empty? and exit
199
242
  ary.reverse!
data/lib/utils/version.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # by hand; it is rewritten on every `rake version` invocation.
6
6
  module Utils
7
7
  # The current version of the Utils gem as a String.
8
- VERSION = '0.102.0'
8
+ VERSION = '0.103.1'
9
9
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
10
10
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
11
11
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/utils.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: utils 0.102.0 ruby lib
2
+ # stub: utils 0.103.1 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "utils".freeze
6
- s.version = "0.102.0".freeze
6
+ s.version = "0.103.1".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]
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.specification_version = 4
25
25
 
26
- s.add_development_dependency("gem_hadar".freeze, [">= 2.26.1".freeze])
26
+ s.add_development_dependency("gem_hadar".freeze, [">= 2.27.1".freeze])
27
27
  s.add_development_dependency("test-unit".freeze, [">= 0".freeze])
28
28
  s.add_runtime_dependency("tins".freeze, ["~> 1.51".freeze])
29
29
  s.add_runtime_dependency("term-ansicolor".freeze, ["~> 1.11".freeze])
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.102.0
4
+ version: 0.103.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -16,7 +16,7 @@ dependencies:
16
16
  -
17
17
  - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.26.1
19
+ version: 2.27.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,7 +24,7 @@ dependencies:
24
24
  -
25
25
  - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 2.26.1
27
+ version: 2.27.1
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: test-unit
30
30
  requirement: !ruby/object:Gem::Requirement