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,72 @@
1
+ module CodeRay
2
+ module Encoders
3
+
4
+ # = XML Encoder
5
+ #
6
+ # Uses REXML. Very slow.
7
+ class XML < Encoder
8
+
9
+ register_for :xml
10
+
11
+ FILE_EXTENSION = 'xml'
12
+
13
+ autoload :REXML, 'rexml/document'
14
+
15
+ DEFAULT_OPTIONS = {
16
+ :tab_width => 8,
17
+ :pretty => -1,
18
+ :transitive => false,
19
+ }
20
+
21
+ protected
22
+ def setup options
23
+ super
24
+
25
+ @doc = REXML::Document.new
26
+ @doc << REXML::XMLDecl.new
27
+ @tab_width = options[:tab_width]
28
+ @root = @node = @doc.add_element('coderay-tokens')
29
+ end
30
+
31
+ def finish options
32
+ @doc.write @out, options[:pretty], options[:transitive], true
33
+
34
+ super
35
+ end
36
+
37
+ public
38
+ def text_token text, kind
39
+ if kind == :space
40
+ token = @node
41
+ else
42
+ token = @node.add_element kind.to_s
43
+ end
44
+ text.scan(/(\x20+)|(\t+)|(\n)|[^\x20\t\n]+/) do |space, tab, nl|
45
+ case
46
+ when space
47
+ token << REXML::Text.new(space, true)
48
+ when tab
49
+ token << REXML::Text.new(tab, true)
50
+ when nl
51
+ token << REXML::Text.new(nl, true)
52
+ else
53
+ token << REXML::Text.new($&)
54
+ end
55
+ end
56
+ end
57
+
58
+ def begin_group kind
59
+ @node = @node.add_element kind.to_s
60
+ end
61
+
62
+ def end_group kind
63
+ if @node == @root
64
+ raise 'no token to close!'
65
+ end
66
+ @node = @node.parent
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,50 @@
1
+ autoload :YAML, 'yaml'
2
+
3
+ module CodeRay
4
+ module Encoders
5
+
6
+ # = YAML Encoder
7
+ #
8
+ # Slow.
9
+ class YAML < Encoder
10
+
11
+ register_for :yaml
12
+
13
+ FILE_EXTENSION = 'yaml'
14
+
15
+ protected
16
+ def setup options
17
+ super
18
+
19
+ @data = []
20
+ end
21
+
22
+ def finish options
23
+ output ::YAML.dump(@data)
24
+ end
25
+
26
+ public
27
+ def text_token text, kind
28
+ @data << [text, kind]
29
+ end
30
+
31
+ def begin_group kind
32
+ @data << [:begin_group, kind]
33
+ end
34
+
35
+ def end_group kind
36
+ @data << [:end_group, kind]
37
+ end
38
+
39
+ def begin_line kind
40
+ @data << [:begin_line, kind]
41
+ end
42
+
43
+ def end_line kind
44
+ @data << [:end_line, kind]
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,18 @@
1
+ module CodeRay
2
+
3
+ # This module holds the Encoder class and its subclasses.
4
+ # For example, the HTML encoder is named CodeRay::Encoders::HTML
5
+ # can be found in coderay/encoders/html.
6
+ #
7
+ # Encoders also provides methods and constants for the register
8
+ # mechanism and the [] method that returns the Encoder class
9
+ # belonging to the given format.
10
+ module Encoders
11
+
12
+ extend PluginHost
13
+ plugin_path File.dirname(__FILE__), 'encoders'
14
+
15
+ autoload :Encoder, CodeRay.coderay_path('encoders', 'encoder')
16
+
17
+ end
18
+ end
@@ -0,0 +1,95 @@
1
+ module CodeRay
2
+
3
+ # A little hack to enable CodeRay highlighting in RedCloth.
4
+ #
5
+ # Usage:
6
+ # require 'coderay'
7
+ # require 'coderay/for_redcloth'
8
+ # RedCloth.new('@[ruby]puts "Hello, World!"@').to_html
9
+ #
10
+ # Make sure you have RedCloth 4.0.3 activated, for example by calling
11
+ # require 'rubygems'
12
+ # before RedCloth is loaded and before calling CodeRay.for_redcloth.
13
+ module ForRedCloth
14
+
15
+ def self.install
16
+ gem 'RedCloth', '>= 4.0.3' if defined? gem
17
+ require 'redcloth'
18
+ unless RedCloth::VERSION.to_s >= '4.0.3'
19
+ if defined? gem
20
+ raise 'CodeRay.for_redcloth needs RedCloth version 4.0.3 or later. ' +
21
+ "You have #{RedCloth::VERSION}. Please gem install RedCloth."
22
+ else
23
+ $".delete 'redcloth.rb' # sorry, but it works
24
+ require 'rubygems'
25
+ return install # retry
26
+ end
27
+ end
28
+ unless RedCloth::VERSION.to_s >= '4.2.2'
29
+ warn 'CodeRay.for_redcloth works best with RedCloth version 4.2.2 or later.'
30
+ end
31
+ RedCloth::TextileDoc.send :include, ForRedCloth::TextileDoc
32
+ RedCloth::Formatters::HTML.module_eval do
33
+ def unescape(html) # :nodoc:
34
+ replacements = {
35
+ '&amp;' => '&',
36
+ '&quot;' => '"',
37
+ '&gt;' => '>',
38
+ '&lt;' => '<',
39
+ }
40
+ html.gsub(/&(?:amp|quot|[gl]t);/) { |entity| replacements[entity] }
41
+ end
42
+ undef code, bc_open, bc_close, escape_pre
43
+ def code(opts) # :nodoc:
44
+ opts[:block] = true
45
+ if !opts[:lang] && RedCloth::VERSION.to_s >= '4.2.0'
46
+ # simulating pre-4.2 behavior
47
+ if opts[:text].sub!(/\A\[(\w+)\]/, '')
48
+ if CodeRay::Scanners[$1].lang == :text
49
+ opts[:text] = $& + opts[:text]
50
+ else
51
+ opts[:lang] = $1
52
+ end
53
+ end
54
+ end
55
+ if opts[:lang] && !filter_coderay
56
+ require 'coderay'
57
+ @in_bc ||= nil
58
+ format = @in_bc ? :div : :span
59
+ opts[:text] = unescape(opts[:text]) unless @in_bc
60
+ highlighted_code = CodeRay.encode opts[:text], opts[:lang], format
61
+ highlighted_code.sub!(/\A<(span|div)/) { |m| m + pba(@in_bc || opts) }
62
+ highlighted_code
63
+ else
64
+ "<code#{pba(opts)}>#{opts[:text]}</code>"
65
+ end
66
+ end
67
+ def bc_open(opts) # :nodoc:
68
+ opts[:block] = true
69
+ @in_bc = opts
70
+ opts[:lang] ? '' : "<pre#{pba(opts)}>"
71
+ end
72
+ def bc_close(opts) # :nodoc:
73
+ opts = @in_bc
74
+ @in_bc = nil
75
+ opts[:lang] ? '' : "</pre>\n"
76
+ end
77
+ def escape_pre(text) # :nodoc:
78
+ if @in_bc ||= nil
79
+ text
80
+ else
81
+ html_esc(text, :html_escape_preformatted)
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ module TextileDoc # :nodoc:
88
+ attr_accessor :filter_coderay
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+ CodeRay::ForRedCloth.install
@@ -0,0 +1,151 @@
1
+ module CodeRay
2
+
3
+ # = FileType
4
+ #
5
+ # A simple filetype recognizer.
6
+ #
7
+ # == Usage
8
+ #
9
+ # # determine the type of the given
10
+ # lang = FileType[file_name]
11
+ #
12
+ # # return :text if the file type is unknown
13
+ # lang = FileType.fetch file_name, :text
14
+ #
15
+ # # try the shebang line, too
16
+ # lang = FileType.fetch file_name, :text, true
17
+ module FileType
18
+
19
+ UnknownFileType = Class.new Exception
20
+
21
+ class << self
22
+
23
+ # Try to determine the file type of the file.
24
+ #
25
+ # +filename+ is a relative or absolute path to a file.
26
+ #
27
+ # The file itself is only accessed when +read_shebang+ is set to true.
28
+ # That means you can get filetypes from files that don't exist.
29
+ def [] filename, read_shebang = false
30
+ name = File.basename filename
31
+ ext = File.extname(name).sub(/^\./, '') # from last dot, delete the leading dot
32
+ ext2 = filename.to_s[/\.(.*)/, 1] # from first dot
33
+
34
+ type =
35
+ TypeFromExt[ext] ||
36
+ TypeFromExt[ext.downcase] ||
37
+ (TypeFromExt[ext2] if ext2) ||
38
+ (TypeFromExt[ext2.downcase] if ext2) ||
39
+ TypeFromName[name] ||
40
+ TypeFromName[name.downcase]
41
+ type ||= type_from_shebang(filename) if read_shebang
42
+
43
+ type
44
+ end
45
+
46
+ # This works like Hash#fetch.
47
+ #
48
+ # If the filetype cannot be found, the +default+ value
49
+ # is returned.
50
+ def fetch filename, default = nil, read_shebang = false
51
+ if default && block_given?
52
+ warn 'Block supersedes default value argument; use either.'
53
+ end
54
+
55
+ if type = self[filename, read_shebang]
56
+ type
57
+ else
58
+ return yield if block_given?
59
+ return default if default
60
+ raise UnknownFileType, 'Could not determine type of %p.' % filename
61
+ end
62
+ end
63
+
64
+ protected
65
+
66
+ def type_from_shebang filename
67
+ return unless File.exist? filename
68
+ File.open filename, 'r' do |f|
69
+ if first_line = f.gets
70
+ if type = first_line[TypeFromShebang]
71
+ type.to_sym
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ TypeFromExt = {
80
+ 'c' => :c,
81
+ 'cfc' => :xml,
82
+ 'cfm' => :xml,
83
+ 'clj' => :clojure,
84
+ 'css' => :css,
85
+ 'diff' => :diff,
86
+ 'dpr' => :delphi,
87
+ 'erb' => :erb,
88
+ 'gemspec' => :ruby,
89
+ 'go' => :go,
90
+ 'groovy' => :groovy,
91
+ 'gvy' => :groovy,
92
+ 'h' => :c,
93
+ 'haml' => :haml,
94
+ 'htm' => :html,
95
+ 'html' => :html,
96
+ 'html.erb' => :erb,
97
+ 'java' => :java,
98
+ 'js' => :java_script,
99
+ 'json' => :json,
100
+ 'lua' => :lua,
101
+ 'mab' => :ruby,
102
+ 'pas' => :delphi,
103
+ 'patch' => :diff,
104
+ 'phtml' => :php,
105
+ 'php' => :php,
106
+ 'php3' => :php,
107
+ 'php4' => :php,
108
+ 'php5' => :php,
109
+ 'prawn' => :ruby,
110
+ 'py' => :python,
111
+ 'py3' => :python,
112
+ 'pyw' => :python,
113
+ 'rake' => :ruby,
114
+ 'raydebug' => :raydebug,
115
+ 'rb' => :ruby,
116
+ 'rbw' => :ruby,
117
+ 'rhtml' => :erb,
118
+ 'rjs' => :ruby,
119
+ 'rpdf' => :ruby,
120
+ 'ru' => :ruby, # config.ru
121
+ 'rxml' => :ruby,
122
+ 'sass' => :sass,
123
+ 'sql' => :sql,
124
+ 'taskpaper' => :taskpaper,
125
+ 'template' => :json, # AWS CloudFormation template
126
+ 'tmproj' => :xml,
127
+ 'xaml' => :xml,
128
+ 'xhtml' => :html,
129
+ 'xml' => :xml,
130
+ 'yaml' => :yaml,
131
+ 'yml' => :yaml,
132
+ }
133
+ for cpp_alias in %w[cc cpp cp cxx c++ C hh hpp h++ cu]
134
+ TypeFromExt[cpp_alias] = :cpp
135
+ end
136
+
137
+ TypeFromShebang = /\b(?:ruby|perl|python|sh)\b/
138
+
139
+ TypeFromName = {
140
+ 'Capfile' => :ruby,
141
+ 'Rakefile' => :ruby,
142
+ 'Rantfile' => :ruby,
143
+ 'Gemfile' => :ruby,
144
+ 'Guardfile' => :ruby,
145
+ 'Vagrantfile' => :ruby,
146
+ 'Appraisals' => :ruby
147
+ }
148
+
149
+ end
150
+
151
+ end
@@ -0,0 +1,55 @@
1
+ module CodeRay
2
+
3
+ # = Plugin
4
+ #
5
+ # Plugins have to include this module.
6
+ #
7
+ # IMPORTANT: Use extend for this module.
8
+ #
9
+ # See CodeRay::PluginHost for examples.
10
+ module Plugin
11
+
12
+ attr_reader :plugin_id
13
+
14
+ # Register this class for the given +id+.
15
+ #
16
+ # Example:
17
+ # class MyPlugin < PluginHost::BaseClass
18
+ # register_for :my_id
19
+ # ...
20
+ # end
21
+ #
22
+ # See PluginHost.register.
23
+ def register_for id
24
+ @plugin_id = id
25
+ plugin_host.register self, id
26
+ end
27
+
28
+ # Returns the title of the plugin, or sets it to the
29
+ # optional argument +title+.
30
+ def title title = nil
31
+ if title
32
+ @title = title.to_s
33
+ else
34
+ @title ||= name[/([^:]+)$/, 1]
35
+ end
36
+ end
37
+
38
+ # The PluginHost for this Plugin class.
39
+ def plugin_host host = nil
40
+ if host.is_a? PluginHost
41
+ const_set :PLUGIN_HOST, host
42
+ end
43
+ self::PLUGIN_HOST
44
+ end
45
+
46
+ def aliases
47
+ plugin_host.plugin_hash.inject [] do |aliases, (key, _)|
48
+ aliases << key if plugin_host[key] == self
49
+ aliases
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,221 @@
1
+ module CodeRay
2
+
3
+ # = PluginHost
4
+ #
5
+ # A simple subclass/subfolder plugin system.
6
+ #
7
+ # Example:
8
+ # class Generators
9
+ # extend PluginHost
10
+ # plugin_path 'app/generators'
11
+ # end
12
+ #
13
+ # class Generator
14
+ # extend Plugin
15
+ # PLUGIN_HOST = Generators
16
+ # end
17
+ #
18
+ # class FancyGenerator < Generator
19
+ # register_for :fancy
20
+ # end
21
+ #
22
+ # Generators[:fancy] #-> FancyGenerator
23
+ # # or
24
+ # CodeRay.require_plugin 'Generators/fancy'
25
+ # # or
26
+ # Generators::Fancy
27
+ module PluginHost
28
+
29
+ # Raised if Encoders::[] fails because:
30
+ # * a file could not be found
31
+ # * the requested Plugin is not registered
32
+ PluginNotFound = Class.new LoadError
33
+ HostNotFound = Class.new LoadError
34
+
35
+ PLUGIN_HOSTS = []
36
+ PLUGIN_HOSTS_BY_ID = {} # dummy hash
37
+
38
+ # Loads all plugins using list and load.
39
+ def load_all
40
+ for plugin in list
41
+ load plugin
42
+ end
43
+ end
44
+
45
+ # Returns the Plugin for +id+.
46
+ #
47
+ # Example:
48
+ # yaml_plugin = MyPluginHost[:yaml]
49
+ def [] id, *args, &blk
50
+ plugin = validate_id(id)
51
+ begin
52
+ plugin = plugin_hash.[](plugin, *args, &blk)
53
+ end while plugin.is_a? String
54
+ plugin
55
+ end
56
+
57
+ alias load []
58
+
59
+ # Tries to +load+ the missing plugin by translating +const+ to the
60
+ # underscore form (eg. LinesOfCode becomes lines_of_code).
61
+ def const_missing const
62
+ id = const.to_s.
63
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
64
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
65
+ downcase
66
+ load id
67
+ end
68
+
69
+ class << self
70
+
71
+ # Adds the module/class to the PLUGIN_HOSTS list.
72
+ def extended mod
73
+ PLUGIN_HOSTS << mod
74
+ end
75
+
76
+ end
77
+
78
+ # The path where the plugins can be found.
79
+ def plugin_path *args
80
+ unless args.empty?
81
+ @plugin_path = File.expand_path File.join(*args)
82
+ end
83
+ @plugin_path ||= ''
84
+ end
85
+
86
+ # Map a plugin_id to another.
87
+ #
88
+ # Usage: Put this in a file plugin_path/_map.rb.
89
+ #
90
+ # class MyColorHost < PluginHost
91
+ # map :navy => :dark_blue,
92
+ # :maroon => :brown,
93
+ # :luna => :moon
94
+ # end
95
+ def map hash
96
+ for from, to in hash
97
+ from = validate_id from
98
+ to = validate_id to
99
+ plugin_hash[from] = to unless plugin_hash.has_key? from
100
+ end
101
+ end
102
+
103
+ # Define the default plugin to use when no plugin is found
104
+ # for a given id, or return the default plugin.
105
+ #
106
+ # See also map.
107
+ #
108
+ # class MyColorHost < PluginHost
109
+ # map :navy => :dark_blue
110
+ # default :gray
111
+ # end
112
+ #
113
+ # MyColorHost.default # loads and returns the Gray plugin
114
+ def default id = nil
115
+ if id
116
+ id = validate_id id
117
+ raise "The default plugin can't be named \"default\"." if id == :default
118
+ plugin_hash[:default] = id
119
+ else
120
+ load :default
121
+ end
122
+ end
123
+
124
+ # Every plugin must register itself for +id+ by calling register_for,
125
+ # which calls this method.
126
+ #
127
+ # See Plugin#register_for.
128
+ def register plugin, id
129
+ plugin_hash[validate_id(id)] = plugin
130
+ end
131
+
132
+ # A Hash of plugion_id => Plugin pairs.
133
+ def plugin_hash
134
+ @plugin_hash ||= (@plugin_hash = make_plugin_hash).tap { load_plugin_map }
135
+ end
136
+
137
+ # Returns an array of all .rb files in the plugin path.
138
+ #
139
+ # The extension .rb is not included.
140
+ def list
141
+ Dir[path_to('*')].select do |file|
142
+ File.basename(file)[/^(?!_)\w+\.rb$/]
143
+ end.map do |file|
144
+ File.basename(file, '.rb').to_sym
145
+ end
146
+ end
147
+
148
+ # Returns an array of all Plugins.
149
+ #
150
+ # Note: This loads all plugins using load_all.
151
+ def all_plugins
152
+ load_all
153
+ plugin_hash.values.grep(Class)
154
+ end
155
+
156
+ # Loads the map file (see map).
157
+ #
158
+ # This is done automatically when plugin_path is called.
159
+ def load_plugin_map
160
+ mapfile = path_to '_map'
161
+ if File.exist? mapfile
162
+ require mapfile
163
+ true
164
+ else
165
+ false
166
+ end
167
+ end
168
+
169
+ protected
170
+
171
+ # Return a plugin hash that automatically loads plugins.
172
+ def make_plugin_hash
173
+ Hash.new do |h, plugin_id|
174
+ id = validate_id(plugin_id)
175
+ path = path_to id
176
+ begin
177
+ require path
178
+ rescue LoadError => boom
179
+ if h.has_key?(:default)
180
+ h[:default]
181
+ else
182
+ raise PluginNotFound, '%p could not load plugin %p: %s' % [self, id, boom]
183
+ end
184
+ else
185
+ # Plugin should have registered by now
186
+ if h.has_key? id
187
+ h[id]
188
+ else
189
+ raise PluginNotFound, "No #{self.name} plugin for #{id.inspect} found in #{path}."
190
+ end
191
+ end
192
+ end
193
+ end
194
+
195
+ # Returns the expected path to the plugin file for the given id.
196
+ def path_to plugin_id
197
+ File.join plugin_path, "#{plugin_id}.rb"
198
+ end
199
+
200
+ # Converts +id+ to a valid plugin ID String, or returns +nil+.
201
+ #
202
+ # Raises +ArgumentError+ for all other objects, or if the
203
+ # given String includes non-alphanumeric characters (\W).
204
+ def validate_id id
205
+ case id
206
+ when Symbol
207
+ id.to_s
208
+ when String
209
+ if id[/\w+/] == id
210
+ id.downcase
211
+ else
212
+ raise ArgumentError, "Invalid id given: #{id}"
213
+ end
214
+ else
215
+ raise ArgumentError, "Symbol or String expected, but #{id.class} given."
216
+ end
217
+ end
218
+
219
+ end
220
+
221
+ end