ollama_chat 0.0.53 → 0.0.55
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/CHANGES.md +41 -0
- data/README.md +1 -0
- data/bin/ollama_chat_send +1 -1
- data/lib/ollama_chat/chat.rb +4 -0
- data/lib/ollama_chat/information.rb +1 -0
- data/lib/ollama_chat/input_content.rb +4 -4
- data/lib/ollama_chat/message_editing.rb +47 -0
- data/lib/ollama_chat/version.rb +1 -1
- data/lib/ollama_chat/vim.rb +23 -1
- data/lib/ollama_chat.rb +1 -0
- data/ollama_chat.gemspec +5 -5
- data/spec/ollama_chat/input_content_spec.rb +127 -0
- data/spec/ollama_chat/message_editing_spec.rb +63 -0
- data/spec/ollama_chat/think_control_spec.rb +154 -0
- data/spec/ollama_chat/vim_spec.rb +88 -0
- metadata +11 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b2e00c933dc3118c04db47cbe4361fadcc500004a4f5ddd5aded07cea3bf6119
|
|
4
|
+
data.tar.gz: 5b959cdf55031620153e8176f69aaa1bb815872a03d8e1ae172fcc0e4b3d2977
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba54894c682fec7e4c3756d6875eb0644b0104a8affcb95b6b55d15416998ffdf667e8e308c21fb04a5191a67a646d7c4d11a2a0516fa20d122e25d825f00d62
|
|
7
|
+
data.tar.gz: e0590805be446b6512ff0fbe3e44e960360be18681e9cd557de20bda2f2c8b44cd59e96059a62bdca4db311a6dcdcf3cb7c0e710e3e56570ba980e3e20dc7948
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-01-08 v0.0.55
|
|
4
|
+
|
|
5
|
+
- Added `OllamaChat::Vim` class for inserting text into Vim buffers using the
|
|
6
|
+
clientserver protocol
|
|
7
|
+
- Implemented `server_name` and `clientserver` attribute readers for the
|
|
8
|
+
`OllamaChat::Vim` class
|
|
9
|
+
- Enhanced error message for missing vim server to include the specific server
|
|
10
|
+
name being used
|
|
11
|
+
- Added error handling to the `insert` method with fallback to `STDERR` output
|
|
12
|
+
when vim command fails
|
|
13
|
+
- Added comprehensive specs for `OllamaChat::Vim` module with **100%** coverage
|
|
14
|
+
- Fixed typo in help text for `ollama_chat_send` command ("reqired" →
|
|
15
|
+
"required")
|
|
16
|
+
- Added comprehensive tests for `ThinkControl` module with **100%** coverage
|
|
17
|
+
- Updated `README.md` and `OllamaChat::Information` to document the new
|
|
18
|
+
`/revise_last` command
|
|
19
|
+
- Improved test coverage for Vim integration
|
|
20
|
+
- Ensured proper state management and no side effects during selection in
|
|
21
|
+
`ThinkControl` tests
|
|
22
|
+
- All tests use `connect_to_ollama_server` for proper setup
|
|
23
|
+
- Fixed edge cases including exit conditions and nil selections in
|
|
24
|
+
`ThinkControl` tests
|
|
25
|
+
- Included tests for combined logic with `think_loud` switch in `ThinkControl`
|
|
26
|
+
tests
|
|
27
|
+
|
|
28
|
+
## 2026-01-08 v0.0.54
|
|
29
|
+
|
|
30
|
+
### New Features
|
|
31
|
+
|
|
32
|
+
- Added `/revise_last` command for editing the last message
|
|
33
|
+
- Implemented `OllamaChat::MessageEditing` module with editor integration
|
|
34
|
+
- Enhanced message editing with proper error handling and user feedback
|
|
35
|
+
|
|
36
|
+
### Improvements
|
|
37
|
+
|
|
38
|
+
- Improved `InputContent` module with better error handling (replaced `$?` with
|
|
39
|
+
direct `system` return)
|
|
40
|
+
- Updated `choose_filename` to use `_1` parameter for Ruby idioms
|
|
41
|
+
- Added comprehensive test suite for `InputContent` module with **100%** line
|
|
42
|
+
coverage
|
|
43
|
+
|
|
3
44
|
## 2026-01-07 v0.0.53
|
|
4
45
|
|
|
5
46
|
- Added `/compose` command functionality to compose content using an external
|
data/README.md
CHANGED
|
@@ -183,6 +183,7 @@ The following commands can be given inside the chat, if prefixed by a `/`:
|
|
|
183
183
|
/compose compose content using an EDITOR
|
|
184
184
|
/input [pattern] select and read content from a file (default: **/*)
|
|
185
185
|
/context [pattern...] collect context with glob patterns
|
|
186
|
+
/revise_last edit the last response in an external editor
|
|
186
187
|
/output filename save last response to filename
|
|
187
188
|
/pipe command write last response to command's stdin
|
|
188
189
|
/vim insert the last message into a vim server
|
data/bin/ollama_chat_send
CHANGED
|
@@ -25,7 +25,7 @@ def usage(rc = 0)
|
|
|
25
25
|
-d DIR the working directory to derive the socket file from
|
|
26
26
|
-h Show this help message
|
|
27
27
|
|
|
28
|
-
Send data to a running
|
|
28
|
+
Send data to a running Ollama Chat client via standard input.
|
|
29
29
|
EOT
|
|
30
30
|
exit rc
|
|
31
31
|
end
|
data/lib/ollama_chat/chat.rb
CHANGED
|
@@ -51,6 +51,7 @@ class OllamaChat::Chat
|
|
|
51
51
|
include OllamaChat::KramdownANSI
|
|
52
52
|
include OllamaChat::Conversation
|
|
53
53
|
include OllamaChat::InputContent
|
|
54
|
+
include OllamaChat::MessageEditing
|
|
54
55
|
|
|
55
56
|
# Initializes a new OllamaChat::Chat instance with the given command-line
|
|
56
57
|
# arguments.
|
|
@@ -340,6 +341,9 @@ class OllamaChat::Chat
|
|
|
340
341
|
context_spook(patterns) or :next
|
|
341
342
|
when %r(^/compose$)
|
|
342
343
|
compose or :next
|
|
344
|
+
when %r(^/revise_last$)
|
|
345
|
+
revise_last
|
|
346
|
+
:next
|
|
343
347
|
when %r(^/save\s+(.+)$)
|
|
344
348
|
save_conversation($1)
|
|
345
349
|
:next
|
|
@@ -150,6 +150,7 @@ module OllamaChat::Information
|
|
|
150
150
|
/compose compose content using an EDITOR
|
|
151
151
|
/input [pattern] select and read content from a file (default: **/*)
|
|
152
152
|
/context [pattern...] collect context with glob patterns
|
|
153
|
+
/revise_last edit the last response in an external editor
|
|
153
154
|
/output filename save last response to filename
|
|
154
155
|
/pipe command write last response to command's stdin
|
|
155
156
|
/vim insert the last message into a vim server
|
|
@@ -36,7 +36,7 @@ module OllamaChat::InputContent
|
|
|
36
36
|
#
|
|
37
37
|
# @return [ String, nil ] the path to the selected file or nil if no file was chosen
|
|
38
38
|
def choose_filename(pattern)
|
|
39
|
-
files = Dir.glob(pattern).select { File.file?(
|
|
39
|
+
files = Dir.glob(pattern).select { File.file?(_1) }
|
|
40
40
|
files.unshift('[EXIT]')
|
|
41
41
|
case chosen = OllamaChat::Utils::Chooser.choose(files)
|
|
42
42
|
when '[EXIT]', nil
|
|
@@ -102,13 +102,13 @@ module OllamaChat::InputContent
|
|
|
102
102
|
# @return [ String, nil ] the composed content if successful, nil otherwise
|
|
103
103
|
def compose
|
|
104
104
|
unless editor = OllamaChat::EnvConfig::EDITOR?
|
|
105
|
-
STDERR.puts "Editor
|
|
105
|
+
STDERR.puts "Editor required for compose, set env var "\
|
|
106
106
|
"#{OllamaChat::EnvConfig::EDITOR!.env_var.inspect}."
|
|
107
107
|
return
|
|
108
108
|
end
|
|
109
109
|
Tempfile.open do |tmp|
|
|
110
|
-
system %{#{editor} #{tmp.path.inspect}}
|
|
111
|
-
if
|
|
110
|
+
result = system %{#{editor} #{tmp.path.inspect}}
|
|
111
|
+
if result
|
|
112
112
|
return File.read(tmp.path)
|
|
113
113
|
else
|
|
114
114
|
STDERR.puts "Editor failed to edit #{tmp.path.inspect}."
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# A module that provides message editing functionality for OllamaChat.
|
|
2
|
+
#
|
|
3
|
+
# The MessageEditing module encapsulates methods for modifying existing chat
|
|
4
|
+
# messages using an external editor. It allows users to edit the last message
|
|
5
|
+
# in the conversation, whether it's a system prompt, user message, or assistant
|
|
6
|
+
# response.
|
|
7
|
+
module OllamaChat::MessageEditing
|
|
8
|
+
# The revise_last method opens the last message in an external editor for
|
|
9
|
+
# modification.
|
|
10
|
+
#
|
|
11
|
+
# This method retrieves the last message from the conversation, writes its
|
|
12
|
+
# content to a temporary file, opens that file in the configured editor,
|
|
13
|
+
# and then updates the message with the edited content upon successful
|
|
14
|
+
# completion.
|
|
15
|
+
#
|
|
16
|
+
# @return [String, nil] the edited content if successful, nil otherwise
|
|
17
|
+
def revise_last
|
|
18
|
+
if message = @messages.last
|
|
19
|
+
unless editor = OllamaChat::EnvConfig::EDITOR?
|
|
20
|
+
STDERR.puts "Editor required for revise, set env var " \
|
|
21
|
+
"#{OllamaChat::EnvConfig::EDITOR!.env_var.inspect}."
|
|
22
|
+
return
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
Tempfile.open do |tmp|
|
|
26
|
+
tmp.write(message.content)
|
|
27
|
+
tmp.flush
|
|
28
|
+
|
|
29
|
+
result = system %{#{editor} #{tmp.path.inspect}}
|
|
30
|
+
|
|
31
|
+
if result
|
|
32
|
+
new_content = File.read(tmp.path)
|
|
33
|
+
old_message = @messages.messages.pop.as_json
|
|
34
|
+
old_message[:content] = new_content
|
|
35
|
+
@messages << Ollama::Message.from_hash(old_message)
|
|
36
|
+
STDOUT.puts "Message edited and updated."
|
|
37
|
+
return new_content
|
|
38
|
+
else
|
|
39
|
+
STDERR.puts "Editor failed to edit message."
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
else
|
|
43
|
+
STDERR.puts "No message available to revise."
|
|
44
|
+
end
|
|
45
|
+
nil
|
|
46
|
+
end
|
|
47
|
+
end
|
data/lib/ollama_chat/version.rb
CHANGED
data/lib/ollama_chat/vim.rb
CHANGED
|
@@ -27,6 +27,18 @@ class OllamaChat::Vim
|
|
|
27
27
|
@clientserver = clientserver || 'socket'
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
# The server_name attribute reader returns the name of the Vim server to
|
|
31
|
+
# connect to.
|
|
32
|
+
#
|
|
33
|
+
# @return [ String ] the name of the Vim server
|
|
34
|
+
attr_reader :server_name
|
|
35
|
+
|
|
36
|
+
# The clientserver attribute reader returns the clientserver protocol to be
|
|
37
|
+
# used.
|
|
38
|
+
#
|
|
39
|
+
# @return [ String ] the clientserver protocol identifier
|
|
40
|
+
attr_reader :clientserver
|
|
41
|
+
|
|
30
42
|
# The default_server_name method generates a standardized server name
|
|
31
43
|
# based on a given name or the current working directory.
|
|
32
44
|
#
|
|
@@ -54,14 +66,24 @@ class OllamaChat::Vim
|
|
|
54
66
|
# The text is automatically indented to match the current column position.
|
|
55
67
|
#
|
|
56
68
|
# @param text [String] The text to be inserted into the Vim buffer
|
|
69
|
+
# @return [OllamaChat::Vim, nil] Returns self if successful or nil.
|
|
57
70
|
def insert(text)
|
|
58
71
|
spaces = (col - 1).clamp(0..)
|
|
59
72
|
text = text.gsub(/^/, ' ' * spaces)
|
|
60
73
|
Tempfile.open do |tmp|
|
|
61
74
|
tmp.write(text)
|
|
62
75
|
tmp.flush
|
|
63
|
-
system %{
|
|
76
|
+
result = system %{
|
|
77
|
+
vim --clientserver "#@clientserver" --servername "#@server_name" --remote-send "<ESC>:r #{tmp.path}<CR>"
|
|
78
|
+
}
|
|
79
|
+
unless result
|
|
80
|
+
STDERR.puts <<~EOT
|
|
81
|
+
Failed! vim is required in path and running with server name "#@server_name".
|
|
82
|
+
EOT
|
|
83
|
+
return
|
|
84
|
+
end
|
|
64
85
|
end
|
|
86
|
+
self
|
|
65
87
|
end
|
|
66
88
|
|
|
67
89
|
# Returns the current column position of the cursor in the Vim server
|
data/lib/ollama_chat.rb
CHANGED
data/ollama_chat.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: ollama_chat 0.0.
|
|
2
|
+
# stub: ollama_chat 0.0.55 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "ollama_chat".freeze
|
|
6
|
-
s.version = "0.0.
|
|
6
|
+
s.version = "0.0.55".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]
|
|
@@ -12,15 +12,15 @@ Gem::Specification.new do |s|
|
|
|
12
12
|
s.description = "The app provides a command-line interface (CLI) to an Ollama AI model,\nallowing users to engage in text-based conversations and generate\nhuman-like responses. Users can import data from local files or web pages,\nwhich are then processed through three different modes: fully importing the\ncontent into the conversation context, summarizing the information for\nconcise reference, or storing it in an embedding vector database for later\nretrieval based on the conversation.\n".freeze
|
|
13
13
|
s.email = "flori@ping.de".freeze
|
|
14
14
|
s.executables = ["ollama_chat".freeze, "ollama_chat_send".freeze]
|
|
15
|
-
s.extra_rdoc_files = ["README.md".freeze, "lib/ollama_chat.rb".freeze, "lib/ollama_chat/chat.rb".freeze, "lib/ollama_chat/clipboard.rb".freeze, "lib/ollama_chat/conversation.rb".freeze, "lib/ollama_chat/dialog.rb".freeze, "lib/ollama_chat/document_cache.rb".freeze, "lib/ollama_chat/env_config.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/input_content.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_format.rb".freeze, "lib/ollama_chat/message_list.rb".freeze, "lib/ollama_chat/message_output.rb".freeze, "lib/ollama_chat/model_handling.rb".freeze, "lib/ollama_chat/ollama_chat_config.rb".freeze, "lib/ollama_chat/parsing.rb".freeze, "lib/ollama_chat/redis_cache.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/think_control.rb".freeze, "lib/ollama_chat/utils.rb".freeze, "lib/ollama_chat/utils/cache_fetcher.rb".freeze, "lib/ollama_chat/utils/chooser.rb".freeze, "lib/ollama_chat/utils/fetcher.rb".freeze, "lib/ollama_chat/utils/file_argument.rb".freeze, "lib/ollama_chat/version.rb".freeze, "lib/ollama_chat/vim.rb".freeze, "lib/ollama_chat/web_searching.rb".freeze]
|
|
16
|
-
s.files = [".utilsrc".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_chat".freeze, "bin/ollama_chat_send".freeze, "config/searxng/settings.yml".freeze, "docker-compose.yml".freeze, "lib/ollama_chat.rb".freeze, "lib/ollama_chat/chat.rb".freeze, "lib/ollama_chat/clipboard.rb".freeze, "lib/ollama_chat/conversation.rb".freeze, "lib/ollama_chat/dialog.rb".freeze, "lib/ollama_chat/document_cache.rb".freeze, "lib/ollama_chat/env_config.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/input_content.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_format.rb".freeze, "lib/ollama_chat/message_list.rb".freeze, "lib/ollama_chat/message_output.rb".freeze, "lib/ollama_chat/model_handling.rb".freeze, "lib/ollama_chat/ollama_chat_config.rb".freeze, "lib/ollama_chat/ollama_chat_config/default_config.yml".freeze, "lib/ollama_chat/parsing.rb".freeze, "lib/ollama_chat/redis_cache.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/think_control.rb".freeze, "lib/ollama_chat/utils.rb".freeze, "lib/ollama_chat/utils/cache_fetcher.rb".freeze, "lib/ollama_chat/utils/chooser.rb".freeze, "lib/ollama_chat/utils/fetcher.rb".freeze, "lib/ollama_chat/utils/file_argument.rb".freeze, "lib/ollama_chat/version.rb".freeze, "lib/ollama_chat/vim.rb".freeze, "lib/ollama_chat/web_searching.rb".freeze, "ollama_chat.gemspec".freeze, "redis/redis.conf".freeze, "spec/assets/api_show.json".freeze, "spec/assets/api_tags.json".freeze, "spec/assets/api_version.json".freeze, "spec/assets/conversation.json".freeze, "spec/assets/duckduckgo.html".freeze, "spec/assets/example.atom".freeze, "spec/assets/example.csv".freeze, "spec/assets/example.html".freeze, "spec/assets/example.pdf".freeze, "spec/assets/example.ps".freeze, "spec/assets/example.rb".freeze, "spec/assets/example.rss".freeze, "spec/assets/example.xml".freeze, "spec/assets/example_with_quote.html".freeze, "spec/assets/kitten.jpg".freeze, "spec/assets/prompt.txt".freeze, "spec/assets/searxng.json".freeze, "spec/ollama_chat/chat_spec.rb".freeze, "spec/ollama_chat/clipboard_spec.rb".freeze, "spec/ollama_chat/follow_chat_spec.rb".freeze, "spec/ollama_chat/information_spec.rb".freeze, "spec/ollama_chat/kramdown_ansi_spec.rb".freeze, "spec/ollama_chat/message_list_spec.rb".freeze, "spec/ollama_chat/message_output_spec.rb".freeze, "spec/ollama_chat/model_handling_spec.rb".freeze, "spec/ollama_chat/parsing_spec.rb".freeze, "spec/ollama_chat/redis_cache_spec.rb".freeze, "spec/ollama_chat/server_socket_spec.rb".freeze, "spec/ollama_chat/source_fetching_spec.rb".freeze, "spec/ollama_chat/switches_spec.rb".freeze, "spec/ollama_chat/utils/cache_fetcher_spec.rb".freeze, "spec/ollama_chat/utils/fetcher_spec.rb".freeze, "spec/ollama_chat/utils/file_argument_spec.rb".freeze, "spec/ollama_chat/web_searching_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tmp/.keep".freeze]
|
|
15
|
+
s.extra_rdoc_files = ["README.md".freeze, "lib/ollama_chat.rb".freeze, "lib/ollama_chat/chat.rb".freeze, "lib/ollama_chat/clipboard.rb".freeze, "lib/ollama_chat/conversation.rb".freeze, "lib/ollama_chat/dialog.rb".freeze, "lib/ollama_chat/document_cache.rb".freeze, "lib/ollama_chat/env_config.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/input_content.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_editing.rb".freeze, "lib/ollama_chat/message_format.rb".freeze, "lib/ollama_chat/message_list.rb".freeze, "lib/ollama_chat/message_output.rb".freeze, "lib/ollama_chat/model_handling.rb".freeze, "lib/ollama_chat/ollama_chat_config.rb".freeze, "lib/ollama_chat/parsing.rb".freeze, "lib/ollama_chat/redis_cache.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/think_control.rb".freeze, "lib/ollama_chat/utils.rb".freeze, "lib/ollama_chat/utils/cache_fetcher.rb".freeze, "lib/ollama_chat/utils/chooser.rb".freeze, "lib/ollama_chat/utils/fetcher.rb".freeze, "lib/ollama_chat/utils/file_argument.rb".freeze, "lib/ollama_chat/version.rb".freeze, "lib/ollama_chat/vim.rb".freeze, "lib/ollama_chat/web_searching.rb".freeze]
|
|
16
|
+
s.files = [".utilsrc".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_chat".freeze, "bin/ollama_chat_send".freeze, "config/searxng/settings.yml".freeze, "docker-compose.yml".freeze, "lib/ollama_chat.rb".freeze, "lib/ollama_chat/chat.rb".freeze, "lib/ollama_chat/clipboard.rb".freeze, "lib/ollama_chat/conversation.rb".freeze, "lib/ollama_chat/dialog.rb".freeze, "lib/ollama_chat/document_cache.rb".freeze, "lib/ollama_chat/env_config.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/input_content.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_editing.rb".freeze, "lib/ollama_chat/message_format.rb".freeze, "lib/ollama_chat/message_list.rb".freeze, "lib/ollama_chat/message_output.rb".freeze, "lib/ollama_chat/model_handling.rb".freeze, "lib/ollama_chat/ollama_chat_config.rb".freeze, "lib/ollama_chat/ollama_chat_config/default_config.yml".freeze, "lib/ollama_chat/parsing.rb".freeze, "lib/ollama_chat/redis_cache.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/think_control.rb".freeze, "lib/ollama_chat/utils.rb".freeze, "lib/ollama_chat/utils/cache_fetcher.rb".freeze, "lib/ollama_chat/utils/chooser.rb".freeze, "lib/ollama_chat/utils/fetcher.rb".freeze, "lib/ollama_chat/utils/file_argument.rb".freeze, "lib/ollama_chat/version.rb".freeze, "lib/ollama_chat/vim.rb".freeze, "lib/ollama_chat/web_searching.rb".freeze, "ollama_chat.gemspec".freeze, "redis/redis.conf".freeze, "spec/assets/api_show.json".freeze, "spec/assets/api_tags.json".freeze, "spec/assets/api_version.json".freeze, "spec/assets/conversation.json".freeze, "spec/assets/duckduckgo.html".freeze, "spec/assets/example.atom".freeze, "spec/assets/example.csv".freeze, "spec/assets/example.html".freeze, "spec/assets/example.pdf".freeze, "spec/assets/example.ps".freeze, "spec/assets/example.rb".freeze, "spec/assets/example.rss".freeze, "spec/assets/example.xml".freeze, "spec/assets/example_with_quote.html".freeze, "spec/assets/kitten.jpg".freeze, "spec/assets/prompt.txt".freeze, "spec/assets/searxng.json".freeze, "spec/ollama_chat/chat_spec.rb".freeze, "spec/ollama_chat/clipboard_spec.rb".freeze, "spec/ollama_chat/follow_chat_spec.rb".freeze, "spec/ollama_chat/information_spec.rb".freeze, "spec/ollama_chat/input_content_spec.rb".freeze, "spec/ollama_chat/kramdown_ansi_spec.rb".freeze, "spec/ollama_chat/message_editing_spec.rb".freeze, "spec/ollama_chat/message_list_spec.rb".freeze, "spec/ollama_chat/message_output_spec.rb".freeze, "spec/ollama_chat/model_handling_spec.rb".freeze, "spec/ollama_chat/parsing_spec.rb".freeze, "spec/ollama_chat/redis_cache_spec.rb".freeze, "spec/ollama_chat/server_socket_spec.rb".freeze, "spec/ollama_chat/source_fetching_spec.rb".freeze, "spec/ollama_chat/switches_spec.rb".freeze, "spec/ollama_chat/think_control_spec.rb".freeze, "spec/ollama_chat/utils/cache_fetcher_spec.rb".freeze, "spec/ollama_chat/utils/fetcher_spec.rb".freeze, "spec/ollama_chat/utils/file_argument_spec.rb".freeze, "spec/ollama_chat/vim_spec.rb".freeze, "spec/ollama_chat/web_searching_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tmp/.keep".freeze]
|
|
17
17
|
s.homepage = "https://github.com/flori/ollama_chat".freeze
|
|
18
18
|
s.licenses = ["MIT".freeze]
|
|
19
19
|
s.rdoc_options = ["--title".freeze, "OllamaChat - A command-line interface (CLI) for interacting with an Ollama AI model.".freeze, "--main".freeze, "README.md".freeze]
|
|
20
20
|
s.required_ruby_version = Gem::Requirement.new(">= 3.2".freeze)
|
|
21
21
|
s.rubygems_version = "4.0.2".freeze
|
|
22
22
|
s.summary = "A command-line interface (CLI) for interacting with an Ollama AI model.".freeze
|
|
23
|
-
s.test_files = ["spec/assets/example.rb".freeze, "spec/ollama_chat/chat_spec.rb".freeze, "spec/ollama_chat/clipboard_spec.rb".freeze, "spec/ollama_chat/follow_chat_spec.rb".freeze, "spec/ollama_chat/information_spec.rb".freeze, "spec/ollama_chat/kramdown_ansi_spec.rb".freeze, "spec/ollama_chat/message_list_spec.rb".freeze, "spec/ollama_chat/message_output_spec.rb".freeze, "spec/ollama_chat/model_handling_spec.rb".freeze, "spec/ollama_chat/parsing_spec.rb".freeze, "spec/ollama_chat/redis_cache_spec.rb".freeze, "spec/ollama_chat/server_socket_spec.rb".freeze, "spec/ollama_chat/source_fetching_spec.rb".freeze, "spec/ollama_chat/switches_spec.rb".freeze, "spec/ollama_chat/utils/cache_fetcher_spec.rb".freeze, "spec/ollama_chat/utils/fetcher_spec.rb".freeze, "spec/ollama_chat/utils/file_argument_spec.rb".freeze, "spec/ollama_chat/web_searching_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
|
23
|
+
s.test_files = ["spec/assets/example.rb".freeze, "spec/ollama_chat/chat_spec.rb".freeze, "spec/ollama_chat/clipboard_spec.rb".freeze, "spec/ollama_chat/follow_chat_spec.rb".freeze, "spec/ollama_chat/information_spec.rb".freeze, "spec/ollama_chat/input_content_spec.rb".freeze, "spec/ollama_chat/kramdown_ansi_spec.rb".freeze, "spec/ollama_chat/message_editing_spec.rb".freeze, "spec/ollama_chat/message_list_spec.rb".freeze, "spec/ollama_chat/message_output_spec.rb".freeze, "spec/ollama_chat/model_handling_spec.rb".freeze, "spec/ollama_chat/parsing_spec.rb".freeze, "spec/ollama_chat/redis_cache_spec.rb".freeze, "spec/ollama_chat/server_socket_spec.rb".freeze, "spec/ollama_chat/source_fetching_spec.rb".freeze, "spec/ollama_chat/switches_spec.rb".freeze, "spec/ollama_chat/think_control_spec.rb".freeze, "spec/ollama_chat/utils/cache_fetcher_spec.rb".freeze, "spec/ollama_chat/utils/fetcher_spec.rb".freeze, "spec/ollama_chat/utils/file_argument_spec.rb".freeze, "spec/ollama_chat/vim_spec.rb".freeze, "spec/ollama_chat/web_searching_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
|
24
24
|
|
|
25
25
|
s.specification_version = 4
|
|
26
26
|
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe OllamaChat::InputContent do
|
|
4
|
+
let :chat do
|
|
5
|
+
OllamaChat::Chat.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
connect_to_ollama_server
|
|
9
|
+
|
|
10
|
+
describe '#input' do
|
|
11
|
+
it 'can read content from a selected file' do
|
|
12
|
+
# Mock the file selection process
|
|
13
|
+
expect(chat).to receive(:choose_filename).with('**/*').
|
|
14
|
+
and_return('spec/assets/example.rb')
|
|
15
|
+
|
|
16
|
+
# Test that it returns the file content
|
|
17
|
+
result = chat.input(nil)
|
|
18
|
+
expect(result).to include('puts "Hello World!"')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'returns nil when no file is selected' do
|
|
22
|
+
expect(chat).to receive(:choose_filename).with('**/*').and_return(nil)
|
|
23
|
+
expect(chat.input(nil)).to be_nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'can read content with specific pattern' do
|
|
27
|
+
expect(chat).to receive(:choose_filename).with('spec/assets/*').
|
|
28
|
+
and_return('spec/assets/example.rb')
|
|
29
|
+
result = chat.input('spec/assets/*')
|
|
30
|
+
expect(result).to include('puts "Hello World!"')
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe '#choose_filename' do
|
|
35
|
+
it 'can select a file from matching patterns' do
|
|
36
|
+
# Test with a pattern that matches existing files
|
|
37
|
+
files = Dir.glob('spec/assets/*')
|
|
38
|
+
expect(files).to_not be_empty
|
|
39
|
+
|
|
40
|
+
# Mock the selection process
|
|
41
|
+
expect(OllamaChat::Utils::Chooser).to receive(:choose).
|
|
42
|
+
with(files.unshift('[EXIT]')).and_return(files[1])
|
|
43
|
+
|
|
44
|
+
result = chat.choose_filename('spec/assets/*')
|
|
45
|
+
expect(result).to eq files[1]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'returns nil when user exits selection' do
|
|
49
|
+
expect(OllamaChat::Utils::Chooser).to receive(:choose).and_return(nil)
|
|
50
|
+
expect(chat.choose_filename('spec/assets/*')).to be_nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'returns nil when user chooses exit' do
|
|
54
|
+
expect(OllamaChat::Utils::Chooser).to receive(:choose).and_return('[EXIT]')
|
|
55
|
+
expect(chat.choose_filename('spec/assets/*')).to be_nil
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe '#context_spook' do
|
|
60
|
+
it 'can collect context with patterns' do
|
|
61
|
+
# Test with specific patterns
|
|
62
|
+
patterns = ['spec/assets/example.rb']
|
|
63
|
+
expect(ContextSpook).to receive(:generate_context).with(hash_including(verbose: true))
|
|
64
|
+
|
|
65
|
+
# This should not raise an error, but return nil since we're not mocking the full implementation
|
|
66
|
+
expect { chat.context_spook(patterns) }.not_to raise_error
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'can load default context when no patterns provided' do
|
|
70
|
+
# Mock finding a context definition file
|
|
71
|
+
filename = '.contexts/code_comment.rb'
|
|
72
|
+
expect(chat).to receive(:choose_filename).with('.contexts/*.rb').
|
|
73
|
+
and_return(filename)
|
|
74
|
+
|
|
75
|
+
expect(ContextSpook).to receive(:generate_context).
|
|
76
|
+
with(filename, hash_including(verbose: true))
|
|
77
|
+
|
|
78
|
+
# This should not raise an error
|
|
79
|
+
expect { chat.context_spook(nil) }.not_to raise_error
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'returns nil when no context file is found' do
|
|
83
|
+
expect(chat).to receive(:choose_filename).with('.contexts/*.rb').
|
|
84
|
+
and_return(nil)
|
|
85
|
+
expect(chat.context_spook(nil)).to be_nil
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe '#compose' do
|
|
90
|
+
it 'can open editor to compose content' do
|
|
91
|
+
# Mock editor configuration
|
|
92
|
+
const_conf_as('OllamaChat::EnvConfig::EDITOR' => '/usr/bin/vim')
|
|
93
|
+
|
|
94
|
+
# Mock Tempfile behavior
|
|
95
|
+
tmp_double = double('tmp', path: '/tmp/test')
|
|
96
|
+
expect(Tempfile).to receive(:open).and_yield(tmp_double)
|
|
97
|
+
|
|
98
|
+
# Mock system call to simulate successful editor execution
|
|
99
|
+
expect(chat).to receive(:system).with('/usr/bin/vim "/tmp/test"').and_return(true)
|
|
100
|
+
|
|
101
|
+
# Mock file reading to return content
|
|
102
|
+
expect(File).to receive(:read).with('/tmp/test').and_return('composed content')
|
|
103
|
+
|
|
104
|
+
result = chat.compose
|
|
105
|
+
expect(result).to eq 'composed content'
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'handles missing editor gracefully' do
|
|
109
|
+
const_conf_as('OllamaChat::EnvConfig::EDITOR' => nil)
|
|
110
|
+
|
|
111
|
+
expect(STDERR).to receive(:puts).with(/Editor required for compose/)
|
|
112
|
+
expect(chat.compose).to be_nil
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'handles editor failure' do
|
|
116
|
+
const_conf_as('OllamaChat::EnvConfig::EDITOR' => '/usr/bin/vim')
|
|
117
|
+
|
|
118
|
+
tmp_double = double('tmp', path: '/tmp/test')
|
|
119
|
+
expect(Tempfile).to receive(:open).and_yield(tmp_double)
|
|
120
|
+
|
|
121
|
+
expect(chat).to receive(:system).with('/usr/bin/vim "/tmp/test"').and_return(false)
|
|
122
|
+
|
|
123
|
+
expect(STDERR).to receive(:puts).with(/Editor failed to edit/)
|
|
124
|
+
expect(chat.compose).to be_nil
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe OllamaChat::MessageEditing do
|
|
4
|
+
let :chat do
|
|
5
|
+
OllamaChat::Chat.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
connect_to_ollama_server
|
|
9
|
+
|
|
10
|
+
describe '#revise_last' do
|
|
11
|
+
it 'can revise the last message' do
|
|
12
|
+
# First add a message to work with
|
|
13
|
+
chat.messages << Ollama::Message.new(role: 'assistant', content: 'original content')
|
|
14
|
+
|
|
15
|
+
const_conf_as('OllamaChat::EnvConfig::EDITOR' => '/usr/bin/vim')
|
|
16
|
+
|
|
17
|
+
# Mock Tempfile behavior to simulate editor interaction
|
|
18
|
+
tmp_double = double('tmp', write: true, flush: true, path: '/tmp/test')
|
|
19
|
+
expect(Tempfile).to receive(:open).and_yield(tmp_double)
|
|
20
|
+
|
|
21
|
+
# Mock system call to simulate successful editor execution
|
|
22
|
+
expect(chat).to receive(:system).with('/usr/bin/vim "/tmp/test"').and_return(true)
|
|
23
|
+
|
|
24
|
+
# Mock file reading to return edited content
|
|
25
|
+
expect(File).to receive(:read).with('/tmp/test').and_return('edited content')
|
|
26
|
+
|
|
27
|
+
# The method should return the edited content
|
|
28
|
+
expect(chat.revise_last).to eq 'edited content'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'handles missing last message' do
|
|
32
|
+
expect(STDERR).to receive(:puts).with(/No message available to revise/)
|
|
33
|
+
expect(chat.revise_last).to be_nil
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'handles missing editor gracefully' do
|
|
37
|
+
chat.messages << Ollama::Message.new(role: 'assistant', content: 'original content')
|
|
38
|
+
|
|
39
|
+
const_conf_as('OllamaChat::EnvConfig::EDITOR' => nil)
|
|
40
|
+
|
|
41
|
+
expect(STDERR).to receive(:puts).with(/Editor required for revise/)
|
|
42
|
+
expect(chat.revise_last).to be_nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'handles no messages to revise' do
|
|
46
|
+
# Clear messages array
|
|
47
|
+
chat.instance_variable_get(:@messages).clear
|
|
48
|
+
|
|
49
|
+
expect(STDERR).to receive(:puts).with(/No message available to revise/)
|
|
50
|
+
expect(chat.revise_last).to be_nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'handles editor failure' do
|
|
54
|
+
const_conf_as('OllamaChat::EnvConfig::EDITOR' => '/usr/bin/vim')
|
|
55
|
+
chat.messages << Ollama::Message.new(role: 'assistant', content: 'original content')
|
|
56
|
+
tmp_double = double('tmp', write: true, flush: true, path: '/tmp/test')
|
|
57
|
+
expect(Tempfile).to receive(:open).and_yield(tmp_double)
|
|
58
|
+
expect(chat).to receive(:system).with('/usr/bin/vim "/tmp/test"').and_return(false)
|
|
59
|
+
expect(STDERR).to receive(:puts).with(/Editor failed to edit message/)
|
|
60
|
+
expect(chat.revise_last).to be_nil
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe OllamaChat::ThinkControl do
|
|
4
|
+
let :chat do
|
|
5
|
+
OllamaChat::Chat.new(
|
|
6
|
+
argv: %w[ -f lib/ollama_chat/ollama_chat_config/default_config.yml ]
|
|
7
|
+
)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
connect_to_ollama_server
|
|
11
|
+
|
|
12
|
+
describe '#think' do
|
|
13
|
+
it 'returns the current think mode state' do
|
|
14
|
+
expect(chat.think).to be false
|
|
15
|
+
chat.instance_variable_set(:@think, true)
|
|
16
|
+
expect(chat.think).to be true
|
|
17
|
+
chat.instance_variable_set(:@think, false)
|
|
18
|
+
expect(chat.think).to be false
|
|
19
|
+
chat.instance_variable_set(:@think, 'low')
|
|
20
|
+
expect(chat.think).to eq 'low'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe '#think?' do
|
|
25
|
+
it 'returns true when think mode is enabled (boolean true)' do
|
|
26
|
+
chat.instance_variable_set(:@think, true)
|
|
27
|
+
expect(chat.think?).to be true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'returns true when think mode is enabled (string value)' do
|
|
31
|
+
chat.instance_variable_set(:@think, 'high')
|
|
32
|
+
expect(chat.think?).to be true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'returns false when think mode is disabled (boolean false)' do
|
|
36
|
+
chat.instance_variable_set(:@think, false)
|
|
37
|
+
expect(chat.think?).to be false
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'returns false when think mode is nil' do
|
|
41
|
+
chat.instance_variable_set(:@think, nil)
|
|
42
|
+
expect(chat.think?).to be false
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe '#think_mode' do
|
|
47
|
+
it 'returns "enabled" when think is true' do
|
|
48
|
+
chat.instance_variable_set(:@think, true)
|
|
49
|
+
expect(chat.think_mode).to eq 'enabled'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'returns the think value when it is a string' do
|
|
53
|
+
chat.instance_variable_set(:@think, 'medium')
|
|
54
|
+
expect(chat.think_mode).to eq 'medium'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'returns "disabled" when think is false' do
|
|
58
|
+
chat.instance_variable_set(:@think, false)
|
|
59
|
+
expect(chat.think_mode).to eq 'disabled'
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'returns "disabled" when think is nil' do
|
|
63
|
+
chat.instance_variable_set(:@think, nil)
|
|
64
|
+
expect(chat.think_mode).to eq 'disabled'
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe '#think_show' do
|
|
69
|
+
it 'displays the current think mode status' do
|
|
70
|
+
chat.instance_variable_set(:@think, true)
|
|
71
|
+
expect(STDOUT).to receive(:puts).with(/Think mode is \e\[1menabled\e\[0m\./)
|
|
72
|
+
chat.think_show
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'displays the think mode level when set to string' do
|
|
76
|
+
chat.instance_variable_set(:@think, 'high')
|
|
77
|
+
expect(STDOUT).to receive(:puts).with(/Think mode is \e\[1mhigh\e\[0m\./)
|
|
78
|
+
chat.think_show
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'displays "disabled" when think is false' do
|
|
82
|
+
chat.instance_variable_set(:@think, false)
|
|
83
|
+
expect(STDOUT).to receive(:puts).with(/Think mode is \e\[1mdisabled\e\[0m\./)
|
|
84
|
+
chat.think_show
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'displays "disabled" when think is nil' do
|
|
88
|
+
chat.instance_variable_set(:@think, nil)
|
|
89
|
+
expect(STDOUT).to receive(:puts).with(/Think mode is \e\[1mdisabled\e\[0m\./)
|
|
90
|
+
chat.think_show
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe '#think_loud?' do
|
|
95
|
+
it 'returns false when think is disabled' do
|
|
96
|
+
chat.instance_variable_set(:@think, false)
|
|
97
|
+
expect(chat.think_loud?).to be false
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'returns false when think_loud is off' do
|
|
101
|
+
chat.instance_variable_set(:@think, true)
|
|
102
|
+
allow(chat).to receive(:think_loud).and_return(double(on?: false))
|
|
103
|
+
expect(chat.think_loud?).to be false
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it 'returns true when both think and think_loud are enabled' do
|
|
107
|
+
chat.instance_variable_set(:@think, true)
|
|
108
|
+
allow(chat).to receive(:think_loud).and_return(double(on?: true))
|
|
109
|
+
expect(chat.think_loud?).to be true
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe '#choose_think_mode' do
|
|
114
|
+
it 'can select "off" mode' do
|
|
115
|
+
expect(OllamaChat::Utils::Chooser).to receive(:choose).and_return('off')
|
|
116
|
+
chat.choose_think_mode
|
|
117
|
+
expect(chat.think).to be false
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'can select "on" mode' do
|
|
121
|
+
expect(OllamaChat::Utils::Chooser).to receive(:choose).and_return('on')
|
|
122
|
+
chat.choose_think_mode
|
|
123
|
+
expect(chat.think).to be true
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'can select "low" mode' do
|
|
127
|
+
expect(OllamaChat::Utils::Chooser).to receive(:choose).and_return('low')
|
|
128
|
+
chat.choose_think_mode
|
|
129
|
+
expect(chat.think).to eq 'low'
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it 'can select "medium" mode' do
|
|
133
|
+
expect(OllamaChat::Utils::Chooser).to receive(:choose).and_return('medium')
|
|
134
|
+
chat.choose_think_mode
|
|
135
|
+
expect(chat.think).to eq 'medium'
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it 'can select "high" mode' do
|
|
139
|
+
expect(OllamaChat::Utils::Chooser).to receive(:choose).and_return('high')
|
|
140
|
+
chat.choose_think_mode
|
|
141
|
+
expect(chat.think).to eq 'high'
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it 'can exit selection' do
|
|
145
|
+
expect(OllamaChat::Utils::Chooser).to receive(:choose).and_return('[EXIT]')
|
|
146
|
+
expect { chat.choose_think_mode }.not_to change { chat.think }
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'can handle nil selection' do
|
|
150
|
+
expect(OllamaChat::Utils::Chooser).to receive(:choose).and_return(nil)
|
|
151
|
+
expect { chat.choose_think_mode }.not_to change { chat.think }
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe OllamaChat::Vim do
|
|
4
|
+
let(:server_name) { 'TEST_SERVER' }
|
|
5
|
+
let(:vim) { described_class.new(server_name) }
|
|
6
|
+
|
|
7
|
+
describe '#initialize' do
|
|
8
|
+
it 'can be initialized with a server name' do
|
|
9
|
+
expect(vim.server_name).to eq server_name
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'can be initialized without a server name' do
|
|
13
|
+
vim_without_name = described_class.new(nil)
|
|
14
|
+
expect(vim_without_name.server_name).to be_a(String)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'uses socket as default clientserver protocol' do
|
|
18
|
+
expect(vim.clientserver).to eq 'socket'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'can specify clientserver protocol' do
|
|
22
|
+
vim_with_protocol = described_class.new(server_name, clientserver: 'pipe')
|
|
23
|
+
expect(vim_with_protocol.clientserver).to eq 'pipe'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe '.default_server_name' do
|
|
28
|
+
it 'generates a standardized server name from a directory' do
|
|
29
|
+
name = described_class.default_server_name('/path/to/project')
|
|
30
|
+
expect(name).to match(/\A[A-Z0-9]+-[A-Z0-9]+\z/)
|
|
31
|
+
expect(name).to include('PROJECT')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'handles current working directory' do
|
|
35
|
+
name = described_class.default_server_name
|
|
36
|
+
expect(name).to be_a(String)
|
|
37
|
+
expect(name).to_not be_empty
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'generates consistent names for same path' do
|
|
41
|
+
name1 = described_class.default_server_name('/tmp/test')
|
|
42
|
+
name2 = described_class.default_server_name('/tmp/test')
|
|
43
|
+
expect(name1).to eq name2
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe '#insert' do
|
|
48
|
+
it 'can insert text into vim' do
|
|
49
|
+
expect(vim).to receive(:`).with(
|
|
50
|
+
/vim.*--remote-expr.*col\('\.'\)/
|
|
51
|
+
).and_return("5\n")
|
|
52
|
+
# Mock the system call to avoid actual vim interaction
|
|
53
|
+
expect(vim).to receive(:system).with(
|
|
54
|
+
/vim.*--servername.*#{server_name}.*--remote-send/
|
|
55
|
+
)
|
|
56
|
+
vim.insert('test content')
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'handles text indentation' do
|
|
60
|
+
# Mock the col method to return a specific column
|
|
61
|
+
expect(vim).to receive(:`).with(
|
|
62
|
+
/vim.*--remote-expr.*col\('\.'\)/).and_return("5\n"
|
|
63
|
+
)
|
|
64
|
+
tmp = double('Tempfile', flush: true, path: '/tmp/test')
|
|
65
|
+
expect(Tempfile).to receive(:open).and_yield(tmp)
|
|
66
|
+
expect(tmp).to receive(:write).with(' test content')
|
|
67
|
+
expect(vim).to receive(:system).with(
|
|
68
|
+
/vim --clientserver.*--servername.*--remote-send.*\/tmp\/test/
|
|
69
|
+
).and_return true
|
|
70
|
+
vim.insert('test content')
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe '#col' do
|
|
75
|
+
it 'can get current column position' do
|
|
76
|
+
# Mock the system call to return a specific column
|
|
77
|
+
expect(vim).to receive(:`).with(
|
|
78
|
+
/vim.*--remote-expr.*col\('\.'\)/
|
|
79
|
+
).and_return("5\n")
|
|
80
|
+
expect(vim.col).to eq 5
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'handles empty response' do
|
|
84
|
+
expect(vim).to receive(:`).and_return("\n")
|
|
85
|
+
expect(vim.col).to eq 0
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
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.
|
|
4
|
+
version: 0.0.55
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Frank
|
|
@@ -420,6 +420,7 @@ extra_rdoc_files:
|
|
|
420
420
|
- lib/ollama_chat/information.rb
|
|
421
421
|
- lib/ollama_chat/input_content.rb
|
|
422
422
|
- lib/ollama_chat/kramdown_ansi.rb
|
|
423
|
+
- lib/ollama_chat/message_editing.rb
|
|
423
424
|
- lib/ollama_chat/message_format.rb
|
|
424
425
|
- lib/ollama_chat/message_list.rb
|
|
425
426
|
- lib/ollama_chat/message_output.rb
|
|
@@ -461,6 +462,7 @@ files:
|
|
|
461
462
|
- lib/ollama_chat/information.rb
|
|
462
463
|
- lib/ollama_chat/input_content.rb
|
|
463
464
|
- lib/ollama_chat/kramdown_ansi.rb
|
|
465
|
+
- lib/ollama_chat/message_editing.rb
|
|
464
466
|
- lib/ollama_chat/message_format.rb
|
|
465
467
|
- lib/ollama_chat/message_list.rb
|
|
466
468
|
- lib/ollama_chat/message_output.rb
|
|
@@ -504,7 +506,9 @@ files:
|
|
|
504
506
|
- spec/ollama_chat/clipboard_spec.rb
|
|
505
507
|
- spec/ollama_chat/follow_chat_spec.rb
|
|
506
508
|
- spec/ollama_chat/information_spec.rb
|
|
509
|
+
- spec/ollama_chat/input_content_spec.rb
|
|
507
510
|
- spec/ollama_chat/kramdown_ansi_spec.rb
|
|
511
|
+
- spec/ollama_chat/message_editing_spec.rb
|
|
508
512
|
- spec/ollama_chat/message_list_spec.rb
|
|
509
513
|
- spec/ollama_chat/message_output_spec.rb
|
|
510
514
|
- spec/ollama_chat/model_handling_spec.rb
|
|
@@ -513,9 +517,11 @@ files:
|
|
|
513
517
|
- spec/ollama_chat/server_socket_spec.rb
|
|
514
518
|
- spec/ollama_chat/source_fetching_spec.rb
|
|
515
519
|
- spec/ollama_chat/switches_spec.rb
|
|
520
|
+
- spec/ollama_chat/think_control_spec.rb
|
|
516
521
|
- spec/ollama_chat/utils/cache_fetcher_spec.rb
|
|
517
522
|
- spec/ollama_chat/utils/fetcher_spec.rb
|
|
518
523
|
- spec/ollama_chat/utils/file_argument_spec.rb
|
|
524
|
+
- spec/ollama_chat/vim_spec.rb
|
|
519
525
|
- spec/ollama_chat/web_searching_spec.rb
|
|
520
526
|
- spec/spec_helper.rb
|
|
521
527
|
- tmp/.keep
|
|
@@ -550,7 +556,9 @@ test_files:
|
|
|
550
556
|
- spec/ollama_chat/clipboard_spec.rb
|
|
551
557
|
- spec/ollama_chat/follow_chat_spec.rb
|
|
552
558
|
- spec/ollama_chat/information_spec.rb
|
|
559
|
+
- spec/ollama_chat/input_content_spec.rb
|
|
553
560
|
- spec/ollama_chat/kramdown_ansi_spec.rb
|
|
561
|
+
- spec/ollama_chat/message_editing_spec.rb
|
|
554
562
|
- spec/ollama_chat/message_list_spec.rb
|
|
555
563
|
- spec/ollama_chat/message_output_spec.rb
|
|
556
564
|
- spec/ollama_chat/model_handling_spec.rb
|
|
@@ -559,8 +567,10 @@ test_files:
|
|
|
559
567
|
- spec/ollama_chat/server_socket_spec.rb
|
|
560
568
|
- spec/ollama_chat/source_fetching_spec.rb
|
|
561
569
|
- spec/ollama_chat/switches_spec.rb
|
|
570
|
+
- spec/ollama_chat/think_control_spec.rb
|
|
562
571
|
- spec/ollama_chat/utils/cache_fetcher_spec.rb
|
|
563
572
|
- spec/ollama_chat/utils/fetcher_spec.rb
|
|
564
573
|
- spec/ollama_chat/utils/file_argument_spec.rb
|
|
574
|
+
- spec/ollama_chat/vim_spec.rb
|
|
565
575
|
- spec/ollama_chat/web_searching_spec.rb
|
|
566
576
|
- spec/spec_helper.rb
|