matheus 0.7.1 → 0.9.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: ac93e4b9cc074bcacf3f6a1876bc7b3b64ed327b9311e38e06296bb0865326fd
4
- data.tar.gz: 1cea1255adfd37b392788346126c47b280e77fbb6efc0e81315e7b136fed3731
3
+ metadata.gz: 5987ece6a74065567cefd14df9cc39f228669eff6ce33eb0e439c2007087f074
4
+ data.tar.gz: 8c9e8e68b8a5b06e5f561f19d1af725a9cda77af588066fd441b5f6a1ea257c8
5
5
  SHA512:
6
- metadata.gz: 65ffbf0cf5faabd5ca15b6dece5e5f5c4be20b6667bac5d593cb529d85198611d9b3339e29acc3fe3751e93515f6a387317228b473ef62aa6854c0d8e3284930
7
- data.tar.gz: febd6039248df0aa1c7ec14be94fe5656a16a393646cab3e1e9564aad73a168a5556584e8e14addc95757440cfca49130929e39ff8eb6dde166c9ae973c85e9c
6
+ metadata.gz: ece556cbd069a9da7f4fd1c9b530a99cfa94c12d09951ea9ac4bdac46b47a33e4db9e6a3535a9df1f561b538b954337d93135f53763702868e6788edbf7c5389
7
+ data.tar.gz: 840f61d4eeb052f52011129d1e2c64823dcbe78742dd907642e6cb2741254429bdbf87f34e7395bda7563a3d771c60e20afae5e661a53854c3ffc304dbee452e
data/.standard.yml ADDED
@@ -0,0 +1 @@
1
+ ruby_version: 3.2
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.3.5
1
+ ruby 3.4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.9.0]
4
+
5
+ - Add `awake-for` command to keep the Mac awake for a given duration.
6
+
7
+ ## [0.8.0]
8
+
9
+ - Replace `ruby-openai` with `ruby_llm` in `q`.
10
+ - Change the `q` model from `gpt-4o-mini` to `gpt-5.4-nano`.
11
+ - Fix the `q` errors that occur when json 3.0 is installed.
12
+
3
13
  ## [0.7.1]
4
14
 
5
15
  - Update sound playback commands to run in the background with success status
data/README.md CHANGED
@@ -15,6 +15,15 @@ $ alert-me 'sleep 1 && echo "Done!"'
15
15
  Done!
16
16
  ```
17
17
 
18
+ ### [`awake-for`](./lib/matheus/awake_for.rb)
19
+
20
+ Keeps the Mac awake for the given duration, using `caffeinate`.
21
+
22
+ ```sh
23
+ $ awake-for 1h30m
24
+ Staying awake until 15:30. Press Ctrl-C to stop.
25
+ ```
26
+
18
27
  ### [`convert-currency`](./lib/matheus/convert_currency.rb)
19
28
 
20
29
  ```sh
