ollama_chat 0.0.140 → 0.0.142
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 +80 -0
- data/Rakefile +1 -1
- data/lib/ollama_chat/compaction.rb +1 -4
- data/lib/ollama_chat/follow_chat.rb +4 -4
- data/lib/ollama_chat/information.rb +1 -1
- data/lib/ollama_chat/ollama_chat_config/default_config.yml +8 -5
- data/lib/ollama_chat/prompt_handling.rb +15 -0
- data/lib/ollama_chat/prompt_management.rb +74 -17
- data/lib/ollama_chat/session_management.rb +1 -1
- data/lib/ollama_chat/tool_call_processor.rb +14 -1
- data/lib/ollama_chat/tools/execute_jira_twg.rb +3 -4
- data/lib/ollama_chat/tools/execute_shell.rb +3 -0
- data/lib/ollama_chat/tools/generate_image.rb +1 -1
- data/lib/ollama_chat/version.rb +1 -1
- data/ollama_chat.gemspec +4 -4
- data/spec/ollama_chat/prompt_handling_spec.rb +3 -3
- data/spec/ollama_chat/prompt_management_spec.rb +2 -2
- data/spec/ollama_chat/tool_call_processor_spec.rb +27 -0
- data/spec/ollama_chat/tools/execute_jira_twg_spec.rb +89 -0
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5df1b778efc290ca00d2228762281fd6b210e44ca63a536620b409a29d73fa93
|
|
4
|
+
data.tar.gz: ef1ce21660c446d41fd5e50c9e27ec69b4bbd361b6e3c5d6bb05b328b0c0efad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b0ea78869a60e2617c3b8d5d990a22121c05c31b46734550429a3bd28806ef0f828b7c664df98f423a744890cf5bdd9e5fccce1236363c62f8364e8d20fbc05d
|
|
7
|
+
data.tar.gz: 5f4f76c131783b5d3c4b8071c94285ebab0b64b6350d1f18ea15de2d818e01c388a34477f8245e1bcd0a3db003eb7eab8053dd9b659f84ba099f7f727ae47795
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,85 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-11-11 v0.0.142
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- Added status markers to the prompt context chooser (`choose_prompt_context`)
|
|
8
|
+
to indicate drift status: `⚠` when shipped config changed since last
|
|
9
|
+
acknowledge, `📌` when drifted but shipped config is unchanged, and no marker
|
|
10
|
+
when in sync.
|
|
11
|
+
- Updated `list_prompts` to display a trailing `📝` marker for user variants,
|
|
12
|
+
while default prompts remain unmarked.
|
|
13
|
+
|
|
14
|
+
### Fixes
|
|
15
|
+
|
|
16
|
+
- Fixed `execute_jira_twg` to replace bare braces (`{` or `[`) in the first
|
|
17
|
+
line of pretty-printed JSON output with `(structured result)`, preventing
|
|
18
|
+
confusing single-character messages.
|
|
19
|
+
- Resolved false positives in `prompt_sync` drift detection by normalizing
|
|
20
|
+
trailing newlines on both shipped and database-stored prompt content using
|
|
21
|
+
`ensure_trailing_newline`.
|
|
22
|
+
|
|
23
|
+
### Improvements
|
|
24
|
+
|
|
25
|
+
- Relocated `current_directory` from `static_runtime_information_values` to
|
|
26
|
+
`dynamic_runtime_information_values` in `information.rb` to maintain a
|
|
27
|
+
byte-stable system prompt prefix across repository switches, preserving LLM
|
|
28
|
+
engine prefix cache efficiency.
|
|
29
|
+
- Extracted drift and orphan computation logic into a private `context_drift`
|
|
30
|
+
method and added `context_shipped_changed?` to share code paths between the
|
|
31
|
+
prompt chooser and `prompt_sync`.
|
|
32
|
+
- Added `ensure_trailing_newline` to `prompt_handling.rb` to canonicalize
|
|
33
|
+
prompt content as if written with a YAML block scalar, ensuring consistent
|
|
34
|
+
newline termination for all DB-stored prompts.
|
|
35
|
+
- Updated `default_config.yml` to add `**Environment**:` and `**State**:`
|
|
36
|
+
headings to the `static_runtime_info` and `dynamic_runtime_info` templates,
|
|
37
|
+
respectively.
|
|
38
|
+
|
|
39
|
+
### Testing
|
|
40
|
+
|
|
41
|
+
- Added specs for `execute_jira_twg` covering pretty-printed JSON, JSON arrays,
|
|
42
|
+
and plain-text output scenarios.
|
|
43
|
+
- Updated `choose_prompt_context` spec to mock `choose_entry` returning a
|
|
44
|
+
`SearchUI::Wrapper`.
|
|
45
|
+
- Updated spec assertions in `prompt_handling_spec.rb` and
|
|
46
|
+
`prompt_management_spec.rb` to expect canonical trailing newlines in prompt
|
|
47
|
+
content.
|
|
48
|
+
|
|
49
|
+
## 2026-11-06 v0.0.141
|
|
50
|
+
|
|
51
|
+
### Improvements
|
|
52
|
+
|
|
53
|
+
- Replaced `Tins::Duration#to_s` with `to_human(style: :abbrev)` in
|
|
54
|
+
`follow_chat.rb`, `session_management.rb`, `tool_call_processor.rb`, and
|
|
55
|
+
`generate_image.rb` to produce compact duration strings (e.g., `45s`,
|
|
56
|
+
`1m30s`) for terminal stats and JSON results.
|
|
57
|
+
- Replaced hand-rolled duration formatting in `compaction.rb` with
|
|
58
|
+
`Tins::Duration#to_human` for compaction TTS reports.
|
|
59
|
+
- Updated `execute_shell` tool description to instruct the LLM to separate
|
|
60
|
+
multi-command scripts with newlines and indentation rather than semicolons
|
|
61
|
+
for improved readability in the review editor.
|
|
62
|
+
- Added an early-return guard in `ToolCallProcessor#handle` to skip tool
|
|
63
|
+
execution when `chat.tools_support.off?`, emitting a `tools_disabled` JSON
|
|
64
|
+
result per tool call to provide proper error feedback to the LLM.
|
|
65
|
+
|
|
66
|
+
### Fixes
|
|
67
|
+
|
|
68
|
+
- Set `default: false` for `get_time` and `get_location` tools in
|
|
69
|
+
`default_config.yml`, as these values are already injected into runtime info
|
|
70
|
+
each turn, making default enablement redundant.
|
|
71
|
+
|
|
72
|
+
### Build & CI
|
|
73
|
+
|
|
74
|
+
- Bumped `tins` dependency to **~> 1.62** in `Rakefile` and
|
|
75
|
+
`ollama_chat.gemspec`.
|
|
76
|
+
|
|
77
|
+
### Testing
|
|
78
|
+
|
|
79
|
+
- Added a spec example in `tool_call_processor_spec.rb` verifying that
|
|
80
|
+
`#handle` returns the expected `tools_disabled` error and message when tool
|
|
81
|
+
support is disabled.
|
|
82
|
+
|
|
3
83
|
## 2026-11-02 v0.0.140
|
|
4
84
|
|
|
5
85
|
### Improvements
|
data/Rakefile
CHANGED
|
@@ -49,7 +49,7 @@ GemHadar do
|
|
|
49
49
|
dependency 'reverse_markdown', '~> 3.0'
|
|
50
50
|
dependency 'kramdown-ansi', '~> 0.9'
|
|
51
51
|
dependency 'complex_config', '~> 0.22', '>= 0.22.2'
|
|
52
|
-
dependency 'tins', '~> 1.
|
|
52
|
+
dependency 'tins', '~> 1.62'
|
|
53
53
|
dependency 'search_ui', '>= 0.2'
|
|
54
54
|
dependency 'amatch', '~> 0.4'
|
|
55
55
|
dependency 'pdf-reader', '~> 2.0'
|
|
@@ -322,10 +322,7 @@ module OllamaChat::Compaction
|
|
|
322
322
|
Context: #{result.context_before} → #{result.context_after}
|
|
323
323
|
Stored total: #{result.stored_total}
|
|
324
324
|
EOT
|
|
325
|
-
|
|
326
|
-
duration_string = duration.format(
|
|
327
|
-
duration.minutes? ? '%M minutes and %u seconds' : '%u seconds'
|
|
328
|
-
)
|
|
325
|
+
duration_string = Tins::Duration.new(duration).to_human
|
|
329
326
|
speak(
|
|
330
327
|
'Compressed conversation context from %.0f percent to %.0f percent in %s.' % [
|
|
331
328
|
100 * result.context_filled_before,
|
|
@@ -245,14 +245,14 @@ class OllamaChat::FollowChat
|
|
|
245
245
|
eval_duration = response.eval_duration.to_f / 1e9
|
|
246
246
|
prompt_eval_duration = response.prompt_eval_duration.to_f / 1e9
|
|
247
247
|
{
|
|
248
|
-
eval_duration: Tins::Duration.new(eval_duration).
|
|
248
|
+
eval_duration: Tins::Duration.new(eval_duration).to_human(style: :abbrev),
|
|
249
249
|
eval_count: response.eval_count.to_i,
|
|
250
250
|
eval_rate: "%.2f t/s" % (response.eval_count.to_i / eval_duration),
|
|
251
|
-
prompt_eval_duration: Tins::Duration.new(prompt_eval_duration).
|
|
251
|
+
prompt_eval_duration: Tins::Duration.new(prompt_eval_duration).to_human(style: :abbrev),
|
|
252
252
|
prompt_eval_count: response.prompt_eval_count.to_i,
|
|
253
253
|
prompt_eval_rate: "%.2f t/s" % (response.prompt_eval_count.to_i / prompt_eval_duration),
|
|
254
|
-
total_duration: Tins::Duration.new(response.total_duration / 1e9).
|
|
255
|
-
load_duration: Tins::Duration.new(response.load_duration / 1e9).
|
|
254
|
+
total_duration: Tins::Duration.new(response.total_duration / 1e9).to_human(style: :abbrev),
|
|
255
|
+
load_duration: Tins::Duration.new(response.load_duration / 1e9).to_human(style: :abbrev),
|
|
256
256
|
}
|
|
257
257
|
end
|
|
258
258
|
|
|
@@ -339,7 +339,6 @@ module OllamaChat::Information
|
|
|
339
339
|
def static_runtime_information_values
|
|
340
340
|
{
|
|
341
341
|
client: ,
|
|
342
|
-
current_directory: Pathname.pwd.expand_path.to_path,
|
|
343
342
|
languages: config.languages * ', ',
|
|
344
343
|
location: location.on?.full? { location_description } || 'n/a',
|
|
345
344
|
machine: machine_profile || 'n/a',
|
|
@@ -385,6 +384,7 @@ module OllamaChat::Information
|
|
|
385
384
|
def dynamic_runtime_information_values
|
|
386
385
|
now = Time.now
|
|
387
386
|
{
|
|
387
|
+
current_directory: Pathname.pwd.expand_path.to_path,
|
|
388
388
|
git_current_branch: `git rev-parse --abbrev-ref HEAD 2>/dev/null`.chomp.full? || 'n/a',
|
|
389
389
|
git_remote_origin: `git remote get-url origin 2>/dev/null`.chomp.full? || 'n/a',
|
|
390
390
|
git_sha: `git rev-parse HEAD 2>/dev/null`.chomp.full? || 'n/a',
|
|
@@ -51,16 +51,19 @@ prompts:
|
|
|
51
51
|
%{results}
|
|
52
52
|
location: You are at %{location_name}, %{location_decimal_degrees}, preferring %{units}
|
|
53
53
|
static_runtime_info: |
|
|
54
|
+
**Environment**:
|
|
54
55
|
- Name of the chat user: %{user}
|
|
55
56
|
- Languages the user prefers: %{languages}
|
|
56
57
|
- Location: %{location}
|
|
57
|
-
- Current directory is "%{current_directory}"
|
|
58
58
|
- Client is %{client}.
|
|
59
59
|
- Machine: %{machine}
|
|
60
60
|
dynamic_runtime_info: |
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
**State**:
|
|
62
|
+
|
|
63
|
+
There is usually no reason to mention this state information to the user
|
|
64
|
+
unless asked about it.
|
|
63
65
|
|
|
66
|
+
- Current directory is "%{current_directory}"
|
|
64
67
|
- Current time is %{weekday}, %{time}
|
|
65
68
|
- **Git**:
|
|
66
69
|
- Current branch is %{git_current_branch}
|
|
@@ -582,10 +585,10 @@ tools:
|
|
|
582
585
|
require_confirmation: true
|
|
583
586
|
get_time:
|
|
584
587
|
result_display_timeout: 3
|
|
585
|
-
default:
|
|
588
|
+
default: false
|
|
586
589
|
get_location:
|
|
587
590
|
result_display_timeout: 3
|
|
588
|
-
default:
|
|
591
|
+
default: false
|
|
589
592
|
list_directory:
|
|
590
593
|
default: true
|
|
591
594
|
require_confirmation: false
|
|
@@ -66,6 +66,7 @@ module OllamaChat::PromptHandling
|
|
|
66
66
|
# @return [OllamaChat::Database::Models::Prompt] the created or updated
|
|
67
67
|
# prompt model instance
|
|
68
68
|
def write_prompt(name, content, context: nil)
|
|
69
|
+
content = ensure_trailing_newline(content)
|
|
69
70
|
context = (context || 'prompt').to_s
|
|
70
71
|
obj = nil
|
|
71
72
|
if found = models::Prompt.where(context:, name: name.to_s).first
|
|
@@ -95,5 +96,19 @@ module OllamaChat::PromptHandling
|
|
|
95
96
|
content
|
|
96
97
|
end
|
|
97
98
|
|
|
99
|
+
private
|
|
98
100
|
|
|
101
|
+
# Normalizes prompt content to the canonical trailing-newline form, i.e.
|
|
102
|
+
# as if the value were always written with a `|` block scalar in YAML
|
|
103
|
+
# (which always carries a final newline). Plain-scalar YAML prompts (no
|
|
104
|
+
# trailing newline) and block-scalar ones then compare equal, and diff
|
|
105
|
+
# tooling that preserves final newlines stays consistent.
|
|
106
|
+
#
|
|
107
|
+
# Non-destructive: content already ending in a newline is returned as-is.
|
|
108
|
+
#
|
|
109
|
+
# @param str [String, nil] the prompt content
|
|
110
|
+
# @return [String, nil] the content, guaranteed to end with a newline
|
|
111
|
+
def ensure_trailing_newline(str)
|
|
112
|
+
str&.sub(/\n?\z/, ?\n)
|
|
113
|
+
end
|
|
99
114
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'tmpdir'
|
|
2
|
+
require 'digest'
|
|
2
3
|
|
|
3
4
|
# Provides administrative and interactive management for
|
|
4
5
|
# prompt templates stored in the database.
|
|
@@ -26,23 +27,42 @@ module OllamaChat::PromptManagement
|
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
# The choose_prompt_context method presents a menu of available prompt
|
|
29
|
-
# contexts for selection.
|
|
30
|
-
#
|
|
30
|
+
# contexts for selection. A context is suffixed with a status marker only
|
|
31
|
+
# when it differs from the shipped defaults:
|
|
32
|
+
#
|
|
33
|
+
# ⚠ drifted and shipped config changed since last acknowledge
|
|
34
|
+
# 📌 drifted but shipped config unchanged (your variant)
|
|
35
|
+
#
|
|
36
|
+
# (no marker) in sync with shipped defaults
|
|
31
37
|
#
|
|
32
38
|
# @return [String, nil] the selected context name, or nil if the user
|
|
33
39
|
# cancels the selection.
|
|
34
40
|
def choose_prompt_context
|
|
35
|
-
contexts = models::Prompt
|
|
36
|
-
|
|
41
|
+
contexts = models::Prompt
|
|
42
|
+
.group(:context).order(:context).pluck(:context)
|
|
43
|
+
|
|
44
|
+
entries = contexts.map do |ctx|
|
|
45
|
+
drifted, orphans, _ = context_drift(ctx)
|
|
46
|
+
marker = if drifted.empty? && orphans.empty?
|
|
47
|
+
''
|
|
48
|
+
elsif context_shipped_changed?(ctx)
|
|
49
|
+
" \u26A0"
|
|
50
|
+
else
|
|
51
|
+
" \u{1F4CC}"
|
|
52
|
+
end
|
|
53
|
+
SearchUI::Wrapper.new(ctx, display: "#{ctx}#{marker}")
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
entries.unshift('[EXIT]')
|
|
37
57
|
case chosen = choose_entry(
|
|
38
|
-
|
|
58
|
+
entries,
|
|
39
59
|
prompt: '📝 Which prompt context shall we work in? %s'
|
|
40
60
|
)
|
|
41
61
|
when '[EXIT]', nil
|
|
42
62
|
feedback("Exiting chooser.")
|
|
43
63
|
return
|
|
44
|
-
|
|
45
|
-
chosen
|
|
64
|
+
when SearchUI::Wrapper
|
|
65
|
+
chosen.value
|
|
46
66
|
end
|
|
47
67
|
end
|
|
48
68
|
|
|
@@ -377,8 +397,8 @@ module OllamaChat::PromptManagement
|
|
|
377
397
|
context ||= 'prompt'
|
|
378
398
|
favs = all_favourited(context)
|
|
379
399
|
each_prompt(context:).sort_by(&:name).map do |p|
|
|
380
|
-
default = p.metadata['default'] ? '
|
|
381
|
-
start =
|
|
400
|
+
default = p.metadata['default'] ? '' : " \u{1F4DD}"
|
|
401
|
+
start = [ bold { p.name }, default ] * ''
|
|
382
402
|
start = prefix_favourite(start, favs[p.name])
|
|
383
403
|
content = p.to_s.inspect[1..-2]
|
|
384
404
|
content = truncate(
|
|
@@ -468,14 +488,7 @@ module OllamaChat::PromptManagement
|
|
|
468
488
|
# @return [self, nil] self on success, nil if no drift was found
|
|
469
489
|
def prompt_sync(context: nil)
|
|
470
490
|
context ||= 'prompt'
|
|
471
|
-
shipped
|
|
472
|
-
db_prompts = each_prompt(context:, default: true).to_a
|
|
473
|
-
|
|
474
|
-
drifted = db_prompts.select do |p|
|
|
475
|
-
shipped.key?(p.name) && shipped[p.name].to_s != p.to_s
|
|
476
|
-
end
|
|
477
|
-
|
|
478
|
-
orphans = db_prompts.select { |p| !shipped.key?(p.name) }
|
|
491
|
+
drifted, orphans, shipped = context_drift(context)
|
|
479
492
|
|
|
480
493
|
if drifted.empty? && orphans.empty?
|
|
481
494
|
feedback("All prompts in context #{bold{context}} are in sync. ✨", type: :success)
|
|
@@ -525,6 +538,50 @@ module OllamaChat::PromptManagement
|
|
|
525
538
|
|
|
526
539
|
private
|
|
527
540
|
|
|
541
|
+
# Computes drift (content differences) and orphans (DB prompts missing
|
|
542
|
+
# from shipped config) for a single context.
|
|
543
|
+
#
|
|
544
|
+
# @param context [String] the prompt context
|
|
545
|
+
# @return [Array] [drifted, orphans, shipped] where drifted/orphans are
|
|
546
|
+
# arrays of Prompt models and shipped is the config hash
|
|
547
|
+
def context_drift(context)
|
|
548
|
+
shipped = config.prompts[context]&.to_h&.stringify_keys_recursive || {}
|
|
549
|
+
db_prompts = each_prompt(context:, default: true).to_a
|
|
550
|
+
|
|
551
|
+
drifted = db_prompts.select do |p|
|
|
552
|
+
shipped.key?(p.name) &&
|
|
553
|
+
ensure_trailing_newline(shipped[p.name].to_s) !=
|
|
554
|
+
ensure_trailing_newline(p.to_s)
|
|
555
|
+
end
|
|
556
|
+
orphans = db_prompts.select { |p| !shipped.key?(p.name) }
|
|
557
|
+
[drifted, orphans, shipped]
|
|
558
|
+
end
|
|
559
|
+
|
|
560
|
+
# Returns true if the shipped config for a context differs from the
|
|
561
|
+
# last-acknowledged state (i.e. the app shipped new or changed prompts
|
|
562
|
+
# since the user last saw the boot notification or ran /prompt sync).
|
|
563
|
+
#
|
|
564
|
+
# @param context [String] the prompt context
|
|
565
|
+
# @return [Boolean] true if shipped content changed
|
|
566
|
+
def context_shipped_changed?(context)
|
|
567
|
+
stored = models::AppState
|
|
568
|
+
.get(:prompt_defaults_fingerprint)&.dig('hashes') || {}
|
|
569
|
+
shipped = config.prompts[context]&.to_h&.stringify_keys_recursive || {}
|
|
570
|
+
prefix = "#{context}/"
|
|
571
|
+
|
|
572
|
+
current_keys = shipped.keys.map { |n| "#{prefix}#{n}" }
|
|
573
|
+
stored_keys = stored.keys.select { |k| k.start_with?(prefix) }
|
|
574
|
+
|
|
575
|
+
return true if (current_keys - stored_keys).any?
|
|
576
|
+
return true if (stored_keys - current_keys).any?
|
|
577
|
+
|
|
578
|
+
shipped.any? do |name, content|
|
|
579
|
+
key = "#{prefix}#{name}"
|
|
580
|
+
stored.key?(key) &&
|
|
581
|
+
stored[key] != Digest::SHA256.hexdigest(content.to_s)
|
|
582
|
+
end
|
|
583
|
+
end
|
|
584
|
+
|
|
528
585
|
# Helper to wrap a prompt name with its favourite status for the UI.
|
|
529
586
|
#
|
|
530
587
|
# @param name [String] the name of the prompt
|
|
@@ -737,7 +737,7 @@ module OllamaChat::SessionManagement
|
|
|
737
737
|
elsif selector
|
|
738
738
|
now = Time.now
|
|
739
739
|
sessions = session_query.order(Sequel.desc(:updated_at)).map { |session|
|
|
740
|
-
duration = session.age(now:)
|
|
740
|
+
duration = session.age(now:).to_human(style: :abbrev)
|
|
741
741
|
es = session.estimate_tokens
|
|
742
742
|
count = session.count_messages
|
|
743
743
|
locked = if pid = session.locked?
|
|
@@ -33,6 +33,19 @@ class OllamaChat::ToolCallProcessor
|
|
|
33
33
|
def handle(response)
|
|
34
34
|
return unless response.message.ask_and_send(:tool_calls)
|
|
35
35
|
|
|
36
|
+
if chat.tools_support.off?
|
|
37
|
+
response.message.tool_calls.each do |tool_call|
|
|
38
|
+
name = tool_call.function.name
|
|
39
|
+
@results[name] << JSON(
|
|
40
|
+
error: 'tools_disabled',
|
|
41
|
+
message: 'Tool support is disabled. ' \
|
|
42
|
+
'Ask the user to re-enable with `/tools on`.'
|
|
43
|
+
)
|
|
44
|
+
chat.log(:warn, 'Tool call ignored: tools disabled',
|
|
45
|
+
data: { tool: name })
|
|
46
|
+
end
|
|
47
|
+
return
|
|
48
|
+
end
|
|
36
49
|
tools_used = {}
|
|
37
50
|
|
|
38
51
|
response.message.tool_calls.each do |tool_call|
|
|
@@ -108,7 +121,7 @@ class OllamaChat::ToolCallProcessor
|
|
|
108
121
|
warn: ,
|
|
109
122
|
size: es.bytes_formatted,
|
|
110
123
|
tokens: es.tokens_formatted,
|
|
111
|
-
duration: Tins::Duration.new(Time.now - start).
|
|
124
|
+
duration: Tins::Duration.new(Time.now - start).to_human(style: :abbrev),
|
|
112
125
|
}
|
|
113
126
|
end
|
|
114
127
|
|
|
@@ -69,10 +69,9 @@ class OllamaChat::Tools::ExecuteJIRATWG
|
|
|
69
69
|
"twg #{command} exited with code #{status}:\n#{result}"
|
|
70
70
|
end
|
|
71
71
|
chat.log(:info, 'TWG executed', data: { tool: name, command: })
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
)
|
|
72
|
+
first = result.lines.map(&:strip).reject(&:empty?).first
|
|
73
|
+
first = '(structured result)' if first =~ /^[\[\{]$/
|
|
74
|
+
message = Kramdown::ANSI::Width.truncate(first || '(empty)', percentage: 90)
|
|
76
75
|
{ cmd:, result:, message: }.to_json
|
|
77
76
|
rescue => e
|
|
78
77
|
chat.log(:error, e, data: { tool: name, command: })
|
|
@@ -45,6 +45,9 @@ class OllamaChat::Tools::ExecuteShell
|
|
|
45
45
|
then a mandatory y/n/i/a confirm prompt gates execution.
|
|
46
46
|
Answering a remembers the command for the session
|
|
47
47
|
(skips editor and confirm on repeat).
|
|
48
|
+
For multi-command scripts, separate commands with newlines
|
|
49
|
+
and proper intendation rather than `;` for readability
|
|
50
|
+
in the review editor.
|
|
48
51
|
Last resort: use ONLY when no dedicated tool covers
|
|
49
52
|
the task (e.g. `git commit`, `bundle install`, `make`).
|
|
50
53
|
Prefer `execute_grep`, `list_directory`, `read_file`,
|
|
@@ -101,7 +101,7 @@ class OllamaChat::Tools::GenerateImage
|
|
|
101
101
|
message: ,
|
|
102
102
|
url: view_url,
|
|
103
103
|
prompt: ,
|
|
104
|
-
duration: Tins::Duration.new(Time.now - started).
|
|
104
|
+
duration: Tins::Duration.new(Time.now - started).to_human(style: :abbrev),
|
|
105
105
|
}.to_json
|
|
106
106
|
rescue => e
|
|
107
107
|
chat.log(:error, e, data: { tool: name, prompt: })
|
data/lib/ollama_chat/version.rb
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# by hand; it is rewritten on every `rake version` invocation.
|
|
6
6
|
module OllamaChat
|
|
7
7
|
# The current version of the OllamaChat gem as a String.
|
|
8
|
-
VERSION = '0.0.
|
|
8
|
+
VERSION = '0.0.142'
|
|
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/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.142 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.142".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]
|
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
|
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
|
-
s.rubygems_version = "4.0.
|
|
21
|
+
s.rubygems_version = "4.0.24".freeze
|
|
22
22
|
s.summary = "A command-line interface (CLI) for interacting with an Ollama AI model.".freeze
|
|
23
23
|
s.test_files = ["spec/assets/example.rb".freeze, "spec/ollama_chat/asr_spec.rb".freeze, "spec/ollama_chat/chat_spec.rb".freeze, "spec/ollama_chat/clipboard_spec.rb".freeze, "spec/ollama_chat/collection_search_spec.rb".freeze, "spec/ollama_chat/command_concern_spec.rb".freeze, "spec/ollama_chat/commands_spec.rb".freeze, "spec/ollama_chat/compaction_spec.rb".freeze, "spec/ollama_chat/config_handling_spec.rb".freeze, "spec/ollama_chat/context_usage_spec.rb".freeze, "spec/ollama_chat/conversation_spec.rb".freeze, "spec/ollama_chat/database/models/favourite_spec.rb".freeze, "spec/ollama_chat/favourites_management_spec.rb".freeze, "spec/ollama_chat/file_editing_spec.rb".freeze, "spec/ollama_chat/follow_chat_spec.rb".freeze, "spec/ollama_chat/history_spec.rb".freeze, "spec/ollama_chat/http_handling_spec.rb".freeze, "spec/ollama_chat/information_spec.rb".freeze, "spec/ollama_chat/input_content_spec.rb".freeze, "spec/ollama_chat/invidious_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/message_spec.rb".freeze, "spec/ollama_chat/model_handling/model_cache_spec.rb".freeze, "spec/ollama_chat/model_handling_spec.rb".freeze, "spec/ollama_chat/parsing_spec.rb".freeze, "spec/ollama_chat/personae_management_spec.rb".freeze, "spec/ollama_chat/prompt_handling_spec.rb".freeze, "spec/ollama_chat/prompt_management_spec.rb".freeze, "spec/ollama_chat/rag_handling_spec.rb".freeze, "spec/ollama_chat/redis_cache_spec.rb".freeze, "spec/ollama_chat/server_socket_spec.rb".freeze, "spec/ollama_chat/session_management_spec.rb".freeze, "spec/ollama_chat/source_fetching_spec.rb".freeze, "spec/ollama_chat/speaker_spec.rb".freeze, "spec/ollama_chat/state_selectors_spec.rb".freeze, "spec/ollama_chat/switches_spec.rb".freeze, "spec/ollama_chat/system_prompt_management_spec.rb".freeze, "spec/ollama_chat/think_control_spec.rb".freeze, "spec/ollama_chat/token_estimator_spec.rb".freeze, "spec/ollama_chat/tool_call_processor_spec.rb".freeze, "spec/ollama_chat/tool_calling_spec.rb".freeze, "spec/ollama_chat/tools/browse_spec.rb".freeze, "spec/ollama_chat/tools/compute_bmi_spec.rb".freeze, "spec/ollama_chat/tools/concern_spec.rb".freeze, "spec/ollama_chat/tools/copy_to_clipboard_spec.rb".freeze, "spec/ollama_chat/tools/delete_file_spec.rb".freeze, "spec/ollama_chat/tools/execute_grep_spec.rb".freeze, "spec/ollama_chat/tools/execute_jira_twg_spec.rb".freeze, "spec/ollama_chat/tools/execute_ri_spec.rb".freeze, "spec/ollama_chat/tools/execute_shell_spec.rb".freeze, "spec/ollama_chat/tools/forget_spec.rb".freeze, "spec/ollama_chat/tools/generate_image_spec.rb".freeze, "spec/ollama_chat/tools/generate_password_spec.rb".freeze, "spec/ollama_chat/tools/get_current_weather_spec.rb".freeze, "spec/ollama_chat/tools/get_cve_spec.rb".freeze, "spec/ollama_chat/tools/get_endoflife_spec.rb".freeze, "spec/ollama_chat/tools/get_ghr_spec.rb".freeze, "spec/ollama_chat/tools/get_jira_issue_spec.rb".freeze, "spec/ollama_chat/tools/get_location_spec.rb".freeze, "spec/ollama_chat/tools/get_rfc_spec.rb".freeze, "spec/ollama_chat/tools/get_time_spec.rb".freeze, "spec/ollama_chat/tools/get_url_spec.rb".freeze, "spec/ollama_chat/tools/list_directory_spec.rb".freeze, "spec/ollama_chat/tools/lookup_gem_path_spec.rb".freeze, "spec/ollama_chat/tools/lookup_group_spec.rb".freeze, "spec/ollama_chat/tools/memorize_spec.rb".freeze, "spec/ollama_chat/tools/move_file_spec.rb".freeze, "spec/ollama_chat/tools/open_file_in_editor_spec.rb".freeze, "spec/ollama_chat/tools/paste_from_clipboard_spec.rb".freeze, "spec/ollama_chat/tools/paste_into_editor_spec.rb".freeze, "spec/ollama_chat/tools/patch_file_spec.rb".freeze, "spec/ollama_chat/tools/read_file_spec.rb".freeze, "spec/ollama_chat/tools/resolve_tag_spec.rb".freeze, "spec/ollama_chat/tools/roll_dice_spec.rb".freeze, "spec/ollama_chat/tools/run_tests_spec.rb".freeze, "spec/ollama_chat/tools/search_knowledge_spec.rb".freeze, "spec/ollama_chat/tools/search_web_spec.rb".freeze, "spec/ollama_chat/tools/write_file_spec.rb".freeze, "spec/ollama_chat/tts_spec.rb".freeze, "spec/ollama_chat/utils/analyze_directory_spec.rb".freeze, "spec/ollama_chat/utils/audio_player_spec.rb".freeze, "spec/ollama_chat/utils/cache_fetcher_spec.rb".freeze, "spec/ollama_chat/utils/excon_logger_spec.rb".freeze, "spec/ollama_chat/utils/fetcher_spec.rb".freeze, "spec/ollama_chat/utils/log_rotation_spec.rb".freeze, "spec/ollama_chat/utils/log_viewer_spec.rb".freeze, "spec/ollama_chat/utils/ordered_queue_spec.rb".freeze, "spec/ollama_chat/utils/path_completer_spec.rb".freeze, "spec/ollama_chat/utils/png_metadata_extractor_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
|
|
|
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
|
|
|
43
43
|
s.add_runtime_dependency(%q<reverse_markdown>.freeze, ["~> 3.0".freeze])
|
|
44
44
|
s.add_runtime_dependency(%q<kramdown-ansi>.freeze, ["~> 0.9".freeze])
|
|
45
45
|
s.add_runtime_dependency(%q<complex_config>.freeze, ["~> 0.22".freeze, ">= 0.22.2".freeze])
|
|
46
|
-
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.
|
|
46
|
+
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.62".freeze])
|
|
47
47
|
s.add_runtime_dependency(%q<search_ui>.freeze, [">= 0.2".freeze])
|
|
48
48
|
s.add_runtime_dependency(%q<amatch>.freeze, ["~> 0.4".freeze])
|
|
49
49
|
s.add_runtime_dependency(%q<pdf-reader>.freeze, ["~> 2.0".freeze])
|
|
@@ -114,7 +114,7 @@ describe OllamaChat::PromptHandling do
|
|
|
114
114
|
|
|
115
115
|
obj = prompt_model.where(name: 'zz_store', context: 'prompt').first
|
|
116
116
|
expect(obj).not_to be_nil
|
|
117
|
-
expect(obj.metadata['content']).to eq(
|
|
117
|
+
expect(obj.metadata['content']).to eq("content-here\n")
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
it 'respects a custom context' do
|
|
@@ -131,7 +131,7 @@ describe OllamaChat::PromptHandling do
|
|
|
131
131
|
|
|
132
132
|
expect(obj.name).to eq('zz_write')
|
|
133
133
|
expect(obj.metadata['default']).to be false
|
|
134
|
-
expect(obj.metadata['content']).to eq(
|
|
134
|
+
expect(obj.metadata['content']).to eq("initial\n")
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
it 'updates content on an existing prompt' do
|
|
@@ -139,7 +139,7 @@ describe OllamaChat::PromptHandling do
|
|
|
139
139
|
updated = chat.write_prompt('zz_upd', 'v2')
|
|
140
140
|
|
|
141
141
|
expect(prompt_model.where(name: 'zz_upd').count).to eq(1)
|
|
142
|
-
expect(updated.metadata['content']).to eq(
|
|
142
|
+
expect(updated.metadata['content']).to eq("v2\n")
|
|
143
143
|
end
|
|
144
144
|
|
|
145
145
|
|
|
@@ -53,7 +53,7 @@ describe OllamaChat::PromptManagement do
|
|
|
53
53
|
prompt_model.create(context: 'prompt', name: 'p', metadata: { default: false, content: 'x' })
|
|
54
54
|
prompt_model.create(context: 'system', name: 's', metadata: { default: false, content: 'y' })
|
|
55
55
|
|
|
56
|
-
expect(chat).to receive(:choose_entry).and_return('system')
|
|
56
|
+
expect(chat).to receive(:choose_entry).and_return(wrapper.('system'))
|
|
57
57
|
expect(chat.choose_prompt_context).to eq('system')
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -406,7 +406,7 @@ describe OllamaChat::PromptManagement do
|
|
|
406
406
|
.and_return('reset_me' => 'original content')
|
|
407
407
|
|
|
408
408
|
expect(chat.reset_prompt_to_default('reset_me')).to be true
|
|
409
|
-
expect(chat.prompt('reset_me').reload.metadata['content']).to eq(
|
|
409
|
+
expect(chat.prompt('reset_me').reload.metadata['content']).to eq("original content\n")
|
|
410
410
|
end
|
|
411
411
|
|
|
412
412
|
it 'returns nil when no default found in config' do
|
|
@@ -48,4 +48,31 @@ describe OllamaChat::ToolCallProcessor do
|
|
|
48
48
|
expect(processor.results).to be_empty
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
|
+
|
|
52
|
+
describe '#handle' do
|
|
53
|
+
let :tool_call do
|
|
54
|
+
double('tool_call', function: double('function', name: 'roll_dice'))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
let :message do
|
|
58
|
+
double('message', ask_and_send: true, tool_calls: [tool_call])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
let :response do
|
|
62
|
+
double('response', message:)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context 'when tools support is disabled' do
|
|
66
|
+
before do
|
|
67
|
+
allow(chat.tools_support).to receive(:off?).and_return(true)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'returns a tools_disabled result per tool call without executing' do
|
|
71
|
+
processor.handle(response)
|
|
72
|
+
data = JSON.parse(processor.results['roll_dice'].first)
|
|
73
|
+
expect(data['error']).to eq('tools_disabled')
|
|
74
|
+
expect(data['message']).to include('/tools on')
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
51
78
|
end
|
|
@@ -48,6 +48,95 @@ describe OllamaChat::Tools::ExecuteJIRATWG do
|
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
context 'when twg returns pretty-printed JSON' do
|
|
52
|
+
let(:command) { 'jira workitem get DEV-29042' }
|
|
53
|
+
|
|
54
|
+
before do
|
|
55
|
+
expect(OC::OLLAMA::CHAT::TOOLS::JIRA).to receive(:TWG?).and_return('true')
|
|
56
|
+
system('true') # reset $? to exit 0
|
|
57
|
+
expect(OllamaChat::Utils::Fetcher).to receive(:execute)
|
|
58
|
+
.with(%w[true jira workitem get DEV-29042])
|
|
59
|
+
.and_return(<<~EOT)
|
|
60
|
+
{
|
|
61
|
+
"key": "DEV-29042"
|
|
62
|
+
}
|
|
63
|
+
EOT
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'reports (structured result) instead of a bare brace' do
|
|
67
|
+
tool_call = double(
|
|
68
|
+
'ToolCall',
|
|
69
|
+
function: double(
|
|
70
|
+
name: 'execute_jira_twg',
|
|
71
|
+
arguments: double(command:)
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
result = described_class.new(chat).execute(tool_call)
|
|
76
|
+
|
|
77
|
+
json = json_object(result)
|
|
78
|
+
expect(json.message).to eq '(structured result)'
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context 'when twg returns a JSON array on its own first line' do
|
|
83
|
+
let(:command) { 'jira workitem query --jql "project = DEV"' }
|
|
84
|
+
|
|
85
|
+
before do
|
|
86
|
+
expect(OC::OLLAMA::CHAT::TOOLS::JIRA).to receive(:TWG?).and_return('true')
|
|
87
|
+
system('true') # reset $? to exit 0
|
|
88
|
+
expect(OllamaChat::Utils::Fetcher).to receive(:execute)
|
|
89
|
+
.with(['true', 'jira', 'workitem', 'query', '--jql', 'project = DEV'])
|
|
90
|
+
.and_return(<<~EOT)
|
|
91
|
+
[
|
|
92
|
+
{ "id": "DEV-1" }
|
|
93
|
+
]
|
|
94
|
+
EOT
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'reports (structured result) instead of a bare bracket' do
|
|
98
|
+
tool_call = double(
|
|
99
|
+
'ToolCall',
|
|
100
|
+
function: double(
|
|
101
|
+
name: 'execute_jira_twg',
|
|
102
|
+
arguments: double(command:)
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
result = described_class.new(chat).execute(tool_call)
|
|
107
|
+
|
|
108
|
+
json = json_object(result)
|
|
109
|
+
expect(json.message).to eq '(structured result)'
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
context 'when twg returns plain-text output' do
|
|
114
|
+
let(:command) { 'user get' }
|
|
115
|
+
|
|
116
|
+
before do
|
|
117
|
+
expect(OC::OLLAMA::CHAT::TOOLS::JIRA).to receive(:TWG?).and_return('true')
|
|
118
|
+
system('true') # reset $? to exit 0
|
|
119
|
+
expect(OllamaChat::Utils::Fetcher).to receive(:execute)
|
|
120
|
+
.with(%w[true user get])
|
|
121
|
+
.and_return("flori: Florian Frank\nflori2: Someone Else\n")
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it 'uses the first line as the message' do
|
|
125
|
+
tool_call = double(
|
|
126
|
+
'ToolCall',
|
|
127
|
+
function: double(
|
|
128
|
+
name: 'execute_jira_twg',
|
|
129
|
+
arguments: double(command:)
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
result = described_class.new(chat).execute(tool_call)
|
|
134
|
+
|
|
135
|
+
json = json_object(result)
|
|
136
|
+
expect(json.message).to eq 'flori: Florian Frank'
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
51
140
|
context 'when command contains quoted arguments' do
|
|
52
141
|
let(:command) { 'jira workitem query --jql "project = DEV AND status != Done"' }
|
|
53
142
|
|
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.142
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Frank
|
|
@@ -287,14 +287,14 @@ dependencies:
|
|
|
287
287
|
requirements:
|
|
288
288
|
- - "~>"
|
|
289
289
|
- !ruby/object:Gem::Version
|
|
290
|
-
version: '1.
|
|
290
|
+
version: '1.62'
|
|
291
291
|
type: :runtime
|
|
292
292
|
prerelease: false
|
|
293
293
|
version_requirements: !ruby/object:Gem::Requirement
|
|
294
294
|
requirements:
|
|
295
295
|
- - "~>"
|
|
296
296
|
- !ruby/object:Gem::Version
|
|
297
|
-
version: '1.
|
|
297
|
+
version: '1.62'
|
|
298
298
|
- !ruby/object:Gem::Dependency
|
|
299
299
|
name: search_ui
|
|
300
300
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -922,7 +922,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
922
922
|
- !ruby/object:Gem::Version
|
|
923
923
|
version: '0'
|
|
924
924
|
requirements: []
|
|
925
|
-
rubygems_version: 4.0.
|
|
925
|
+
rubygems_version: 4.0.24
|
|
926
926
|
specification_version: 4
|
|
927
927
|
summary: A command-line interface (CLI) for interacting with an Ollama AI model.
|
|
928
928
|
test_files:
|