ollama_chat 0.0.113 → 0.0.115

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.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +120 -0
  3. data/README.md +7 -0
  4. data/bin/ollama_chat_log +1 -1
  5. data/bin/ollama_chat_send +3 -1
  6. data/lib/ollama_chat/chat.rb +30 -14
  7. data/lib/ollama_chat/commands.rb +36 -18
  8. data/lib/ollama_chat/compaction.rb +289 -0
  9. data/lib/ollama_chat/config_handling.rb +32 -0
  10. data/lib/ollama_chat/database/migrations/010_add_enabled_to_collections.rb +7 -0
  11. data/lib/ollama_chat/database/models/app_state.rb +48 -16
  12. data/lib/ollama_chat/database/models/session.rb +1 -2
  13. data/lib/ollama_chat/database.rb +4 -2
  14. data/lib/ollama_chat/information.rb +53 -6
  15. data/lib/ollama_chat/logging.rb +3 -2
  16. data/lib/ollama_chat/message.rb +22 -1
  17. data/lib/ollama_chat/message_format.rb +1 -2
  18. data/lib/ollama_chat/message_list.rb +223 -9
  19. data/lib/ollama_chat/model_handling.rb +1 -1
  20. data/lib/ollama_chat/oc.rb +17 -7
  21. data/lib/ollama_chat/ollama_chat_config/default_config.yml +72 -3
  22. data/lib/ollama_chat/parsing.rb +2 -1
  23. data/lib/ollama_chat/prompt_handling.rb +1 -1
  24. data/lib/ollama_chat/prompt_management.rb +1 -0
  25. data/lib/ollama_chat/rag_handling.rb +19 -5
  26. data/lib/ollama_chat/session_management.rb +5 -3
  27. data/lib/ollama_chat/token_estimator/crude.rb +1 -1
  28. data/lib/ollama_chat/token_estimator.rb +1 -1
  29. data/lib/ollama_chat/tools/concern.rb +17 -0
  30. data/lib/ollama_chat/tools/directory_structure.rb +11 -7
  31. data/lib/ollama_chat/tools/eval_ruby.rb +16 -6
  32. data/lib/ollama_chat/tools/execute_shell.rb +158 -0
  33. data/lib/ollama_chat/tools/get_rfc.rb +2 -0
  34. data/lib/ollama_chat/tools/lookup_group.rb +100 -0
  35. data/lib/ollama_chat/tools/paste_from_clipboard.rb +1 -1
  36. data/lib/ollama_chat/tools/patch_file.rb +23 -5
  37. data/lib/ollama_chat/tools/read_file.rb +1 -1
  38. data/lib/ollama_chat/tools/resolve_tag.rb +1 -1
  39. data/lib/ollama_chat/tools/search_knowledge.rb +7 -1
  40. data/lib/ollama_chat/tools/write_file.rb +25 -6
  41. data/lib/ollama_chat/tools.rb +2 -0
  42. data/lib/ollama_chat/utils/analyze_directory.rb +5 -4
  43. data/lib/ollama_chat/utils/fetcher.rb +1 -1
  44. data/lib/ollama_chat/utils/log_rotation.rb +29 -0
  45. data/lib/ollama_chat/utils/strip_ansi.rb +22 -0
  46. data/lib/ollama_chat/utils/tag_resolver.rb +3 -3
  47. data/lib/ollama_chat/utils.rb +2 -0
  48. data/lib/ollama_chat/version.rb +1 -1
  49. data/lib/ollama_chat.rb +7 -0
  50. data/ollama_chat.gemspec +5 -5
  51. data/spec/ollama_chat/commands_spec.rb +25 -0
  52. data/spec/ollama_chat/compaction_spec.rb +381 -0
  53. data/spec/ollama_chat/config_handling_spec.rb +60 -0
  54. data/spec/ollama_chat/message_list_spec.rb +229 -0
  55. data/spec/ollama_chat/message_spec.rb +143 -0
  56. data/spec/ollama_chat/rag_handling_spec.rb +3 -0
  57. data/spec/ollama_chat/system_prompt_management_spec.rb +0 -2
  58. data/spec/ollama_chat/tools/browse_spec.rb +7 -0
  59. data/spec/ollama_chat/tools/compute_bmi_spec.rb +15 -0
  60. data/spec/ollama_chat/tools/concern_spec.rb +77 -0
  61. data/spec/ollama_chat/tools/copy_to_clipboard_spec.rb +8 -0
  62. data/spec/ollama_chat/tools/delete_file_spec.rb +8 -0
  63. data/spec/ollama_chat/tools/directory_structure_spec.rb +4 -0
  64. data/spec/ollama_chat/tools/execute_grep_spec.rb +13 -0
  65. data/spec/ollama_chat/tools/execute_ri_spec.rb +8 -0
  66. data/spec/ollama_chat/tools/execute_shell_spec.rb +232 -0
  67. data/spec/ollama_chat/tools/file_context_spec.rb +5 -0
  68. data/spec/ollama_chat/tools/gem_path_lookup_spec.rb +2 -0
  69. data/spec/ollama_chat/tools/generate_image_spec.rb +12 -0
  70. data/spec/ollama_chat/tools/generate_password_spec.rb +5 -0
  71. data/spec/ollama_chat/tools/get_cve_spec.rb +4 -0
  72. data/spec/ollama_chat/tools/get_endoflife_spec.rb +4 -0
  73. data/spec/ollama_chat/tools/get_ghr_spec.rb +6 -0
  74. data/spec/ollama_chat/tools/get_location_spec.rb +4 -0
  75. data/spec/ollama_chat/tools/get_rfc_spec.rb +2 -0
  76. data/spec/ollama_chat/tools/get_time_spec.rb +2 -0
  77. data/spec/ollama_chat/tools/get_url_spec.rb +7 -0
  78. data/spec/ollama_chat/tools/lookup_group_spec.rb +111 -0
  79. data/spec/ollama_chat/tools/move_file_spec.rb +10 -0
  80. data/spec/ollama_chat/tools/open_file_in_editor_spec.rb +6 -0
  81. data/spec/ollama_chat/tools/paste_from_clipboard_spec.rb +5 -0
  82. data/spec/ollama_chat/tools/paste_into_editor_spec.rb +6 -0
  83. data/spec/ollama_chat/tools/patch_file_spec.rb +62 -0
  84. data/spec/ollama_chat/tools/read_file_spec.rb +10 -3
  85. data/spec/ollama_chat/tools/resolve_tag_spec.rb +46 -0
  86. data/spec/ollama_chat/tools/roll_dice_spec.rb +11 -0
  87. data/spec/ollama_chat/tools/run_tests_spec.rb +8 -0
  88. data/spec/ollama_chat/tools/search_knowledge_spec.rb +2 -0
  89. data/spec/ollama_chat/tools/write_file_spec.rb +98 -2
  90. data/spec/ollama_chat/utils/analyze_directory_spec.rb +46 -7
  91. data/spec/ollama_chat/utils/log_rotation_spec.rb +71 -0
  92. data/spec/spec_helper.rb +2 -1
  93. metadata +25 -1
