ollama_chat 0.0.37 → 0.0.38

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: a8737b3ea415deaf19cbb41d63443f0fc2c3b6df1e5ae4e69f4043384a098623
4
- data.tar.gz: 70d915252d3c56a408b49d896f90e3a1373facd6eb7333365abf87c371435b6a
3
+ metadata.gz: 1702d897811e762ef2ba3b5018efcec7e55e01e96e14bbb56f09eb3be8d7d0a3
4
+ data.tar.gz: 0f27aa44e2574249ac90b4979a87afae0fc1b9f525643db523c7b392c7fad95a
5
5
  SHA512:
6
- metadata.gz: e61bbeb22039ef2e511ec1ad73f7e88f0cfb51d0ce2dbbc22633bed45f37fba958f768e02452894cbf0ba167db3e7705181f16962ecd8449f0b1d7046b7f2c78
7
- data.tar.gz: b914199f030b8a7472c7602a8b6fe119bc49fc587e56a1ae8d808388e99920dd16a4908516c7c568a1bb8c68e4766e28ad083fa2896621788dc15beb8250c299
6
+ metadata.gz: b686679959f9662811104f7e12951106cfaca0d7a9820878bd6885548c3b16090da2d5f6473cb95df5387b30ece2f06eb2225bf78a76c1124cd2bb84f2f0a8f1
7
+ data.tar.gz: 1b26360782e6018faf976c248aef147dc6e4938618eb95db287ca2cc4a2248c8ca7ca7ce45586d780e7e14cdc5d66a80ac2546f7d77843507e3b5194a60cd07b
data/.utilsrc CHANGED
@@ -59,7 +59,6 @@ code_indexer do
59
59
  tins
60
60
  unix_socks
61
61
  webmock
62
- xdg
63
62
  ]
64
63
 
65
64
  paths {
data/CHANGES.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-11-11 v0.0.38
4
+
5
+ - Added `ask?` method call to confirm overwriting existing files when saving
6
+ conversations
7
+ - Modified `save_conversation` in `OllamaChat::Conversation` to prompt before
8
+ overwriting
9
+ - Removed explicit file existence check from `MessageList#save_conversation`
10
+ - Both `/save` and `/output` commands now support overwrite confirmation
11
+ - Replace `write_file_unless_exist` method with `attempt_to_write_file`
12
+ - Add user confirmation prompt before overwriting existing files
13
+ - Update method documentation to reflect new overwrite behavior
14
+ - Modify file writing logic to use `attempt_to_write_file` instead of direct
15
+ write
16
+ - Update `output` method to check return value of `attempt_to_write_file`
17
+ before printing success message
18
+ - Removed `xdg` gem from the list of dependencies in `code_indexer` block
19
+
3
20
  ## 2025-10-31 v0.0.37
4
21
 
5
22
  - Refactored system prompt selection logic to use `case`/`when` statement
@@ -24,6 +24,9 @@ module OllamaChat::Conversation
24
24
  # @example Save conversation with explicit filename
25
25
  # chat.save_conversation('conversations/2023-10-15_my_session.json')
26
26
  def save_conversation(filename)
27
+ File.exist?(filename) &&
28
+ ask?(prompt: "File #{filename.inspect} already exists, overwrite? (y/n) ") !~ /\Ay/i and
29
+ return
27
30
  if messages.save_conversation(filename)
28
31
  STDOUT.puts "Saved conversation to #{filename.inspect}."
29
32
  else
@@ -124,10 +124,6 @@ class OllamaChat::MessageList
124
124
  #
125
125
  # @return [ OllamaChat::MessageList ] self
126
126
  def save_conversation(filename)
127
- if File.exist?(filename)
128
- STDERR.puts "File #{filename.inspect} already exists. Choose another filename."
129
- return
130
- end
131
127
  File.open(filename, ?w) do |output|
132
128
  output.puts JSON(@messages)
133
129
  end
@@ -43,18 +43,16 @@ module OllamaChat::MessageOutput
43
43
 
44
44
  # The output method writes the last assistant message to a file.
45
45
  #
46
- # @param filename [ String ] the path to the file where the output should be written
46
+ # @param filename [ String ] the path to the file where the last assistant
47
+ # message should be written
47
48
  #
48
- # @return [ Chat ] returns self on success, nil on failure
49
- #
50
- # @see write_file_unless_exist
51
- #
52
- # @note If no assistant message is available, an error message is printed to stderr.
49
+ # @return [ OllamaChat::Chat ] returns self
53
50
  def output(filename)
54
51
  if message = @messages.last and message.role == 'assistant'
55
52
  begin
56
- write_file_unless_exist(filename, message)
57
- STDOUT.puts "Last response was written to #{filename.inspect}."
53
+ if attempt_to_write_file(filename, message)
54
+ STDOUT.puts "Last response was written to #{filename.inspect}."
55
+ end
58
56
  self
59
57
  rescue => e
60
58
  STDERR.puts "Writing to #{filename.inspect}, caused #{e.class}: #{e}."
@@ -66,22 +64,29 @@ module OllamaChat::MessageOutput
66
64
 
67
65
  private
68
66
 
69
- # The write_file_unless_exist method creates a new file with the specified
70
- # message content, but only if a file with that name does not already exist.
67
+ # The attempt_to_write_file method handles writing content to a file with
68
+ # overwrite confirmation.
71
69
  #
72
- # @param filename [ String ] the path of the file to be created
70
+ # This method checks if a file already exists and prompts the user for
71
+ # confirmation before overwriting it. If the user declines or if the file
72
+ # doesn't exist, the method returns early without writing. Otherwise, it
73
+ # opens the file in write mode and writes the message content to it.
74
+ #
75
+ # @param filename [ String ] the path to the file where the content should be written
73
76
  # @param message [ Ollama::Message ] the message object containing the content to write
74
77
  #
75
- # @return [ TrueClass ] if the file was successfully created
76
- # @return [ nil ] if the file already exists and was not created
77
- def write_file_unless_exist(filename, message)
78
- if File.exist?(filename)
79
- STDERR.puts "File #{filename.inspect} already exists. Choose another filename."
78
+ # @return [ TrueClass ] returns true if the file was successfully written
79
+ # @return [ nil ] returns nil if the user chose not to overwrite or if an error occurred
80
+ def attempt_to_write_file(filename, message)
81
+ if !File.exist?(filename) ||
82
+ ask?(prompt: "File #{filename.inspect} already exists, overwrite? (y/n) ") =~ /\Ay/i
83
+ then
84
+ File.open(filename, ?w) do |output|
85
+ output.write(message.content)
86
+ end
87
+ else
80
88
  return
81
89
  end
82
- File.open(filename, ?w) do |output|
83
- output.write(message.content)
84
- end
85
90
  true
86
91
  end
87
92
  end
@@ -1,6 +1,6 @@
1
1
  module OllamaChat
2
2
  # OllamaChat version
3
- VERSION = '0.0.37'
3
+ VERSION = '0.0.38'
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/ollama_chat.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama_chat 0.0.37 ruby lib
2
+ # stub: ollama_chat 0.0.38 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama_chat".freeze
6
- s.version = "0.0.37".freeze
6
+ s.version = "0.0.38".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]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ollama_chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.37
4
+ version: 0.0.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank