-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcodebuff-wrapper.sh
More file actions
executable file
·134 lines (116 loc) · 3.49 KB
/
codebuff-wrapper.sh
File metadata and controls
executable file
·134 lines (116 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/expect -f
# Version 1.0.1 - Testing build update
# Log to stderr
proc log {msg} {
puts stderr "\[WRAPPER\] \[$msg\]"
}
proc debug {msg} {
puts stderr "\[WRAPPER DEBUG\] \[$msg\]"
}
proc strip_ansi {text} {
# Strip ANSI escape sequences
regsub -all {\x1b\[[0-9;]*[mGJK]} $text {} text
return $text
}
proc write_response {line} {
if {![info exists ::env(PROJECT_PATH)]} {
log "ERROR: PROJECT_PATH environment variable not set"
exit 1
}
set project_path $::env(PROJECT_PATH)
set comm_dir "/workspace/$project_path/.codebuff/comm"
debug "Writing response to $comm_dir/responses.txt: $line"
if [catch {
set f [open "$comm_dir/responses.txt" "a"]
puts $f $line
close $f
debug "Successfully wrote response"
} err] {
log "Error writing response: $err"
}
}
log "Starting codebuff wrapper..."
# Verify required environment variables
if {![info exists ::env(PROJECT_PATH)]} {
log "ERROR: PROJECT_PATH environment variable not set"
exit 1
}
if {![info exists ::env(PROJECT_NAME)]} {
log "ERROR: PROJECT_NAME environment variable not set"
exit 1
}
set project_name $::env(PROJECT_NAME)
set project_path $::env(PROJECT_PATH)
debug "Project name: $project_name"
debug "Project path: $project_path"
debug "Comm dir: /workspace/$project_path/.codebuff/comm"
# Always enable debugging
exp_internal 1
log_user 1
# Signal ready before starting codebuff
write_response "CONTAINER READY"
# Start codebuff
spawn codebuff
debug "Spawned codebuff process"
# Monitor messages.txt and send input
set timeout -1
while {1} {
set messages_file "/workspace/$project_path/.codebuff/comm/messages.txt"
debug "Checking messages file: $messages_file"
if {[file exists $messages_file]} {
debug "Found messages.txt file"
# Wait for a modification event
debug "Running inotifywait on $messages_file"
set result [catch {exec inotifywait -q -e modify $messages_file} err]
if {$result != 0} {
debug "inotifywait error: $err"
sleep 0.1
continue
}
debug "Got inotifywait event"
if [catch {
set f [open $messages_file r]
set message [read $f]
close $f
debug "Read message content: '$message'"
if {$message != ""} {
debug "Sending message to codebuff"
send "$message"
sleep 1
send "\r"
debug "Message sent"
# Clear the message file after sending
debug "Clearing message file..."
if [catch {
set f [open $messages_file w]
close $f
debug "Message file cleared"
} err] {
log "Error clearing message file: $err"
}
} else {
debug "Message was empty"
}
} err] {
log "Error processing message: $err"
}
} else {
debug "Messages file does not exist"
}
# Check for output from codebuff
expect {
-re "(.+)\r\n" {
debug "Got output: $expect_out(1,string)"
write_response $expect_out(1,string)
exp_continue
}
"$project_name > " {
debug "Got prompt"
write_response "$project_name > "
}
timeout {
# No output, continue checking messages
}
}
sleep 0.1
}