shell echo fix, faster startup
frdel committed
Aug 1, 2025 at 15:38 UTC
d0a0bf67b8bfcd0942fdb2082921411109b10974
2 files changed
+36
-30
python/helpers/shell_ssh.py
+33
-28
@@ -44,6 +44,8 @@ class SSHInteractiveSession:
44
self.shell = self.client.invoke_shell(width=100, height=50)
45
# self.shell.send(f'PS1="{SSHInteractiveSession.ps1_label}"'.encode())
46
# return
47
+ self.shell.send("stty -echo\n".encode()) # disable shell echo
48
+
49
while True: # wait for end of initial output
50
full, part = await self.read_output()
51
if full and not part:
@@ -100,32 +102,32 @@ class SSHInteractiveSession:
102
# data = self.shell.recv(1024)
103
data = self.receive_bytes()
104
103
- # Trim own command from output
104
- if (
105
- self.last_command
106
- and len(self.last_command) > self.trimmed_command_length
107
- ):
108
- command_to_trim = self.last_command[self.trimmed_command_length :]
109
- data_to_trim = leftover + data
110
-
111
- trim_com, trim_out = calculate_valid_match_lengths(
112
- command_to_trim,
113
- data_to_trim,
114
- deviation_threshold=8,
115
- deviation_reset=2,
116
- ignore_patterns=[
117
- rb"\x1b\[\?\d{4}[a-zA-Z](?:> )?", # ANSI escape sequences
118
- rb"\r", # Carriage return
119
- rb">\s", # Greater-than symbol
120
- ],
121
- debug=False,
122
- )
123
-
124
- leftover = b""
125
- if trim_com > 0 and trim_out > 0:
126
- data = data_to_trim[trim_out:]
127
- leftover = data
128
- self.trimmed_command_length += trim_com
105
+ # # Trim own command from output
106
+ # if (
107
+ # self.last_command
108
+ # and len(self.last_command) > self.trimmed_command_length
109
+ # ):
110
+ # command_to_trim = self.last_command[self.trimmed_command_length :]
111
+ # data_to_trim = leftover + data
112
+
113
+ # trim_com, trim_out = calculate_valid_match_lengths(
114
+ # command_to_trim,
115
+ # data_to_trim,
116
+ # deviation_threshold=8,
117
+ # deviation_reset=2,
118
+ # ignore_patterns=[
119
+ # rb"\x1b\[\?\d{4}[a-zA-Z](?:> )?", # ANSI escape sequences
120
+ # rb"\r", # Carriage return
121
+ # rb">\s", # Greater-than symbol
122
+ # ],
123
+ # debug=False,
124
+ # )
125
+
126
+ # leftover = b""
127
+ # if trim_com > 0 and trim_out > 0:
128
+ # data = data_to_trim[trim_out:]
129
+ # leftover = data
130
+ # self.trimmed_command_length += trim_com
131
132
partial_output += data
133
self.full_output += data
@@ -196,11 +198,14 @@ class SSHInteractiveSession:
198
# remove null bytes
199
cleaned = cleaned.replace("\x00", "")
200
201
+ # remove ipython \r\r\n> sequences from the start
202
+ cleaned = re.sub(r'^[ \r]*(?:\r*\n>[ \r]*)*', '', cleaned)
203
+
204
# Replace '\r\n' with '\n'
205
cleaned = cleaned.replace("\r\n", "\n")
206
202
- # remove leading \r
203
- cleaned = cleaned.lstrip("\r")
207
+ # remove leading \r and spaces
208
+ cleaned = cleaned.lstrip("\r ")
209
210
# Split the string by newline characters to process each segment separately
211
lines = cleaned.split("\n")
run_ui.py
+3
-2
@@ -245,14 +245,15 @@ def run():
245
def init_a0():
246
# initialize contexts and MCP
247
init_chats = initialize.initialize_chats()
248
+ # only wait for init chats, otherwise they would seem to disappear for a while on restart
249
+ init_chats.result_sync()
250
+
251
initialize.initialize_mcp()
252
# start job loop
253
initialize.initialize_job_loop()
254
# preload
255
initialize.initialize_preload()
256
254
- # only wait for init chats, otherwise they would seem to dissapear for a while on restart
255
- init_chats.result_sync()
257
258
259
# run the internal server