Module: PWN::AI::Agent::Result
- Defined in:
- lib/pwn/ai/agent/result.rb
Overview
Conditioning applied to every tool result before it re-enters the conversation as a role:'tool' message: hard size cap + credential redaction. Keeps the context window bounded and avoids leaking PWN::Env credentials back into the model.
Constant Summary collapse
- DEFAULT_MAX =
24_000- LOCAL_DEFAULT_MAX =
4_000- REDACT_PATTERNS =
Generic high-confidence credential shapes scrubbed from tool output regardless of PWN::Env contents. Built via concatenation so nothing token-shaped appears as a literal in this source file.
[ Regexp.new(%w[s k - [A-Za-z0-9]{20,}].join), # OpenAI-style Regexp.new(%w[x o x [baprs]-[A-Za-z0-9-]{10,}].join), # Slack Regexp.new(%w[g h [pousr]_[A-Za-z0-9]{36,}].join), # GitHub PAT Regexp.new(%w[A K I A [0-9A-Z]{16}].join), # AWS access key id Regexp.new(%w[A I z a [A-Za-z0-9_-]{35}].join), # Google API key Regexp.new( '-----BEGIN [A-Z ]*PRIVATE KEY-----.*?-----END [A-Z ]*PRIVATE KEY-----', Regexp::MULTILINE ) ].freeze
- SENSITIVE_KEYS =
%i[api_key key pass password psk token secret bearer].freeze
Class Method Summary collapse
-
.authors ⇒ Object
- Author(s)
0day Inc.
-
.condition(opts = {}) ⇒ Object
- Supported Method Parameters
safe = PWN::AI::Agent::Result.condition( content: 'required - String returned by Dispatch.call', entry: 'optional - Registry::Entry (used for max_chars; nil → DEFAULT_MAX)' ).
-
.default_max ⇒ Object
Engine-aware default: ollama keeps history inside a tight num_ctx; a 24k tool dump on every call eats the window before useful work.
-
.help ⇒ Object
Display Usage for this Module.
-
.redact(opts = {}) ⇒ Object
- Supported Method Parameters
safe = PWN::AI::Agent::Result.redact( content: 'required - String to scrub of credential-shaped substrings' ).
Class Method Details
.authors ⇒ Object
- Author(s)
0day Inc. support@0dayinc.com
101 102 103 |
# File 'lib/pwn/ai/agent/result.rb', line 101 public_class_method def self. "AUTHOR(S):\n 0day Inc. <support@0dayinc.com>\n" end |
.condition(opts = {}) ⇒ Object
- Supported Method Parameters
safe = PWN::AI::Agent::Result.condition( content: 'required - String returned by Dispatch.call', entry: 'optional - Registry::Entry (used for max_chars; nil → DEFAULT_MAX)' )
37 38 39 40 41 42 43 44 |
# File 'lib/pwn/ai/agent/result.rb', line 37 public_class_method def self.condition(opts = {}) content = opts[:content].to_s entry = opts[:entry] cap = entry ? entry.max_chars : default_max content = "#{content[0, cap]}…[truncated #{opts[:content].to_s.length - cap} chars]" if content.length > cap redact(content: content) end |
.default_max ⇒ Object
Engine-aware default: ollama keeps history inside a tight num_ctx; a 24k tool dump on every call eats the window before useful work. Override via PWN::Env[:ollama][:result_max].
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pwn/ai/agent/result.rb', line 49 public_class_method def self.default_max eng = (PWN::Env.dig(:ai, :active) if defined?(PWN::Env)).to_s.downcase if eng == 'ollama' v = (PWN::Env.dig(:ai, :ollama, :result_max) if defined?(PWN::Env)) return v.to_i if v.to_i.positive? return LOCAL_DEFAULT_MAX end DEFAULT_MAX rescue StandardError DEFAULT_MAX end |
.help ⇒ Object
Display Usage for this Module
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/pwn/ai/agent/result.rb', line 107 public_class_method def self.help puts <<~USAGE USAGE: safe = PWN::AI::Agent::Result.condition( content: json_string, entry: PWN::AI::Agent::Registry.lookup(name: 'shell') ) safe = PWN::AI::Agent::Result.redact(content: string) #{self}.authors USAGE end |
.redact(opts = {}) ⇒ Object
- Supported Method Parameters
safe = PWN::AI::Agent::Result.redact( content: 'required - String to scrub of credential-shaped substrings' )
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pwn/ai/agent/result.rb', line 67 public_class_method def self.redact(opts = {}) out = opts[:content].to_s.dup env_credential_values.each do |val| next if val.to_s.length < 6 out = out.gsub(val.to_s, '<<<REDACTED>>>') end REDACT_PATTERNS.each { |re| out = out.gsub(re, '<<<REDACTED>>>') } out end |