Class: Agent::SessionContext::Summarizers::Codex

Inherits:
Object
  • Object
show all
Includes:
CommandExecutionPolicy
Defined in:
lib/agent/session_context/summarizers/codex.rb

Constant Summary collapse

MAX_OUTPUT_BYTES =
1_048_576

Instance Method Summary collapse

Constructor Details

#initialize(runner: nil, timeout_seconds: Config::DEFAULT_TIMEOUT_SECONDS) ⇒ Codex

Returns a new instance of Codex.



17
18
19
20
21
22
23
24
# File 'lib/agent/session_context/summarizers/codex.rb', line 17

def initialize(runner: nil, timeout_seconds: Config::DEFAULT_TIMEOUT_SECONDS)
  initialize_command_execution_policy(
    runner:,
    timeout_seconds:,
    max_output_bytes: MAX_OUTPUT_BYTES,
    provider_env_keys: PROVIDER_ENV_KEYS
  )
end

Instance Method Details

#call(prompt:, schema:) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/agent/session_context/summarizers/codex.rb', line 30

def call(prompt:, schema:)
  Tempfile.create(["agent-context-codex-schema", ".json"]) do |schema_file|
    schema_file.write(JSON.generate(schema))
    schema_file.flush

    Tempfile.create(["agent-context-codex-output", ".json"]) do |output_file|
      stdout, stderr, status = run_command!(
        prompt:,
        argv: command_argv(schema_path: schema_file.path, output_path: output_file.path)
      )

      fail_command!(stdout:, stderr:, status:) unless status.success?

      payload = read_last_message!(output_file.path, stdout:, stderr:)
      normalize_json!(payload, source: "last message", stdout:, stderr:)
    end
  end
end

#name ⇒ Object



26
27
28
# File 'lib/agent/session_context/summarizers/codex.rb', line 26

def name
  :codex
end