ollama_chat 0.0.32 → 0.0.34
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 +24 -0
- data/README.md +10 -0
- data/bin/ollama_chat_send +10 -4
- data/lib/ollama_chat/parsing.rb +2 -1
- data/lib/ollama_chat/server_socket.rb +8 -4
- data/lib/ollama_chat/source_fetching.rb +1 -1
- data/lib/ollama_chat/version.rb +1 -1
- data/ollama_chat.gemspec +2 -2
- data/spec/ollama_chat/parsing_spec.rb +16 -0
- data/spec/ollama_chat/server_socket_spec.rb +31 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1285d76eebf4b0382986bb3bcf9d3d3df08bbf95e2d8b7fd5bf82c60baf82e79
|
4
|
+
data.tar.gz: '0384dce9df4bbb3ebe371dedb09fb8ef8697950f8b0b2e3960038e93fc0a67b6'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d161dba8d86bdd135395b4b5949dd721544b4bdb475904cb2642733762c5aee00a0176399048582b304aa02140aa9317f2c7a78cae0df8082b4776d146105ebb
|
7
|
+
data.tar.gz: ac519d43fb532ac993fe396c9afbdd71e65fef7fd4ac42b4be9f04067ae6df684b8cbd0574d409ebe3388ce9d5603abbbc725a2ae323ce8725200efab3f8f539
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 2025-09-17 v0.0.34
|
4
|
+
|
5
|
+
- Modified `-d` flag semantics to use working directory instead of runtime
|
6
|
+
directory for socket path derivation
|
7
|
+
- Updated `send_to_server_socket` and `create_socket_server` methods to accept
|
8
|
+
`working_dir` parameter
|
9
|
+
- Changed argument parsing in `ollama_chat_send` binary to utilize
|
10
|
+
`working_dir` instead of `runtime_dir`
|
11
|
+
- Updated documentation and help text to reflect new `-d` option semantics
|
12
|
+
- Added tests covering new `working_dir` functionality with default fallback to
|
13
|
+
current directory
|
14
|
+
- Maintained backward compatibility by preserving existing `runtime_dir`
|
15
|
+
behavior when specified
|
16
|
+
- Modified method signatures to support both old and new parameter styles
|
17
|
+
|
18
|
+
## 2025-09-15 v0.0.33
|
19
|
+
|
20
|
+
- Enhanced `CONTENT_REGEXP` to support escaped spaces in file paths using
|
21
|
+
`(?:\\\ |\\|[^\\ ]+)`
|
22
|
+
- Modified `SourceFetching` module to properly unescape spaces with `gsub('\ ',
|
23
|
+
' ')`
|
24
|
+
- Added new test case `can parse file path with escaped spaces` to verify
|
25
|
+
functionality
|
26
|
+
|
3
27
|
## 2025-09-15 v0.0.32
|
4
28
|
|
5
29
|
- Fixed file path parsing for escaped spaces and URI handling
|
data/README.md
CHANGED
@@ -228,6 +228,16 @@ The `ollama_chat_send` command now supports additional parameters to enhance fun
|
|
228
228
|
$ echo "Visit https://example.com for more info" | ollama_chat_send -p
|
229
229
|
```
|
230
230
|
|
231
|
+
- **Working Directory (`-d`)**: Specifies the working directory used to derive
|
232
|
+
the Unix socket file path. When the ollama chat configuration is set to use a
|
233
|
+
working directory dependent socket (via `working_dir_dependent_socket: true`),
|
234
|
+
this option determines the base path for socket naming. If not specified, the
|
235
|
+
current working directory is assumed.
|
236
|
+
|
237
|
+
```bash
|
238
|
+
$ echo "Hello world" | ollama_chat_send -d /tmp/my_working_dir -r
|
239
|
+
```
|
240
|
+
|
231
241
|
- **Runtime Directory (`-d`)**: Specifies the directory where the Unix socket
|
232
242
|
file of `ollama_chat` was created, if you want to send to a specific
|
233
243
|
`ollama_chat`.
|
data/bin/ollama_chat_send
CHANGED
@@ -4,9 +4,15 @@ require 'ollama_chat'
|
|
4
4
|
require 'tins/go'
|
5
5
|
include Tins::GO
|
6
6
|
|
7
|
-
|
8
7
|
opts = go 'f:d:rtph', ARGV
|
9
8
|
|
9
|
+
# Displays the usage information for the ollama_chat_send command.
|
10
|
+
#
|
11
|
+
# This method outputs a formatted help message that describes the available
|
12
|
+
# options and usage of the ollama_chat_send command, including details about
|
13
|
+
# sending input to a running Ollama Chat client.
|
14
|
+
#
|
15
|
+
# @param rc [ Integer ] the exit code to use when exiting the program
|
10
16
|
def usage(rc = 0)
|
11
17
|
puts <<~EOT
|
12
18
|
Usage: #{File.basename($0)} [OPTIONS]
|
@@ -16,7 +22,7 @@ def usage(rc = 0)
|
|
16
22
|
-t Send input as terminal input including commands, e. g. /import
|
17
23
|
-p Send input with source parsing enabled (defaults to disabled)
|
18
24
|
-f CONFIG file to read
|
19
|
-
-d DIR the
|
25
|
+
-d DIR the working directory to derive the socket file from
|
20
26
|
-h Show this help message
|
21
27
|
|
22
28
|
Send data to a running Ollame Chat client via standard input.
|
@@ -36,8 +42,8 @@ begin
|
|
36
42
|
STDIN.read,
|
37
43
|
type:,
|
38
44
|
config:,
|
39
|
-
|
40
|
-
parse:
|
45
|
+
working_dir: opts[?d],
|
46
|
+
parse: !!opts[?p]
|
41
47
|
)
|
42
48
|
type == :socket_input_with_response and puts response.content
|
43
49
|
rescue => e
|
data/lib/ollama_chat/parsing.rb
CHANGED
@@ -200,7 +200,7 @@ module OllamaChat::Parsing
|
|
200
200
|
| # OR
|
201
201
|
"((?:\.\.|[~.]?)/(?:\\"|\\|[^"\\]+)+)" # Quoted file path with escaped " quotes
|
202
202
|
| # OR
|
203
|
-
(
|
203
|
+
((?:\.\.|[~.]?)/(?:\\\ |\\|[^\\ ]+)+) # File path with escaped spaces
|
204
204
|
}x
|
205
205
|
private_constant :CONTENT_REGEXP
|
206
206
|
|
@@ -237,6 +237,7 @@ module OllamaChat::Parsing
|
|
237
237
|
check_exist = true
|
238
238
|
source = file
|
239
239
|
when file
|
240
|
+
file = file.gsub('\ ', ' ')
|
240
241
|
file =~ %r(\A[~./]) or file.prepend('./')
|
241
242
|
check_exist = true
|
242
243
|
source = file
|
@@ -38,12 +38,13 @@ module OllamaChat::ServerSocket
|
|
38
38
|
# @param config [ ComplexConfig::Settings ] the configuration object containing server settings
|
39
39
|
# @param type [ Symbol ] the type of message transmission, defaults to :socket_input
|
40
40
|
# @param runtime_dir [ String ] pathname to runtime_dir of socket file
|
41
|
+
# @param working_dir [ String ] pathname to working_dir used for deriving socket file
|
41
42
|
# @param parse [ TrueClass, FalseClass ] whether to parse the response, defaults to false
|
42
43
|
#
|
43
44
|
# @return [ UnixSocks::Message, nil ] the response from transmit_with_response if type
|
44
45
|
# is :socket_input_with_response, otherwise nil
|
45
|
-
def send_to_server_socket(content, config:, type: :socket_input, runtime_dir: nil, parse: false)
|
46
|
-
server = create_socket_server(config:, runtime_dir:)
|
46
|
+
def send_to_server_socket(content, config:, type: :socket_input, runtime_dir: nil, working_dir: nil, parse: false)
|
47
|
+
server = create_socket_server(config:, runtime_dir:, working_dir:)
|
47
48
|
message = { content:, type:, parse: }
|
48
49
|
if type.to_sym == :socket_input_with_response
|
49
50
|
server.transmit_with_response(message)
|
@@ -65,15 +66,18 @@ module OllamaChat::ServerSocket
|
|
65
66
|
#
|
66
67
|
# @param config [ComplexConfig::Settings] the configuration object
|
67
68
|
# containing server settings
|
69
|
+
# @param runtime_dir [ String ] pathname to runtime_dir of socket file
|
70
|
+
# @param working_dir [ String ] pathname to working_dir used for deriving socket file
|
68
71
|
#
|
69
72
|
# @return [UnixSocks::Server] a configured Unix domain socket server
|
70
73
|
# instance ready to receive messages
|
71
|
-
def create_socket_server(config:, runtime_dir: nil)
|
74
|
+
def create_socket_server(config:, runtime_dir: nil, working_dir: nil)
|
75
|
+
working_dir ||= Dir.pwd
|
72
76
|
if runtime_dir
|
73
77
|
return UnixSocks::Server.new(socket_name: 'ollama_chat.sock', runtime_dir:)
|
74
78
|
end
|
75
79
|
if config.working_dir_dependent_socket
|
76
|
-
path = File.expand_path(
|
80
|
+
path = File.expand_path(working_dir)
|
77
81
|
digest = Digest::MD5.hexdigest(path)
|
78
82
|
UnixSocks::Server.new(socket_name: "ollama_chat-#{digest}.sock")
|
79
83
|
else
|
@@ -76,7 +76,7 @@ module OllamaChat::SourceFetching
|
|
76
76
|
filename = File.expand_path(filename)
|
77
77
|
check_exist && !File.exist?(filename) and return
|
78
78
|
fetch_source_as_filename(filename, &block)
|
79
|
-
when %r{\A((?:\.\.|[~.]?)/(?:\\ |\\|[^\\]+)
|
79
|
+
when %r{\A((?:\.\.|[~.]?)/(?:\\ |\\|[^\\]+)+)}
|
80
80
|
filename = $1
|
81
81
|
filename = filename.gsub('\ ', ' ')
|
82
82
|
filename = File.expand_path(filename)
|
data/lib/ollama_chat/version.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.34 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.34".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]
|
@@ -222,6 +222,22 @@ EOT
|
|
222
222
|
FileUtils.rm_f file_path
|
223
223
|
end
|
224
224
|
|
225
|
+
it 'can parse file path with escaped spaces' do
|
226
|
+
file_path = Pathname.pwd.join('spec/assets/example with .html')
|
227
|
+
FileUtils.cp 'spec/assets/example_with_quote.html', file_path
|
228
|
+
quoted_file_path = file_path.to_s.gsub(' ', '\\ ')
|
229
|
+
content, = chat.parse_content(%{see #{quoted_file_path}}, [])
|
230
|
+
expect(content).to include(<<~EOT)
|
231
|
+
Imported "#{file_path}":
|
232
|
+
|
233
|
+
# My First Heading
|
234
|
+
|
235
|
+
My first paragraph.
|
236
|
+
EOT
|
237
|
+
ensure
|
238
|
+
FileUtils.rm_f file_path
|
239
|
+
end
|
240
|
+
|
225
241
|
it 'can add images' do
|
226
242
|
images = []
|
227
243
|
expect(chat).to receive(:add_image).
|
@@ -13,7 +13,7 @@ describe OllamaChat::ServerSocket do
|
|
13
13
|
|
14
14
|
before do
|
15
15
|
expect(OllamaChat::ServerSocket).to receive(:create_socket_server).
|
16
|
-
with(config: config, runtime_dir: nil).and_return(server)
|
16
|
+
with(config: config, runtime_dir: nil, working_dir: nil).and_return(server)
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'with default parameters' do
|
@@ -50,7 +50,8 @@ describe OllamaChat::ServerSocket do
|
|
50
50
|
message = { content: 'test', type: :socket_input_with_response, parse: false }
|
51
51
|
response = double('Response')
|
52
52
|
|
53
|
-
expect(server).to receive(:transmit_with_response).with(message).
|
53
|
+
expect(server).to receive(:transmit_with_response).with(message).
|
54
|
+
and_return(response)
|
54
55
|
|
55
56
|
result = OllamaChat::ServerSocket.send_to_server_socket(
|
56
57
|
'test',
|
@@ -68,7 +69,8 @@ describe OllamaChat::ServerSocket do
|
|
68
69
|
message = { content: 'test', type: :socket_input_with_response, parse: true }
|
69
70
|
response = double('Response')
|
70
71
|
|
71
|
-
expect(server).to receive(:transmit_with_response).with(message).
|
72
|
+
expect(server).to receive(:transmit_with_response).with(message).
|
73
|
+
and_return(response)
|
72
74
|
|
73
75
|
result = OllamaChat::ServerSocket.send_to_server_socket(
|
74
76
|
'test',
|
@@ -82,10 +84,32 @@ describe OllamaChat::ServerSocket do
|
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
87
|
+
context 'with working_dir' do
|
88
|
+
before do
|
89
|
+
expect(OllamaChat::ServerSocket).to receive(:create_socket_server).
|
90
|
+
with(config: config, runtime_dir: nil, working_dir: 'foo/path').
|
91
|
+
and_return(server)
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'with working_dir parameter' do
|
95
|
+
it 'uses correct parameter' do
|
96
|
+
message = { content: 'test', type: :socket_input, parse: false }
|
97
|
+
expect(server).to receive(:transmit).with(message).and_return(nil)
|
98
|
+
|
99
|
+
result = OllamaChat::ServerSocket.send_to_server_socket(
|
100
|
+
'test', config: config, working_dir: 'foo/path'
|
101
|
+
)
|
102
|
+
|
103
|
+
expect(result).to be_nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
85
108
|
context 'with runtime_dir parameter' do
|
86
109
|
before do
|
87
110
|
expect(OllamaChat::ServerSocket).to receive(:create_socket_server).
|
88
|
-
with(config: config, runtime_dir: '/foo/bar').
|
111
|
+
with(config: config, runtime_dir: '/foo/bar', working_dir: nil).
|
112
|
+
and_return(server)
|
89
113
|
end
|
90
114
|
|
91
115
|
it 'uses correct defaults' do
|
@@ -94,7 +118,9 @@ describe OllamaChat::ServerSocket do
|
|
94
118
|
expect(server).to receive(:transmit).with(message).and_return(nil)
|
95
119
|
|
96
120
|
|
97
|
-
result = OllamaChat::ServerSocket.send_to_server_socket(
|
121
|
+
result = OllamaChat::ServerSocket.send_to_server_socket(
|
122
|
+
'test', config: config, runtime_dir: '/foo/bar'
|
123
|
+
)
|
98
124
|
|
99
125
|
expect(result).to be_nil
|
100
126
|
end
|