llm-shell 0.9.2 → 0.10.0

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 (258) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +61 -66
  3. data/lib/llm/shell/command.rb +40 -40
  4. data/lib/llm/shell/commands/clear_screen.rb +4 -18
  5. data/lib/llm/shell/commands/debug_mode.rb +12 -0
  6. data/lib/llm/shell/commands/dir_import.rb +4 -20
  7. data/lib/llm/shell/commands/disable_tool.rb +33 -0
  8. data/lib/llm/shell/commands/enable_tool.rb +33 -0
  9. data/lib/llm/shell/commands/file_import.rb +4 -20
  10. data/lib/llm/shell/commands/help.rb +23 -36
  11. data/lib/llm/shell/commands/show_chat.rb +4 -19
  12. data/lib/llm/shell/commands/show_version.rb +4 -20
  13. data/lib/llm/shell/commands/system_prompt.rb +4 -18
  14. data/lib/llm/shell/completion.rb +5 -5
  15. data/lib/llm/shell/config.rb +4 -5
  16. data/lib/llm/shell/formatter.rb +1 -2
  17. data/lib/llm/shell/internal/coderay/lib/coderay/duo.rb +81 -0
  18. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/_map.rb +17 -0
  19. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/comment_filter.rb +25 -0
  20. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/count.rb +39 -0
  21. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/debug.rb +49 -0
  22. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/debug_lint.rb +63 -0
  23. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/div.rb +23 -0
  24. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/encoder.rb +190 -0
  25. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/filter.rb +58 -0
  26. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/css.rb +65 -0
  27. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/numbering.rb +108 -0
  28. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html/output.rb +164 -0
  29. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/html.rb +333 -0
  30. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/json.rb +83 -0
  31. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/lines_of_code.rb +45 -0
  32. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/lint.rb +59 -0
  33. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/null.rb +18 -0
  34. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/page.rb +24 -0
  35. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/span.rb +23 -0
  36. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/statistic.rb +95 -0
  37. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/terminal.rb +195 -0
  38. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/text.rb +46 -0
  39. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/token_kind_filter.rb +111 -0
  40. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/xml.rb +72 -0
  41. data/lib/llm/shell/internal/coderay/lib/coderay/encoders/yaml.rb +50 -0
  42. data/lib/llm/shell/internal/coderay/lib/coderay/encoders.rb +18 -0
  43. data/lib/llm/shell/internal/coderay/lib/coderay/for_redcloth.rb +95 -0
  44. data/lib/llm/shell/internal/coderay/lib/coderay/helpers/file_type.rb +151 -0
  45. data/lib/llm/shell/internal/coderay/lib/coderay/helpers/plugin.rb +55 -0
  46. data/lib/llm/shell/internal/coderay/lib/coderay/helpers/plugin_host.rb +221 -0
  47. data/lib/llm/shell/internal/coderay/lib/coderay/helpers/word_list.rb +72 -0
  48. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/_map.rb +24 -0
  49. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/c.rb +189 -0
  50. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/clojure.rb +217 -0
  51. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/cpp.rb +217 -0
  52. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/css.rb +196 -0
  53. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/debug.rb +75 -0
  54. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/delphi.rb +144 -0
  55. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/diff.rb +221 -0
  56. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/erb.rb +81 -0
  57. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/go.rb +208 -0
  58. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/groovy.rb +268 -0
  59. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/haml.rb +168 -0
  60. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/html.rb +275 -0
  61. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java/builtin_types.rb +421 -0
  62. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java.rb +174 -0
  63. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/java_script.rb +236 -0
  64. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/json.rb +98 -0
  65. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/lua.rb +280 -0
  66. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/php.rb +527 -0
  67. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/python.rb +287 -0
  68. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/raydebug.rb +75 -0
  69. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby/patterns.rb +178 -0
  70. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby/string_state.rb +79 -0
  71. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/ruby.rb +477 -0
  72. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/sass.rb +232 -0
  73. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/scanner.rb +337 -0
  74. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/sql.rb +169 -0
  75. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/taskpaper.rb +36 -0
  76. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/text.rb +26 -0
  77. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/xml.rb +17 -0
  78. data/lib/llm/shell/internal/coderay/lib/coderay/scanners/yaml.rb +140 -0
  79. data/lib/llm/shell/internal/coderay/lib/coderay/scanners.rb +27 -0
  80. data/lib/llm/shell/internal/coderay/lib/coderay/styles/_map.rb +7 -0
  81. data/lib/llm/shell/internal/coderay/lib/coderay/styles/alpha.rb +153 -0
  82. data/lib/llm/shell/internal/coderay/lib/coderay/styles/style.rb +18 -0
  83. data/lib/llm/shell/internal/coderay/lib/coderay/styles.rb +15 -0
  84. data/lib/llm/shell/internal/coderay/lib/coderay/token_kinds.rb +85 -0
  85. data/lib/llm/shell/internal/coderay/lib/coderay/tokens.rb +164 -0
  86. data/lib/llm/shell/internal/coderay/lib/coderay/tokens_proxy.rb +55 -0
  87. data/lib/llm/shell/internal/coderay/lib/coderay/version.rb +3 -0
  88. data/lib/llm/shell/internal/coderay/lib/coderay.rb +284 -0
  89. data/lib/llm/shell/internal/io-line/lib/io/line/multiple.rb +19 -0
  90. data/lib/{io → llm/shell/internal/io-line/lib/io}/line.rb +2 -0
  91. data/lib/llm/shell/internal/llm.rb/lib/llm/bot/builder.rb +31 -0
  92. data/lib/llm/shell/internal/llm.rb/lib/llm/bot/conversable.rb +37 -0
  93. data/lib/llm/shell/internal/llm.rb/lib/llm/bot/prompt/completion.rb +49 -0
  94. data/lib/llm/shell/internal/llm.rb/lib/llm/bot/prompt/respond.rb +49 -0
  95. data/lib/llm/shell/internal/llm.rb/lib/llm/bot.rb +150 -0
  96. data/lib/llm/shell/internal/llm.rb/lib/llm/buffer.rb +162 -0
  97. data/lib/llm/shell/internal/llm.rb/lib/llm/client.rb +36 -0
  98. data/lib/llm/shell/internal/llm.rb/lib/llm/error.rb +49 -0
  99. data/lib/llm/shell/internal/llm.rb/lib/llm/eventhandler.rb +44 -0
  100. data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream/event.rb +69 -0
  101. data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream/parser.rb +88 -0
  102. data/lib/llm/shell/internal/llm.rb/lib/llm/eventstream.rb +8 -0
  103. data/lib/llm/shell/internal/llm.rb/lib/llm/file.rb +91 -0
  104. data/lib/llm/shell/internal/llm.rb/lib/llm/function.rb +177 -0
  105. data/lib/llm/shell/internal/llm.rb/lib/llm/message.rb +178 -0
  106. data/lib/llm/shell/internal/llm.rb/lib/llm/mime.rb +140 -0
  107. data/lib/llm/shell/internal/llm.rb/lib/llm/multipart.rb +101 -0
  108. data/lib/llm/shell/internal/llm.rb/lib/llm/object/builder.rb +38 -0
  109. data/lib/llm/shell/internal/llm.rb/lib/llm/object/kernel.rb +53 -0
  110. data/lib/llm/shell/internal/llm.rb/lib/llm/object.rb +89 -0
  111. data/lib/llm/shell/internal/llm.rb/lib/llm/provider.rb +352 -0
  112. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/error_handler.rb +36 -0
  113. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/files.rb +155 -0
  114. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/format/completion_format.rb +88 -0
  115. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/format.rb +29 -0
  116. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/models.rb +54 -0
  117. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/completion.rb +39 -0
  118. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/enumerable.rb +11 -0
  119. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/file.rb +23 -0
  120. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/response/web_search.rb +21 -0
  121. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic/stream_parser.rb +66 -0
  122. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/anthropic.rb +138 -0
  123. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek/format/completion_format.rb +68 -0
  124. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek/format.rb +27 -0
  125. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/deepseek.rb +75 -0
  126. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/audio.rb +73 -0
  127. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/error_handler.rb +47 -0
  128. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/files.rb +146 -0
  129. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format/completion_format.rb +69 -0
  130. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/format.rb +39 -0
  131. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/images.rb +133 -0
  132. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/models.rb +60 -0
  133. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/completion.rb +35 -0
  134. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/embedding.rb +8 -0
  135. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/file.rb +11 -0
  136. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/files.rb +15 -0
  137. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/image.rb +31 -0
  138. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/models.rb +15 -0
  139. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/response/web_search.rb +22 -0
  140. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/stream_parser.rb +86 -0
  141. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini.rb +173 -0
  142. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/llamacpp.rb +74 -0
  143. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/error_handler.rb +36 -0
  144. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/format/completion_format.rb +77 -0
  145. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/format.rb +29 -0
  146. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/models.rb +56 -0
  147. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/response/completion.rb +28 -0
  148. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/response/embedding.rb +9 -0
  149. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/stream_parser.rb +44 -0
  150. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama.rb +116 -0
  151. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/audio.rb +91 -0
  152. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/error_handler.rb +46 -0
  153. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/files.rb +134 -0
  154. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/completion_format.rb +90 -0
  155. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/moderation_format.rb +35 -0
  156. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format/respond_format.rb +72 -0
  157. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/format.rb +54 -0
  158. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/images.rb +109 -0
  159. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/models.rb +55 -0
  160. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/moderations.rb +65 -0
  161. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/audio.rb +7 -0
  162. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/completion.rb +40 -0
  163. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/embedding.rb +9 -0
  164. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/enumerable.rb +23 -0
  165. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/file.rb +7 -0
  166. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/image.rb +16 -0
  167. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/moderations.rb +34 -0
  168. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/responds.rb +48 -0
  169. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/response/web_search.rb +21 -0
  170. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/responses/stream_parser.rb +76 -0
  171. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/responses.rb +99 -0
  172. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/stream_parser.rb +86 -0
  173. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/vector_stores.rb +228 -0
  174. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/openai.rb +206 -0
  175. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/xai/images.rb +58 -0
  176. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/xai.rb +72 -0
  177. data/lib/llm/shell/internal/llm.rb/lib/llm/providers/zai.rb +74 -0
  178. data/lib/llm/shell/internal/llm.rb/lib/llm/response.rb +67 -0
  179. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/array.rb +26 -0
  180. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/boolean.rb +13 -0
  181. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/integer.rb +43 -0
  182. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/leaf.rb +78 -0
  183. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/null.rb +13 -0
  184. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/number.rb +43 -0
  185. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/object.rb +41 -0
  186. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/string.rb +34 -0
  187. data/lib/llm/shell/internal/llm.rb/lib/llm/schema/version.rb +8 -0
  188. data/lib/llm/shell/internal/llm.rb/lib/llm/schema.rb +81 -0
  189. data/lib/llm/shell/internal/llm.rb/lib/llm/server_tool.rb +32 -0
  190. data/lib/llm/shell/internal/llm.rb/lib/llm/tool/param.rb +75 -0
  191. data/lib/llm/shell/internal/llm.rb/lib/llm/tool.rb +78 -0
  192. data/lib/llm/shell/internal/llm.rb/lib/llm/utils.rb +19 -0
  193. data/lib/llm/shell/internal/llm.rb/lib/llm/version.rb +5 -0
  194. data/lib/llm/shell/internal/llm.rb/lib/llm.rb +121 -0
  195. data/lib/llm/shell/internal/optparse/lib/optionparser.rb +2 -0
  196. data/lib/llm/shell/internal/optparse/lib/optparse/ac.rb +70 -0
  197. data/lib/llm/shell/internal/optparse/lib/optparse/date.rb +18 -0
  198. data/lib/llm/shell/internal/optparse/lib/optparse/kwargs.rb +27 -0
  199. data/lib/llm/shell/internal/optparse/lib/optparse/shellwords.rb +7 -0
  200. data/lib/llm/shell/internal/optparse/lib/optparse/time.rb +11 -0
  201. data/lib/llm/shell/internal/optparse/lib/optparse/uri.rb +7 -0
  202. data/lib/llm/shell/internal/optparse/lib/optparse/version.rb +80 -0
  203. data/lib/llm/shell/internal/optparse/lib/optparse.rb +2469 -0
  204. data/lib/llm/shell/internal/paint/lib/paint/constants.rb +104 -0
  205. data/lib/llm/shell/internal/paint/lib/paint/pa.rb +13 -0
  206. data/lib/llm/shell/internal/paint/lib/paint/rgb_colors.rb +14 -0
  207. data/lib/llm/shell/internal/paint/lib/paint/shortcuts.rb +100 -0
  208. data/lib/llm/shell/internal/paint/lib/paint/shortcuts_version.rb +5 -0
  209. data/lib/llm/shell/internal/paint/lib/paint/util.rb +16 -0
  210. data/lib/llm/shell/internal/paint/lib/paint/version.rb +5 -0
  211. data/lib/llm/shell/internal/paint/lib/paint.rb +261 -0
  212. data/lib/llm/shell/internal/reline/lib/reline/config.rb +378 -0
  213. data/lib/llm/shell/internal/reline/lib/reline/face.rb +199 -0
  214. data/lib/llm/shell/internal/reline/lib/reline/history.rb +76 -0
  215. data/lib/llm/shell/internal/reline/lib/reline/io/ansi.rb +322 -0
  216. data/lib/llm/shell/internal/reline/lib/reline/io/dumb.rb +120 -0
  217. data/lib/llm/shell/internal/reline/lib/reline/io/windows.rb +530 -0
  218. data/lib/llm/shell/internal/reline/lib/reline/io.rb +55 -0
  219. data/lib/llm/shell/internal/reline/lib/reline/key_actor/base.rb +37 -0
  220. data/lib/llm/shell/internal/reline/lib/reline/key_actor/composite.rb +17 -0
  221. data/lib/llm/shell/internal/reline/lib/reline/key_actor/emacs.rb +517 -0
  222. data/lib/llm/shell/internal/reline/lib/reline/key_actor/vi_command.rb +518 -0
  223. data/lib/llm/shell/internal/reline/lib/reline/key_actor/vi_insert.rb +517 -0
  224. data/lib/llm/shell/internal/reline/lib/reline/key_actor.rb +8 -0
  225. data/lib/llm/shell/internal/reline/lib/reline/key_stroke.rb +119 -0
  226. data/lib/llm/shell/internal/reline/lib/reline/kill_ring.rb +125 -0
  227. data/lib/llm/shell/internal/reline/lib/reline/line_editor.rb +2356 -0
  228. data/lib/llm/shell/internal/reline/lib/reline/unicode/east_asian_width.rb +1292 -0
  229. data/lib/llm/shell/internal/reline/lib/reline/unicode.rb +421 -0
  230. data/lib/llm/shell/internal/reline/lib/reline/version.rb +3 -0
  231. data/lib/llm/shell/internal/reline/lib/reline.rb +527 -0
  232. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/generated_parser.rb +712 -0
  233. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/handler.rb +268 -0
  234. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_date.rb +35 -0
  235. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_date_time.rb +42 -0
  236. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/local_time.rb +40 -0
  237. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/parser.rb +21 -0
  238. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/scanner.rb +92 -0
  239. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/string_utils.rb +40 -0
  240. data/lib/llm/shell/internal/tomlrb/lib/tomlrb/version.rb +5 -0
  241. data/lib/llm/shell/internal/tomlrb/lib/tomlrb.rb +49 -0
  242. data/lib/llm/shell/options.rb +1 -1
  243. data/lib/llm/shell/renderer.rb +2 -3
  244. data/lib/llm/shell/repl.rb +21 -16
  245. data/lib/llm/shell/tool.rb +42 -0
  246. data/lib/llm/shell/tools/read_file.rb +15 -0
  247. data/lib/llm/shell/tools/system.rb +17 -0
  248. data/lib/llm/shell/tools/write_file.rb +16 -0
  249. data/lib/llm/shell/version.rb +1 -1
  250. data/lib/llm/shell.rb +83 -39
  251. data/libexec/llm-shell/shell +4 -6
  252. data/llm-shell.gemspec +0 -4
  253. metadata +233 -63
  254. data/lib/llm/function.rb +0 -17
  255. data/lib/llm/shell/command/extension.rb +0 -42
  256. data/lib/llm/shell/commands/utils.rb +0 -21
  257. data/lib/llm/shell/functions/read_file.rb +0 -22
  258. data/lib/llm/shell/functions/write_file.rb +0 -22
