Class: EnvironmentProbe

Inherits:
Object
  • Object
show all
Defined in:
lib/environment_probe.rb

Overview

Probes the shell environment and assembles a lightweight metadata block for injection into the system prompt. Gives the agent awareness of its working directory, OS, Git status, and nearby project files — without loading any file content.

Examples:

EnvironmentProbe.to_prompt("/home/user/projects/my-app")
# => "## Environment\n\nOS: Arch Linux (pacman, yay)\n..."

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pwd) ⇒ EnvironmentProbe

Returns a new instance of EnvironmentProbe.

Parameters:

  • pwd (String, nil)

    current working directory



28
29
30
# File 'lib/environment_probe.rb', line 28

def initialize(pwd)
  @pwd = pwd
end

Class Method Details

.to_prompt(pwd) ⇒ String?

Assembles the environment context block for a given working directory.

Parameters:

  • pwd (String, nil)

    current working directory

Returns:

  • (String, nil)

    Markdown-formatted environment block, or nil when pwd is unknown



23
24
25
# File 'lib/environment_probe.rb', line 23

def self.to_prompt(pwd)
  new(pwd).to_prompt
end

Instance Method Details

#to_promptString?

Returns Markdown-formatted environment block.

Returns:

  • (String, nil)

    Markdown-formatted environment block



33
34
35
36
37
38
39
40
# File 'lib/environment_probe.rb', line 33

def to_prompt
  return unless @pwd

  sections = [os_section, working_directory_section, project_files_section].compact
  return if sections.empty?

  "## Environment\n\n#{sections.join("\n\n")}"
end