File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " @moonshot-ai/agent-core " : patch
3+ " @moonshot-ai/kimi-code " : patch
4+ ---
5+
6+ fix(read): report both MAX_LINES and MAX_BYTES caps when both are hit
7+
8+ Fixes #94
Original file line number Diff line number Diff line change @@ -446,9 +446,11 @@ export class ReadTool implements BuiltinTool<ReadInput> {
446446 parts . push ( `Total lines in file: ${ String ( input . totalLines ) } .` ) ;
447447 if ( input . maxLinesReached ) {
448448 parts . push ( `Max ${ String ( MAX_LINES ) } lines reached.` ) ;
449- } else if ( input . maxBytesReached ) {
449+ }
450+ if ( input . maxBytesReached ) {
450451 parts . push ( `Max ${ String ( MAX_BYTES ) } bytes reached.` ) ;
451- } else if ( lineCount < input . requestedLines ) {
452+ }
453+ if ( ! input . maxLinesReached && ! input . maxBytesReached && lineCount < input . requestedLines ) {
452454 parts . push ( 'End of file reached.' ) ;
453455 }
454456 if ( input . truncatedLineNumbers . length > 0 ) {
Original file line number Diff line number Diff line change @@ -622,6 +622,19 @@ describe('ReadTool', () => {
622622 expect ( result . output ) . not . toContain ( `${ String ( MAX_LINES + 1 ) } \tline ${ String ( MAX_LINES + 1 ) } ` ) ;
623623 } ) ;
624624
625+ it ( 'reports both line and byte caps when both limits are hit' , async ( ) => {
626+ const longLine = 'x' . repeat ( 200 ) ;
627+ const content = Array . from ( { length : MAX_LINES + 1 } , ( ) => longLine ) . join ( '\n' ) ;
628+ const tool = toolWithContent ( content ) ;
629+
630+ const result = await executeTool ( tool , context ( { path : '/tmp/dual-limit.txt' } ) ) ;
631+ const output = toolContentString ( result ) ;
632+
633+ expect ( output ) . toContain ( `Max ${ String ( MAX_LINES ) } lines reached.` ) ;
634+ expect ( output ) . toContain ( `Max ${ String ( MAX_BYTES ) } bytes reached.` ) ;
635+ expect ( output ) . not . toContain ( 'End of file reached.' ) ;
636+ } ) ;
637+
625638 it ( 'tail byte truncation keeps the newest lines closest to EOF' , async ( ) => {
626639 const numLines = Math . floor ( MAX_BYTES / 1001 ) + 20 ;
627640 const content = Array . from ( { length : numLines } , ( _ , i ) => {
You can’t perform that action at this time.
0 commit comments