Class: Harnex::Adapters::Codex
- Inherits:
-
Base
- Object
- Base
- Harnex::Adapters::Codex
show all
- Defined in:
- lib/harnex/adapters/codex.rb
Constant Summary
collapse
- SUBMIT_DELAY_MS =
75
- SUBMIT_DELAY_PER_KB_MS =
50
- SEND_WAIT_SECONDS =
2.0
Constants inherited
from Base
Base::PROMPT_PREFIXES
Instance Attribute Summary
Attributes inherited from Base
#key
Instance Method Summary
collapse
Methods inherited from Base
#build_command, #wait_for_sendable
Constructor Details
#initialize(extra_args = []) ⇒ Codex
Returns a new instance of Codex.
8
9
10
|
# File 'lib/harnex/adapters/codex.rb', line 8
def initialize( = [])
super("codex", )
end
|
Instance Method Details
#base_command ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/harnex/adapters/codex.rb', line 12
def base_command
[
"codex",
"--dangerously-bypass-approvals-and-sandbox",
"--no-alt-screen"
]
end
|
#build_send_payload(text:, submit:, enter_only:, screen_text:, force: false) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/harnex/adapters/codex.rb', line 69
def build_send_payload(text:, submit:, enter_only:, screen_text:, force: false)
state = input_state(screen_text)
if !force && submit && !enter_only && state[:input_ready] != true
raise ArgumentError, blocked_message(state, enter_only: enter_only)
end
steps = []
unless enter_only
body = text.to_s
steps << { text: body, newline: false } unless body.empty?
end
if submit || enter_only
step = { text: submit_bytes, newline: false }
step[:delay_ms] = submit_delay_ms(text) if steps.any?
steps << step
end
{
steps: steps,
input_state: state,
force: force
}
end
|
#infer_repo_path(argv) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/harnex/adapters/codex.rb', line 20
def infer_repo_path(argv)
index = 0
while index < argv.length
arg = argv[index]
case arg
when "-C", "--cd"
next_value = argv[index + 1]
return next_value if next_value
break
when /\A-C(.+)\z/
return Regexp.last_match(1)
end
index += 1
end
Dir.pwd
end
|
#inject_exit(writer) ⇒ Object
94
95
96
|
# File 'lib/harnex/adapters/codex.rb', line 94
def inject_exit(writer)
super(writer, delay_ms: SUBMIT_DELAY_MS)
end
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/harnex/adapters/codex.rb', line 38
def input_state(screen_text)
lines = recent_lines(screen_text)
return super unless lines.any? { |line| line.include?("OpenAI Codex") || line.include?("gpt-") }
if lines.any? { |line| prompt_line?(line) }
{
state: "prompt",
input_ready: true
}
else
{
state: "session",
input_ready: nil
}
end
end
|
#send_wait_seconds(submit:, enter_only:) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/harnex/adapters/codex.rb', line 55
def send_wait_seconds(submit:, enter_only:)
return 0.0 unless submit
return 0.0 if enter_only
SEND_WAIT_SECONDS
end
|
#wait_for_sendable_state?(state, submit:, enter_only:) ⇒ Boolean
62
63
64
65
66
67
|
# File 'lib/harnex/adapters/codex.rb', line 62
def wait_for_sendable_state?(state, submit:, enter_only:)
return false unless submit
return false if enter_only
state[:input_ready] != true
end
|