@@ -0,0 +1,71 @@
1
+ require 'tmpdir'
2
+
3
+ describe OllamaChat::Utils::LogRotation do
4
+ describe '.truncate_tail' do
5
+ it 'is a no-op when the file does not exist' do
6
+ described_class.truncate_tail('/nonexistent/test.log', keep_lines: 10)
7
+ end
8
+
9
+ it 'is a no-op for an empty file' do
10
+ Dir.mktmpdir do |dir|
11
+ log = File.join(dir, 'test.log')
12
+ File.write(log, '')
13
+ described_class.truncate_tail(log, keep_lines: 10)
14
+ expect(File.read(log)).to eq ''
15
+ end
16
+ end
17
+
18
+ it 'is a no-op when the file has fewer lines than keep_lines' do
19
+ Dir.mktmpdir do |dir|
20
+ log = File.join(dir, 'test.log')
21
+ File.write(log, "line1\nline2\nline3\n")
22
+ described_class.truncate_tail(log, keep_lines: 10)
23
+ expect(File.read(log)).to eq "line1\nline2\nline3\n"
24
+ end
25
+ end
26
+
27
+ it 'is a no-op when the file has exactly keep_lines lines' do
28
+ Dir.mktmpdir do |dir|
29
+ log = File.join(dir, 'test.log')
30
+ File.write(log, (1..10).map { |i| "line #{i}\n" }.join)
31
+ described_class.truncate_tail(log, keep_lines: 10)
32
+ expect(File.read(log).lines.length).to eq 10
33
+ end
34
+ end
35
+
36
+ it 'truncates to the last keep_lines lines' do
37
+ Dir.mktmpdir do |dir|
38
+ log = File.join(dir, 'test.log')
39
+ File.write(log, (1..100).map { |i| "line #{i}\n" }.join)
40
+ described_class.truncate_tail(log, keep_lines: 10)
41
+ content = File.read(log)
42
+ lines = content.lines
43
+ expect(lines.length).to eq 10
44
+ expect(lines.first).to eq "line 91\n"
45
+ expect(lines.last).to eq "line 100\n"
46
+ end
47
+ end
48
+
49
+ it 'preserves the inode' do
50
+ Dir.mktmpdir do |dir|
51
+ log = File.join(dir, 'test.log')
52
+ File.write(log, (1..100).map { |i| "line #{i}\n" }.join)
53
+ before_ino = File.stat(log).ino
54
+ described_class.truncate_tail(log, keep_lines: 10)
55
+ expect(File.stat(log).ino).to eq before_ino
56
+ end
57
+ end
58
+
59
+ it 'handles a file without a trailing newline' do
60
+ Dir.mktmpdir do |dir|
61
+ log = File.join(dir, 'test.log')
62
+ File.write(log, (1..50).map { |i| "line #{i}\n" }.join)
63
+ File.open(log, 'a') { |f| f.puts('final') }
64
+ described_class.truncate_tail(log, keep_lines: 10)
65
+ lines = File.read(log).lines
66
+ expect(lines.length).to eq 10
67
+ expect(lines.last).to eq "final\n"
68
+ end
69
+ end
70
+ end
71
+ end
data/spec/spec_helper.rb CHANGED
@@ -218,7 +218,8 @@ RSpec.configure do |config|
218
218
  OllamaChat.test_mode = true
