Module: PWN::Plugins::REPL::AIConsoleCommands

Defined in:
lib/pwn/plugins/repl/ai_console_commands.rb

Overview

Live slash-command parameter completion. Never calls a provider.

Constant Summary collapse

COMMANDS =
%w[
  /back /clear /cron /debug /delegate /help /input /learning /mcp /memory /menu /model /system-role
  /sessions /skills /status /steer /swarm /trace /verbose
].freeze
SWARM =
%w[dashboard help roster status create use spawn retire ask debate broadcast tail steer cancel].freeze

Class Method Summary collapse

Class Method Details

.authors ⇒ Object



34
35
36
# File 'lib/pwn/plugins/repl/ai_console_commands.rb', line 34

public_class_method def self.authors
  'AUTHOR(S): 0day Inc. <[email protected]>'
end

.complete(opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pwn/plugins/repl/ai_console_commands.rb', line 14

public_class_method def self.complete(opts = {})
  line = opts[:line].to_s
  cursor = opts[:cursor].to_i
  tokens = scan(line: line, cursor: cursor)
  current = tokens.find { |token| token[:current] } || tokens.last || { text: '', start: 0, finish: 0 }
  prefix = line.scan(/\X/)[current[:start]...cursor].to_a.join
  values, hint = if prefix.start_with?('PWN')
                   pwn_constants(prefix: prefix)
                 elsif path_token?(prefix: prefix)
                   paths(prefix: prefix)
                 else
                   candidates(tokens: tokens, prefix: prefix, pry: opts[:pry], swarm: opts[:swarm])
                 end
  items = values.map do |value|
    replacement = line_replace(line: line, token: current, value: value)
    { label: value, text: replacement[:text], cursor: replacement[:cursor] }
  end
  { items: items, hint: hint }
end

.help ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pwn/plugins/repl/ai_console_commands.rb', line 38

public_class_method def self.help
  puts "USAGE:
    # Complete the token at a grapheme cursor. Returned text replaces the whole line.
    #{self}.complete(
      line: 'required - current mission text',
      cursor: 'optional - grapheme index, default 0',
      pry: 'optional - Pry instance for Ruby completion',
      swarm: 'optional - controller exposing completion_context'
    )

    # Return module authors.
    #{self}.authors
  "
end