@@ -104,49 +104,37 @@ public static String prepareOutputForModel(String output) {
104104 * Attempts to complete a command using shell integration markers.
105105 *
106106 * @param output terminal output buffer
107- * @param activeCommand command currently being executed
108- * @param skipCompletion whether to skip the next completed command region
109107 * @return the completion check result
110108 */
111- public static CompletionCheckResult tryCompleteWithMarker (StringBuilder output , String activeCommand ,
112- boolean skipCompletion ) {
113- MarkerRange commandFinishMarkerRange = findCommandFinishMarker (output );
109+ public static CompletionCheckResult tryCompleteWithMarker (StringBuilder output ) {
110+ MarkerRange commandFinishMarkerRange = findMarker (output , COMMAND_FINISH_MARKER_PATTERN , 0 );
114111 if (commandFinishMarkerRange == null ) {
115112 // Startup or idle prompts can arrive before a command runs. Keep the visible prompt text, but remove marker
116113 // bytes so later command output cleanup does not have to handle stale prompt boundaries.
117114 removePromptMarkers (output );
118115 return CompletionCheckResult .incomplete ();
119116 }
120117
121- // The command-finished marker is emitted before the next prompt. Wait for prompt end so the returned output keeps
122- // the prompt line, which gives the language model the terminal's current working directory.
118+ // A complete marker command is the command finish marker followed by the next prompt end. Waiting for B keeps the
119+ // prompt line in the returned output , which gives the language model the terminal's current working directory.
123120 MarkerRange promptEndMarkerRange = findMarker (output , PROMPT_END_MARKER_PATTERN , commandFinishMarkerRange .endIndex );
124121 if (promptEndMarkerRange == null ) {
125122 return CompletionCheckResult .incomplete ();
126123 }
127124
128- // Keep command output plus the next prompt, but remove the command-finished marker itself, including exit code .
125+ // Keep terminal output plus the next prompt, but exclude command finish markers .
129126 String completedOutput = output .substring (0 , commandFinishMarkerRange .startIndex )
130127 + output .substring (commandFinishMarkerRange .endIndex , promptEndMarkerRange .endIndex );
131- if (shouldSkipCompletion (completedOutput , activeCommand , skipCompletion )) {
132- // This region belongs to a command that was interrupted by Ctrl+C. Drop it so it cannot complete the next
133- // foreground command that may already be listening on the same terminal output buffer.
134- output .delete (0 , promptEndMarkerRange .endIndex );
135- return CompletionCheckResult .skipped ();
136- }
137- return CompletionCheckResult .completed (cleanCommandOutput (completedOutput , activeCommand ));
128+ return CompletionCheckResult .completed (cleanCommandOutput (completedOutput ));
138129 }
139130
140131 /**
141132 * Attempts to complete a command by detecting a shell prompt.
142133 *
143134 * @param output terminal output buffer
144- * @param activeCommand command currently being executed
145- * @param skipCompletion whether to skip the next completed command region
146135 * @return the completion check result
147136 */
148- public static CompletionCheckResult tryCompleteWithPrompt (StringBuilder output , String activeCommand ,
149- boolean skipCompletion ) {
137+ public static CompletionCheckResult tryCompleteWithPrompt (StringBuilder output ) {
150138 String terminalOutput = output .toString ().trim ();
151139 int lastNewLineIndex = terminalOutput .lastIndexOf ('\n' );
152140 if (lastNewLineIndex <= 0 ) {
@@ -164,11 +152,6 @@ public static CompletionCheckResult tryCompleteWithPrompt(StringBuilder output,
164152 return CompletionCheckResult .incomplete ();
165153 }
166154
167- if (shouldSkipCompletion (terminalOutput , activeCommand , skipCompletion )) {
168- output .setLength (0 );
169- return CompletionCheckResult .skipped ();
170- }
171-
172155 String contentWithoutLastPrompt = terminalOutput .substring (0 , lastNewLineIndex );
173156 int promptStartIndex = contentWithoutLastPrompt .indexOf (lastLine );
174157 if (promptStartIndex == -1 ) {
@@ -183,17 +166,6 @@ public static CompletionCheckResult tryCompleteWithPrompt(StringBuilder output,
183166 return CompletionCheckResult .completed (contentWithoutLastPrompt .substring (promptStartIndex ).trim ());
184167 }
185168
186- private static boolean shouldSkipCompletion (String completedRegion , String activeCommand , boolean skipCompletion ) {
187- if (!skipCompletion ) {
188- return false ;
189- }
190- String normalizedCommand = normalizeLineEndings (activeCommand == null ? "" : activeCommand ).trim ();
191- if (normalizedCommand .isBlank ()) {
192- return true ;
193- }
194- return !normalizeLineEndings (completedRegion ).contains (normalizedCommand );
195- }
196-
197169 private static String removeBracketedPasteMarkers (String output ) {
198170 return output .replace (BRACKETED_PASTE_START , "" ).replace (BRACKETED_PASTE_END , "" );
199171 }
@@ -217,10 +189,6 @@ private static String removeTrailingLineEndings(String value) {
217189 return value .substring (0 , endIndex );
218190 }
219191
220- private static MarkerRange findCommandFinishMarker (StringBuilder output ) {
221- return findMarker (output , COMMAND_FINISH_MARKER_PATTERN , 0 );
222- }
223-
224192 private static MarkerRange findMarker (StringBuilder output , Pattern markerPattern , int startIndex ) {
225193 Matcher matcher = markerPattern .matcher (output );
226194 if (!matcher .find (startIndex )) {
@@ -248,18 +216,10 @@ private static Pattern buildMarkerPattern(String markerKind, boolean includeExit
248216 + exitCodePattern + "(?:\u0007 |\u001B \\ \\ )?" );
249217 }
250218
251- private static String cleanCommandOutput (String output , String activeCommand ) {
219+ private static String cleanCommandOutput (String output ) {
252220 String normalizedOutput = normalizeLineEndings (output );
253221 normalizedOutput = removeShellIntegrationMarkers (normalizedOutput );
254222 normalizedOutput = removeBracketedPasteMarkers (normalizedOutput );
255- String normalizedCommand = normalizeLineEndings (activeCommand == null ? "" : activeCommand ).trim ();
256- if (normalizedCommand .isBlank ()) {
257- return normalizedOutput .trim ();
258- }
259- int commandIndex = normalizedOutput .lastIndexOf (normalizedCommand );
260- if (commandIndex >= 0 ) {
261- normalizedOutput = normalizedOutput .substring (commandIndex + normalizedCommand .length ());
262- }
263223 return normalizedOutput .trim ();
264224 }
265225
@@ -294,10 +254,6 @@ private static CompletionCheckResult incomplete() {
294254 return new CompletionCheckResult (CompletionCheckState .INCOMPLETE , "" );
295255 }
296256
297- private static CompletionCheckResult skipped () {
298- return new CompletionCheckResult (CompletionCheckState .SKIPPED , "" );
299- }
300-
301257 private static CompletionCheckResult completed (String output ) {
302258 return new CompletionCheckResult (CompletionCheckState .COMPLETED , output );
303259 }
@@ -308,7 +264,6 @@ private static CompletionCheckResult completed(String output) {
308264 */
309265 public enum CompletionCheckState {
310266 INCOMPLETE ,
311- SKIPPED ,
312267 COMPLETED
313268 }
314- }
269+ }
0 commit comments