219
219
  const_conf_as(
220
220
  'OC::OLLAMA::CHAT::HISTORY' => Pathname.pwd.join('tmp', 'history.json'),
221
- 'OC::OLLAMA::CHAT::LOGFILE' => Pathname.pwd.join('tmp', 'chat.log'),
221
+ 'OC::OLLAMA::CHAT::LOG::CHAT' => Pathname.pwd.join('tmp', 'chat.log'),
222
+ 'OC::OLLAMA::CHAT::LOG::DATABASE' => Pathname.pwd.join('tmp', 'database.log'),
222
223
  )
223
224
  end
224
225
 
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.113
4
+ version: 0.0.115
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -484,6 +484,7 @@ extra_rdoc_files:
484
484
  - lib/ollama_chat/clipboard.rb
485
485
  - lib/ollama_chat/command_concern.rb
486
486
  - lib/ollama_chat/commands.rb
487
+ - lib/ollama_chat/compaction.rb
487
488
  - lib/ollama_chat/config_handling.rb
488
489
  - lib/ollama_chat/conversation.rb
489
490
  - lib/ollama_chat/database.rb
@@ -498,6 +499,7 @@ extra_rdoc_files:
498
499
  - lib/ollama_chat/database/migrations/007_add_collections_table.rb
499
500
  - lib/ollama_chat/database/migrations/008_drop_think_mode_constraint.rb
500
501
  - lib/ollama_chat/database/migrations/009_add_app_states_table.rb
502
+ - lib/ollama_chat/database/migrations/010_add_enabled_to_collections.rb
501
503
  - lib/ollama_chat/database/models/app_state.rb
