File tree Expand file tree Collapse file tree
src/agents/sessions/tools Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -154,12 +154,12 @@ describe("edit tool", () => {
154154 expect ( message ) . not . toContain ( targetTail ) ;
155155 } ) ;
156156
157- it ( "bounds many-line mismatch candidate diagnostics before collecting lines" , async ( ) => {
157+ it ( "bounds CRLF mismatch candidate diagnostics before collecting lines" , async ( ) => {
158158 const scannedCandidate = "inside-scan-candidate" ;
159159 const unscannedCandidate = "outside-scan-candidate" ;
160160 const filler = Array . from ( { length : 999 } , ( _ , index ) => `filler ${ index + 1 } ` ) ;
161161 const filePath = await createTempFile (
162- `${ filler . join ( "\n" ) } \nalpha ${ scannedCandidate } \nalpha ${ unscannedCandidate } \n` ,
162+ `${ filler . join ( "\r\ n" ) } \r\ nalpha ${ scannedCandidate } \r\ nalpha ${ unscannedCandidate } \r \n` ,
163163 ) ;
164164 const tool = createEditTool ( tmpDir ) ;
165165
Original file line number Diff line number Diff line change @@ -214,17 +214,39 @@ function splitBoundedDiagnosticLines(text: string): string[] {
214214}
215215
216216function collectBoundedDiagnosticLines ( text : string ) : string [ ] {
217- const normalized = normalizeToLF ( text ) ;
218217 const lines : string [ ] = [ ] ;
219- let start = 0 ;
220- while ( lines . length < EDIT_MISMATCH_SCAN_LINE_LIMIT ) {
221- const end = normalized . indexOf ( "\n" , start ) ;
222- const rawLine = end === - 1 ? normalized . slice ( start ) : normalized . slice ( start , end ) ;
223- lines . push ( truncateDiagnosticLine ( rawLine ) ) ;
224- if ( end === - 1 ) {
225- break ;
218+ let line = "" ;
219+ let lineTruncated = false ;
220+
221+ const pushLine = ( ) => {
222+ lines . push ( lineTruncated ? `${ line } ... (line truncated)` : line ) ;
223+ line = "" ;
224+ lineTruncated = false ;
225+ } ;
226+
227+ for (
228+ let index = 0 ;
229+ index < text . length && lines . length < EDIT_MISMATCH_SCAN_LINE_LIMIT ;
230+ index ++
231+ ) {
232+ const char = text [ index ] ;
233+ if ( char === "\r" || char === "\n" ) {
234+ pushLine ( ) ;
235+ if ( char === "\r" && text [ index + 1 ] === "\n" ) {
236+ index ++ ;
237+ }
238+ continue ;
226239 }
227- start = end + 1 ;
240+
241+ if ( line . length < EDIT_MISMATCH_LINE_TEXT_LIMIT ) {
242+ line += char ;
243+ } else {
244+ lineTruncated = true ;
245+ }
246+ }
247+
248+ if ( lines . length < EDIT_MISMATCH_SCAN_LINE_LIMIT ) {
249+ pushLine ( ) ;
228250 }
229251 if ( lines . length > 1 && lines [ lines . length - 1 ] === "" ) {
230252 lines . pop ( ) ;
You can’t perform that action at this time.
0 commit comments