data/exe/awake-for ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require "matheus"
6
+
7
+ Matheus::AwakeFor.call ARGV
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Matheus
4
+ # Usage:
5
+ # $ awake-for 4h
6
+ # $ awake-for 30min
7
+ # $ awake-for 1h30m
8
+ # Keeps the Mac awake for the given duration, using `caffeinate`.
9
+ class AwakeFor < Command
10
+ class Duration < Data.define(:seconds)
11
+ UNITS = {
12
+ "h" => 3600, "hr" => 3600, "hrs" => 3600, "hour" => 3600, "hours" => 3600,
13
+ "m" => 60, "min" => 60, "mins" => 60, "minute" => 60, "minutes" => 60,
14
+ "s" => 1, "sec" => 1, "secs" => 1, "second" => 1, "seconds" => 1
15
+ }.freeze
16
+ PART = /(\d+(?:\.\d+)?)\s*(#{Regexp.union(UNITS.keys.sort_by { -_1.size })})/
17
+ FORMAT = /\A(?:#{PART})+\z/
18
+
19
+ def self.parse(input)
20
+ input = input.downcase.delete(" ")
21
+ return unless input.match?(FORMAT)
22
+
23
+ seconds = input.scan(PART).sum { |amount, unit| UNITS.fetch(unit) * amount.to_f }
24
+ new(seconds.round) if seconds.positive?
25
+ end
26
+
27
+ def from_now = Time.now + seconds
28
+ end
29
+
30
+ def call(args)
31
+ input = args.join(" ")
32
+ duration = Duration.parse(input) or return Failure("invalid duration: #{input.inspect}. Try something like 4h, 30min or 1h30m.")
33
+
34
+ puts "Staying awake until #{duration.from_now.strftime("%H:%M")}. Press Ctrl-C to stop."
35
+ exec("caffeinate", "-dims", "-t", duration.seconds.to_s)
36
+ end
37
+ end
38
+ end
@@ -32,7 +32,7 @@ module Matheus
32
32
  def parse_args(args)
33
33
  first_arg = args.fetch(0) { raise "Missing amount or source currency" }
34
34
 
35
- if (amount = Float(first_arg) rescue nil) # standard:disable Style/RescueModifier
35
+ if (amount = Float(first_arg, exception: false))
36
36
  source = args.fetch(1) { raise "Missing source currency" }
37
37
  target = args.fetch(2) { raise "Missing target currency" }
38
38
  date = Date.parse(args.fetch(3, Date.today.to_s))
data/lib/matheus/q.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "openai"
1
+ require "ruby_llm"
2
2
  require "tty-markdown"
3
3
  require "tty-prompt"
4
4
  require "json"
@@ -21,7 +21,7 @@ module Matheus
21
21
  save_qa(question, answer)
22
22
  end
23
23
 
24
- answer.tap { |it| print_markdown(it) }
24
+ answer.tap { |text| print_markdown(text) }
25
25
  rescue => e
26
26
  Failure(e.message)
27
27
  end
@@ -31,26 +31,16 @@ module Matheus
31
31
  def ask_llm(question)
32
32
  raise "Question can't be blank." if question.blank?
33
33
 
34
- response = client.chat(
35
- parameters: {
36
- model: "gpt-4o-mini",
37
- messages: [{role: "user", content: "#{BASE_PROMPT}#{question}"}]
38
- }
39
- )
40
-
41
- raise response["error"]["message"] if response.has_key?("error")
42
-
43
- response.dig("choices", 0, "message", "content")
44
- rescue Faraday::ClientError => error
45
- raise error.response_body.dig("error", "message") || error
34
+ chat.ask("#{BASE_PROMPT}#{question}").content
46
35
  end
47
36
 
48
37
  def print_markdown(text)
49
38
  puts TTY::Markdown.parse(text)
50
39
  end
51
40
 
52
- def client
53
- OpenAI::Client.new(access_token: ENV.fetch("OPENAI_API_KEY"))
41
+ def chat
42
+ RubyLLM.configure { |config| config.openai_api_key = ENV.fetch("OPENAI_API_KEY") }
43
+ RubyLLM.chat(model: "gpt-5.4-nano")
54
44
  end
55
45
 
56
46
  def save_qa(question, answer)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Matheus
4
- VERSION = "0.7.1"
4
+ VERSION = "0.9.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matheus Richard
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-03-11 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: zeitwerk
@@ -39,19 +38,19 @@ dependencies:
39
38
  - !ruby/object:Gem::Version
40
39
  version: 7.2.0
41
40
  - !ruby/object:Gem::Dependency
42
- name: ruby-openai
41
+ name: ruby_llm
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: 7.1.0
46
+ version: '2.0'
48
47
  type: :runtime
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: 7.1.0
53
+ version: '2.0'
55
54
  - !ruby/object:Gem::Dependency
56
55
  name: tty-markdown
57
56
  requirement: !ruby/object:Gem::Requirement
@@ -113,6 +112,7 @@ email:
113
112
  - matheusrichardt@gmail.com
114
113
  executables:
115
114
  - alert-me
115
+ - awake-for
116
116
  - convert-currency
117
117
  - date-of-last
118
118
  - puts
@@ -123,12 +123,14 @@ extensions: []
123
123
  extra_rdoc_files: []
124
124
  files:
125
125
  - ".rspec"
126
+ - ".standard.yml"
126
127
  - ".tool-versions"
127
128
  - CHANGELOG.md
128
129
  - LICENSE.txt
129
130
  - README.md
130
131
  - Rakefile
131
132
  - exe/alert-me
133
+ - exe/awake-for
132
134
  - exe/convert-currency
133
135
  - exe/date-of-last
134
136
  - exe/puts
@@ -137,6 +139,7 @@ files:
137
139
  - exe/quick-commit
138
140
  - lib/matheus.rb
139
141
  - lib/matheus/alert_me.rb
142
+ - lib/matheus/awake_for.rb
140
143
  - lib/matheus/command.rb
141
144
  - lib/matheus/convert_currency.rb
142
145
  - lib/matheus/date_of_last.rb
@@ -154,7 +157,7 @@ metadata:
154
157
  homepage_uri: https://github.com/MatheusRich/matheus
155
158
  source_code_uri: https://github.com/MatheusRich/matheus
156
159
  changelog_uri: https://github.com/MatheusRich/matheus/blob/main/CHANGELOG.md
157
- post_install_message:
160
+ rubygems_mfa_required: 'true'
158
161
  rdoc_options: []
159
162
  require_paths:
160
163
  - lib
@@ -169,8 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
172
  - !ruby/object:Gem::Version
170
173
  version: '0'
171
174
  requirements: []
172
- rubygems_version: 3.5.16
173
- signing_key:
175
+ rubygems_version: 3.6.9
174
176
  specification_version: 4
175
177
  summary: A bunch of CLI tools I made for my own use.
176
178
  test_files: []