502
504
  - lib/ollama_chat/database/models/collection.rb
503
505
  - lib/ollama_chat/database/models/favourite.rb
@@ -555,6 +557,7 @@ extra_rdoc_files:
555
557
  - lib/ollama_chat/tools/execute_grep.rb
556
558
  - lib/ollama_chat/tools/execute_jira_twg.rb
557
559
  - lib/ollama_chat/tools/execute_ri.rb
560
+ - lib/ollama_chat/tools/execute_shell.rb
558
561
  - lib/ollama_chat/tools/file_context.rb
559
562
  - lib/ollama_chat/tools/gem_path_lookup.rb
560
563
  - lib/ollama_chat/tools/generate_image.rb
@@ -568,6 +571,7 @@ extra_rdoc_files:
568
571
  - lib/ollama_chat/tools/get_rfc.rb
569
572
  - lib/ollama_chat/tools/get_time.rb
570
573
  - lib/ollama_chat/tools/get_url.rb
574
+ - lib/ollama_chat/tools/lookup_group.rb
571
575
  - lib/ollama_chat/tools/move_file.rb
572
576
  - lib/ollama_chat/tools/open_file_in_editor.rb
573
577
  - lib/ollama_chat/tools/paste_from_clipboard.rb
@@ -587,10 +591,12 @@ extra_rdoc_files:
587
591
  - lib/ollama_chat/utils/chooser.rb
588
592
  - lib/ollama_chat/utils/fetcher.rb
589
593
  - lib/ollama_chat/utils/json_jsonl_io.rb
594
+ - lib/ollama_chat/utils/log_rotation.rb
590
595
  - lib/ollama_chat/utils/log_viewer.rb
591
596
  - lib/ollama_chat/utils/path_completer.rb
592
597
  - lib/ollama_chat/utils/path_validator.rb
593
598
  - lib/ollama_chat/utils/png_metadata_extractor.rb
599
+ - lib/ollama_chat/utils/strip_ansi.rb
594
600
  - lib/ollama_chat/utils/tag_resolver.rb
595
601
  - lib/ollama_chat/utils/utf8_converter.rb
596
602
  - lib/ollama_chat/utils/value_formatter.rb
@@ -616,6 +622,7 @@ files:
616
622
  - lib/ollama_chat/clipboard.rb
617
623
  - lib/ollama_chat/command_concern.rb
618
624
  - lib/ollama_chat/commands.rb
625
+ - lib/ollama_chat/compaction.rb
619
626
  - lib/ollama_chat/config_handling.rb
620
627
  - lib/ollama_chat/conversation.rb
621
628
  - lib/ollama_chat/database.rb
@@ -630,6 +637,7 @@ files:
630
637
  - lib/ollama_chat/database/migrations/007_add_collections_table.rb
631
638
  - lib/ollama_chat/database/migrations/008_drop_think_mode_constraint.rb
632
639
  - lib/ollama_chat/database/migrations/009_add_app_states_table.rb
640
+ - lib/ollama_chat/database/migrations/010_add_enabled_to_collections.rb
633
641
  - lib/ollama_chat/database/models/app_state.rb
634
642
  - lib/ollama_chat/database/models/collection.rb
635
643
  - lib/ollama_chat/database/models/favourite.rb
@@ -688,6 +696,7 @@ files:
688
696
  - lib/ollama_chat/tools/execute_grep.rb
689
697
  - lib/ollama_chat/tools/execute_jira_twg.rb
690
698
  - lib/ollama_chat/tools/execute_ri.rb
699
+ - lib/ollama_chat/tools/execute_shell.rb
691
700
  - lib/ollama_chat/tools/file_context.rb
692
701
  - lib/ollama_chat/tools/gem_path_lookup.rb
693
702
  - lib/ollama_chat/tools/generate_image.rb
@@ -701,6 +710,7 @@ files:
701
710
  - lib/ollama_chat/tools/get_rfc.rb
702
711
  - lib/ollama_chat/tools/get_time.rb
703
712
  - lib/ollama_chat/tools/get_url.rb
713
+ - lib/ollama_chat/tools/lookup_group.rb
704
714
  - lib/ollama_chat/tools/move_file.rb
705
715
  - lib/ollama_chat/tools/open_file_in_editor.rb
706
716
  - lib/ollama_chat/tools/paste_from_clipboard.rb
@@ -720,10 +730,12 @@ files:
720
730
  - lib/ollama_chat/utils/chooser.rb
721
731
  - lib/ollama_chat/utils/fetcher.rb
722
732
  - lib/ollama_chat/utils/json_jsonl_io.rb
733
+ - lib/ollama_chat/utils/log_rotation.rb
723
734
  - lib/ollama_chat/utils/log_viewer.rb
724
735
  - lib/ollama_chat/utils/path_completer.rb
725
736
  - lib/ollama_chat/utils/path_validator.rb
726
737
  - lib/ollama_chat/utils/png_metadata_extractor.rb
738
+ - lib/ollama_chat/utils/strip_ansi.rb
727
739
  - lib/ollama_chat/utils/tag_resolver.rb
728
740
  - lib/ollama_chat/utils/utf8_converter.rb
729
741
  - lib/ollama_chat/utils/value_formatter.rb
@@ -762,6 +774,7 @@ files:
762
774
  - spec/ollama_chat/chat_spec.rb
763
775
  - spec/ollama_chat/clipboard_spec.rb
764
776
  - spec/ollama_chat/commands_spec.rb
777
+ - spec/ollama_chat/compaction_spec.rb
765
778
  - spec/ollama_chat/config_handling_spec.rb
766
779
  - spec/ollama_chat/conversation_spec.rb
767
780
  - spec/ollama_chat/database/models/favourite_spec.rb
@@ -775,6 +788,7 @@ files:
775
788
  - spec/ollama_chat/message_editing_spec.rb
776
789
  - spec/ollama_chat/message_list_spec.rb
777
790
  - spec/ollama_chat/message_output_spec.rb
791
+ - spec/ollama_chat/message_spec.rb
778
792
  - spec/ollama_chat/model_handling_spec.rb
779
793
  - spec/ollama_chat/parsing_spec.rb
780
794
  - spec/ollama_chat/prompt_handling_spec.rb
@@ -792,12 +806,14 @@ files:
792
806
  - spec/ollama_chat/tool_calling_spec.rb
793
807
  - spec/ollama_chat/tools/browse_spec.rb
794
808
  - spec/ollama_chat/tools/compute_bmi_spec.rb
809
+ - spec/ollama_chat/tools/concern_spec.rb
795
810
  - spec/ollama_chat/tools/copy_to_clipboard_spec.rb
796
811
  - spec/ollama_chat/tools/delete_file_spec.rb
797
812
  - spec/ollama_chat/tools/directory_structure_spec.rb
798
813
  - spec/ollama_chat/tools/execute_grep_spec.rb
799
814
  - spec/ollama_chat/tools/execute_jira_twg_spec.rb
800
815
  - spec/ollama_chat/tools/execute_ri_spec.rb
816
+ - spec/ollama_chat/tools/execute_shell_spec.rb
801
817
  - spec/ollama_chat/tools/file_context_spec.rb
802
818
  - spec/ollama_chat/tools/gem_path_lookup_spec.rb
803
819
  - spec/ollama_chat/tools/generate_image_spec.rb
@@ -811,6 +827,7 @@ files:
811
827
  - spec/ollama_chat/tools/get_rfc_spec.rb
812
828
  - spec/ollama_chat/tools/get_time_spec.rb
813
829
  - spec/ollama_chat/tools/get_url_spec.rb
830
+ - spec/ollama_chat/tools/lookup_group_spec.rb
814
831
  - spec/ollama_chat/tools/move_file_spec.rb
815
832
  - spec/ollama_chat/tools/open_file_in_editor_spec.rb
816
833
  - spec/ollama_chat/tools/paste_from_clipboard_spec.rb
