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- 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)’ ).
-
.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>
84 85 86 |
# File 'lib/pwn/ai/agent/result.rb', line 84 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)')
36 37 38 39 40 41 42 43 |
# File 'lib/pwn/ai/agent/result.rb', line 36 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 |
.help ⇒ Object
Display Usage for this Module
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/pwn/ai/agent/result.rb', line 90 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')
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pwn/ai/agent/result.rb', line 50 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 |