@@ -0,0 +1,221 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ # Scanner for output of the diff command.
5
+ #
6
+ # Alias: +patch+
7
+ class Diff < Scanner
8
+
9
+ register_for :diff
10
+ title 'diff output'
11
+
12
+ DEFAULT_OPTIONS = {
13
+ :highlight_code => true,
14
+ :inline_diff => true,
15
+ }
16
+
17
+ protected
18
+
19
+ def scan_tokens encoder, options
20
+
21
+ line_kind = nil
22
+ state = :initial
23
+ deleted_lines_count = 0
24
+ scanners = Hash.new do |h, lang|
25
+ h[lang] = Scanners[lang].new '', :keep_tokens => true, :keep_state => true
26
+ end
27
+ content_scanner = scanners[:plain]
28
+ content_scanner_entry_state = nil
29
+
30
+ until eos?
31
+
32
+ if match = scan(/\n/)
33
+ deleted_lines_count = 0 unless line_kind == :delete
34
+ if line_kind
35
+ encoder.end_line line_kind
36
+ line_kind = nil
37
+ end
38
+ encoder.text_token match, :space
39
+ next
40
+ end
41
+
42
+ case state
43
+
44
+ when :initial
45
+ if match = scan(/--- |\+\+\+ |=+|_+/)
46
+ encoder.begin_line line_kind = :head
47
+ encoder.text_token match, :head
48
+ if match = scan(/[^\x00\n]+?(?=$|[\t\n]| \(revision)/)
49
+ encoder.text_token match, :filename
50
+ if options[:highlight_code] && match != '/dev/null'
51
+ file_type = CodeRay::FileType.fetch(match, :text)
52
+ file_type = :text if file_type == :diff
53
+ content_scanner = scanners[file_type]
54
+ content_scanner_entry_state = nil
55
+ end
56
+ end
57
+ next unless match = scan(/.+/)
58
+ encoder.text_token match, :plain
59
+ elsif match = scan(/Index: |Property changes on: /)
60
+ encoder.begin_line line_kind = :head
61
+ encoder.text_token match, :head
62
+ next unless match = scan(/.+/)
63
+ encoder.text_token match, :plain
64
+ elsif match = scan(/Added: /)
65
+ encoder.begin_line line_kind = :head
66
+ encoder.text_token match, :head
67
+ next unless match = scan(/.+/)
68
+ encoder.text_token match, :plain
69
+ state = :added
70
+ elsif match = scan(/\\ .*/)
71
+ encoder.text_token match, :comment
72
+ elsif match = scan(/@@(?>[^@\n]+)@@/)
73
+ content_scanner.state = :initial unless match?(/\n\+/)
74
+ content_scanner_entry_state = nil
75
+ if check(/\n|$/)
76
+ encoder.begin_line line_kind = :change
77
+ else
78
+ encoder.begin_group :change
79
+ end
80
+ encoder.text_token match[0,2], :change
81
+ encoder.text_token match[2...-2], :plain
82
+ encoder.text_token match[-2,2], :change
83
+ encoder.end_group :change unless line_kind
84
+ next unless match = scan(/.+/)
85
+ if options[:highlight_code]
86
+ content_scanner.tokenize match, :tokens => encoder
87
+ else
88
+ encoder.text_token match, :plain
89
+ end
90
+ next
91
+ elsif match = scan(/\+/)
92
+ encoder.begin_line line_kind = :insert
93
+ encoder.text_token match, :insert
94
+ next unless match = scan(/.+/)
95
+ if options[:highlight_code]
96
+ content_scanner.tokenize match, :tokens => encoder
97
+ else
98
+ encoder.text_token match, :plain
99
+ end
100
+ next
101
+ elsif match = scan(/-/)
102
+ deleted_lines_count += 1
103
+ if options[:inline_diff] && deleted_lines_count == 1 && (changed_lines_count = 1 + check(/.*(?:\n\-.*)*/).count("\n")) && changed_lines_count <= 100_000 && match?(/(?>.*(?:\n\-.*){#{changed_lines_count - 1}}(?:\n\+.*){#{changed_lines_count}})$(?!\n\+)/)
104
+ deleted_lines = Array.new(changed_lines_count) { |i| skip(/\n\-/) if i > 0; scan(/.*/) }
105
+ inserted_lines = Array.new(changed_lines_count) { |i| skip(/\n\+/) ; scan(/.*/) }
106
+
107
+ deleted_lines_tokenized = []
108
+ inserted_lines_tokenized = []
109
+ for deleted_line, inserted_line in deleted_lines.zip(inserted_lines)
110
+ pre, deleted_part, inserted_part, post = diff deleted_line, inserted_line
111
+ content_scanner_entry_state = content_scanner.state
112
+ deleted_lines_tokenized << content_scanner.tokenize([pre, deleted_part, post], :tokens => Tokens.new)
113
+ content_scanner.state = content_scanner_entry_state || :initial
114
+ inserted_lines_tokenized << content_scanner.tokenize([pre, inserted_part, post], :tokens => Tokens.new)
115
+ end
116
+
117
+ for pre, deleted_part, post in deleted_lines_tokenized
118
+ encoder.begin_line :delete
119
+ encoder.text_token '-', :delete
120
+ encoder.tokens pre
121
+ unless deleted_part.empty?
122
+ encoder.begin_group :eyecatcher
123
+ encoder.tokens deleted_part
124
+ encoder.end_group :eyecatcher
125
+ end
126
+ encoder.tokens post
127
+ encoder.end_line :delete
128
+ encoder.text_token "\n", :space
129
+ end
130
+
131
+ for pre, inserted_part, post in inserted_lines_tokenized
132
+ encoder.begin_line :insert
133
+ encoder.text_token '+', :insert
134
+ encoder.tokens pre
135
+ unless inserted_part.empty?
136
+ encoder.begin_group :eyecatcher
137
+ encoder.tokens inserted_part
138
+ encoder.end_group :eyecatcher
139
+ end
140
+ encoder.tokens post
141
+ changed_lines_count -= 1
142
+ if changed_lines_count > 0
143
+ encoder.end_line :insert
144
+ encoder.text_token "\n", :space
145
+ end
146
+ end
147
+
148
+ line_kind = :insert
149
+
150
+ elsif match = scan(/.*/)
151
+ encoder.begin_line line_kind = :delete
152
+ encoder.text_token '-', :delete
153
+ if options[:highlight_code]
154
+ if deleted_lines_count == 1
155
+ content_scanner_entry_state = content_scanner.state
156
+ end
157
+ content_scanner.tokenize match, :tokens => encoder unless match.empty?
158
+ if !match?(/\n-/)
159
+ if match?(/\n\+/)
160
+ content_scanner.state = content_scanner_entry_state || :initial
161
+ end
162
+ content_scanner_entry_state = nil
163
+ end
164
+ else
165
+ encoder.text_token match, :plain
166
+ end
167
+ end
168
+ next
169
+ elsif match = scan(/ .*/)
170
+ if options[:highlight_code]
171
+ content_scanner.tokenize match, :tokens => encoder
172
+ else
173
+ encoder.text_token match, :plain
174
+ end
175
+ next
176
+ elsif match = scan(/.+/)
177
+ encoder.begin_line line_kind = :comment
178
+ encoder.text_token match, :plain
179
+ else
180
+ raise_inspect 'else case rached'
181
+ end
182
+
183
+ when :added
184
+ if match = scan(/ \+/)
185
+ encoder.begin_line line_kind = :insert
186
+ encoder.text_token match, :insert
187
+ next unless match = scan(/.+/)
188
+ encoder.text_token match, :plain
189
+ else
190
+ state = :initial
191
+ next
192
+ end
193
+ end
194
+
195
+ end
196
+
197
+ encoder.end_line line_kind if line_kind
198
+
199
+ encoder
200
+ end
201
+
202
+ private
203
+
204
+ def diff a, b
205
+ # i will be the index of the leftmost difference from the left.
206
+ i_max = [a.size, b.size].min
207
+ i = 0
208
+ i += 1 while i < i_max && a[i] == b[i]
209
+ # j_min will be the index of the leftmost difference from the right.
210
+ j_min = i - i_max
211
+ # j will be the index of the rightmost difference from the right which
212
+ # does not precede the leftmost one from the left.
213
+ j = -1
214
+ j -= 1 while j >= j_min && a[j] == b[j]
215
+ return a[0...i], a[i..j], b[i..j], (j < -1) ? a[j + 1..-1] : ''
216
+ end
217
+
218
+ end
219
+
220
+ end
221
+ end
@@ -0,0 +1,81 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ load :html
5
+ load :ruby
6
+
7
+ # Scanner for HTML ERB templates.
8
+ class ERB < Scanner
9
+
10
+ register_for :erb
11
+ title 'HTML ERB Template'
12
+
13
+ KINDS_NOT_LOC = HTML::KINDS_NOT_LOC
14
+
15
+ ERB_RUBY_BLOCK = /
16
+ (<%(?!%)[-=\#]?)
17
+ ((?>
18
+ [^\-%]* # normal*
19
+ (?> # special
20
+ (?: %(?!>) | -(?!%>) )
21
+ [^\-%]* # normal*
22
+ )*
23
+ ))
24
+ ((?: -?%> )?)
25
+ /x # :nodoc:
26
+
27
+ START_OF_ERB = /
28
+ <%(?!%)
29
+ /x # :nodoc:
30
+
31
+ protected
32
+
33
+ def setup
34
+ @ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true
35
+ @html_scanner = CodeRay.scanner :html, :tokens => @tokens, :keep_tokens => true, :keep_state => true
36
+ end
37
+
38
+ def reset_instance
39
+ super
40
+ @html_scanner.reset
41
+ end
42
+
43
+ def scan_tokens encoder, options
44
+
45
+ until eos?
46
+
47
+ if (match = scan_until(/(?=#{START_OF_ERB})/o) || scan_rest) and not match.empty?
48
+ @html_scanner.tokenize match, :tokens => encoder
49
+
50
+ elsif match = scan(/#{ERB_RUBY_BLOCK}/o)
51
+ start_tag = self[1]
52
+ code = self[2]
53
+ end_tag = self[3]
54
+
55
+ encoder.begin_group :inline
56
+ encoder.text_token start_tag, :inline_delimiter
57
+
58
+ if start_tag == '<%#'
59
+ encoder.text_token code, :comment
60
+ else
61
+ @ruby_scanner.tokenize code, :tokens => encoder
62
+ end unless code.empty?
63
+
64
+ encoder.text_token end_tag, :inline_delimiter unless end_tag.empty?
65
+ encoder.end_group :inline
66
+
67
+ else
68
+ raise_inspect 'else-case reached!', encoder
69
+
70
+ end
71
+
72
+ end
73
+
74
+ encoder
75
+
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,208 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ class Go < Scanner
5
+
6
+ register_for :go
7
+ file_extension 'go'
8
+
9
+ # http://golang.org/ref/spec#Keywords
10
+ KEYWORDS = [
11
+ 'break', 'default', 'func', 'interface', 'select',
12
+ 'case', 'defer', 'go', 'map', 'struct',
13
+ 'chan', 'else', 'goto', 'package', 'switch',
14
+ 'const', 'fallthrough', 'if', 'range', 'type',
15
+ 'continue', 'for', 'import', 'return', 'var',
16
+ ] # :nodoc:
17
+
18
+ # http://golang.org/ref/spec#Types
19
+ PREDEFINED_TYPES = [
20
+ 'bool',
21
+ 'uint8', 'uint16', 'uint32', 'uint64',
22
+ 'int8', 'int16', 'int32', 'int64',
23
+ 'float32', 'float64',
24
+ 'complex64', 'complex128',
25
+ 'byte', 'rune', 'string', 'error',
26
+ 'uint', 'int', 'uintptr',
27
+ ] # :nodoc:
28
+
29
+ PREDEFINED_CONSTANTS = [
30
+ 'nil', 'iota',
31
+ 'true', 'false',
32
+ ] # :nodoc:
33
+
34
+ PREDEFINED_FUNCTIONS = %w[
35
+ append cap close complex copy delete imag len
36
+ make new panic print println real recover
37
+ ] # :nodoc:
38
+
39
+ IDENT_KIND = WordList.new(:ident).
40
+ add(KEYWORDS, :keyword).
41
+ add(PREDEFINED_TYPES, :predefined_type).
42
+ add(PREDEFINED_CONSTANTS, :predefined_constant).
43
+ add(PREDEFINED_FUNCTIONS, :predefined) # :nodoc:
44
+
45
+ ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
46
+ UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
47
+
48
+ protected
49
+
50
+ def scan_tokens encoder, options
51
+
52
+ state = :initial
53
+ label_expected = true
54
+ case_expected = false
55
+ label_expected_before_preproc_line = nil
56
+ in_preproc_line = false
57
+
58
+ until eos?
59
+
60
+ case state
61
+
62
+ when :initial
63
+
64
+ if match = scan(/ \s+ | \\\n /x)
65
+ if in_preproc_line && match != "\\\n" && match.index(?\n)
66
+ in_preproc_line = false
67
+ case_expected = false
68
+ label_expected = label_expected_before_preproc_line
69
+ end
70
+ encoder.text_token match, :space
71
+
72
+ elsif match = scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
73
+ encoder.text_token match, :comment
74
+
75
+ elsif match = scan(/ <?- (?![\d.]) | [+*=<>?:;,!&^|()\[\]{}~%]+ | \/=? | \.(?!\d) /x)
76
+ if case_expected
77
+ label_expected = true if match == ':'
78
+ case_expected = false
79
+ end
80
+ encoder.text_token match, :operator
81
+
82
+ elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
83
+ kind = IDENT_KIND[match]
84
+ if kind == :ident && label_expected && !in_preproc_line && scan(/:(?!:)/)
85
+ kind = :label
86
+ label_expected = false
87
+ match << matched
88
+ else
89
+ label_expected = false
90
+ if kind == :keyword
91
+ case match
92
+ when 'case', 'default'
93
+ case_expected = true
94
+ end
95
+ end
96
+ end
97
+ encoder.text_token match, kind
98
+
99
+ elsif match = scan(/L?"/)
100
+ encoder.begin_group :string
101
+ if match[0] == ?L
102
+ encoder.text_token 'L', :modifier
103
+ match = '"'
104
+ end
105
+ encoder.text_token match, :delimiter
106
+ state = :string
107
+
108
+ elsif match = scan(/ ` ([^`]+)? (`)? /x)
109
+ encoder.begin_group :shell
110
+ encoder.text_token '`', :delimiter
111
+ encoder.text_token self[1], :content if self[1]
112
+ encoder.text_token self[2], :delimiter if self[2]
113
+ encoder.end_group :shell
114
+
115
+ elsif match = scan(/ \# \s* if \s* 0 /x)
116
+ match << scan_until(/ ^\# (?:elif|else|endif) .*? $ | \z /xm) unless eos?
117
+ encoder.text_token match, :comment
118
+
119
+ elsif match = scan(/#[ \t]*(\w*)/)
120
+ encoder.text_token match, :preprocessor
121
+ in_preproc_line = true
122
+ label_expected_before_preproc_line = label_expected
123
+ state = :include_expected if self[1] == 'include'
124
+
125
+ elsif match = scan(/ L?' (?: [^\'\n\\] | \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) )? '? /ox)
126
+ label_expected = false
127
+ encoder.text_token match, :char
128
+
129
+ elsif match = scan(/\$/)
130
+ encoder.text_token match, :ident
131
+
132
+ elsif match = scan(/-?\d*(\.\d*)?([eE][+-]?\d+)?i/)
133
+ label_expected = false
134
+ encoder.text_token match, :imaginary
135
+
136
+ elsif match = scan(/-?0[xX][0-9A-Fa-f]+/)
137
+ label_expected = false
138
+ encoder.text_token match, :hex
139
+
140
+ elsif match = scan(/-?(?:0[0-7]+)(?![89.eEfF])/)
141
+ label_expected = false
142
+ encoder.text_token match, :octal
143
+
144
+ elsif match = scan(/-?(?:\d*\.\d+|\d+\.)(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+/)
145
+ label_expected = false
146
+ encoder.text_token match, :float
147
+
148
+ elsif match = scan(/-?(?:\d+)(?![.eEfF])L?L?/)
149
+ label_expected = false
150
+ encoder.text_token match, :integer
151
+
152
+ else
153
+ encoder.text_token getch, :error
154
+
155
+ end
156
+
157
+ when :string
158
+ if match = scan(/[^\\\n"]+/)
159
+ encoder.text_token match, :content
160
+ elsif match = scan(/"/)
161
+ encoder.text_token match, :delimiter
162
+ encoder.end_group :string
163
+ state = :initial
164
+ label_expected = false
165
+ elsif match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
166
+ encoder.text_token match, :char
167
+ elsif match = scan(/ \\ /x)
168
+ encoder.text_token match, :error
169
+ elsif match = scan(/$/)
170
+ encoder.end_group :string
171
+ state = :initial
172
+ label_expected = false
173
+ else
174
+ raise_inspect "else case \" reached; %p not handled." % peek(1), encoder
175
+ end
176
+
177
+ when :include_expected
178
+ if match = scan(/<[^>\n]+>?|"[^"\n\\]*(?:\\.[^"\n\\]*)*"?/)
179
+ encoder.text_token match, :include
180
+ state = :initial
181
+
182
+ elsif match = scan(/\s+/)
183
+ encoder.text_token match, :space
184
+ state = :initial if match.index ?\n
185
+
186
+ else
187
+ state = :initial
188
+
189
+ end
190
+
191
+ else
192
+ raise_inspect 'Unknown state', encoder
193
+
194
+ end
195
+
196
+ end
197
+
198
+ if state == :string
199
+ encoder.end_group :string
200
+ end
201
+
202
+ encoder
203
+ end
204
+
205
+ end
206
+
207
+ end
208
+ end