@@ -826,6 +843,7 @@ files:
826
843
  - spec/ollama_chat/utils/analyze_directory_spec.rb
827
844
  - spec/ollama_chat/utils/cache_fetcher_spec.rb
828
845
  - spec/ollama_chat/utils/fetcher_spec.rb
846
+ - spec/ollama_chat/utils/log_rotation_spec.rb
829
847
  - spec/ollama_chat/utils/log_viewer_spec.rb
830
848
  - spec/ollama_chat/utils/path_completer_spec.rb
831
849
  - spec/ollama_chat/utils/png_metadata_extractor_spec.rb
@@ -863,6 +881,7 @@ test_files:
863
881
  - spec/ollama_chat/chat_spec.rb
864
882
  - spec/ollama_chat/clipboard_spec.rb
865
883
  - spec/ollama_chat/commands_spec.rb
884
+ - spec/ollama_chat/compaction_spec.rb
866
885
  - spec/ollama_chat/config_handling_spec.rb
867
886
  - spec/ollama_chat/conversation_spec.rb
868
887
  - spec/ollama_chat/database/models/favourite_spec.rb
@@ -876,6 +895,7 @@ test_files:
876
895
  - spec/ollama_chat/message_editing_spec.rb
877
896
  - spec/ollama_chat/message_list_spec.rb
878
897
  - spec/ollama_chat/message_output_spec.rb
898
+ - spec/ollama_chat/message_spec.rb
879
899
  - spec/ollama_chat/model_handling_spec.rb
880
900
  - spec/ollama_chat/parsing_spec.rb
881
901
  - spec/ollama_chat/prompt_handling_spec.rb
@@ -893,12 +913,14 @@ test_files:
893
913
  - spec/ollama_chat/tool_calling_spec.rb
894
914
  - spec/ollama_chat/tools/browse_spec.rb
895
915
  - spec/ollama_chat/tools/compute_bmi_spec.rb
916
+ - spec/ollama_chat/tools/concern_spec.rb
896
917
  - spec/ollama_chat/tools/copy_to_clipboard_spec.rb
897
918
  - spec/ollama_chat/tools/delete_file_spec.rb
898
919
  - spec/ollama_chat/tools/directory_structure_spec.rb
899
920
  - spec/ollama_chat/tools/execute_grep_spec.rb
900
921
  - spec/ollama_chat/tools/execute_jira_twg_spec.rb
901
922
  - spec/ollama_chat/tools/execute_ri_spec.rb
923
+ - spec/ollama_chat/tools/execute_shell_spec.rb
902
924
  - spec/ollama_chat/tools/file_context_spec.rb
903
925
  - spec/ollama_chat/tools/gem_path_lookup_spec.rb
904
926
  - spec/ollama_chat/tools/generate_image_spec.rb
@@ -912,6 +934,7 @@ test_files:
912
934
  - spec/ollama_chat/tools/get_rfc_spec.rb
913
935
  - spec/ollama_chat/tools/get_time_spec.rb
914
936
  - spec/ollama_chat/tools/get_url_spec.rb
937
+ - spec/ollama_chat/tools/lookup_group_spec.rb
915
938
  - spec/ollama_chat/tools/move_file_spec.rb
916
939
  - spec/ollama_chat/tools/open_file_in_editor_spec.rb
917
940
  - spec/ollama_chat/tools/paste_from_clipboard_spec.rb
@@ -927,6 +950,7 @@ test_files:
927
950
  - spec/ollama_chat/utils/analyze_directory_spec.rb
928
951
  - spec/ollama_chat/utils/cache_fetcher_spec.rb
929
952
  - spec/ollama_chat/utils/fetcher_spec.rb
953
+ - spec/ollama_chat/utils/log_rotation_spec.rb
930
954
  - spec/ollama_chat/utils/log_viewer_spec.rb
931
955
  - spec/ollama_chat/utils/path_completer_spec.rb
932
956
  - spec/ollama_chat/utils/png_metadata_extractor_spec.rb