ollama_chat 0.0.141 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e928fba1669bde0639cbaba045d872c71f3630dc5ca2b00fec128dfe1217836
4
- data.tar.gz: e781850be5059fd1bc79ba476557c49841177ce1965106d538f689b80a7fba70
3
+ metadata.gz: 5df1b778efc290ca00d2228762281fd6b210e44ca63a536620b409a29d73fa93
4
+ data.tar.gz: ef1ce21660c446d41fd5e50c9e27ec69b4bbd361b6e3c5d6bb05b328b0c0efad
5
5
  SHA512:
6
- metadata.gz: 2adcab92a8314bf93d0e322e63413321c49a85f1ecd8d6df63a70b32ed5a98bd1df6c5996302c1e2cdd4eed74d4bde4c6213596f3d16ab543c7803b29f94726f
7
- data.tar.gz: 289d236ebec4be3474931ca20eeeebb8161f57260638cd19f366145fd08eb0be24b261cf1c1037b2c064c5133ca5cf209df39d937125b92903877878865c4cbe
6
+ metadata.gz: b0ea78869a60e2617c3b8d5d990a22121c05c31b46734550429a3bd28806ef0f828b7c664df98f423a744890cf5bdd9e5fccce1236363c62f8364e8d20fbc05d
7
+ data.tar.gz: 5f4f76c131783b5d3c4b8071c94285ebab0b64b6350d1f18ea15de2d818e01c388a34477f8245e1bcd0a3db003eb7eab8053dd9b659f84ba099f7f727ae47795
data/CHANGES.md CHANGED
@@ -1,5 +1,51 @@
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
+
3
49
  ## 2026-11-06 v0.0.141
4
50
 
5
51
  ### Improvements
@@ -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
- There is usually no reason to mention this information to the user unless
62
- asked about it.
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}
@@ -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. It allows the user to choose between 'prompt',
30
- # 'system', and 'suggest' contexts.
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.group(:context).order(:context).pluck(:context)
36
- contexts.unshift('[EXIT]')
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
- contexts,
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
- else
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 = '%s %s' % [ default, bold { p.name } ]
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 = config.prompts[context].to_h.stringify_keys_recursive
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
@@ -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
- message = Kramdown::ANSI::Width.truncate(
73
- result.lines.map(&:strip).reject(&:empty?).first || '(empty)',
74
- percentage: 90
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: })
@@ -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.141'
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.141 ruby lib
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.141".freeze
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.23".freeze
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
 
@@ -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('content-here')
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('initial')
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('v2')
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('original content')
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,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.141
4
+ version: 0.0.142
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -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.23
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: