Module: OllamaChat::Commands

Includes:
CommandConcern
Included in:
Chat
Defined in:
lib/ollama_chat/commands.rb

Overview

Namespace for all available slash commands within the Ollama Chat application.

This module acts as a central repository where various functional commands are declared using the DSL provided by CommandConcern. Each command definition includes a unique name, a triggering regular expression, and a help string for documentation.

The commands are categorized into several areas:

  • Clipboard management (/copy, /paste)
  • Application settings (/config, /document policy, /toggle)
  • Model & System Prompt configuration (/model, /system, /think)
  • Tooling support (/tools)
  • Session management (/session)
  • Conversation history and manipulation (/list, /last, /drop, /clear, /regenerate)
  • RAG collection management (/collection)
  • Persona & Character roleplay (/persona, /character)
  • Input/Output operations (/compose, /web, /input, /pipe, /vim, /output)
  • System actions and info (/reconnect, /quit, /info, /help)

Instance Method Summary collapse

Instance Method Details

#collectionObject

Collection



651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
# File 'lib/ollama_chat/commands.rb', line 651

command(
  name: :collection,
  regexp: %r(^/collection(?:\s+(change|clear|list|rename|update(?: all)?|new|edit|delete))?$),
  complete: [ 'collection', %w[ change clear list rename update update\ all new edit delete ] ],
  optional: true,
  help: "    \u{1F4DA} Manage RAG collections:\n       - change/clear/list/rename\n       - update: Re-index modified docs\n       - update all: Re-index all collections\n       - new: Interactively create a new collection\n       - edit: Interactively update an existing collection\n       - delete: Permanently remove a collection\n       - (no subcommand): Show stats\n  EOT\n) do |subcommand|\n  case subcommand\n  when 'clear'\n    clear_collection\n  when 'change'\n    choose_collection(collection)\n  when 'list'\n    list_collections\n  when 'rename'\n    rename_collection(collection)\n  when 'update all'\n    results = ''\n    all_collections.pluck(:name).each do |collection|\n      STDOUT.puts \"\u{1F4DD} Updating collection \#{collection.inspect}\u2026 \"\n      results << update_collection(collection) << ?\\n\n      STDOUT.puts \"\u2705 Done.\"\n    end\n    results.full? and next results\n  when 'update'\n    if results = update_collection(collection)\n      disable_content_parsing\n      next results\n    end\n  when 'new'\n    create_collection\n  when 'edit'\n    edit_collection\n  when 'delete'\n    delete_collection\n  when nil\n    collection_stats\n  end\n  :next\nend\n"

#composeObject

Input



825
826
827
828
829
830
831
832
833
# File 'lib/ollama_chat/commands.rb', line 825

command(
  name: :compose,
  regexp: %r(^/compose$),
  help: "    \\u270D\\uFE0F  Compose message in external editor\n  EOT\n) do\n  edit_text.full? or :next\nend\n"

#configObject

Settings



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ollama_chat/commands.rb', line 63

command(
  name: :config,
  regexp: %r(^/config(?:\s+(edit|diff|reload))?$),
  complete: [ 'config', %w[ edit diff reload ] ],
  optional: true,
  help: "    \\u2699\\uFE0F View, edit, diff, or reload configuration\n  EOT\n) do |subcommand|\n  case subcommand\n  when 'edit'\n    edit_config\n  when 'diff'\n    diff_config\n    reload_config\n  when 'reload'\n    reload_config\n  else\n    display_config\n  end\n\n  :next\nend\n"

#copyObject

Clipboard



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ollama_chat/commands.rb', line 27

command(
  name: :copy,
  regexp: %r(^/copy(\s+-e)?\s*$),
  options: '[-e]',
  help: "    \u{1F4CB} Copy the last response to the clipboard.\n       Options: -e to edit before copying.\n  EOT\n) do |opts|\n  opts = go_command('e', opts)\n  copy_to_clipboard(edit: opts[?e])\n  :next\nend\n"

#listObject

Conversation



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/ollama_chat/commands.rb', line 378

command(
  name: :list,
  regexp: %r(^/list((?:\s+(?:-[ts]))*)(?:\s+(\d*))?$),
  options: '[-t|-s|n=1]',
  help: "    \u{1F4DC} List conversation history\n       Options: -t (show thinking), -s (hide)\n  EOT\n) do |opts,number|\n  opts = go_command('ts', opts.to_s)\n  n    = 2 * number.to_i if number\n  think_loud = if opts[?t]\n                 true\n               elsif opts[?s]\n                 false\n               else\n                 self.think_loud.on?\n               end\n  messages.list_conversation(n, think_loud:)\n  :next\nend\n"

#pipeObject

Output



967
968
969
970
971
972
973
974
975
976
977
978
979
# File 'lib/ollama_chat/commands.rb', line 967

command(
  name: :pipe,
  regexp: %r(^/pipe(\s+-e)?\s+([^-].*)$),
  options: 'path',
  help: "    \u{1F50C} Pipe last response to command stdin\n       (-e to edit before piping)\n  EOT\n) do |opts, command|\n  opts = go_command('e', opts)\n  pipe(command, edit: opts[?e])\n  :next\nend\n"

#reconnectObject

Actions



1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
# File 'lib/ollama_chat/commands.rb', line 1014

command(
  name: :reconnect,
  regexp: %r(^/reconnect$),
  help: "    \u{1F50C} Reconnect to Ollama server\n  EOT\n) do\n  STDERR.print green { \"Reconnecting to ollama \#{base_url.to_s.inspect}\u2026\" }\n  connect_ollama\n  STDERR.puts green { \" Done.\" }\n  :next\nend\n"

#sessionObject

Session



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/ollama_chat/commands.rb', line 292

command(
  name: :session,
  regexp: %r(^/session(?:\s+(change|previous|list|new|duplicate|rename|summarize|delete|model options change|model options))?((?:\s+-(?:[sf]|p\s*\w+))*)(?:\s+([^-].*))?$),
  complete: [ 'session', %w[ change previous list new duplicate rename summarize delete model\ options\ change model\ options ] ],
  optional: true,
  options: "[-s|-f|-p profile]\n[name]",
  help: "    \u{1F4AC} Manage sessions:\n       - list/new/delete/rename/duplicate\n       - change [name]/previous\n       - summarize (-s sentence, -f save to file)\n       - model options/change\n  EOT\n) do |subcommand, opts, name|\n  case subcommand\n  when nil\n    info_session\n  when 'list'\n    list_sessions\n  when 'new'\n    set_new_session\n  when 'duplicate'\n    duplicate_session\n  when 'delete'\n    delete_session\n  when 'rename'\n    rename_session\n  when 'summarize'\n    opts = go_command('fs', opts)\n    if opts[?f] and\n      filename = switch_history(:filename) {\n        ask?(prompt: \"\u2753 Enter filename: \")\n      }.full? { Pathname.new(_1) }\n    then\n      if filename.exist? && !confirm?(\n          prompt: \"\u{1F514} File \#{filename.to_s.inspect} already exists, overwrite? (y/n) \",\n          yes: /\\Ay/i\n        )\n      then\n        STDERR.puts \"File not written!\"\n        next :next\n      end\n      summary = summarize_session(pretty: true, sentence: opts[?s]) do |content|\n        infobar.puts kramdown_ansi_parse(content)\n      end\n      if summary.full?\n        filename.write(summary)\n        STDOUT.puts \"File successfully written.\"\n        next :next\n      else\n        STDERR.puts \"Nothing to summarize!\"\n        next :next\n      end\n    end\n    summary = summarize_session(pretty: true, sentence: opts[?s]) do |content|\n      infobar.puts kramdown_ansi_parse(content) << ?\\n\n    end\n    if summary.full?\n      use_pager do |output|\n        output.puts kramdown_ansi_parse(summary)\n      end\n    else\n      STDERR.puts \"Nothing to summarize!\"\n      next :next\n    end\n  when 'change'\n    change_session(name)\n  when 'model options'\n    edit_session_model_options\n  when 'model options change'\n    opts = go_command('p:', opts)\n    if profile = opts[?p] || choose_profile_for_model(@model)\n      copy_model_options_to_session(profile:)\n    end\n  when 'previous'\n    if prev = previous_session\n      change_session(prev.id)\n    else\n      STDOUT.puts \"No previous session defined.\"\n    end\n  end\n  :next\nend\n"